-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref #376 - fixing error where sql2o might throw an exception if autoC…
…ommit is set to false on data source level
- Loading branch information
Showing
6 changed files
with
63 additions
and
8 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
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
41 changes: 41 additions & 0 deletions
41
extensions/postgres/src/test/java/org/sql2o/extensions/postgres/DataSourceTest.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 org.sql2o.extensions.postgres; | ||
|
||
import com.zaxxer.hikari.HikariConfig; | ||
import com.zaxxer.hikari.HikariDataSource; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.sql2o.Sql2o; | ||
|
||
public class DataSourceTest { | ||
|
||
private Sql2o sql2o; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
var dsConfig = new HikariConfig(); | ||
dsConfig.setDataSourceClassName("org.postgresql.ds.PGSimpleDataSource"); | ||
dsConfig.addDataSourceProperty("serverName", "localhost"); | ||
dsConfig.addDataSourceProperty("portNumber", 15432); | ||
dsConfig.addDataSourceProperty("databaseName", "postgres"); | ||
dsConfig.addDataSourceProperty("user", "testuser"); | ||
dsConfig.addDataSourceProperty("password", "testpassword"); | ||
dsConfig.setMaximumPoolSize(5); | ||
dsConfig.setSchema("public"); | ||
|
||
// this is important to test, as it make the data source automatically open a connection when a connection is | ||
// created. This might break some functionality of sql2o. | ||
dsConfig.setAutoCommit(false); | ||
dsConfig.setReadOnly(false); | ||
|
||
var ds = new HikariDataSource(dsConfig); | ||
sql2o = new Sql2o(ds); | ||
} | ||
|
||
@Test | ||
void testQueryUsingHikariDataSource() { | ||
try (var con = sql2o.beginTransaction()) { | ||
var result = con.createQuery("SELECT 1").executeScalar(Integer.class); | ||
System.out.println(result); | ||
} | ||
} | ||
} |
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