/** * Looks up the table element for <code>tableName</code> in the * table element cache <code>knownTables</code>. If the table * element is not found, the table name is looked up in the * database schema and registered in the cache. * * @param tableName Table name. * @param knownTables A Map which contains primary and secondary tables * for beans in the set. Keys: table names Values: TableElement objects * @param schema dbschema information for all beans. * @return Table element for table <code>tableName</code>. * @exception DBException * @exception ConversionException */ private TableElement getTableElement(String tableName, Map knownTables, SchemaElement schema) throws DBException, ConversionException { TableElement te = (TableElement) knownTables.get(tableName); if (null == te) { te = getTableElement(schema, DBIdentifier.create(tableName), helper); knownTables.put(tableName, te); } return te; }
/** * 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; }
private List getRelativeColumnNames (ColumnElement[] columns) { int i, count = ((columns != null) ? columns.length : 0); List columnNames = new ArrayList(count); for (i = 0; i < count; i++) { columnNames.add(NameUtil.getRelativeMemberName( columns[i].getName().getFullName())); } return columnNames; } private boolean isKeyField (MappingFieldElement field)
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; }
/** * 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(); } }
DBIdentifier n = DBIdentifier.create(schemaElementValue); n.setFullName(schemaElementValue); bar.setName(n);
/** 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())); }
/** * Get the primary table element for the mapping class. * @param mappingClass That which is associated with the table. * @return Table that is associated with mapping class. * @throws DBException */ private TableElement getPrimaryTable(MappingClassElement mappingClass) throws DBException { List tables = mappingClass.getTables(); MappingTableElement tbl = (MappingTableElement) tables.get(0); if (tbl != null) { DBIdentifier tblName = DBIdentifier.create(tbl.getTable()); return schema.getTable(tblName); } else { return null; } }
/** 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())); }
private List getRelativeColumnNames (ColumnElement[] columns) { int i, count = ((columns != null) ? columns.length : 0); List columnNames = new ArrayList(count); for (i = 0; i < count; i++) { columnNames.add(NameUtil.getRelativeMemberName( columns[i].getName().getFullName())); } return columnNames; } private boolean isKeyField (MappingFieldElement field)
/** Accept an arraylist of column names and return an array list containing * the corresponding column or column pair objects. * @param schemaName the database root used to find the column objects * @param columnNames array of column names. * @return an array of corresponding column objects * @see org.netbeans.modules.dbschema.TableElement#forName * @see org.netbeans.modules.dbschema.TableElement#getMember */ protected static ArrayList toColumnObjects (String schemaName, ArrayList columnNames) { Iterator iterator = columnNames.iterator(); ArrayList objects = new ArrayList(); while (iterator.hasNext()) { String columnName = (String)iterator.next(); String absoluteColumnName = NameUtil.getAbsoluteMemberName(schemaName, columnName); final TableElement table = TableElement.forName(NameUtil.getTableName(absoluteColumnName)); objects.add(table.getMember( DBIdentifier.create(absoluteColumnName))); } return objects; }
/** * 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; }
/** * 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); }
private boolean testColumn (ColumnElement column, ArrayList masterList) { if ((column != null) && !isPrimaryKeyColumn(column)) { return !masterList.contains(NameUtil. getRelativeMemberName(column.getName().getFullName())); } return true; } private ColumnElement getLocalColumn (String pairName,
/** Accept an arraylist of column names and return an array list containing * the corresponding column or column pair objects. * @param schemaName the database root used to find the column objects * @param columnNames array of column names. * @return an array of corresponding column objects * @see org.netbeans.modules.dbschema.TableElement#forName * @see org.netbeans.modules.dbschema.TableElement#getMember */ protected static ArrayList toColumnObjects (String schemaName, ArrayList columnNames) { Iterator iterator = columnNames.iterator(); ArrayList objects = new ArrayList(); while (iterator.hasNext()) { String columnName = (String)iterator.next(); String absoluteColumnName = NameUtil.getAbsoluteMemberName(schemaName, columnName); final TableElement table = TableElement.forName(NameUtil.getTableName(absoluteColumnName)); objects.add(table.getMember( DBIdentifier.create(absoluteColumnName))); } return objects; }
/** 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 testColumn (ColumnElement column, ArrayList masterList) { if ((column != null) && !isPrimaryKeyColumn(column)) { return !masterList.contains(NameUtil. getRelativeMemberName(column.getName().getFullName())); } return true; } private ColumnElement getLocalColumn (String pairName,