/** 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; }
private boolean isPrimaryKeyColumn (ColumnElement column) { if (column != null) { KeyElement key = column.getDeclaringTable().getPrimaryKey(); return ((key != null) && (key.getColumn(column.getName()) != null)); } return false; } private boolean isExactMatch (ArrayList columns1,
/** * Debug support. Returns a string describing the table and it's keys * (only the first key is listed). * @param tblName name of the table described * @param tbl table being described * @param relName name of a relationship */ private static String getTblInfo(String tblName, TableElement tbl, String relName) { int numFK = tbl.getForeignKeys().length; ForeignKeyElement fk = null; if (numFK > 0) { fk = tbl.getForeignKeys()[0]; } return " " + tblName + "=" + tbl.toString() + ", # keys=" + numFK // NOI18N + ", 1st key=" + fk // NOI18N + "; relationship Name=" + relName; // NOI18N } }
private ColumnPairElement getPair (String pairName, String databaseRoot) { String absoluteName = NameUtil.getAbsoluteMemberName( databaseRoot, pairName); TableElement tableElement = TableElement.forName( NameUtil.getTableName(absoluteName)); DBMemberElement pair = ((tableElement == null) ? null : tableElement.getMember(DBIdentifier.create(absoluteName))); return ((pair instanceof ColumnPairElement) ? ((ColumnPairElement)pair) : null); }
/** * 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); }
UniqueKeyElement key = table.getPrimaryKey(); MappingTableElement mappingTable = new MappingTableElementImpl(table, this); SchemaElement schema = table.getDeclaringSchema(); String currentRoot = getDatabaseRoot(); table.toString(), currentRoot)); UniqueKeyElement[] uniqueKeys = table.getUniqueKeys();
retVal = new TableElement(); retVal.setName(dbId); retVal.setDeclaringSchema(schema); org.netbeans.modules.dbschema.UniqueKeyElement tkey = new org.netbeans.modules.dbschema.UniqueKeyElement(); ColumnElement fakeKeyCol = new ColumnElement(); fakeKeyCol.setName(DBIdentifier.create(retVal.getName().getName()+ "."+"fookeyng")); //NOI18N tkey.setPrimaryKey(true); tkey.addColumn(fakeKeyCol); retVal.addColumn(fakeKeyCol); retVal.addKey(tkey);
(TableElementImpl) declaringTbl. getElementImpl(); ForeignKeyElementImpl fkeyImpl = new ForeignKeyElementImpl(tableImpl, fkeyName); ForeignKeyElement fkey = new ForeignKeyElement(fkeyImpl, declaringTbl); UniqueKeyElement pk = refTbl.getPrimaryKey(); ColumnElement [] pkColumns = pk.getColumns(); String refTblName = refTbl.getName().getName(); declaringTbl.addKey(fkey); return fkey;
/** * 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; }
/** 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())); }
UniqueKeyElement[] uks = table.getUniqueKeys(); ForeignKeyElement[] fks = table.getForeignKeys(); int i, count = ((uks != null) ? uks.length : 0);
String absoluteTableName = NameUtil.getAbsoluteTableName( _databaseRoot, mappingTable.getTable()); ForeignKeyElement[] foreignKeys = TableElement.forName( absoluteTableName).getForeignKeys(); int i, count = ((foreignKeys != null) ? foreignKeys.length : 0);
TableElement primaryTable = getTableElement(primaryTableName, knownTables, schema); UniqueKeyElement pk = primaryTable.getPrimaryKey(); ForeignKeyElement fks[] = primaryTable.getForeignKeys(); Iterator iter = primaryTableColumns.iterator();
/** Creates new MappingTableElementImpl with a corresponding * table and declaring class. * @param table table element to be used by the mapping table. * @param declaringClass the class to attach to */ public MappingTableElementImpl (TableElement table, MappingClassElement declaringClass) throws ModelException { this(table.toString(), declaringClass); // don't use setTable so as not to fire property change events _table = getName(); }
/** Checks whether the specified TableElement has a FK that * exactly matches the list of column pair names. * @return the matching FK if it exactly matches the list * of column pairs; <code>null</code> otherwise. */ private ForeignKeyElement getMatchingFK (List pairNames, TableElement table) { ForeignKeyElement[] foreignKeys = (table != null) ? table.getForeignKeys() : null; int count = ((foreignKeys != null) ? foreignKeys.length : 0); for (int i = 0; i < count; i++) { if (matchesFK(pairNames, foreignKeys[i])) return foreignKeys[i]; } return null; }
/** * 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; }
/** * 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; }
String[] oneParam = { table.getName().getName() }; ColumnElement[] columns = table.getColumns(); String constraint = createPrimaryKeyConstraint(table); int size = columns.length;
private ColumnElement getColumnElement(TableElement sourceTableEl, DBIdentifier sourceColumnName, ConversionHelper helper) throws DBException, ConversionException { ColumnElement aCol = sourceTableEl.getColumn(sourceColumnName); if (null == aCol && !helper.ensureValidation()) { aCol = new ColumnElement(); aCol.setName(DBIdentifier.create(sourceTableEl.getName().toString()+"."+sourceColumnName.toString())); // NOI18N aCol.setDeclaringTable(sourceTableEl); aCol.setNullable(true); } if (aCol == null) { throw new ConversionException( I18NHelper.getMessage( messages, "ERR_INVALID_COLUMN", //NOI18N new Object [] {sourceColumnName, sourceTableEl})); } return aCol; }
private TableElement getTable (String tableName, String databaseRoot) { String absoluteName = NameUtil.getAbsoluteTableName(databaseRoot, tableName); return TableElement.forName(absoluteName); }