/** * Finds the table with the specified name, using case insensitive matching. * Note that this method is not called getTable to avoid introspection * problems. * * @param name The name of the table to find * @return The table or <code>null</code> if there is no such table */ public Table findTable(String name) { return findTable(name, false); }
/** * {@inheritDoc} */ public Table findChangedTable(Database model, boolean caseSensitive) { return model.findTable(_tableName, caseSensitive); } }
/** * Returns the indicated tables. * * @param tableNames The names of the tables * @param caseSensitive Whether the case of the table names matters * @return The tables */ public Table[] findTables(String[] tableNames, boolean caseSensitive) { ArrayList tables = new ArrayList(); if (tableNames != null) { for (int idx = 0; idx < tableNames.length; idx++) { Table table = findTable(tableNames[idx], caseSensitive); if (table != null) { tables.add(table); } } } return (Table[])tables.toArray(new Table[tables.size()]); }
/** * Returns the {@link org.apache.ddlutils.dynabean.SqlDynaClass} for the given table name. If the it does not * exist yet, a new one will be created based on the Table definition. * * @param tableName The name of the table to create the bean for * @return The <code>SqlDynaClass</code> for the indicated table or <code>null</code> * if the model contains no such table */ public SqlDynaClass getDynaClassFor(String tableName) { Table table = findTable(tableName); return table != null ? getDynaClassCache().getDynaClass(table) : null; }
/** * Convenience method that combines {@link #createDynaBeanFor(Table)} and * {@link #findTable(String, boolean)}. * * @param tableName The name of the table to create the bean for * @param caseSensitive Whether case matters for the names * @return The new dyna bean */ public DynaBean createDynaBeanFor(String tableName, boolean caseSensitive) throws SqlDynaException { return getDynaClassCache().createNewInstance(findTable(tableName, caseSensitive)); }
/** * Creates the SQL for querying for the id generated by the last insert of an object of the given type. * * @param model The database model * @param dynaClass The type * @return The SQL required for querying for the id, or <code>null</code> if the database does not * support this */ protected String createSelectLastInsertIdSql(Database model, SqlDynaClass dynaClass) { Table table = model.findTable(dynaClass.getTableName()); return _builder.getSelectLastIdentityValues(table); }
/** * Creates the SQL for updating an object of the given type. If a concrete bean is given, * then a concrete update statement is created, otherwise an update statement usable in a * prepared statement is build. * * @param model The database model * @param dynaClass The type * @param primaryKeys The primary keys * @param properties The properties to write * @param bean Optionally the concrete bean to update * @return The SQL required to update the instance */ protected String createUpdateSql(Database model, SqlDynaClass dynaClass, SqlDynaProperty[] primaryKeys, SqlDynaProperty[] properties, DynaBean bean) { Table table = model.findTable(dynaClass.getTableName()); HashMap columnValues = toColumnValues(properties, bean); columnValues.putAll(toColumnValues(primaryKeys, bean)); return _builder.getUpdateSql(table, columnValues, bean == null); }
private void modifyVarBinaryColumn(Database targetModel, String tableName, String columnName) { Table table = targetModel.findTable(tableName); Column c = table.findColumn(columnName); c.setType("VARCHAR"); c.setSize("2000"); System.out.println("updating column " + c.getName() + " for table " + table.getName()); } /**
/** * Creates the SQL for inserting an object of the given type. If a concrete bean is given, * then a concrete insert statement is created, otherwise an insert statement usable in a * prepared statement is build. * * @param model The database model * @param dynaClass The type * @param properties The properties to write * @param bean Optionally the concrete bean to insert * @return The SQL required to insert an instance of the class */ protected String createInsertSql(Database model, SqlDynaClass dynaClass, SqlDynaProperty[] properties, DynaBean bean) { Table table = model.findTable(dynaClass.getTableName()); HashMap columnValues = toColumnValues(properties, bean); return _builder.getInsertSql(table, columnValues, bean == null); }
/** * Creates the SQL for deleting an object of the given type. If a concrete bean is given, * then a concrete delete statement is created, otherwise a delete statement usable in a * prepared statement is build. * * @param model The database model * @param dynaClass The type * @param primaryKeys The primary keys * @param bean Optionally the concrete bean to update * @return The SQL required to delete the instance */ protected String createDeleteSql(Database model, SqlDynaClass dynaClass, SqlDynaProperty[] primaryKeys, DynaBean bean) { Table table = model.findTable(dynaClass.getTableName()); HashMap pkValues = toColumnValues(primaryKeys, bean); return _builder.getDeleteSql(table, pkValues, bean == null); }
private Database identifyNewTables() { Database _database = new Database(); _database.setName(database.getName()); Collection<String> tableNames = tblNameMap.values(); LOG.info("Initializing database and creating tables"); for (String tableName : tableNames) { if (database.findTable(tableName) == null) { Table table = createTable(tableName); LOG.info("Creating {}", table.toVerboseString()); _database.addTable(table); database.addTable(table); } else { LOG.debug("Table {} already exists", tableName); } } return _database; }
/** * Creates the SQL for updating an object of the given type. If a concrete bean is given, * then a concrete update statement is created, otherwise an update statement usable in a * prepared statement is build. * * @param model The database model * @param dynaClass The type * @param primaryKeys The primary keys * @param properties The properties to write * @param oldBean Contains column values to identify the rows to update (i.e. for the WHERE clause) * @param newBean Contains the new column values to write * @return The SQL required to update the instance */ protected String createUpdateSql(Database model, SqlDynaClass dynaClass, SqlDynaProperty[] primaryKeys, SqlDynaProperty[] properties, DynaBean oldBean, DynaBean newBean) { Table table = model.findTable(dynaClass.getTableName()); HashMap oldColumnValues = toColumnValues(primaryKeys, oldBean); HashMap newColumnValues = toColumnValues(properties, newBean); if (primaryKeys.length == 0) { _log.info("Cannot update instances of type " + dynaClass + " because it has no primary keys"); return null; } else { return _builder.getUpdateSql(table, oldColumnValues, newColumnValues, newBean == null); } }
private Database identifyNewTables(){ Database _database = new Database(); _database.setName(database.getName()); Collection<JdbcEntityDefinition> entityDefinitions = JdbcEntityDefinitionManager.getJdbcEntityDefinitionMap().values(); LOG.info("Initializing database and creating tables"); for (JdbcEntityDefinition entityDefinition : entityDefinitions) { if (database.findTable(entityDefinition.getJdbcTableName()) == null) { Table table = createTable(entityDefinition); LOG.info("Creating {}", table.toVerboseString()); _database.addTable(table); database.addTable(table); } else { LOG.debug("Table {} already exists", entityDefinition.getJdbcTableName()); } } return _database; }
private Database identifyNewTables(){ Database _database = new Database(); _database.setName(database.getName()); Collection<JdbcEntityDefinition> entityDefinitions = JdbcEntityDefinitionManager.getJdbcEntityDefinitionMap().values(); LOG.info("Initializing database and creating tables"); for (JdbcEntityDefinition entityDefinition : entityDefinitions) { if (database.findTable(entityDefinition.getJdbcTableName()) == null) { Table table = createTable(entityDefinition); LOG.info("Creating {}", table.toVerboseString()); _database.addTable(table); database.addTable(table); } else { LOG.debug("Table {} already exists", entityDefinition.getJdbcTableName()); } } return _database; }
Table targetTable = targetModel.findTable(intermediateTable.getQualifiedName(), _caseSensitive); ForeignKey[] intermediateFks = intermediateTable.getForeignKeys();
/** * Finds the table changed by the change object in the given model. * * @param currentModel The model to find the table in * @param change The table change * @return The table * @throws ModelException If the table could not be found */ protected Table findChangedTable(Database currentModel, TableChange change) throws ModelException { Table table = currentModel.findTable(change.getChangedTable(), getPlatformInfo().isDelimitedIdentifiersSupported()); if (table == null) { throw new ModelException("Could not find table " + change.getChangedTable() + " in the given model"); } else { return table; } }
public List getRows(JetspeedDDLUtil ddlUtil, String tableName) { Table table = ddlUtil.getModel().findTable(tableName, ddlUtil.getPlatform().isDelimitedIdentifierModeOn()); return ddlUtil.getPlatform().fetch(ddlUtil.getModel(), getSelectQueryForAllString(ddlUtil, table), new Table[] {table}); }
public List getRows(String tableName) { Table table = getModel().findTable(tableName, getPlatform().isDelimitedIdentifierModeOn()); return getPlatform().fetch(getModel(), getSelectQueryForAllString( table), new Table[] { table }); }
/** * Returns a clone of the given source foreign key. * * @param source The source foreign key * @param owningTable The table owning the source foreign key * @param targetModel The target model containing the tables that the clone shall link * @param caseSensitive Whether comparison is case sensitive (for finding the columns * in the target model) * @return The clone */ public ForeignKey clone(ForeignKey source, Table owningTable, Database targetModel, boolean caseSensitive) { ForeignKey result = new ForeignKey(); Table foreignTable = targetModel.findTable(source.getForeignTableName(), caseSensitive); result.setName(source.getName()); result.setForeignTable(foreignTable); result.setAutoIndexPresent(source.isAutoIndexPresent()); result.setOnDelete(source.getOnDelete()); result.setOnUpdate(source.getOnUpdate()); for (int refIdx = 0; refIdx < source.getReferenceCount(); refIdx++) { Reference ref = source.getReference(refIdx); result.addReference(clone(ref, owningTable, foreignTable, caseSensitive)); } return result; }