private MappedCreate(Dao<T, ID> dao, TableInfo<T, ID> tableInfo, String statement, FieldType[] argFieldTypes, String queryNextSequenceStmt, int versionFieldTypeIndex) { super(dao, tableInfo, statement, argFieldTypes); this.dataClassName = tableInfo.getDataClass().getSimpleName(); this.queryNextSequenceStmt = queryNextSequenceStmt; this.versionFieldTypeIndex = versionFieldTypeIndex; }
private MappedCreate(TableInfo<T, ID> tableInfo, String statement, FieldType[] argFieldTypes, String queryNextSequenceStmt, int versionFieldTypeIndex) { super(tableInfo, statement, argFieldTypes); this.dataClassName = tableInfo.getDataClass().getSimpleName(); this.queryNextSequenceStmt = queryNextSequenceStmt; this.versionFieldTypeIndex = versionFieldTypeIndex; }
protected BaseMappedStatement(TableInfo<T, ID> tableInfo, String statement, FieldType[] argFieldTypes) { this.tableInfo = tableInfo; this.clazz = tableInfo.getDataClass(); this.idField = tableInfo.getIdField(); this.statement = statement; this.argFieldTypes = argFieldTypes; }
/** * Match up our joined fields so we can throw a nice exception immediately if you can't join with this type. */ private void matchJoinedFieldsByName(JoinInfo joinInfo, String localColumnName, String joinedColumnName, QueryBuilder<?, ?> joinedQueryBuilder) throws SQLException { joinInfo.localField = tableInfo.getFieldTypeByColumnName(localColumnName); if (joinInfo.localField == null) { throw new SQLException("Could not find field in " + tableInfo.getDataClass() + " that has column-name '" + localColumnName + "'"); } joinInfo.remoteField = joinedQueryBuilder.tableInfo.getFieldTypeByColumnName(joinedColumnName); if (joinInfo.remoteField == null) { throw new SQLException("Could not find field in " + joinedQueryBuilder.tableInfo.getDataClass() + " that has column-name '" + joinedColumnName + "'"); } }
/** * Match up our joined fields so we can throw a nice exception immediately if you can't join with this type. */ private void matchJoinedFieldsByName(JoinInfo joinInfo, String localColumnName, String joinedColumnName, QueryBuilder<?, ?> joinedQueryBuilder) throws SQLException { joinInfo.localField = tableInfo.getFieldTypeByColumnName(localColumnName); if (joinInfo.localField == null) { throw new SQLException("Could not find field in " + tableInfo.getDataClass() + " that has column-name '" + localColumnName + "'"); } joinInfo.remoteField = joinedQueryBuilder.tableInfo.getFieldTypeByColumnName(joinedColumnName); if (joinInfo.remoteField == null) { throw new SQLException("Could not find field in " + joinedQueryBuilder.tableInfo.getDataClass() + " that has column-name '" + joinedColumnName + "'"); } }
protected BaseMappedStatement(Dao<T, ID> dao, TableInfo<T, ID> tableInfo, String statement, FieldType[] argFieldTypes) { this.dao = dao; this.connectionSource = dao.getConnectionSource(); this.tableInfo = tableInfo; this.clazz = tableInfo.getDataClass(); this.idField = tableInfo.getIdField(); this.statement = statement; this.argFieldTypes = argFieldTypes; }
public static <T, ID> MappedDelete<T, ID> build(DatabaseType databaseType, TableInfo<T, ID> tableInfo) throws SQLException { FieldType idField = tableInfo.getIdField(); if (idField == null) { throw new SQLException("Cannot delete from " + tableInfo.getDataClass() + " because it doesn't have an id field"); } StringBuilder sb = new StringBuilder(64); appendTableName(databaseType, sb, "DELETE FROM ", tableInfo.getTableName()); appendWhereFieldEq(databaseType, idField, sb, null); return new MappedDelete<T, ID>(tableInfo, sb.toString(), new FieldType[] { idField }); }
public static <T, ID> MappedUpdateId<T, ID> build(DatabaseType databaseType, TableInfo<T, ID> tableInfo) throws SQLException { FieldType idField = tableInfo.getIdField(); if (idField == null) { throw new SQLException("Cannot update-id in " + tableInfo.getDataClass() + " because it doesn't have an id field"); } StringBuilder sb = new StringBuilder(64); appendTableName(databaseType, sb, "UPDATE ", tableInfo.getTableName()); sb.append("SET "); appendFieldColumnName(databaseType, sb, idField, null); sb.append("= ? "); appendWhereFieldEq(databaseType, idField, sb, null); return new MappedUpdateId<T, ID>(tableInfo, sb.toString(), new FieldType[] { idField, idField }); }
/** * Delete all of the objects in the collection. This builds a {@link MappedDeleteCollection} on the fly because the * datas could be variable sized. */ public static <T, ID> int deleteObjects(Dao<T, ID> dao, TableInfo<T, ID> tableInfo, DatabaseConnection databaseConnection, Collection<T> datas, ObjectCache objectCache) throws SQLException { MappedDeleteCollection<T, ID> deleteCollection = MappedDeleteCollection.build(dao, tableInfo, datas.size()); Object[] fieldObjects = new Object[datas.size()]; FieldType idField = tableInfo.getIdField(); int objC = 0; for (T data : datas) { fieldObjects[objC] = idField.extractJavaFieldToSqlArgValue(data); objC++; } return updateRows(databaseConnection, tableInfo.getDataClass(), deleteCollection, fieldObjects, objectCache); }
/** * This is private because the execute is the only method that should be called here. */ private static <T, ID> MappedDeleteCollection<T, ID> build(DatabaseType databaseType, TableInfo<T, ID> tableInfo, int dataSize) throws SQLException { FieldType idField = tableInfo.getIdField(); if (idField == null) { throw new SQLException("Cannot delete " + tableInfo.getDataClass() + " because it doesn't have an id field defined"); } StringBuilder sb = new StringBuilder(128); appendTableName(databaseType, sb, "DELETE FROM ", tableInfo.getTableName()); FieldType[] argFieldTypes = new FieldType[dataSize]; appendWhereIds(databaseType, idField, sb, dataSize, argFieldTypes); return new MappedDeleteCollection<T, ID>(tableInfo, sb.toString(), argFieldTypes); }
/** * Delete all of the objects in the collection. This builds a {@link MappedDeleteCollection} on the fly because the * ids could be variable sized. */ public static <T, ID> int deleteIds(Dao<T, ID> dao, TableInfo<T, ID> tableInfo, DatabaseConnection databaseConnection, Collection<ID> ids, ObjectCache objectCache) throws SQLException { MappedDeleteCollection<T, ID> deleteCollection = MappedDeleteCollection.build(dao, tableInfo, ids.size()); Object[] fieldObjects = new Object[ids.size()]; FieldType idField = tableInfo.getIdField(); int objC = 0; for (ID id : ids) { fieldObjects[objC] = idField.convertJavaFieldToSqlArgValue(id); objC++; } return updateRows(databaseConnection, tableInfo.getDataClass(), deleteCollection, fieldObjects, objectCache); }
/** * Delete all of the objects in the collection. This builds a {@link MappedDeleteCollection} on the fly because the * datas could be variable sized. */ public static <T, ID> int deleteObjects(DatabaseType databaseType, TableInfo<T, ID> tableInfo, DatabaseConnection databaseConnection, Collection<T> datas, ObjectCache objectCache) throws SQLException { MappedDeleteCollection<T, ID> deleteCollection = MappedDeleteCollection.build(databaseType, tableInfo, datas.size()); Object[] fieldObjects = new Object[datas.size()]; FieldType idField = tableInfo.getIdField(); int objC = 0; for (T data : datas) { fieldObjects[objC] = idField.extractJavaFieldToSqlArgValue(data); objC++; } return updateRows(databaseConnection, tableInfo.getDataClass(), deleteCollection, fieldObjects, objectCache); }
public static <T, ID> MappedQueryForFieldEq<T, ID> build(DatabaseType databaseType, TableInfo<T, ID> tableInfo, FieldType idFieldType) throws SQLException { if (idFieldType == null) { idFieldType = tableInfo.getIdField(); if (idFieldType == null) { throw new SQLException("Cannot query-for-id with " + tableInfo.getDataClass() + " because it doesn't have an id field"); } } String statement = buildStatement(databaseType, tableInfo, idFieldType); return new MappedQueryForFieldEq<T, ID>(tableInfo, statement, new FieldType[] { idFieldType }, tableInfo.getFieldTypes(), "query-for-id"); }
public static <T, ID> MappedDelete<T, ID> build(Dao<T, ID> dao, TableInfo<T, ID> tableInfo) throws SQLException { FieldType idField = tableInfo.getIdField(); if (idField == null) { throw new SQLException( "Cannot delete from " + tableInfo.getDataClass() + " because it doesn't have an id field"); } StringBuilder sb = new StringBuilder(64); DatabaseType databaseType = dao.getConnectionSource().getDatabaseType(); appendTableName(databaseType, sb, "DELETE FROM ", tableInfo.getTableName()); appendWhereFieldEq(databaseType, idField, sb, null); return new MappedDelete<T, ID>(dao, tableInfo, sb.toString(), new FieldType[] { idField }); }
public static <T, ID> MappedUpdateId<T, ID> build(Dao<T, ID> dao, TableInfo<T, ID> tableInfo) throws SQLException { FieldType idField = tableInfo.getIdField(); if (idField == null) { throw new SQLException( "Cannot update-id in " + tableInfo.getDataClass() + " because it doesn't have an id field"); } StringBuilder sb = new StringBuilder(64); DatabaseType databaseType = dao.getConnectionSource().getDatabaseType(); appendTableName(databaseType, sb, "UPDATE ", tableInfo.getTableName()); sb.append("SET "); appendFieldColumnName(databaseType, sb, idField, null); sb.append("= ? "); appendWhereFieldEq(databaseType, idField, sb, null); return new MappedUpdateId<T, ID>(dao, tableInfo, sb.toString(), new FieldType[] { idField, idField }); }
public static <T, ID> MappedRefresh<T, ID> build(DatabaseType databaseType, TableInfo<T, ID> tableInfo) throws SQLException { FieldType idField = tableInfo.getIdField(); if (idField == null) { throw new SQLException("Cannot refresh " + tableInfo.getDataClass() + " because it doesn't have an id field"); } String statement = buildStatement(databaseType, tableInfo, idField); return new MappedRefresh<T, ID>(tableInfo, statement, new FieldType[] { tableInfo.getIdField() }, tableInfo.getFieldTypes()); } }
/** * This is private because the execute is the only method that should be called here. */ private static <T, ID> MappedDeleteCollection<T, ID> build(Dao<T, ID> dao, TableInfo<T, ID> tableInfo, int dataSize) throws SQLException { FieldType idField = tableInfo.getIdField(); if (idField == null) { throw new SQLException( "Cannot delete " + tableInfo.getDataClass() + " because it doesn't have an id field defined"); } StringBuilder sb = new StringBuilder(128); DatabaseType databaseType = dao.getConnectionSource().getDatabaseType(); appendTableName(databaseType, sb, "DELETE FROM ", tableInfo.getTableName()); FieldType[] argFieldTypes = new FieldType[dataSize]; appendWhereIds(databaseType, idField, sb, dataSize, argFieldTypes); return new MappedDeleteCollection<T, ID>(dao, tableInfo, sb.toString(), argFieldTypes); }
public static <T, ID> MappedQueryForFieldEq<T, ID> build(Dao<T, ID> dao, TableInfo<T, ID> tableInfo, FieldType idFieldType) throws SQLException { if (idFieldType == null) { idFieldType = tableInfo.getIdField(); if (idFieldType == null) { throw new SQLException("Cannot query-for-id with " + tableInfo.getDataClass() + " because it doesn't have an id field"); } } DatabaseType databaseType = dao.getConnectionSource().getDatabaseType(); String statement = buildStatement(databaseType, tableInfo, idFieldType); return new MappedQueryForFieldEq<T, ID>(dao, tableInfo, statement, new FieldType[] { idFieldType }, tableInfo.getFieldTypes(), "query-for-id"); }
public static <T, ID> MappedRefresh<T, ID> build(Dao<T, ID> dao, TableInfo<T, ID> tableInfo) throws SQLException { FieldType idField = tableInfo.getIdField(); if (idField == null) { throw new SQLException( "Cannot refresh " + tableInfo.getDataClass() + " because it doesn't have an id field"); } DatabaseType databaseType = dao.getConnectionSource().getDatabaseType(); String statement = buildStatement(databaseType, tableInfo, idField); return new MappedRefresh<T, ID>(dao, tableInfo, statement, new FieldType[] { tableInfo.getIdField() }, tableInfo.getFieldTypes()); } }
@Test public void testBasic() throws SQLException { TableInfo<Foo, String> tableInfo = new TableInfo<Foo, String>(databaseType, Foo.class); assertEquals(Foo.class, tableInfo.getDataClass()); assertEquals(TABLE_NAME, tableInfo.getTableName()); assertEquals(COLUMN_NAME, tableInfo.getIdField().getColumnName()); assertEquals(1, tableInfo.getFieldTypes().length); assertSame(tableInfo.getIdField(), tableInfo.getFieldTypes()[0]); assertEquals(COLUMN_NAME, tableInfo.getFieldTypeByColumnName(COLUMN_NAME).getColumnName()); }