/** * {@inheritDoc} */ public void apply(Database database, boolean caseSensitive) { Table table = new CloneHelper().clone(_newTable, true, false, database, caseSensitive); database.addTable(table); } }
/** * Compares the two models and returns the changes necessary to create the second * model from the first one. * * @param sourceModel The source model * @param targetModel The target model * @return The changes */ public List compare(Database sourceModel, Database targetModel) { Database intermediateModel = _cloneHelper.clone(sourceModel); return compareModels(sourceModel, intermediateModel, targetModel); }
intermediateTable = _cloneHelper.clone(targetTable, true, false, intermediateModel, _caseSensitive);
/** * Processes the given changes in the specified order. Basically, this method finds the * appropriate handler method (one of the <code>processChange</code> methods) defined in * the concrete sql builder for each change, and invokes it. * * @param model The database model; this object is not going to be changed by this method * @param changes The changes * @param params The parameters used in the creation of new tables. Note that for existing * tables, the parameters won't be applied * @return The changed database model */ protected Database processChanges(Database model, Collection changes, CreationParameters params) throws IOException, DdlUtilsException { Database currentModel = new CloneHelper().clone(model); for (Iterator it = changes.iterator(); it.hasNext();) { invokeChangeHandler(currentModel, params, (ModelChange)it.next()); } return currentModel; }
Index clonedIndex = _cloneHelper.clone(targetIndex, intermediateTable, _caseSensitive); AddIndexChange change = new AddIndexChange(intermediateTable.getQualifiedName(), clonedIndex);
/** * {@inheritDoc} */ public void apply(Database database, boolean caseSensitive) { // we only need to replace the table in the model, as there can't be a // foreign key from or to it when these kind of changes are created for (int tableIdx = 0; tableIdx < database.getTableCount(); tableIdx++) { Table curTable = database.getTable(tableIdx); if ((caseSensitive && curTable.getQualifiedName().equals(getChangedTable())) || (!caseSensitive && curTable.getQualifiedName().equalsIgnoreCase(getChangedTable()))) { database.removeTable(tableIdx); database.addTable(tableIdx, new CloneHelper().clone(_targetTable, true, false, database, caseSensitive)); break; } } } }
Table tmpTable = _cloneHelper.clone(intermediateTable, true, false, intermediateModel, _caseSensitive);
/** * {@inheritDoc} */ public void apply(Database model, boolean caseSensitive) { Table table = findChangedTable(model, caseSensitive); Column newColumn = new CloneHelper().clone(_newColumn, true); if (_previousColumnName != null) { Column prevColumn = table.findColumn(_previousColumnName, caseSensitive); int idx = table.getColumnIndex(prevColumn) + 1; table.addColumn(idx, newColumn); } else if (_nextColumnName != null) { table.addColumn(0, newColumn); } else { table.addColumn(newColumn); } } }
intermediateFk = _cloneHelper.clone(targetFk, intermediateTable, intermediateModel, _caseSensitive);
targetModel = new CloneHelper().clone(model); targetModel.initialize();
CloneHelper cloneHelper = new CloneHelper(); addTable(cloneHelper.clone(table, true, false, this, true)); localTable.addForeignKey(cloneHelper.clone(fk, localTable, this, false));
/** * Returns a clone of the given source index. * * @param source The source index * @param targetTable The table whose columns shall be used by the clone * @param caseSensitive Whether comparison is case sensitive (for finding the columns * in the target table) * @return The clone */ public Index clone(Index source, Table targetTable, boolean caseSensitive) { Index result = (source.isUnique() ? (Index)new UniqueIndex() : (Index)new NonUniqueIndex()); result.setName(source.getName()); for (int colIdx = 0; colIdx < source.getColumnCount(); colIdx++) { IndexColumn column = source.getColumn(colIdx); result.addColumn(clone(column, targetTable, caseSensitive)); } return result; }
/** * Creates a temporary table object that corresponds to the given table. * Database-specific implementations may redefine this method if e.g. the * database directly supports temporary tables. The default implementation * simply appends an underscore to the table name and uses that as the * table name. * * @param targetTable The target table * @return The temporary table */ protected Table getTemporaryTableFor(Table targetTable) { CloneHelper cloneHelper = new CloneHelper(); Table table = new Table(); table.setCatalog(targetTable.getCatalog()); table.setSchema(targetTable.getSchema()); table.setName(targetTable.getName() + "_"); table.setType(targetTable.getType()); for (int idx = 0; idx < targetTable.getColumnCount(); idx++) { // TODO: clone PK status ? table.addColumn(cloneHelper.clone(targetTable.getColumn(idx), true)); } return table; }
Column clonedColumn = _cloneHelper.clone(targetColumn, false); AddColumnChange change = new AddColumnChange(intermediateTable.getQualifiedName(), clonedColumn, prevColumn, nextColumn);
/** * Returns a deep clone of the given model object, including all tables, foreign keys, indexes etc. * * @param source The source model * @return The clone */ public Database clone(Database source) { Database result = new Database(); result.setName(source.getName()); result.setIdMethod(source.getIdMethod()); result.setVersion(source.getVersion()); for (int tableIdx = 0; tableIdx < source.getTableCount(); tableIdx++) { Table sourceTable = source.getTable(tableIdx); result.addTable(clone(sourceTable, true, false, result, true)); } for (int tableIdx = 0; tableIdx < source.getTableCount(); tableIdx++) { Table sourceTable = source.getTable(tableIdx); Table clonedTable = result.getTable(tableIdx); for (int fkIdx = 0; fkIdx < sourceTable.getForeignKeyCount(); fkIdx++) { ForeignKey sourceFk = sourceTable.getForeignKey(fkIdx); clonedTable.addForeignKey(clone(sourceFk, clonedTable, result, true)); } } return result; }
/** * 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; }
Column newColumnDef = _cloneHelper.clone(sourceColumn, true); int targetTypeCode = _platformInfo.getTargetJdbcType(targetColumn.getTypeCode()); boolean sizeMatters = _platformInfo.hasSize(targetTypeCode);