DBElementFactorypublic class DBElementFactory extends Object
Fields Summary |
---|
private static final String | TAGLINEString which indicates that schema was generated. | private static final String | SIGNATURESignature which identifies version of database generator. Updated
each time the file is checked in to CVS. | private static final String | UNKNOWN_FIELD_TYPEField type used if null is given in getColumnType. | private static final String | DEFAULT_FIELD_TYPEField type used for user-defined types in getColumnType. |
Constructors Summary |
---|
private DBElementFactory()Disallow outside construction. // NOI18N
|
Methods Summary |
---|
static ColumnElement | createAndAttachColumn(java.lang.String columnName, TableElement table, JDBCInfo ji)Create column and add to the table.
// 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;
| static ForeignKeyElement | createAndAttachForeignKey(TableElement declaringTbl, TableElement refTbl, java.lang.String keyName, MappingPolicy mappingPolicy, java.lang.String uniqueId)Create foreign key between declaring table and reference table with
relationship name.
String fkeyName = mappingPolicy.getConstraintName(keyName, uniqueId);
TableElementImpl tableImpl =
(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();
// Each PK column contributes to the FK.
if (pkColumns != null) {
for (int i = 0; i < pkColumns.length; i++) {
ColumnElement refColumn = pkColumns[i];
// get name from mappingPolicy
String columnName =
mappingPolicy.getConstraintColumnName(
refTblName, refColumn.getName().getName());
// create column to ref primary key of ref table
JDBCInfo ji = new JDBCInfo(
refColumn.getType(),
refColumn.getPrecision(),
refColumn.getScale(),
refColumn.getLength(),
true);
// create column and add to declaring table
ColumnElement column = createAndAttachColumn(
columnName, declaringTbl, ji);
// create column pairs and add to foreign key
ColumnPairElement pair = createColumnPair(
column, refColumn, declaringTbl);
fkey.addColumnPair(pair);
}
}
declaringTbl.addKey(fkey);
return fkey;
| static UniqueKeyElement | createAndAttachPrimaryKey(TableElement table, java.lang.String pKeyName)Create primary key and add to table.
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;
| static TableElement | createAndAttachTable(SchemaElement schema, java.lang.String tableName)Create table and add to schema.
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;
| static ColumnPairElement | createColumnPair(ColumnElement column, ColumnElement refColumn, TableElement declaringTbl)Create column pair from local column and reference column.
ColumnPairElementImpl pairImpl = new ColumnPairElementImpl();
ColumnPairElement pair = new ColumnPairElement(
pairImpl, column, refColumn, declaringTbl);
return pair;
| static SchemaElement | createSchema(java.lang.String schemaName)Creates and returns a schema from give schema name
SchemaElementImpl schemaImpl = new SchemaElementImpl();
SchemaElement schema = new SchemaElement(schemaImpl);
schema.setName(DBIdentifier.create(schemaName));
schema.setDatabaseProductVersion(TAGLINE + SIGNATURE);
return schema;
| static JDBCInfo | getColumnType(java.lang.String fieldName, java.lang.String fieldType, MappingPolicy mappingPolicy)Returns properties of a type of a field.
// fieldType will be null when we are handling an unknown PK
// situation. Use a Long in that case.
if (fieldType == null) {
fieldType = UNKNOWN_FIELD_TYPE;
}
JDBCInfo rc = mappingPolicy.getJDBCInfo(fieldName, fieldType);
// We won't find a JDBCInfo for user-defined types. Treat them as
// Object.
if (null == rc) {
// Treat as user-defined object type.
rc = mappingPolicy.getJDBCInfo(null, DEFAULT_FIELD_TYPE); // NOI18N
}
return rc;
|
|