Search in sources :

Example 6 with SchemaManager

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

the class EmployeeProjectTestSuite method setUp.

@BeforeClass
public static void setUp() {
    DynamicClassLoader dcl = new DynamicClassLoader(EmployeeProjectTestSuite.class.getClassLoader());
    Project project = null;
    try {
        project = DynamicTypeBuilder.loadDynamicProject(PROJECT_XML, createLogin(), dcl);
    } catch (IOException e) {
        // e.printStackTrace();
        fail("cannot find employee-project.xml");
    }
    session = project.createDatabaseSession();
    if (SessionLog.OFF == logLevel) {
        session.dontLogMessages();
    } else {
        session.setLogLevel(logLevel);
    }
    dynamicHelper = new DynamicHelper(session);
    session.login();
    new SchemaManager(session).replaceDefaultTables();
}
Also used : DynamicClassLoader(org.eclipse.persistence.dynamic.DynamicClassLoader) Project(org.eclipse.persistence.sessions.Project) DynamicHelper(org.eclipse.persistence.dynamic.DynamicHelper) IOException(java.io.IOException) SchemaManager(org.eclipse.persistence.tools.schemaframework.SchemaManager) BeforeClass(org.junit.BeforeClass)

Example 7 with SchemaManager

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

the class EntityTypeFromScratch method entityTypeFromDescriptor.

@Test
public void entityTypeFromDescriptor() throws Exception {
    DynamicType entityType = buildMyEntityType();
    assertEquals(MyEntity.class, entityType.getJavaClass());
    DatabaseSession session = createSession();
    session.login();
    session.addDescriptor(entityType.getDescriptor());
    new SchemaManager(session).replaceDefaultTables();
    DynamicEntity entity = entityType.newDynamicEntity();
    entity.set("id", 1);
    entity.set("name", "Name");
    session.insertObject(entity);
    session.logout();
}
Also used : DatabaseSession(org.eclipse.persistence.sessions.DatabaseSession) DynamicEntity(org.eclipse.persistence.dynamic.DynamicEntity) DynamicType(org.eclipse.persistence.dynamic.DynamicType) SchemaManager(org.eclipse.persistence.tools.schemaframework.SchemaManager) Test(org.junit.Test)

Example 8 with SchemaManager

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

the class BrokerTestModel method buildBroker.

/**
 * Build the session broker, this assume two data-sources Broker1 and Broker2 (JConnect).
 */
public SessionBroker buildBroker() {
    SessionBroker broker = new SessionBroker();
    DatabaseSession session1 = new DatabaseSessionImpl(getLogin1());
    DatabaseSession session2 = new DatabaseSessionImpl(getLogin2());
    session1.addDescriptors(new EmployeeProject1());
    session2.addDescriptors(new EmployeeProject2());
    broker.registerSession("broker1", session1);
    broker.registerSession("broker2", session2);
    broker.setSessionLog(oldSession.getSessionLog());
    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();
    new org.eclipse.persistence.testing.models.employee.relational.EmployeeSystem().populate(broker);
    return broker;
}
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 9 with SchemaManager

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

the class ServerBrokerTestModel method createTables.

/**
 * Create the tables on both databases.
 */
public void createTables() {
    SessionBroker broker = new SessionBroker();
    DatabaseSession session1 = new DatabaseSessionImpl(getLogin1());
    DatabaseSession session2 = new DatabaseSessionImpl(getLogin2());
    session1.addDescriptors(new EmployeeProject1());
    session2.addDescriptors(new EmployeeProject2());
    broker.registerSession("broker1", session1);
    broker.registerSession("broker2", session2);
    broker.setLog(oldSession.getLog());
    broker.setLogLevel(oldSession.getLogLevel());
    broker.login();
    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 : DatabaseSession(org.eclipse.persistence.sessions.DatabaseSession) SessionBroker(org.eclipse.persistence.sessions.broker.SessionBroker) SchemaManager(org.eclipse.persistence.tools.schemaframework.SchemaManager) DatabaseSessionImpl(org.eclipse.persistence.internal.sessions.DatabaseSessionImpl)

Example 10 with SchemaManager

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

the class AutoTableGeneratorEmployeeSystem method createTables.

/**
 * Drop tables/constraints, and then create default tables via schema
 * manager
 */
@Override
public void createTables(DatabaseSession session) {
    boolean orig_FAST_TABLE_CREATOR = SchemaManager.FAST_TABLE_CREATOR;
    // on Symfoware, to avoid table locking issues, don't drop old tables
    if (useFastTableCreatorAfterInitialCreate) {
        SchemaManager.FAST_TABLE_CREATOR = true;
    }
    try {
        dropTableConstraints(session);
        // drop tables and then create 'default' tables.
        new SchemaManager(session).replaceDefaultTables();
    } finally {
        if (useFastTableCreatorAfterInitialCreate) {
            SchemaManager.FAST_TABLE_CREATOR = orig_FAST_TABLE_CREATOR;
        }
    }
}
Also used : 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