use of org.simpleflatmapper.jdbc.impl.DatabaseMeta in project SimpleFlatMapper by arnaudroger.
the class MysqlCrudTest method testSplitBatch.
@Test
public void testSplitBatch() throws SQLException {
Connection connection = mock(Connection.class);
PreparedStatement ps = mock(PreparedStatement.class);
PreparedStatement ps2 = mock(PreparedStatement.class);
when(connection.prepareStatement("INSERT INTO TEST(id) VALUES(?), (?), (?), (?), (?), (?), (?), (?), (?), (?)")).thenReturn(ps);
when(connection.prepareStatement("INSERT INTO TEST(id) VALUES(?), (?), (?), (?), (?)")).thenReturn(ps2);
when(ps.executeUpdate()).thenThrow(getPacketTooBigException());
Crud<DbObject, Long> objectCrud = CrudFactory.<DbObject, Long>newInstance(ReflectionService.newInstance().getClassMeta(DbObject.class), ReflectionService.newInstance().getClassMeta(Long.class), new CrudMeta(new DatabaseMeta("MySQL", 5, 5), "TEST", new ColumnMeta[] { new ColumnMeta("id", Types.INTEGER, true, null) }), JdbcMapperFactory.newInstance());
final int batchsize = 10;
final List<DbObject> values = new ArrayList<DbObject>();
for (int i = 0; i < batchsize; i++) {
values.add(DbObject.newInstance());
}
objectCrud.create(connection, values);
for (int i = 0; i < batchsize; i++) {
verify(ps).setLong(i + 1, values.get(i).getId());
}
verify(ps).executeUpdate();
for (int i = 0; i < batchsize / 2; i++) {
ArgumentCaptor<Long> captor = ArgumentCaptor.forClass(Long.class);
verify(ps2, times(2)).setLong(eq(i + 1), captor.capture());
final List<Long> allValues = captor.getAllValues();
assertEquals(values.get(i).getId(), allValues.get(0).longValue());
assertEquals(values.get(i + batchsize / 2).getId(), allValues.get(1).longValue());
}
verify(ps).executeUpdate();
}
use of org.simpleflatmapper.jdbc.impl.DatabaseMeta in project SimpleFlatMapper by arnaudroger.
the class DatabaseMetaTest method isVersionMet.
@Test
public void isVersionMet() throws Exception {
DatabaseMeta databaseMeta = new DatabaseMeta("foo", 3, 4);
assertTrue(databaseMeta.isVersionMet(2, 9));
assertTrue(databaseMeta.isVersionMet(3, 3));
assertTrue(databaseMeta.isVersionMet(3, 4));
assertFalse(databaseMeta.isVersionMet(3, 5));
assertFalse(databaseMeta.isVersionMet(4, 1));
}
use of org.simpleflatmapper.jdbc.impl.DatabaseMeta in project SimpleFlatMapper by arnaudroger.
the class MysqlCrudTest method testBatch.
@Test
public void testBatch() throws SQLException {
Connection connection = mock(Connection.class);
PreparedStatement ps = mock(PreparedStatement.class);
when(connection.prepareStatement("INSERT INTO TEST(id) VALUES(?), (?), (?), (?), (?), (?), (?), (?), (?), (?)")).thenReturn(ps);
Crud<DbObject, Long> objectCrud = CrudFactory.<DbObject, Long>newInstance(ReflectionService.newInstance().getClassMeta(DbObject.class), ReflectionService.newInstance().getClassMeta(Long.class), new CrudMeta(new DatabaseMeta("MySQL", 5, 5), "TEST", new ColumnMeta[] { new ColumnMeta("id", Types.INTEGER, true, null) }), JdbcMapperFactory.newInstance());
final List<DbObject> values = new ArrayList<DbObject>();
for (int i = 0; i < 10; i++) {
values.add(DbObject.newInstance());
}
objectCrud.create(connection, values);
for (int i = 0; i < 10; i++) {
verify(ps).setLong(i + 1, values.get(i).getId());
}
verify(ps).executeUpdate();
}
Aggregations