Search in sources :

Example 26 with SchemaManager

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

the class DistributedSystem method createTables.

@Override
public void createTables(DatabaseSession session) {
    SchemaManager schemaManager = new SchemaManager(session);
    // Start Build fieldTypes
    schemaManager.buildFieldTypes(Dist_Employee.tableDefinition());
    schemaManager.buildFieldTypes(Company.tableDefinition());
    schemaManager.buildFieldTypes(Item.tableDefinition());
    // start drop constraints
    try {
        schemaManager.dropConstraints(Dist_Employee.tableDefinition());
        schemaManager.dropConstraints(Company.tableDefinition());
        schemaManager.dropConstraints(Item.tableDefinition());
    } catch (org.eclipse.persistence.exceptions.DatabaseException dbE) {
    // ignore
    }
    // end drop constraints
    // start replace tables
    schemaManager.replaceObject(Dist_Employee.tableDefinition());
    schemaManager.replaceObject(Company.tableDefinition());
    schemaManager.replaceObject(Item.tableDefinition());
    // end replace tables
    // start create constraints
    schemaManager.createConstraints(Dist_Employee.tableDefinition());
    schemaManager.createConstraints(Company.tableDefinition());
    schemaManager.createConstraints(Item.tableDefinition());
    // end create constraints
    schemaManager.createSequences();
}
Also used : SchemaManager(org.eclipse.persistence.tools.schemaframework.SchemaManager)

Example 27 with SchemaManager

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

the class SubstituteSequencingWithReturningPolicyAdapter method createSequences.

public void createSequences(Session session) {
    if (!session.getPlatform().supportsSequenceObjects()) {
        throw new TestWarningException("Requires database platform that supports sequence objects (like Oracle) - they will be used by triggers");
    }
    SchemaManager schemaManager = new SchemaManager((DatabaseSession) session);
    Hashtable sequenceNameToDefinition = new Hashtable();
    Enumeration tableNames = tableToField.keys();
    while (tableNames.hasMoreElements()) {
        String tableName = (String) tableNames.nextElement();
        String sequenceName = getSequenceNameFromTableName(tableName);
        if (!sequenceNameToDefinition.containsKey(sequenceName)) {
            SequenceObjectDefinition definition = new SequenceObjectDefinition(new NativeSequence(sequenceName, 1, false));
            sequenceNameToDefinition.put(sequenceName, definition);
            schemaManager.createObject(definition);
        }
    }
}
Also used : NativeSequence(org.eclipse.persistence.sequencing.NativeSequence) SequenceObjectDefinition(org.eclipse.persistence.tools.schemaframework.SequenceObjectDefinition) SchemaManager(org.eclipse.persistence.tools.schemaframework.SchemaManager)

Example 28 with SchemaManager

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

the class RMISessionBrokerRemoteModel method createTables.

public void createTables() {
    SessionBroker broker = new SessionBroker();
    DatabaseSession session1 = new DatabaseSessionImpl(Server.getLogin1());
    DatabaseSession session2 = new DatabaseSessionImpl(Server.getLogin2());
    session1.addDescriptors(new EmployeeProject1());
    session2.addDescriptors(new EmployeeProject2());
    broker.registerSession("broker1", session1);
    broker.registerSession("broker2", session2);
    broker.setLogLevel(getSession().getLogLevel());
    broker.setLog(getSession().getLog());
    broker.login();
    // Set session for join table.
    ((ManyToManyMapping) session1.getDescriptor(Employee.class).getObjectBuilder().getMappingForAttributeName("projects")).setSessionName("broker2");
    // Disable delete verify.
    ((OneToOneMapping) session1.getDescriptor(Employee.class).getObjectBuilder().getMappingForAttributeName("address")).setShouldVerifyDelete(false);
    org.eclipse.persistence.testing.models.employee.relational.EmployeeTableCreator tables = new org.eclipse.persistence.testing.models.employee.relational.EmployeeTableCreator();
    tables.replaceTables(session1);
    tables.replaceTables(session2);
    tables.dropConstraints(session1);
    tables.dropConstraints(session2);
    new SchemaManager(session1).createSequences();
    new SchemaManager(session2).createSequences();
    broker.logout();
}
Also used : ManyToManyMapping(org.eclipse.persistence.mappings.ManyToManyMapping) DatabaseSession(org.eclipse.persistence.sessions.DatabaseSession) SessionBroker(org.eclipse.persistence.sessions.broker.SessionBroker) SchemaManager(org.eclipse.persistence.tools.schemaframework.SchemaManager) Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) DatabaseSessionImpl(org.eclipse.persistence.internal.sessions.DatabaseSessionImpl) OneToOneMapping(org.eclipse.persistence.mappings.OneToOneMapping)

Example 29 with SchemaManager

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

the class ReadOnlySystem method createTables.

@Override
public void createTables(DatabaseSession session) {
    SchemaManager schemaManager = new SchemaManager(session);
    schemaManager.replaceObject(Promoter.tableDefinition());
    schemaManager.replaceObject(Actor.tableDefinition());
    schemaManager.replaceObject(Actor.actorMovieJoinTableDefinition());
    schemaManager.replaceObject(Actor.actorCharityJoinTableDefinition());
    schemaManager.replaceObject(Address.tableDefinition());
    schemaManager.replaceObject(Charity.tableDefinition());
    schemaManager.replaceObject(HollywoodAgent.tableDefinition());
    schemaManager.replaceObject(Movie.tableDefinition());
    schemaManager.replaceObject(Country.tableDefinition());
    // schemaManager.replaceObject(PhoneNumber.tableDefinition());
    schemaManager.replaceObject(DefaultReadOnlyTestClass.tableDefinition());
    schemaManager.createSequences();
}
Also used : SchemaManager(org.eclipse.persistence.tools.schemaframework.SchemaManager)

Example 30 with SchemaManager

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

the class EmployeePopulator method persistExample.

public void persistExample(Session session) {
    Vector allObjects = new Vector();
    UnitOfWork unitOfWork = session.acquireUnitOfWork();
    // Disable the read-only classes for model population. Specifically,
    // in this case we want to be able to create EquipmentCode objects.
    unitOfWork.removeAllReadOnlyClasses();
    PopulationManager.getDefaultManager().addAllObjectsForClass(Employee.class, allObjects);
    PopulationManager.getDefaultManager().addAllObjectsForClass(SmallProject.class, allObjects);
    PopulationManager.getDefaultManager().addAllObjectsForClass(LargeProject.class, allObjects);
    PopulationManager.getDefaultManager().addAllObjectsForClass(GoldBuyer.class, allObjects);
    PopulationManager.getDefaultManager().addAllObjectsForClass(PlatinumBuyer.class, allObjects);
    PopulationManager.getDefaultManager().addAllObjectsForClass(EquipmentCode.class, allObjects);
    PopulationManager.getDefaultManager().addAllObjectsForClass(MyTestEntity.class, allObjects);
    unitOfWork.registerAllObjects(allObjects);
    unitOfWork.commit();
    if (TestCase.supportsStoredProcedures(session)) {
        boolean orig_FAST_TABLE_CREATOR = SchemaManager.FAST_TABLE_CREATOR;
        // of an instance of this class (drops & re-)creates the tables.
        if (useFastTableCreatorAfterInitialCreate && !isFirstCreation) {
            SchemaManager.FAST_TABLE_CREATOR = true;
        }
        try {
            SchemaManager schema = new SchemaManager((DatabaseSession) session);
            schema.replaceObject(buildOracleStoredProcedureReadFromAddress((DatabaseSession) session));
            schema.replaceObject(buildOracleStoredProcedureReadFromEmployee((DatabaseSession) session));
            schema.replaceObject(buildOracleStoredProcedureReadInOut((DatabaseSession) session));
        } finally {
            if (useFastTableCreatorAfterInitialCreate && !isFirstCreation) {
                SchemaManager.FAST_TABLE_CREATOR = orig_FAST_TABLE_CREATOR;
            }
        }
        // next time it deletes the rows instead.
        isFirstCreation = false;
    }
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) DatabaseSession(org.eclipse.persistence.sessions.DatabaseSession) SchemaManager(org.eclipse.persistence.tools.schemaframework.SchemaManager)

Aggregations

SchemaManager (org.eclipse.persistence.tools.schemaframework.SchemaManager)40 DatabaseSession (org.eclipse.persistence.sessions.DatabaseSession)17 UnitOfWork (org.eclipse.persistence.sessions.UnitOfWork)9 Vector (java.util.Vector)4 DatabasePlatform (org.eclipse.persistence.internal.databaseaccess.DatabasePlatform)4 StoredProcedureDefinition (org.eclipse.persistence.tools.schemaframework.StoredProcedureDefinition)4 EntityManager (jakarta.persistence.EntityManager)3 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)3 EntityManagerFactoryProvider.getConfigPropertyAsString (org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.getConfigPropertyAsString)3 DatabaseSessionImpl (org.eclipse.persistence.internal.sessions.DatabaseSessionImpl)3 DatabasePlatform (org.eclipse.persistence.platform.database.DatabasePlatform)3 SessionBroker (org.eclipse.persistence.sessions.broker.SessionBroker)3 Employee (org.eclipse.persistence.testing.models.employee.domain.Employee)3 DynamicClassLoader (org.eclipse.persistence.dynamic.DynamicClassLoader)2 DynamicEntity (org.eclipse.persistence.dynamic.DynamicEntity)2 DynamicHelper (org.eclipse.persistence.dynamic.DynamicHelper)2 DynamicType (org.eclipse.persistence.dynamic.DynamicType)2 Platform (org.eclipse.persistence.internal.databaseaccess.Platform)2 EntityManagerImpl (org.eclipse.persistence.internal.jpa.EntityManagerImpl)2 ManyToManyMapping (org.eclipse.persistence.mappings.ManyToManyMapping)2