forked from hantsy/spring-r2dbc-sample
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
440 additions
and
11 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
33 changes: 33 additions & 0 deletions
33
connection-factories/src/main/java/com/example/demo/H2ConnectionFactories.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,33 @@ | ||
package com.example.demo; | ||
|
||
import io.r2dbc.h2.H2ConnectionConfiguration; | ||
import io.r2dbc.h2.H2ConnectionFactory; | ||
import io.r2dbc.h2.H2ConnectionOption; | ||
import io.r2dbc.spi.ConnectionFactories; | ||
import io.r2dbc.spi.ConnectionFactory; | ||
|
||
public class H2ConnectionFactories { | ||
static ConnectionFactory fromUrl() { | ||
return ConnectionFactories.get("r2dbc:h2:mem:https:///test?options=DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"); | ||
} | ||
|
||
static ConnectionFactory inMemory() { | ||
// H2ConnectionFactory connectionFactory = new H2ConnectionFactory(H2ConnectionConfiguration.builder() | ||
// .inMemory("...") | ||
// .property(H2ConnectionOption.DB_CLOSE_DELAY, "-1") | ||
// .build()); | ||
return H2ConnectionFactory.inMemory("test"); | ||
} | ||
|
||
static ConnectionFactory file() { | ||
return new H2ConnectionFactory( | ||
H2ConnectionConfiguration.builder() | ||
//.inMemory("testdb") | ||
.file("./testdb") | ||
.username("sa") | ||
.password("password") | ||
.build() | ||
); | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
connection-factories/src/main/java/com/example/demo/PgConnectionFactories.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,41 @@ | ||
package com.example.demo; | ||
|
||
import io.r2dbc.postgresql.PostgresqlConnectionConfiguration; | ||
import io.r2dbc.postgresql.PostgresqlConnectionFactory; | ||
import io.r2dbc.postgresql.PostgresqlConnectionFactoryProvider; | ||
import io.r2dbc.spi.ConnectionFactories; | ||
import io.r2dbc.spi.ConnectionFactory; | ||
import io.r2dbc.spi.ConnectionFactoryOptions; | ||
|
||
import java.util.Map; | ||
|
||
public class PgConnectionFactories { | ||
|
||
static ConnectionFactory fromUrl() { | ||
return ConnectionFactories.get("r2dbc:postgres:https://user:password@localhost/test"); | ||
} | ||
|
||
static ConnectionFactory fromOptions() { | ||
var options = ConnectionFactoryOptions.builder() | ||
.option(ConnectionFactoryOptions.HOST, "localhost") | ||
.option(ConnectionFactoryOptions.DATABASE, "test") | ||
.option(ConnectionFactoryOptions.USER, "user") | ||
.option(ConnectionFactoryOptions.PASSWORD, "password") | ||
.option(ConnectionFactoryOptions.DRIVER, "postgresql") | ||
//.option(PostgresqlConnectionFactoryProvider.OPTIONS, Map.of("lock_timeout", "30s")) | ||
.build(); | ||
return ConnectionFactories.get(options); | ||
} | ||
|
||
static ConnectionFactory pgConnectionFactory() { | ||
return new PostgresqlConnectionFactory( | ||
PostgresqlConnectionConfiguration.builder() | ||
.host("localhost") | ||
.database("test") | ||
.username("user") | ||
.password("password") | ||
//.codecRegistrar(EnumCodec.builder().withEnum("post_status", Post.Status.class).build()) | ||
.build() | ||
); | ||
} | ||
} |
Oops, something went wrong.