Search in sources :

Example 1 with FieldDefinition

use of org.eclipse.persistence.tools.schemaframework.FieldDefinition in project eclipselink by eclipse-ee4j.

the class LegacyTableMaker method buildMUL_ADDRTable.

protected void buildMUL_ADDRTable() {
    TableDefinition tabledefinition = new TableDefinition();
    // SECTION: TABLE
    tabledefinition.setName("MUL_ADDR");
    // SECTION: FIELD
    FieldDefinition field = new FieldDefinition();
    field.setName("CITY");
    field.setTypeName("VARCHAR");
    field.setSize(10);
    field.setShouldAllowNull(true);
    field.setIsPrimaryKey(false);
    field.setUnique(false);
    field.setIsIdentity(false);
    tabledefinition.addField(field);
    // SECTION: FIELD
    FieldDefinition field1 = new FieldDefinition();
    field1.setName("CNTRY_ID");
    field1.setTypeName("NUMERIC");
    field1.setSize(5);
    field1.setShouldAllowNull(true);
    field1.setIsPrimaryKey(false);
    field1.setUnique(false);
    field1.setIsIdentity(false);
    tabledefinition.addField(field1);
    // SECTION: FIELD
    FieldDefinition field2 = new FieldDefinition();
    field2.setName("PROVINCE");
    field2.setTypeName("VARCHAR");
    field2.setSize(10);
    field2.setShouldAllowNull(true);
    field2.setIsPrimaryKey(false);
    field2.setUnique(false);
    field2.setIsIdentity(false);
    tabledefinition.addField(field2);
    // SECTION: FIELD
    FieldDefinition field3 = new FieldDefinition();
    field3.setName("ADDR_ID");
    field3.setTypeName("NUMERIC");
    field3.setSize(10);
    field3.setShouldAllowNull(false);
    field3.setIsPrimaryKey(true);
    field3.setUnique(false);
    field3.setIsIdentity(false);
    tabledefinition.addField(field3);
    ForeignKeyConstraint foreignKeyADDRESS_COUNTRY = new ForeignKeyConstraint();
    foreignKeyADDRESS_COUNTRY.setName("ADDRESS_COUNTRY");
    foreignKeyADDRESS_COUNTRY.setTargetTable("MUL_CTRY");
    foreignKeyADDRESS_COUNTRY.addSourceField("CNTRY_ID");
    foreignKeyADDRESS_COUNTRY.addTargetField("CNTRY_ID");
    tabledefinition.addForeignKeyConstraint(foreignKeyADDRESS_COUNTRY);
    addTableDefinition(tabledefinition);
}
Also used : FieldDefinition(org.eclipse.persistence.tools.schemaframework.FieldDefinition) ForeignKeyConstraint(org.eclipse.persistence.tools.schemaframework.ForeignKeyConstraint) TableDefinition(org.eclipse.persistence.tools.schemaframework.TableDefinition)

Example 2 with FieldDefinition

use of org.eclipse.persistence.tools.schemaframework.FieldDefinition in project eclipselink by eclipse-ee4j.

the class MultipleTableTestTableMaker method buildMUL2_EMPTable.

protected void buildMUL2_EMPTable() {
    TableDefinition tabledefinition = new TableDefinition();
    // SECTION: TABLE
    tabledefinition.setName("MUL2_EMP");
    // SECTION: FIELD
    FieldDefinition field1 = new FieldDefinition();
    field1.setName("EMP_ID");
    field1.setTypeName("NUMERIC");
    field1.setSize(10);
    field1.setShouldAllowNull(false);
    field1.setIsPrimaryKey(true);
    field1.setUnique(false);
    field1.setIsIdentity(false);
    tabledefinition.addField(field1);
    // SECTION: FIELD
    FieldDefinition field2 = new FieldDefinition();
    field2.setName("EMP_NUM");
    field2.setTypeName("NUMERIC");
    field2.setSize(10);
    field2.setShouldAllowNull(false);
    field2.setIsPrimaryKey(true);
    field2.setUnique(true);
    field2.setIsIdentity(false);
    tabledefinition.addField(field2);
    // SECTION: FIELD
    FieldDefinition field3 = new FieldDefinition();
    field3.setName("FNAME");
    field3.setTypeName("VARCHAR");
    field3.setSize(30);
    field3.setShouldAllowNull(true);
    field3.setIsPrimaryKey(false);
    field3.setUnique(false);
    field3.setIsIdentity(false);
    tabledefinition.addField(field3);
    addTableDefinition(tabledefinition);
}
Also used : FieldDefinition(org.eclipse.persistence.tools.schemaframework.FieldDefinition) TableDefinition(org.eclipse.persistence.tools.schemaframework.TableDefinition)

Example 3 with FieldDefinition

use of org.eclipse.persistence.tools.schemaframework.FieldDefinition in project eclipselink by eclipse-ee4j.

the class DatabasePlatform method writeCreateTempTableSql.

/**
 * INTERNAL:
 * Don't override this method.
 * Write an sql string for creation of the temporary table.
 * Note that in case of local temp table support it's possible to limit
 * the fields in the temp table to those needed for the operation it supports (usedFields) -
 * the temp table will be dropped in the end of query execution.
 * Alternatively, in global temp table case the table with a given name is created just once
 * and will be potentially used by various operations with various sets of used fields,
 * therefore global temp table should contain all mapped fields (allFields).
 * Precondition: supportsTempTables() == true.
 * Precondition: pkFields contained in usedFields contained in allFields
 * @param writer for writing the sql
 * @param table is original table for which temp table is created.
 * @param pkFields primary key fields for the original table.
 * @param usedFields fields that will be used by operation for which temp table is created.
 * @param allFields all mapped fields for the original table.
 */
public void writeCreateTempTableSql(Writer writer, DatabaseTable table, AbstractSession session, Collection<DatabaseField> pkFields, Collection<DatabaseField> usedFields, Collection<DatabaseField> allFields) throws IOException {
    String body = getCreateTempTableSqlBodyForTable(table);
    if (body == null) {
        TableDefinition tableDef = new TableDefinition();
        Collection<DatabaseField> fields;
        if (supportsLocalTempTables()) {
            fields = usedFields;
        } else {
            // supportsGlobalTempTables() == true
            fields = allFields;
        }
        Iterator<DatabaseField> itFields = fields.iterator();
        while (itFields.hasNext()) {
            DatabaseField field = itFields.next();
            FieldDefinition fieldDef;
            // gfbug3307, should use columnDefinition if it was defined.
            if ((field.getColumnDefinition() != null) && (field.getColumnDefinition().length() == 0)) {
                Class<?> type = ConversionManager.getObjectClass(field.getType());
                // Default type to VARCHAR, if unknown.
                if (type == null) {
                    type = ConversionManager.getObjectClass(ClassConstants.STRING);
                }
                fieldDef = new FieldDefinition(field.getNameDelimited(this), type);
            } else {
                fieldDef = new FieldDefinition(field.getNameDelimited(this), field.getColumnDefinition());
            }
            if (pkFields.contains(field) && shouldTempTableSpecifyPrimaryKeys()) {
                fieldDef.setIsPrimaryKey(true);
            }
            tableDef.addField(fieldDef);
        }
        tableDef.setCreationPrefix(getCreateTempTableSqlPrefix());
        tableDef.setName(getTempTableForTable(table).getQualifiedNameDelimited(this));
        tableDef.setCreationSuffix(getCreateTempTableSqlSuffix());
        tableDef.buildCreationWriter(session, writer);
    } else {
        writer.write(getCreateTempTableSqlPrefix());
        writer.write(getTempTableForTable(table).getQualifiedNameDelimited(this));
        writer.write(body);
        writer.write(getCreateTempTableSqlSuffix());
    }
}
Also used : ObjectRelationalDatabaseField(org.eclipse.persistence.mappings.structures.ObjectRelationalDatabaseField) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) FieldDefinition(org.eclipse.persistence.tools.schemaframework.FieldDefinition) TableDefinition(org.eclipse.persistence.tools.schemaframework.TableDefinition)

Example 4 with FieldDefinition

use of org.eclipse.persistence.tools.schemaframework.FieldDefinition in project eclipselink by eclipse-ee4j.

the class Builder method houseTableDefinition.

/**
 * Return a platform independent definition of the database table.
 */
public static TableDefinition houseTableDefinition() {
    TableDefinition definition = House.tableDefinition();
    definition.setName("BUILDER_HOUSE");
    for (int i = 0; i < definition.getFields().size(); i++) {
        FieldDefinition field = definition.getFields().get(i);
        if (field.getName().equals("AGENT_ID")) {
            field.setName("BUILDER_ID");
            break;
        }
    }
    return definition;
}
Also used : FieldDefinition(org.eclipse.persistence.tools.schemaframework.FieldDefinition) TableDefinition(org.eclipse.persistence.tools.schemaframework.TableDefinition)

Example 5 with FieldDefinition

use of org.eclipse.persistence.tools.schemaframework.FieldDefinition in project eclipselink by eclipse-ee4j.

the class Builder method customerTableDefinition.

/**
 * Return a platform independent definition of the database table.
 */
public static TableDefinition customerTableDefinition() {
    TableDefinition definition = Customer.tableDefinition();
    definition.setName("BUILDER_CUSTOMER");
    for (int i = 0; i < definition.getFields().size(); i++) {
        FieldDefinition field = definition.getFields().get(i);
        if (field.getName().equals("AGENT_ID")) {
            field.setName("BUILDER_ID");
            break;
        }
    }
    return definition;
}
Also used : FieldDefinition(org.eclipse.persistence.tools.schemaframework.FieldDefinition) TableDefinition(org.eclipse.persistence.tools.schemaframework.TableDefinition)

Aggregations

FieldDefinition (org.eclipse.persistence.tools.schemaframework.FieldDefinition)414 TableDefinition (org.eclipse.persistence.tools.schemaframework.TableDefinition)405 ForeignKeyConstraint (org.eclipse.persistence.tools.schemaframework.ForeignKeyConstraint)17 StoredProcedureDefinition (org.eclipse.persistence.tools.schemaframework.StoredProcedureDefinition)2 NonreflectiveMethodDefinition (org.eclipse.persistence.internal.codegen.NonreflectiveMethodDefinition)1 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)1 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)1 ObjectRelationalDatabaseField (org.eclipse.persistence.mappings.structures.ObjectRelationalDatabaseField)1