use of org.seasar.doma.internal.jdbc.mock.MockConnection in project doma by domaframework.
the class BuiltinTableIdGeneratorTest method test.
@Test
public void test() {
MockConfig config = new MockConfig();
config.setDialect(new PostgresDialect());
MockConnection connection = new MockConnection();
MockConnection connection2 = new MockConnection();
MockResultSet resultSet2 = connection2.preparedStatement.resultSet;
resultSet2.rows.add(new RowData(11L));
final LinkedList<MockConnection> connections = new LinkedList<>();
connections.add(connection);
connections.add(connection2);
config.dataSource = new MockDataSource() {
@Override
public Connection getConnection() {
return connections.pop();
}
};
BuiltinTableIdGenerator idGenerator = new BuiltinTableIdGenerator();
idGenerator.setQualifiedTableName("aaa");
idGenerator.setPkColumnName("PK");
idGenerator.setPkColumnValue("EMP_ID");
idGenerator.setValueColumnName("VALUE");
idGenerator.setInitialValue(1);
idGenerator.setAllocationSize(1);
idGenerator.initialize();
IdGenerationConfig idGenerationConfig = new IdGenerationConfig(config, _IdGeneratedEmp.getSingletonInternal());
Long value = idGenerator.generatePreInsert(idGenerationConfig);
assertEquals(new Long(10), value);
assertEquals("update aaa set VALUE = VALUE + ? where PK = ?", connection.preparedStatement.sql);
assertEquals(2, connection.preparedStatement.bindValues.size());
assertEquals("select VALUE from aaa where PK = ?", connection2.preparedStatement.sql);
assertEquals(1, connection2.preparedStatement.bindValues.size());
}
use of org.seasar.doma.internal.jdbc.mock.MockConnection in project doma by domaframework.
the class KeepAliveLocalTransactionTest method testBegin_failedToSetTransactionIsolation.
@Test
public void testBegin_failedToSetTransactionIsolation() {
final SQLException exception = new SQLException();
MockConnection connection = new MockConnection() {
@Override
public void setTransactionIsolation(int level) throws SQLException {
throw exception;
}
};
LocalTransactionDataSource dataSource = new LocalTransactionDataSource(new MockDataSource(connection));
LocalTransaction transaction = dataSource.getKeepAliveLocalTransaction(jdbcLogger);
try {
transaction.begin(TransactionIsolationLevel.READ_COMMITTED);
dataSource.getConnection();
fail();
} catch (JdbcException expected) {
System.out.println(expected.getMessage());
assertEquals(exception, expected.getCause());
}
}
use of org.seasar.doma.internal.jdbc.mock.MockConnection in project doma by domaframework.
the class LocalTransactionConnectionTest method testIsWrapperFor.
@Test
public void testIsWrapperFor() throws Exception {
try (Connection connection = new LocalTransactionConnection(new MockConnection(), Connection.TRANSACTION_READ_COMMITTED, true)) {
assertTrue(connection.isWrapperFor(LocalTransactionConnection.class));
assertTrue(connection.isWrapperFor(MockConnection.class));
assertFalse(connection.isWrapperFor(Runnable.class));
}
}
use of org.seasar.doma.internal.jdbc.mock.MockConnection in project doma by domaframework.
the class LocalTransactionConnectionTest method testUnwrap.
@Test
public void testUnwrap() throws Exception {
try (Connection connection = new LocalTransactionConnection(new MockConnection(), Connection.TRANSACTION_READ_COMMITTED, true)) {
assertNotNull(connection.unwrap(LocalTransactionConnection.class));
assertNotNull(connection.unwrap(LocalTransactionConnection.class));
try {
connection.unwrap(Runnable.class);
fail();
} catch (SQLException ignored) {
}
}
}
use of org.seasar.doma.internal.jdbc.mock.MockConnection in project doma by domaframework.
the class LocalTransactionTest method testBegin_failedToSetTransactionIsolation.
@Test
public void testBegin_failedToSetTransactionIsolation() {
final SQLException exception = new SQLException();
MockConnection connection = new MockConnection() {
@Override
public void setTransactionIsolation(int level) throws SQLException {
throw exception;
}
};
LocalTransactionDataSource dataSource = new LocalTransactionDataSource(new MockDataSource(connection));
LocalTransaction transaction = dataSource.getLocalTransaction(jdbcLogger);
try {
transaction.begin(TransactionIsolationLevel.READ_COMMITTED);
dataSource.getConnection();
fail();
} catch (JdbcException expected) {
System.out.println(expected.getMessage());
assertEquals(exception, expected.getCause());
}
}
Aggregations