public <T, K> CrudDSL<T, K> crud(final Class<T> target, final Class<K> keyTarget) { return crud((Type)target, (Type)keyTarget); }
public <T, K> CrudDSL<T, K> crud(final Class<T> target, final Class<K> keyTarget) { return crud((Type)target, (Type)keyTarget); }
@Override public Crud<T, K> doInConnection(Connection connection) throws SQLException, DataAccessException { return factory.<T, K>crud(target, keyTarget).table(connection, table); } });
@Override public Crud<T, K> doInConnection(Connection connection) throws SQLException, DataAccessException { return factory.<T, K>crud(target, keyTarget).to(connection); } });
public JdbcTemplateCrud<T, K> lazilyTo(JdbcOperations jdbcOperations) { final JdbcMapperFactory factory = JdbcMapperFactory.newInstance(jdbcTemplateMapperFactory); Crud<T, K> crud = factory.<T, K>crud(target, keyTarget).crud(); return new JdbcTemplateCrud<T, K>(jdbcOperations, crud); } }
public JdbcTemplateCrud<T, K> lazilyTo(JdbcOperations jdbcOperations, final String table) { final JdbcMapperFactory factory = JdbcMapperFactory.newInstance(jdbcTemplateMapperFactory); Crud<T, K> crud = factory.<T, K>crud(target, keyTarget).table(table); return new JdbcTemplateCrud<T, K>(jdbcOperations, crud); }
public <T, K> CrudDSL<T, K> crud(final Type target, final Type keyTarget) { return crud(this.<T>getClassMeta(target), this.<K>getClassMeta(TypeHelper.toBoxedClass(keyTarget))); }
public <T, K> CrudDSL<T, K> crud(final Type target, final Type keyTarget) { return crud(this.<T>getClassMeta(target), this.<K>getClassMeta(TypeHelper.toBoxedClass(keyTarget))); }
@Test public void testFailOnNoPrimaryKey() throws SQLException { try { JdbcMapperFactory.newInstance().crud(MyObject.class, long.class).table(connection, "CRUDNOKEY"); fail(); } catch (IllegalArgumentException e) { System.out.println("e = " + e); } } @Test
public static void main(String[] args) throws SQLException { Connection connection = MysqlDbHelper.objectDb(); Crud<DbObject, Long> crud = JdbcMapperFactory .newInstance() .crud(DbObject.class, Long.class) .table(connection, "TEST_DB_OBJECT"); connection.createStatement().execute("TRUNCATE TABLE TEST_DB_OBJECT"); List<DbObject> objects = new ArrayList<DbObject>(10000); for(int i = 0; i < 65001; i++) { DbObject e = DbObject.newInstance(); e.setId(i + 1); objects.add(e); } crud.create(connection, objects); }
@Test public void testDbObjectLazyCrud() throws SQLException { Connection connection = DbHelper.getDbConnection(targetDB); if (connection == null) { System.err.println("Db " + targetDB + " not available"); return; } try { Crud<DbObject, Long> objectCrud = JdbcMapperFactory.newInstance().<DbObject, Long>crud(DbObject.class, Long.class).table("TEST_DB_OBJECT"); checkCrudDbObject(connection, objectCrud, DbObject.newInstance()); } finally { connection.close(); } }
@Test public void testDbObjectCrud() throws SQLException { Connection connection = DbHelper.getDbConnection(targetDB); if (connection == null) { System.err.println("Db " + targetDB + " not available"); return; } try { Crud<DbObject, Long> objectCrud = JdbcMapperFactory.newInstance().<DbObject, Long>crud(DbObject.class, Long.class).table(connection, "TEST_DB_OBJECT"); checkCrudDbObject(connection, objectCrud, DbObject.newInstance()); } finally { connection.close(); } }
@Test public void testDbObjectLazyCrudTable() throws SQLException { Connection connection = DbHelper.getDbConnection(targetDB); if (connection == null) { System.err.println("Db " + targetDB + " not available"); return; } try { Crud<DbObjectTable, Long> objectCrud = JdbcMapperFactory.newInstance().<DbObjectTable, Long>crud(DbObjectTable.class, Long.class).crud(); checkCrudDbObject(connection, objectCrud, DbObject.newInstance(new DbObjectTable())); } finally { connection.close(); } }
@Test public void testDbObjectCrudTable() throws SQLException { Connection connection = DbHelper.getDbConnection(targetDB); if (connection == null) { System.err.println("Db " + targetDB + " not available"); return; } try { Crud<DbObjectTable, Long> objectCrud = JdbcMapperFactory.newInstance().<DbObjectTable, Long>crud(DbObjectTable.class, Long.class).to(connection); checkCrudDbObject(connection, objectCrud, DbObject.newInstance(new DbObjectTable())); } finally { connection.close(); } }
@Test public void testDbObjectCrudTestDbObject() throws SQLException { Connection connection = DbHelper.getDbConnection(targetDB); if (connection == null) { System.err.println("Db " + targetDB + " not available"); return; } try { Crud<TestDbObject, Long> objectCrud = JdbcMapperFactory.newInstance().<TestDbObject, Long>crud(TestDbObject.class, Long.class).to(connection); checkCrudDbObject(connection, objectCrud, DbObject.newInstance(new TestDbObject())); } finally { connection.close(); } }
@Test public void testUpsertHsqlBatch() throws Exception { testDefaultCrudCreateOrUpdate(DbHelper.getDbConnection(DbHelper.TargetDB.HSQLDB), JdbcMapperFactory.newInstance().crud(DbObject.class, Long.class).table(DbHelper.getDbConnection(DbHelper.TargetDB.HSQLDB), "TEST_DB_OBJECT")); testDefaultCrudCreateOrUpdate(DbHelper.getDbConnection(DbHelper.TargetDB.HSQLDB), JdbcMapperFactory.newInstance().crud(DbObject.class, Long.class).table("TEST_DB_OBJECT")); testConnectedCrudCreateOrUpdate(JdbcMapperFactory.newInstance().crud(DbObject.class, Long.class).table(DbHelper.getHsqlDataSource(), "TEST_DB_OBJECT")); }
@Test public void testDbObjectCrud() throws Exception { DataSource dataSource = DbHelper.getHsqlDataSource(); ConnectedCrud<DbObject, Long> objectCrud = JdbcMapperFactory.newInstance().<DbObject, Long>crud(DbObject.class, Long.class).table(dataSource, "TEST_DB_OBJECT"); checkCrudDbObject(objectCrud, DbObject.newInstance()); Connection connection = dataSource.getConnection(); try { CrudTest.checkCrudDbObject(connection, objectCrud.crud(), DbObject.newInstance()); } finally { connection.close(); } }
@Test public void testDbObjectCrudTable() throws Exception { DataSource dataSource = DbHelper.getHsqlDataSource(); ConnectedCrud<CrudTest.DbObjectTable, Long> objectCrud = JdbcMapperFactory.newInstance().<CrudTest.DbObjectTable, Long>crud(CrudTest.DbObjectTable.class, Long.class).to(dataSource); checkCrudDbObject(objectCrud, DbObject.newInstance(new CrudTest.DbObjectTable())); Connection connection = dataSource.getConnection(); try { CrudTest.checkCrudDbObject(connection, objectCrud.crud(), DbObject.newInstance(new CrudTest.DbObjectTable())); } finally { connection.close(); } }
@Test public void testWithManualKey() throws SQLException { Crud<MyObject, Long> table = JdbcMapperFactory .newInstance() .addKeys("id") .<MyObject, Long>crud(MyObject.class, Long.class) .table(connection, "CRUDNOKEY"); assertEquals(new MyObject(1l, "name"), table.read(connection, 1l)); }
@Test public void testUpsert() throws SQLException { Connection connection = DbHelper.getDbConnection(DbHelper.TargetDB.MYSQL); if (connection == null) { System.err.println("Db MySQL not available"); return; } try { Crud<DbObject, Long> objectCrud = JdbcMapperFactory.newInstance().<DbObject, Long>crud(DbObject.class, Long.class).table(connection, "TEST_DB_OBJECT"); final DbObject object = DbObject.newInstance(); objectCrud.createOrUpdate(connection, object); assertEquals(object, objectCrud.read(connection, object.getId())); object.setEmail("Updated Email"); objectCrud.createOrUpdate(connection, object); assertEquals(object, objectCrud.read(connection, object.getId())); } finally { connection.close(); } }