/** * 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; }
/** * 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; } }
/** 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; }
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); }
/** * Creates and returns a schema from give schema name * @param schemaName A name for schema. * @return Newly created schema element. * @throws DBException */ static SchemaElement createSchema(String schemaName) throws DBException { SchemaElementImpl schemaImpl = new SchemaElementImpl(); SchemaElement schema = new SchemaElement(schemaImpl); schema.setName(DBIdentifier.create(schemaName)); schema.setDatabaseProductVersion(TAGLINE + SIGNATURE); return schema; }
/** 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,
DBIdentifier n = DBIdentifier.create(schemaElementValue); n.setFullName(schemaElementValue); bar.setName(n);
/** * 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; }
DBIdentifier.create(primaryTableName), helper);
/** 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
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; }
/** * 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; }
new org.netbeans.modules.dbschema.UniqueKeyElement(); ColumnElement fakeKeyCol = new ColumnElement(); fakeKeyCol.setName(DBIdentifier.create(retVal.getName().getName()+ "."+"fookeyng")); //NOI18N
/** * 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; }