/** * Returns a comma-separated list of column names. * @param columns Array of ColumnElements * @return String of form "columnA, columnB", with as many named columns * as there are in given array. */ private static String getColumnNames(ColumnElement[] columns) { StringBuffer columnNames = new StringBuffer(); for (int i = 0; i < columns.length; i++) { if (i > 0) { columnNames.append(COLUMN_SEPARATOR); } columnNames.append(columns[i].getName().getName()); } return columnNames.toString(); } }
/** Check if the table of the column matches one of the list of tables. * @param tableNames A list of table names in which to check for a match * @param column A ColumnElement object to be checked * @return <code>true</code> if the column belongs to a table found * in the supplied list of table names, <code>false</code> otherwise */ private boolean matchesTable (List tableNames, ColumnElement column) { return ((column == null) ? true : tableNames.contains( column.getDeclaringTable().getName().getName())); }
/** Check if the table of the column matches one of the list of tables. * @param tableNames A list of table names in which to check for a match * @param column A ColumnElement object to be checked * @return <code>true</code> if the column belongs to a table found * in the supplied list of table names, <code>false</code> otherwise */ private boolean matchesTable (List tableNames, ColumnElement column) { return ((column == null) ? true : tableNames.contains( column.getDeclaringTable().getName().getName())); }
/** * Returns DDL in String form to drop a table. The returned string has * the format: * <pre> * DROP TABLE table_name * </pre> * @param table Table for which dropping DDL is returned. * @return DDL to drop a table. */ private static String createDropTableDDL(TableElement table) { String[] oneParam = { table.getName().getName() }; return DDLTemplateFormatter.formatDropTable(oneParam); }
/** Returns a List of Strings of "drop constraint" DDL commands. Each * String has the format: * <pre> * DROP TABLE table_name * </pre> * @param table Table for which constraints are to be dropped. * @return List of Strings, one per "drop constraint" command. */ private static List createDropConstraintsDDL(TableElement table) { List alterTbls = new ArrayList(); String[] twoParams = new String[2]; twoParams[0] = table.getName().getName(); ForeignKeyElement[] fkeys = table.getForeignKeys(); if (fkeys != null) { for (int i = 0; i < fkeys.length; i++) { twoParams[1] = fkeys[i].getName().getName(); String alterTblString = DDLTemplateFormatter.formatAlterTableDropConstraint( twoParams); alterTbls.add(alterTblString); } } return alterTbls; }
/** * Writes to *.dbschema file from schema * @param schema a SchemaElement * @param filePath a directory where *.dbschema is located * @throws IOException */ private static void writeSchemaFile(SchemaElement schema, File filePath) throws IOException { OutputStream schemaStream = null; try { schemaStream = new FileOutputStream( new File(filePath, NameUtil.getSchemaResourceName( schema.getName().getName()))); schema.save(schemaStream); } catch (IOException ex) { throw ex; } finally { try { if (schemaStream != null) { schemaStream.close(); } } catch (IOException ex) { if (logger.isLoggable(Logger.FINE)) logger.fine(ex.toString()); } } }
String[] oneParam = { table.getName().getName() };
StringBuffer columnContent = new StringBuffer(); columnContent.append(column.getName().getName()); columnContent.append(SPACE); columnContent.append(sqlType);
List alterTblDDL = new ArrayList(); String[] fourParams = new String[4]; String[] oneParam = { table.getName().getName() }; fourParams[0] = fkey.getName().getName(); fourParams[1] = getColumnNames(fkey.getLocalColumns()); fourParams[2] = fkey.getReferencedTable().getName().getName(); fourParams[3] = getColumnNames(fkey.getReferencedColumns());
/** * createIndexDDL has been added for Symfoware support. Returns DDL in String form * to create index. The returned string has the format: * <pre> * CREATE INDEX table_name.table_name KEY(id, name) * </pre> * @param table Table for which DDL is to be created. * @return DDL to create index. */ private static String createIndexDDL(TableElement table) { String[] twoParam = { table.getName().getName() , getColumnNames(table.getPrimaryKey().getColumns()) }; return DDLTemplateFormatter.formatCreateIndex(twoParam); }
dbVendorName); DDLTemplateFormatter.reset(mappingPolicy); String schemaName = schema.getName().getName(); List createAllTblDDL = new ArrayList();
/** * Returns DDL in String form to create a primary key constraint. The * string has the format: * <pre> * CONSTRAINT pk_name PRIMARY KEY(id, name) * </pre> * @param table Table for which constraint DDL is returned. * @return DDL to create a PK constraint or null if there is no PK. */ private static String createPrimaryKeyConstraint(TableElement table) { String rc = null; UniqueKeyElement pk = table.getPrimaryKey(); if (pk != null) { String[] twoParams = new String[2]; twoParams[0] = pk.getName().getName(); twoParams[1] = getColumnNames(pk.getColumns()); rc = DDLTemplateFormatter.formatPKConstraint(twoParams); } return rc; }
/** * Create table and add to schema. * @param schema Schema to which the table gets attached. * @param tableName Name of the table without the schema name. * @return TableElement for this table name * @throws DBException */ static TableElement createAndAttachTable(SchemaElement schema, String tableName) throws DBException { String fullName = NameUtil.getAbsoluteTableName( schema.getName().getName(), tableName); TableElementImpl tableImpl = new TableElementImpl(tableName); TableElement table = new TableElement(tableImpl, schema); table.setName(DBIdentifier.create(fullName)); table.setTableOrView(true); schema.addTable(table); return table; }
SchemaElement.removeFromCache(schema.getName().getName());
table, mappingPolicy.getPrimaryKeyConstraintName( table.getName().getName())); MappingClassElement mappingClass = createMappingClass( pcClass, table);
/** * Create primary key and add to table. * @param table TableElement for adding primary key. * @return UniqueKeyElement that represents the primary key. * @throws DBException */ static UniqueKeyElement createAndAttachPrimaryKey(TableElement table, String pKeyName) throws DBException { String tableName = table.getName().getName(); String fullName = NameUtil.getAbsoluteMemberName(tableName, pKeyName); // create index for primary key TableElementImpl tableImpl = (TableElementImpl)table.getElementImpl(); IndexElementImpl indexImpl = new IndexElementImpl(tableImpl, fullName, true); IndexElement index = new IndexElement(indexImpl, table); index.setUnique(true); UniqueKeyElementImpl pKeyImpl = new UniqueKeyElementImpl(); UniqueKeyElement pKey = new UniqueKeyElement(pKeyImpl, table, index); pKey.setName(DBIdentifier.create(fullName)); pKey.setPrimaryKey(true); table.addKey(pKey); table.addIndex(pKey.getAssociatedIndex()); return pKey; }
/** * Create column and add to the table. * @param columnName Name of the column to create. * @param declaringTbl The declaring table to which column gets added. * @return ColumnElement that represents the newly-added column. * @throws DBException */ static ColumnElement createAndAttachColumn(String columnName, TableElement table, JDBCInfo ji) throws DBException { // Create column id String fullName = NameUtil.getAbsoluteMemberName( table.getName().getName(), columnName); DBIdentifier columnId = DBIdentifier.create(columnName); ColumnElementImpl columnImpl = new ColumnElementImpl(); ColumnElement column = new ColumnElement(columnImpl, table); column.setName(columnId); column.setType(ji.getJdbcType()); column.setNullable(ji.getNullable()); column.setPrecision(ji.getPrecision()); column.setScale(ji.getScale()); column.setLength(ji.getLength()); table.addColumn(column); return column; }