Search in sources :

Example 1 with TableSequenceConfig

use of org.eclipse.persistence.internal.sessions.factories.model.sequencing.TableSequenceConfig in project eclipselink by eclipse-ee4j.

the class SessionsFactory method buildSequence.

/**
 * INTERNAL:
 * Builds a Sequence from the given SequenceConfig.
 */
protected Sequence buildSequence(SequenceConfig sequenceConfig) {
    if (sequenceConfig == null) {
        return null;
    }
    String name = sequenceConfig.getName();
    int size = sequenceConfig.getPreallocationSize();
    if (sequenceConfig instanceof DefaultSequenceConfig) {
        return new DefaultSequence(name, size);
    } else if (sequenceConfig instanceof NativeSequenceConfig) {
        return new NativeSequence(name, size);
    } else if (sequenceConfig instanceof TableSequenceConfig) {
        TableSequenceConfig tsc = (TableSequenceConfig) sequenceConfig;
        return new TableSequence(name, size, tsc.getTable(), tsc.getNameField(), tsc.getCounterField());
    } else if (sequenceConfig instanceof UnaryTableSequenceConfig) {
        UnaryTableSequenceConfig utsc = (UnaryTableSequenceConfig) sequenceConfig;
        return new UnaryTableSequence(name, size, utsc.getCounterField());
    } else if (sequenceConfig instanceof XMLFileSequenceConfig) {
        try {
            // Can no longer reference class directly as in a different project.
            @SuppressWarnings({ "unchecked" }) Class<Sequence> xmlClass = (Class<Sequence>) Class.forName("org.eclipse.persistence.eis.adapters.xmlfile.XMLFileSequence");
            Sequence sequence = xmlClass.getConstructor().newInstance();
            sequence.setName(name);
            sequence.setInitialValue(size);
            return sequence;
        } catch (Exception missing) {
            return null;
        }
    } else {
        // Unknown SequenceConfig subclass - should never happen
        return null;
    }
}
Also used : UnaryTableSequenceConfig(org.eclipse.persistence.internal.sessions.factories.model.sequencing.UnaryTableSequenceConfig) Sequence(org.eclipse.persistence.sequencing.Sequence) NativeSequence(org.eclipse.persistence.sequencing.NativeSequence) DefaultSequence(org.eclipse.persistence.sequencing.DefaultSequence) UnaryTableSequence(org.eclipse.persistence.sequencing.UnaryTableSequence) TableSequence(org.eclipse.persistence.sequencing.TableSequence) XMLFileSequenceConfig(org.eclipse.persistence.internal.sessions.factories.model.sequencing.XMLFileSequenceConfig) ValidationException(org.eclipse.persistence.exceptions.ValidationException) PrivilegedActionException(java.security.PrivilegedActionException) SessionLoaderException(org.eclipse.persistence.exceptions.SessionLoaderException) UnaryTableSequence(org.eclipse.persistence.sequencing.UnaryTableSequence) TableSequence(org.eclipse.persistence.sequencing.TableSequence) DefaultSequenceConfig(org.eclipse.persistence.internal.sessions.factories.model.sequencing.DefaultSequenceConfig) NativeSequenceConfig(org.eclipse.persistence.internal.sessions.factories.model.sequencing.NativeSequenceConfig) NativeSequence(org.eclipse.persistence.sequencing.NativeSequence) UnaryTableSequenceConfig(org.eclipse.persistence.internal.sessions.factories.model.sequencing.UnaryTableSequenceConfig) TableSequenceConfig(org.eclipse.persistence.internal.sessions.factories.model.sequencing.TableSequenceConfig) DefaultSequence(org.eclipse.persistence.sequencing.DefaultSequence) PrivilegedNewInstanceFromClass(org.eclipse.persistence.internal.security.PrivilegedNewInstanceFromClass) UnaryTableSequence(org.eclipse.persistence.sequencing.UnaryTableSequence)

Aggregations

PrivilegedActionException (java.security.PrivilegedActionException)1 SessionLoaderException (org.eclipse.persistence.exceptions.SessionLoaderException)1 ValidationException (org.eclipse.persistence.exceptions.ValidationException)1 PrivilegedNewInstanceFromClass (org.eclipse.persistence.internal.security.PrivilegedNewInstanceFromClass)1 DefaultSequenceConfig (org.eclipse.persistence.internal.sessions.factories.model.sequencing.DefaultSequenceConfig)1 NativeSequenceConfig (org.eclipse.persistence.internal.sessions.factories.model.sequencing.NativeSequenceConfig)1 TableSequenceConfig (org.eclipse.persistence.internal.sessions.factories.model.sequencing.TableSequenceConfig)1 UnaryTableSequenceConfig (org.eclipse.persistence.internal.sessions.factories.model.sequencing.UnaryTableSequenceConfig)1 XMLFileSequenceConfig (org.eclipse.persistence.internal.sessions.factories.model.sequencing.XMLFileSequenceConfig)1 DefaultSequence (org.eclipse.persistence.sequencing.DefaultSequence)1 NativeSequence (org.eclipse.persistence.sequencing.NativeSequence)1 Sequence (org.eclipse.persistence.sequencing.Sequence)1 TableSequence (org.eclipse.persistence.sequencing.TableSequence)1 UnaryTableSequence (org.eclipse.persistence.sequencing.UnaryTableSequence)1