-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support procedure invocation (#2502)
- Loading branch information
Showing
64 changed files
with
1,948 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
data-hibernate-jpa/src/test/groovy/io/micronaut/data/hibernate/PostgresDbInit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package io.micronaut.data.hibernate; | ||
|
||
import io.micronaut.context.annotation.Context; | ||
import io.micronaut.context.event.BeanCreatedEvent; | ||
import io.micronaut.context.event.BeanCreatedEventListener; | ||
import io.micronaut.jdbc.BasicJdbcConfiguration; | ||
import jakarta.inject.Singleton; | ||
|
||
import java.sql.CallableStatement; | ||
import java.sql.Connection; | ||
import java.sql.DriverManager; | ||
import java.sql.SQLException; | ||
import java.util.Locale; | ||
import java.util.Properties; | ||
|
||
@Context | ||
@Singleton | ||
public class PostgresDbInit implements BeanCreatedEventListener<BasicJdbcConfiguration> { | ||
|
||
@Override | ||
public BasicJdbcConfiguration onCreated(BeanCreatedEvent<BasicJdbcConfiguration> event) { | ||
BasicJdbcConfiguration configuration = event.getBean(); | ||
if (!configuration.getConfiguredDriverClassName().toLowerCase(Locale.ROOT).contains("postgres")) { | ||
return configuration; | ||
} | ||
|
||
try { | ||
// Rancher local testing delay | ||
Thread.sleep(2000); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
final Properties info = new Properties(); | ||
info.put("user", configuration.getUsername()); | ||
info.put("password", configuration.getPassword()); | ||
|
||
try { | ||
try (Connection connection = DriverManager.getConnection(configuration.getUrl(), info)) { | ||
try (CallableStatement st = connection.prepareCall(""" | ||
CREATE PROCEDURE add1(IN myInput integer, OUT myOutput integer) | ||
LANGUAGE plpgsql | ||
AS $$ | ||
BEGIN | ||
myOutput := myInput + 1; | ||
END; | ||
$$; | ||
""")) { | ||
st.execute(); | ||
} catch (SQLException e) { | ||
e.printStackTrace(); | ||
// Ignore if already exists | ||
} | ||
|
||
} | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
return configuration; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
data-hibernate-jpa/src/test/java/io/micronaut/data/hibernate/AnimalRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.micronaut.data.hibernate; | ||
|
||
import io.micronaut.data.annotation.Repository; | ||
import io.micronaut.data.annotation.sql.Procedure; | ||
import io.micronaut.data.hibernate.entities.Animal; | ||
import io.micronaut.data.jpa.repository.JpaRepository; | ||
|
||
@Repository | ||
public interface AnimalRepository extends JpaRepository<Animal, Long> { | ||
|
||
@Procedure(named = "myAdd1Named") | ||
int add1Named(int myInput); | ||
|
||
@Procedure(named = "myAdd1Indexed") | ||
int add1Indexed(int myInput); | ||
|
||
@Procedure | ||
int add1(int myInput); | ||
|
||
@Procedure("add1") | ||
int add1Alias(int myInput); | ||
|
||
} |
Oops, something went wrong.