Search in sources :

Example 1 with SequenceGeneratorMetadata

use of org.eclipse.persistence.internal.jpa.metadata.sequencing.SequenceGeneratorMetadata in project eclipselink by eclipse-ee4j.

the class MetadataProject method addTableGenerator.

/**
 * INTERNAL:
 * Add a table generator metadata to the project. The actual processing
 * isn't done till processSequencing is called.
 */
public void addTableGenerator(TableGeneratorMetadata tableGenerator, String defaultCatalog, String defaultSchema) {
    // Process the default values.
    processTable(tableGenerator, "", defaultCatalog, defaultSchema, tableGenerator);
    String generatorName = tableGenerator.getGeneratorName();
    // Check if the table generator name uses a reserved name.
    if (generatorName.equals(DEFAULT_SEQUENCE_GENERATOR)) {
        throw ValidationException.tableGeneratorUsingAReservedName(DEFAULT_SEQUENCE_GENERATOR, tableGenerator.getLocation());
    } else if (generatorName.equals(DEFAULT_IDENTITY_GENERATOR)) {
        throw ValidationException.tableGeneratorUsingAReservedName(DEFAULT_IDENTITY_GENERATOR, tableGenerator.getLocation());
    }
    // Check if the generator name is used with a sequence generator.
    SequenceGeneratorMetadata otherSequenceGenerator = m_sequenceGenerators.get(generatorName);
    if (otherSequenceGenerator != null) {
        if (tableGenerator.shouldOverride(otherSequenceGenerator)) {
            m_sequenceGenerators.remove(generatorName);
        } else {
            throw ValidationException.conflictingSequenceAndTableGeneratorsSpecified(generatorName, otherSequenceGenerator.getLocation(), tableGenerator.getLocation());
        }
    }
    for (SequenceGeneratorMetadata sequenceGenerator : m_sequenceGenerators.values()) {
        if ((otherSequenceGenerator != sequenceGenerator) && (sequenceGenerator.getSequenceName() != null) && sequenceGenerator.getSequenceName().equals(tableGenerator.getPkColumnValue())) {
            // generator name will be used instead of an empty sequence name / pk column name
            if (sequenceGenerator.getSequenceName().length() > 0) {
                throw ValidationException.conflictingSequenceNameAndTablePkColumnValueSpecified(sequenceGenerator.getSequenceName(), sequenceGenerator.getLocation(), tableGenerator.getLocation());
            }
        }
    }
    // should override an existing one.
    if (tableGenerator.shouldOverride(m_tableGenerators.get(generatorName))) {
        m_tableGenerators.put(generatorName, tableGenerator);
    }
}
Also used : SequenceGeneratorMetadata(org.eclipse.persistence.internal.jpa.metadata.sequencing.SequenceGeneratorMetadata)

Example 2 with SequenceGeneratorMetadata

use of org.eclipse.persistence.internal.jpa.metadata.sequencing.SequenceGeneratorMetadata in project eclipselink by eclipse-ee4j.

the class MetadataProject method processSequencingAccessors.

/**
 * INTERNAL:
 * Process the sequencing information. At this point, through validation, it
 * is not possible to have:
 *   1 - a table generator with the generator name equal to
 *       DEFAULT_SEQUENCE_GENERATOR or DEFAULT_IDENTITY_GENERATOR
 *   2 - a sequence generator with the name eqaul to DEFAULT_TABLE_GENERATOR
 *       or DEFAULT_IDENTITY_GENERATOR
 *   3 - you can't have both a sequence generator and a table generator with
 *       the same DEFAULT_AUTO_GENERATOR name.
 *
 * @see addTableGenerator and addSequenceGenerator.
 */
protected void processSequencingAccessors() {
    if (!m_generatedValues.isEmpty()) {
        // 1 - Build our map of sequences keyed on generator names.
        Hashtable<String, Sequence> sequences = new Hashtable<String, Sequence>();
        for (SequenceGeneratorMetadata sequenceGenerator : m_sequenceGenerators.values()) {
            sequences.put(sequenceGenerator.getName(), sequenceGenerator.process(m_logger));
        }
        for (UuidGeneratorMetadata uuidGenerator : m_uuidGenerators.values()) {
            sequences.put(uuidGenerator.getName(), uuidGenerator.process(m_logger));
        }
        for (TableGeneratorMetadata tableGenerator : m_tableGenerators.values()) {
            sequences.put(tableGenerator.getGeneratorName(), tableGenerator.process(m_logger));
        }
        // create them using the Table and Sequence generator metadata.
        if (!sequences.containsKey(DEFAULT_TABLE_GENERATOR)) {
            TableGeneratorMetadata tableGenerator = new TableGeneratorMetadata(DEFAULT_TABLE_GENERATOR);
            // This code was attempting to use the platform default sequence name,
            // however the platform has not been set yet, so it would never work,
            // it was also causing the platform default sequence to be set, causing the DatabasePlatform default to be used,
            // so I am removing this code, as it breaks the platform default sequence and does not work.
            // Sequence seq = m_session.getDatasourcePlatform().getDefaultSequence();
            // Using "" as the default should make the platform default it.
            String defaultTableGeneratorName = "";
            // Process the default values.
            processTable(tableGenerator, defaultTableGeneratorName, getPersistenceUnitDefaultCatalog(), getPersistenceUnitDefaultSchema(), tableGenerator);
            sequences.put(DEFAULT_TABLE_GENERATOR, tableGenerator.process(m_logger));
        }
        if (!sequences.containsKey(DEFAULT_SEQUENCE_GENERATOR)) {
            sequences.put(DEFAULT_SEQUENCE_GENERATOR, new SequenceGeneratorMetadata(DEFAULT_SEQUENCE_GENERATOR, getPersistenceUnitDefaultCatalog(), getPersistenceUnitDefaultSchema()).process(m_logger));
        }
        if (!sequences.containsKey(DEFAULT_IDENTITY_GENERATOR)) {
            sequences.put(DEFAULT_IDENTITY_GENERATOR, new SequenceGeneratorMetadata(DEFAULT_IDENTITY_GENERATOR, 1, getPersistenceUnitDefaultCatalog(), getPersistenceUnitDefaultSchema(), true).process(m_logger));
        }
        if (!sequences.containsKey(DEFAULT_UUID_GENERATOR)) {
            sequences.put(DEFAULT_UUID_GENERATOR, new UuidGeneratorMetadata().process(m_logger));
        }
        // Use a temporary sequence generator to build a qualifier to set on
        // the default generator. Don't use this generator as the default
        // auto generator though.
        SequenceGeneratorMetadata tempGenerator = new SequenceGeneratorMetadata(DEFAULT_AUTO_GENERATOR, getPersistenceUnitDefaultCatalog(), getPersistenceUnitDefaultSchema());
        DatasourceLogin login = m_session.getProject().getLogin();
        login.setTableQualifier(tempGenerator.processQualifier());
        // 3 - Loop through generated values and set sequences for each.
        for (MetadataClass entityClass : m_generatedValues.keySet()) {
            // Skip setting sequences if our accessor is null, must be a mapped superclass
            ClassAccessor accessor = m_allAccessors.get(entityClass.getName());
            if (accessor != null) {
                m_generatedValues.get(entityClass).process(accessor.getDescriptor(), sequences, login);
            }
        }
    }
}
Also used : DatasourceLogin(org.eclipse.persistence.sessions.DatasourceLogin) SequenceGeneratorMetadata(org.eclipse.persistence.internal.jpa.metadata.sequencing.SequenceGeneratorMetadata) UuidGeneratorMetadata(org.eclipse.persistence.internal.jpa.metadata.sequencing.UuidGeneratorMetadata) MetadataClass(org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataClass) ClassAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor) Hashtable(java.util.Hashtable) TableGeneratorMetadata(org.eclipse.persistence.internal.jpa.metadata.sequencing.TableGeneratorMetadata) Sequence(org.eclipse.persistence.sequencing.Sequence)

Example 3 with SequenceGeneratorMetadata

use of org.eclipse.persistence.internal.jpa.metadata.sequencing.SequenceGeneratorMetadata in project eclipselink by eclipse-ee4j.

the class XMLEntityMappings method process.

/**
 * INTERNAL:
 * Process the metadata from the &lt;entity-mappings&gt; level except for the
 * classes themselves. They will be processed afterwards and controlled
 * by the MetadataProcessor. Note: this method does a few things of
 * interest. It not only adds metadata to the project but it will also
 * override (that is EclipseLink-ORM-XML--&gt;JPA-XML {@literal &&} JPA-XML--&gt;Annotation)
 * the necessary metadata and log messages to the user. A validation
 * exception could also be thrown. See the related processing methods for
 * more details.
 *
 * Any XML metadata of the types processed below should call these methods.
 * That is, as an example, a converter can be found at the entity-mappings
 * and entity level. Therefore you must ensure that those from levels other
 * than the entity-mappings call these methods as well to ensure consistent
 * metadata processing (and behavior).
 */
public void process() {
    // Add the XML converters to the project.
    for (ConverterMetadata converter : m_converters) {
        converter.initXMLObject(m_file, this);
        m_project.addConverter(converter);
    }
    // Add the XML type converters to the project.
    for (TypeConverterMetadata typeConverter : m_typeConverters) {
        typeConverter.initXMLObject(m_file, this);
        m_project.addConverter(typeConverter);
    }
    // Add the XML object type converters to the project.
    for (ObjectTypeConverterMetadata objectTypeConverter : m_objectTypeConverters) {
        objectTypeConverter.initXMLObject(m_file, this);
        m_project.addConverter(objectTypeConverter);
    }
    // Add the XML serialized converters to the project.
    for (SerializedConverterMetadata serializedConverter : m_serializedConverters) {
        serializedConverter.initXMLObject(m_file, this);
        m_project.addConverter(serializedConverter);
    }
    // Add the XML struct converters to the project.
    for (StructConverterMetadata structConverter : m_structConverters) {
        structConverter.initXMLObject(m_file, this);
        m_project.addConverter(structConverter);
    }
    // Add the XML table generators to the project.
    for (TableGeneratorMetadata tableGenerator : m_tableGenerators) {
        tableGenerator.initXMLObject(m_file, this);
        m_project.addTableGenerator(tableGenerator, getDefaultCatalog(), getDefaultSchema());
    }
    // Add the XML sequence generators to the project.
    for (SequenceGeneratorMetadata sequenceGenerator : m_sequenceGenerators) {
        sequenceGenerator.initXMLObject(m_file, this);
        m_project.addSequenceGenerator(sequenceGenerator, getDefaultCatalog(), getDefaultSchema());
    }
    // Add the XML uuid generators to the project.
    for (UuidGeneratorMetadata uuidGenerator : m_uuidGenerators) {
        uuidGenerator.initXMLObject(m_file, this);
        m_project.addUuidGenerator(uuidGenerator);
    }
    // Add the partitioning to the project.
    for (PartitioningMetadata partitioning : m_partitioning) {
        partitioning.initXMLObject(m_file, this);
        m_project.addPartitioningPolicy(partitioning);
    }
    // Add the replication partitioning to the project.
    for (ReplicationPartitioningMetadata partitioning : m_replicationPartitioning) {
        partitioning.initXMLObject(m_file, this);
        m_project.addPartitioningPolicy(partitioning);
    }
    // Add the round robin partitioning to the project.
    for (RoundRobinPartitioningMetadata partitioning : m_roundRobinPartitioning) {
        partitioning.initXMLObject(m_file, this);
        m_project.addPartitioningPolicy(partitioning);
    }
    // Add the pinned partitioning to the project.
    for (PinnedPartitioningMetadata partitioning : m_pinnedPartitioning) {
        partitioning.initXMLObject(m_file, this);
        m_project.addPartitioningPolicy(partitioning);
    }
    // Add the range partitioning to the project.
    for (RangePartitioningMetadata partitioning : m_rangePartitioning) {
        partitioning.initXMLObject(m_file, this);
        m_project.addPartitioningPolicy(partitioning);
    }
    // Add the value partitioning to the project.
    for (ValuePartitioningMetadata partitioning : m_valuePartitioning) {
        partitioning.initXMLObject(m_file, this);
        m_project.addPartitioningPolicy(partitioning);
    }
    // Add the hash partitioning to the project.
    for (HashPartitioningMetadata partitioning : m_hashPartitioning) {
        partitioning.initXMLObject(m_file, this);
        m_project.addPartitioningPolicy(partitioning);
    }
    // Add the XML named queries to the project.
    for (NamedQueryMetadata namedQuery : m_namedQueries) {
        namedQuery.initXMLObject(m_file, this);
        m_project.addQuery(namedQuery);
    }
    // Add the XML named native queries to the project.
    for (NamedNativeQueryMetadata namedNativeQuery : m_namedNativeQueries) {
        namedNativeQuery.initXMLObject(m_file, this);
        m_project.addQuery(namedNativeQuery);
    }
    // Add the XML named stored procedure queries to the project.
    for (NamedStoredProcedureQueryMetadata namedStoredProcedureQuery : m_namedStoredProcedureQueries) {
        namedStoredProcedureQuery.initXMLObject(m_file, this);
        m_project.addQuery(namedStoredProcedureQuery);
    }
    // Add the XML named stored function queries to the project.
    for (NamedStoredFunctionQueryMetadata namedStoredFunctionQuery : m_namedStoredFunctionQueries) {
        namedStoredFunctionQuery.initXMLObject(m_file, this);
        m_project.addQuery(namedStoredFunctionQuery);
    }
    // Add the XML named stored procedure queries to the project.
    for (NamedPLSQLStoredProcedureQueryMetadata namedPLSQLStoredProcedureQuery : m_namedPLSQLStoredProcedureQueries) {
        namedPLSQLStoredProcedureQuery.initXMLObject(m_file, this);
        m_project.addQuery(namedPLSQLStoredProcedureQuery);
    }
    // Add the XML named stored function queries to the project.
    for (NamedPLSQLStoredFunctionQueryMetadata namedPLSQLStoredFunctionQuery : m_namedPLSQLStoredFunctionQueries) {
        namedPLSQLStoredFunctionQuery.initXMLObject(m_file, this);
        m_project.addQuery(namedPLSQLStoredFunctionQuery);
    }
    // Add the XML sql result set mappings to the project.
    for (SQLResultSetMappingMetadata sqlResultSetMapping : m_sqlResultSetMappings) {
        sqlResultSetMapping.initXMLObject(m_file, this);
        m_project.addSQLResultSetMapping(sqlResultSetMapping);
    }
    // Add the Oracle object types to the project.
    for (OracleObjectTypeMetadata oType : m_oracleObjectTypes) {
        oType.initXMLObject(m_file, this);
        m_project.addComplexMetadataType(oType);
    }
    // Add the Oracle array types to the project.
    for (OracleArrayTypeMetadata aType : m_oracleArrayTypes) {
        aType.initXMLObject(m_file, this);
        m_project.addComplexMetadataType(aType);
    }
    // Add the PLSQL types to the project.
    for (PLSQLRecordMetadata record : m_plsqlRecords) {
        record.initXMLObject(m_file, this);
        m_project.addComplexMetadataType(record);
    }
    // Add the PLSQL tables to the project.
    for (PLSQLTableMetadata table : m_plsqlTables) {
        table.initXMLObject(m_file, this);
        m_project.addComplexMetadataType(table);
    }
}
Also used : NamedStoredFunctionQueryMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.NamedStoredFunctionQueryMetadata) RoundRobinPartitioningMetadata(org.eclipse.persistence.internal.jpa.metadata.partitioning.RoundRobinPartitioningMetadata) PLSQLRecordMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.PLSQLRecordMetadata) PinnedPartitioningMetadata(org.eclipse.persistence.internal.jpa.metadata.partitioning.PinnedPartitioningMetadata) TypeConverterMetadata(org.eclipse.persistence.internal.jpa.metadata.converters.TypeConverterMetadata) ObjectTypeConverterMetadata(org.eclipse.persistence.internal.jpa.metadata.converters.ObjectTypeConverterMetadata) ReplicationPartitioningMetadata(org.eclipse.persistence.internal.jpa.metadata.partitioning.ReplicationPartitioningMetadata) TableGeneratorMetadata(org.eclipse.persistence.internal.jpa.metadata.sequencing.TableGeneratorMetadata) HashPartitioningMetadata(org.eclipse.persistence.internal.jpa.metadata.partitioning.HashPartitioningMetadata) OracleArrayTypeMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.OracleArrayTypeMetadata) StructConverterMetadata(org.eclipse.persistence.internal.jpa.metadata.converters.StructConverterMetadata) RangePartitioningMetadata(org.eclipse.persistence.internal.jpa.metadata.partitioning.RangePartitioningMetadata) NamedStoredProcedureQueryMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.NamedStoredProcedureQueryMetadata) NamedQueryMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.NamedQueryMetadata) StructConverterMetadata(org.eclipse.persistence.internal.jpa.metadata.converters.StructConverterMetadata) SerializedConverterMetadata(org.eclipse.persistence.internal.jpa.metadata.converters.SerializedConverterMetadata) TypeConverterMetadata(org.eclipse.persistence.internal.jpa.metadata.converters.TypeConverterMetadata) ConverterMetadata(org.eclipse.persistence.internal.jpa.metadata.converters.ConverterMetadata) MixedConverterMetadata(org.eclipse.persistence.internal.jpa.metadata.converters.MixedConverterMetadata) ObjectTypeConverterMetadata(org.eclipse.persistence.internal.jpa.metadata.converters.ObjectTypeConverterMetadata) SequenceGeneratorMetadata(org.eclipse.persistence.internal.jpa.metadata.sequencing.SequenceGeneratorMetadata) OracleObjectTypeMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.OracleObjectTypeMetadata) UuidGeneratorMetadata(org.eclipse.persistence.internal.jpa.metadata.sequencing.UuidGeneratorMetadata) SQLResultSetMappingMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.SQLResultSetMappingMetadata) ObjectTypeConverterMetadata(org.eclipse.persistence.internal.jpa.metadata.converters.ObjectTypeConverterMetadata) ValuePartitioningMetadata(org.eclipse.persistence.internal.jpa.metadata.partitioning.ValuePartitioningMetadata) SerializedConverterMetadata(org.eclipse.persistence.internal.jpa.metadata.converters.SerializedConverterMetadata) PLSQLTableMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.PLSQLTableMetadata) NamedPLSQLStoredProcedureQueryMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.NamedPLSQLStoredProcedureQueryMetadata) NamedNativeQueryMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.NamedNativeQueryMetadata) PartitioningMetadata(org.eclipse.persistence.internal.jpa.metadata.partitioning.PartitioningMetadata) UnionPartitioningMetadata(org.eclipse.persistence.internal.jpa.metadata.partitioning.UnionPartitioningMetadata) ReplicationPartitioningMetadata(org.eclipse.persistence.internal.jpa.metadata.partitioning.ReplicationPartitioningMetadata) RoundRobinPartitioningMetadata(org.eclipse.persistence.internal.jpa.metadata.partitioning.RoundRobinPartitioningMetadata) HashPartitioningMetadata(org.eclipse.persistence.internal.jpa.metadata.partitioning.HashPartitioningMetadata) RangePartitioningMetadata(org.eclipse.persistence.internal.jpa.metadata.partitioning.RangePartitioningMetadata) ValuePartitioningMetadata(org.eclipse.persistence.internal.jpa.metadata.partitioning.ValuePartitioningMetadata) PinnedPartitioningMetadata(org.eclipse.persistence.internal.jpa.metadata.partitioning.PinnedPartitioningMetadata) NamedPLSQLStoredFunctionQueryMetadata(org.eclipse.persistence.internal.jpa.metadata.queries.NamedPLSQLStoredFunctionQueryMetadata)

Aggregations

SequenceGeneratorMetadata (org.eclipse.persistence.internal.jpa.metadata.sequencing.SequenceGeneratorMetadata)3 TableGeneratorMetadata (org.eclipse.persistence.internal.jpa.metadata.sequencing.TableGeneratorMetadata)2 UuidGeneratorMetadata (org.eclipse.persistence.internal.jpa.metadata.sequencing.UuidGeneratorMetadata)2 Hashtable (java.util.Hashtable)1 ClassAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor)1 MetadataClass (org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataClass)1 ConverterMetadata (org.eclipse.persistence.internal.jpa.metadata.converters.ConverterMetadata)1 MixedConverterMetadata (org.eclipse.persistence.internal.jpa.metadata.converters.MixedConverterMetadata)1 ObjectTypeConverterMetadata (org.eclipse.persistence.internal.jpa.metadata.converters.ObjectTypeConverterMetadata)1 SerializedConverterMetadata (org.eclipse.persistence.internal.jpa.metadata.converters.SerializedConverterMetadata)1 StructConverterMetadata (org.eclipse.persistence.internal.jpa.metadata.converters.StructConverterMetadata)1 TypeConverterMetadata (org.eclipse.persistence.internal.jpa.metadata.converters.TypeConverterMetadata)1 HashPartitioningMetadata (org.eclipse.persistence.internal.jpa.metadata.partitioning.HashPartitioningMetadata)1 PartitioningMetadata (org.eclipse.persistence.internal.jpa.metadata.partitioning.PartitioningMetadata)1 PinnedPartitioningMetadata (org.eclipse.persistence.internal.jpa.metadata.partitioning.PinnedPartitioningMetadata)1 RangePartitioningMetadata (org.eclipse.persistence.internal.jpa.metadata.partitioning.RangePartitioningMetadata)1 ReplicationPartitioningMetadata (org.eclipse.persistence.internal.jpa.metadata.partitioning.ReplicationPartitioningMetadata)1 RoundRobinPartitioningMetadata (org.eclipse.persistence.internal.jpa.metadata.partitioning.RoundRobinPartitioningMetadata)1 UnionPartitioningMetadata (org.eclipse.persistence.internal.jpa.metadata.partitioning.UnionPartitioningMetadata)1 ValuePartitioningMetadata (org.eclipse.persistence.internal.jpa.metadata.partitioning.ValuePartitioningMetadata)1