Search in sources :

Example 1 with UnaryTableSequence

use of org.eclipse.persistence.sequencing.UnaryTableSequence 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)

Example 2 with UnaryTableSequence

use of org.eclipse.persistence.sequencing.UnaryTableSequence in project eclipselink by eclipse-ee4j.

the class ProjectClassGenerator method setDefaultOrAddSequenceString.

protected String setDefaultOrAddSequenceString(Sequence sequence, boolean isSetDefault) {
    String prefix;
    if (isSetDefault) {
        prefix = "login.setDefaultSequence(new ";
    } else {
        prefix = "login.addSequence(new ";
    }
    String str;
    if (sequence instanceof TableSequence) {
        TableSequence ts = (TableSequence) sequence;
        str = "TableSequence(\"" + ts.getName() + "\", " + ts.getPreallocationSize() + ", \"" + ts.getTableName() + "\", \"" + ts.getNameFieldName() + "\", \"" + ts.getCounterFieldName() + "\"));";
    } else if (sequence instanceof UnaryTableSequence) {
        UnaryTableSequence uts = (UnaryTableSequence) sequence;
        str = "UnaryTableSequence(\"" + uts.getName() + "\", " + uts.getPreallocationSize() + ", \"" + uts.getCounterFieldName() + "\"));";
    } else {
        String typeName = Helper.getShortClassName(sequence);
        str = typeName + "(\"" + sequence.getName() + "\", " + sequence.getPreallocationSize() + "));";
    }
    return prefix + str;
}
Also used : UnaryTableSequence(org.eclipse.persistence.sequencing.UnaryTableSequence) UnaryTableSequence(org.eclipse.persistence.sequencing.UnaryTableSequence) TableSequence(org.eclipse.persistence.sequencing.TableSequence)

Example 3 with UnaryTableSequence

use of org.eclipse.persistence.sequencing.UnaryTableSequence in project eclipselink by eclipse-ee4j.

the class UnaryTableSequencingTestSuite method setUp.

@BeforeClass
public static void setUp() {
    session = createSession();
    dynamicHelper = new DynamicHelper(session);
    DynamicClassLoader dcl = dynamicHelper.getDynamicClassLoader();
    Class<?> dynamicType = dcl.createDynamicClass("simple.sequencing." + ENTITY_TYPE);
    DynamicTypeBuilder typeBuilder = new DynamicTypeBuilder(dynamicType, null, TABLE_NAME);
    typeBuilder.setPrimaryKeyFields("SID");
    typeBuilder.addDirectMapping("id", int.class, "SID");
    typeBuilder.addDirectMapping("value1", String.class, "VAL_1");
    // configureSequencing
    UnaryTableSequence sequence = new UnaryTableSequence(SEQ_TABLE_NAME);
    sequence.setCounterFieldName("SEQ_VALUE");
    sequence.setPreallocationSize(5);
    session.getProject().getLogin().setDefaultSequence(sequence);
    sequence.onConnect(session.getPlatform());
    typeBuilder.configureSequencing(sequence, SEQ_TABLE_NAME, "SID");
    dynamicHelper.addTypes(true, true, typeBuilder.getType());
}
Also used : DynamicClassLoader(org.eclipse.persistence.dynamic.DynamicClassLoader) DynamicHelper(org.eclipse.persistence.dynamic.DynamicHelper) DynamicTypeBuilder(org.eclipse.persistence.dynamic.DynamicTypeBuilder) UnaryTableSequence(org.eclipse.persistence.sequencing.UnaryTableSequence) BeforeClass(org.junit.BeforeClass)

Example 4 with UnaryTableSequence

use of org.eclipse.persistence.sequencing.UnaryTableSequence in project eclipselink by eclipse-ee4j.

the class UnaryTableSequencingTestSuite method setUp.

@BeforeClass
public static void setUp() {
    emf = DynamicTestHelper.createEMF(DYNAMIC_PERSISTENCE_NAME);
    helper = new JPADynamicHelper(emf);
    DynamicClassLoader dcl = helper.getDynamicClassLoader();
    UnaryTableSequence sequence = new UnaryTableSequence(SEQ_TABLE_NAME);
    sequence.setCounterFieldName("SEQ_VALUE");
    sequence.setPreallocationSize(5);
    helper.getSession().getProject().getLogin().setDefaultSequence(sequence);
    sequence.onConnect(helper.getSession().getPlatform());
    Class<?> javaType = dcl.createDynamicClass("model.sequencing." + ENTITY_TYPE);
    DynamicTypeBuilder typeBuilder = new JPADynamicTypeBuilder(javaType, null, TABLE_NAME);
    typeBuilder.setPrimaryKeyFields("SID");
    typeBuilder.addDirectMapping("id", int.class, "SID");
    typeBuilder.addDirectMapping("value1", String.class, "VAL_1");
    typeBuilder.configureSequencing(sequence, SEQ_TABLE_NAME, "SID");
    helper.addTypes(true, true, typeBuilder.getType());
}
Also used : DynamicClassLoader(org.eclipse.persistence.dynamic.DynamicClassLoader) JPADynamicTypeBuilder(org.eclipse.persistence.jpa.dynamic.JPADynamicTypeBuilder) UnaryTableSequence(org.eclipse.persistence.sequencing.UnaryTableSequence) JPADynamicTypeBuilder(org.eclipse.persistence.jpa.dynamic.JPADynamicTypeBuilder) DynamicTypeBuilder(org.eclipse.persistence.dynamic.DynamicTypeBuilder) JPADynamicHelper(org.eclipse.persistence.jpa.dynamic.JPADynamicHelper) BeforeClass(org.junit.BeforeClass)

Aggregations

UnaryTableSequence (org.eclipse.persistence.sequencing.UnaryTableSequence)4 DynamicClassLoader (org.eclipse.persistence.dynamic.DynamicClassLoader)2 DynamicTypeBuilder (org.eclipse.persistence.dynamic.DynamicTypeBuilder)2 TableSequence (org.eclipse.persistence.sequencing.TableSequence)2 BeforeClass (org.junit.BeforeClass)2 PrivilegedActionException (java.security.PrivilegedActionException)1 DynamicHelper (org.eclipse.persistence.dynamic.DynamicHelper)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 JPADynamicHelper (org.eclipse.persistence.jpa.dynamic.JPADynamicHelper)1 JPADynamicTypeBuilder (org.eclipse.persistence.jpa.dynamic.JPADynamicTypeBuilder)1 DefaultSequence (org.eclipse.persistence.sequencing.DefaultSequence)1 NativeSequence (org.eclipse.persistence.sequencing.NativeSequence)1 Sequence (org.eclipse.persistence.sequencing.Sequence)1