/** 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; }
/** 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; }
/** Get the declaring table. This method is provided as part of * the implementation of the ReferenceKey interface but should only * be used when a ReferenceKey object is used or by the runtime. * @return the table that owns this reference key element, or * <code>null</code> if the element is not attached to any table */ public TableElement getDeclaringTable () { ArrayList locals = getReferencingKey(); if ((locals != null) && (locals.size() > 0)) { String absoluteName = NameUtil.getAbsoluteMemberName( getDeclaringClass().getDatabaseRoot(), locals.get(0).toString()); return TableElement.forName(NameUtil.getTableName(absoluteName)); } return null; }
/** Get the declaring table. This method is provided as part of * the implementation of the ReferenceKey interface but should only * be used when a ReferenceKey object is used or by the runtime. * @return the table that owns this reference key element, or * <code>null</code> if the element is not attached to any table */ public TableElement getDeclaringTable () { ArrayList locals = getReferencingKey(); if ((locals != null) && (locals.size() > 0)) { String absoluteName = NameUtil.getAbsoluteMemberName( getDeclaringClass().getDatabaseRoot(), locals.get(0).toString()); return TableElement.forName(NameUtil.getTableName(absoluteName)); } return null; }
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); }
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); }
/** Get all column pairs in this holder. * @return the column pairs */ public ColumnPairElement[] getColumnPairs () { ArrayList pairNames = getColumnPairNames(); TableElement table = getDeclaringTable(); int i, count = ((pairNames != null) ? pairNames.size() : 0); ColumnPairElement[] pairs = new ColumnPairElement[count]; String databaseRoot = getDeclaringClass().getDatabaseRoot(); for (i = 0; i < count; i++) { String absoluteName = NameUtil.getAbsoluteMemberName( databaseRoot, (String)pairNames.get(i)); pairs[i] = (ColumnPairElement)table.getMember( DBIdentifier.create(absoluteName)); } return pairs; }
/** Get all column pairs in this holder. * @return the column pairs */ public ColumnPairElement[] getColumnPairs () { ArrayList pairNames = getColumnPairNames(); TableElement table = getDeclaringTable(); int i, count = ((pairNames != null) ? pairNames.size() : 0); ColumnPairElement[] pairs = new ColumnPairElement[count]; String databaseRoot = getDeclaringClass().getDatabaseRoot(); for (i = 0; i < count; i++) { String absoluteName = NameUtil.getAbsoluteMemberName( databaseRoot, (String)pairNames.get(i)); pairs[i] = (ColumnPairElement)table.getMember( DBIdentifier.create(absoluteName)); } return pairs; }
private boolean isMappedToBlob (MappingFieldElement mappingField, String schema) { if (mappingField instanceof MappingRelationshipElement) { return isMappedToBlob( (MappingRelationshipElement)mappingField, schema); } else { Iterator iterator = mappingField.getColumns().iterator(); while (iterator.hasNext()) { String absoluteName = NameUtil.getAbsoluteMemberName( schema, (String)iterator.next()); TableElement table = TableElement.forName( NameUtil.getTableName(absoluteName)); ColumnElement columnElement = ((table != null) ? (ColumnElement)table.getMember( DBIdentifier.create(absoluteName)) : null); if (isMappedToBlob(columnElement)) return true; } } return false; } private boolean isMappedToBlob (MappingRelationshipElement rel,
private boolean isMappedToBlob (MappingFieldElement mappingField, String schema) { if (mappingField instanceof MappingRelationshipElement) { return isMappedToBlob( (MappingRelationshipElement)mappingField, schema); } else { Iterator iterator = mappingField.getColumns().iterator(); while (iterator.hasNext()) { String absoluteName = NameUtil.getAbsoluteMemberName( schema, (String)iterator.next()); TableElement table = TableElement.forName( NameUtil.getTableName(absoluteName)); ColumnElement columnElement = ((table != null) ? (ColumnElement)table.getMember( DBIdentifier.create(absoluteName)) : null); if (isMappedToBlob(columnElement)) return true; } } return false; } private boolean isMappedToBlob (MappingRelationshipElement rel,
/** Helper method validating the column mapping of the version * field is from the primary table. */ private ColumnElement validateTableMatch (String className, String fieldName, String columnName) throws ModelValidationException { String schema = getSchemaForClass(className); String absoluteName = NameUtil.getAbsoluteMemberName(schema, columnName); TableElement table = TableElement.forName(NameUtil.getTableName(absoluteName)); String primaryName = ((MappingTableElement)mappingClass. getTables().get(0)).getName(); TableElement pTable = getTable(primaryName, schema); // column must be from the PT if (table != pTable) { throw new ModelValidationException( getModel().getField(className, fieldName), I18NHelper.getMessage(getMessages(), "util.validation.version_field_table_mismatch", //NOI18N new Object[]{columnName, fieldName, className})); } return ((table != null) ? (ColumnElement)table.getMember( DBIdentifier.create(absoluteName)) : null); } /** Helper method validating the attributes of the column of the
/** Helper method validating the column mapping of the version * field is from the primary table. */ private ColumnElement validateTableMatch (String className, String fieldName, String columnName) throws ModelValidationException { String schema = getSchemaForClass(className); String absoluteName = NameUtil.getAbsoluteMemberName(schema, columnName); TableElement table = TableElement.forName(NameUtil.getTableName(absoluteName)); String primaryName = ((MappingTableElement)mappingClass. getTables().get(0)).getName(); TableElement pTable = getTable(primaryName, schema); // column must be from the PT if (table != pTable) { throw new ModelValidationException( getModel().getField(className, fieldName), I18NHelper.getMessage(getMessages(), "util.validation.version_field_table_mismatch", //NOI18N new Object[]{columnName, fieldName, className})); } return ((table != null) ? (ColumnElement)table.getMember( DBIdentifier.create(absoluteName)) : null); } /** Helper method validating the attributes of the column of the
/** * 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; }
String absoluteName = NameUtil.getAbsoluteMemberName( getSchemaForClass(className), columnName); TableElement table = TableElement.forName(
String absoluteName = NameUtil.getAbsoluteMemberName( getSchemaForClass(className), columnName); TableElement table = TableElement.forName(
/** * 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; }