Search in sources :

Example 1 with ValuePartitioningPolicy

use of org.eclipse.persistence.descriptors.partitioning.ValuePartitioningPolicy in project eclipselink by eclipse-ee4j.

the class ValuePartitioningMetadata method buildPolicy.

/**
 * INTERNAL:
 * Build/process the partitioning policy.
 */
@Override
public PartitioningPolicy buildPolicy() {
    ValuePartitioningPolicy policy = new ValuePartitioningPolicy();
    super.buildPolicy(policy);
    // Set the partition value type name. Will be used to initialize the
    // individual partition values.
    policy.setPartitionValueTypeName(getPartitionValueType().getName());
    // Set the default connection pool.
    policy.setDefaultConnectionPool(this.defaultConnectionPool);
    // Set only the partition value names (they will be initialized at runtime).
    for (ValuePartitionMetadata partition : getPartitions()) {
        policy.addPartitionName(partition.getValue(), partition.getConnectionPool());
    }
    return policy;
}
Also used : ValuePartitioningPolicy(org.eclipse.persistence.descriptors.partitioning.ValuePartitioningPolicy)

Example 2 with ValuePartitioningPolicy

use of org.eclipse.persistence.descriptors.partitioning.ValuePartitioningPolicy in project eclipselink by eclipse-ee4j.

the class PartitionedTestSuite method testSetup.

/**
 * The setup is done as a test, both to record its failure, and to allow execution in the server.
 */
public void testSetup() {
    Map properties = new HashMap(JUnitTestCaseHelper.getDatabaseProperties());
    if (getServerSession().getPlatform().isDerby()) {
        properties.put(PersistenceUnitProperties.CONNECTION_POOL + "node2." + PersistenceUnitProperties.CONNECTION_POOL_MIN, "2");
        properties.put(PersistenceUnitProperties.CONNECTION_POOL + "node2." + PersistenceUnitProperties.CONNECTION_POOL_URL, "jdbc:derby:node2;create=true");
        properties.put(PersistenceUnitProperties.CONNECTION_POOL + "node3." + PersistenceUnitProperties.CONNECTION_POOL_URL, "jdbc:derby:node3;create=true");
        properties.put(PersistenceUnitProperties.CONNECTION_POOL + "node3." + PersistenceUnitProperties.CONNECTION_POOL_MAX, "8");
        properties.put(PersistenceUnitProperties.CONNECTION_POOL + "node3." + PersistenceUnitProperties.CONNECTION_POOL_FAILOVER, "node2, node1");
    } else if (getServerSession().getPlatform().isH2()) {
        properties.put(PersistenceUnitProperties.CONNECTION_POOL + "node2." + PersistenceUnitProperties.CONNECTION_POOL_MIN, "2");
        properties.put(PersistenceUnitProperties.CONNECTION_POOL + "node2." + PersistenceUnitProperties.CONNECTION_POOL_URL, "jdbc:h2:test2");
        properties.put(PersistenceUnitProperties.CONNECTION_POOL + "node3." + PersistenceUnitProperties.CONNECTION_POOL_URL, "jdbc:h2:test3");
        properties.put(PersistenceUnitProperties.CONNECTION_POOL + "node3." + PersistenceUnitProperties.CONNECTION_POOL_MAX, "8");
    } else if (getServerSession().getPlatform().isHSQL()) {
        properties.put(PersistenceUnitProperties.CONNECTION_POOL + "node2." + PersistenceUnitProperties.CONNECTION_POOL_MIN, "2");
        properties.put(PersistenceUnitProperties.CONNECTION_POOL + "node2." + PersistenceUnitProperties.CONNECTION_POOL_URL, "jdbc:hsqldb:file:test2");
        properties.put(PersistenceUnitProperties.CONNECTION_POOL + "node3." + PersistenceUnitProperties.CONNECTION_POOL_URL, "jdbc:hsqldb:file:test3");
        properties.put(PersistenceUnitProperties.CONNECTION_POOL + "node3." + PersistenceUnitProperties.CONNECTION_POOL_MAX, "8");
    } else if (!isOnServer() && getServerSession().getPlatform().isOracle() && (getServerSession().getLogin().getURL().indexOf("ems56442") != -1)) {
        isRAC = true;
        // RAC testing (direct node).
        String url = getServerSession().getLogin().getURL();
        properties.put(PersistenceUnitProperties.CONNECTION_POOL + "node2." + PersistenceUnitProperties.CONNECTION_POOL_MIN, "2");
        properties.put(PersistenceUnitProperties.CONNECTION_POOL + "node2." + PersistenceUnitProperties.CONNECTION_POOL_URL, (url.substring(0, url.length() - 1)) + "3");
        properties.put(PersistenceUnitProperties.CONNECTION_POOL + "node3." + PersistenceUnitProperties.CONNECTION_POOL_URL, url);
        properties.put(PersistenceUnitProperties.CONNECTION_POOL + "node3." + PersistenceUnitProperties.CONNECTION_POOL_MAX, "8");
    } else if (!isOnServer() && getServerSession().getPlatform().isOracle() && (getServerSession().getLogin().getURL().indexOf("@(DESCRIPTION") != -1)) {
        isRAC = true;
        // UCP RAC callback testing.
        properties.put(PersistenceUnitProperties.PARTITIONING_CALLBACK, "org.eclipse.persistence.platform.database.oracle.ucp.UCPDataPartitioningCallback");
    } else if (isOnServer()) {
        isRAC = true;
        try {
            Class.forName("weblogic.jdbc.common.internal.DataSourceManager");
        } catch (Exception notWebLogic) {
            warning("Partitioning tests only run on WebLogic with GridLink.");
            return;
        }
    } else {
        // Do not run on Sybase as may hang.
        if (getServerSession().getPlatform().isSybase()) {
            validDatabase = false;
            return;
        }
        isRAC = true;
        // Simulate a RAC using multiple connection pools to the same database.
        properties.put(PersistenceUnitProperties.CONNECTION_POOL + "node2." + PersistenceUnitProperties.CONNECTION_POOL_MIN, "2");
        properties.put(PersistenceUnitProperties.CONNECTION_POOL + "node2." + PersistenceUnitProperties.CONNECTION_POOL_URL, getServerSession().getLogin().getURL());
        properties.put(PersistenceUnitProperties.CONNECTION_POOL + "node3." + PersistenceUnitProperties.CONNECTION_POOL_URL, getServerSession().getLogin().getURL());
        properties.put(PersistenceUnitProperties.CONNECTION_POOL + "node3." + PersistenceUnitProperties.CONNECTION_POOL_MAX, "8");
    }
    getEntityManagerFactory(getPersistenceUnitName(), properties);
    if (isRAC) {
        // Disable replication and unioning in RAC.
        for (PartitioningPolicy policy : getDatabaseSession().getProject().getPartitioningPolicies().values()) {
            if (policy instanceof RoundRobinPartitioningPolicy) {
                ((RoundRobinPartitioningPolicy) policy).setReplicateWrites(false);
            } else if (policy instanceof UnionPartitioningPolicy) {
                ((UnionPartitioningPolicy) policy).setReplicateWrites(false);
            } else if (policy instanceof CustomPartitioningPolicy) {
                ((EmployeePartitioningPolicy) ((CustomPartitioningPolicy) policy).getPolicy()).setReplicate(false);
            } else if (policy instanceof RangePartitioningPolicy) {
                ((RangePartitioningPolicy) policy).setUnionUnpartitionableQueries(false);
            } else if (policy instanceof ValuePartitioningPolicy) {
                ((ValuePartitioningPolicy) policy).setUnionUnpartitionableQueries(false);
            }
        }
        CollectionMapping mapping = (CollectionMapping) getDatabaseSession().getDescriptor(Employee.class).getMappingForAttributeName("projects");
        PartitioningPolicy policy = getDatabaseSession().getProject().getPartitioningPolicy("defaut");
        mapping.setPartitioningPolicy(policy);
        mapping.getSelectionQuery().setPartitioningPolicy(policy);
        mapping = (CollectionMapping) getDatabaseSession().getDescriptor(Employee.class).getMappingForAttributeName("managedEmployees");
        mapping.setPartitioningPolicy(policy);
        mapping.getSelectionQuery().setPartitioningPolicy(policy);
    }
    new PartitionedTableCreator().replaceTables(getDatabaseSession());
    EntityManager em = createEntityManager();
    try {
        PopulationManager.resetDefaultManager();
        beginTransaction(em);
        new EmployeePopulator().persistExample(em);
        commitTransaction(em);
    } finally {
        closeEntityManagerAndTransaction(em);
    }
    clearCache();
}
Also used : RangePartitioningPolicy(org.eclipse.persistence.descriptors.partitioning.RangePartitioningPolicy) HashMap(java.util.HashMap) ValuePartitioningPolicy(org.eclipse.persistence.descriptors.partitioning.ValuePartitioningPolicy) PartitioningPolicy(org.eclipse.persistence.descriptors.partitioning.PartitioningPolicy) RoundRobinPartitioningPolicy(org.eclipse.persistence.descriptors.partitioning.RoundRobinPartitioningPolicy) CustomPartitioningPolicy(org.eclipse.persistence.descriptors.partitioning.CustomPartitioningPolicy) RangePartitioningPolicy(org.eclipse.persistence.descriptors.partitioning.RangePartitioningPolicy) UnionPartitioningPolicy(org.eclipse.persistence.descriptors.partitioning.UnionPartitioningPolicy) ValuePartitioningPolicy(org.eclipse.persistence.descriptors.partitioning.ValuePartitioningPolicy) UnionPartitioningPolicy(org.eclipse.persistence.descriptors.partitioning.UnionPartitioningPolicy) CustomPartitioningPolicy(org.eclipse.persistence.descriptors.partitioning.CustomPartitioningPolicy) RoundRobinPartitioningPolicy(org.eclipse.persistence.descriptors.partitioning.RoundRobinPartitioningPolicy) HashMap(java.util.HashMap) Map(java.util.Map) CollectionMapping(org.eclipse.persistence.mappings.CollectionMapping)

Aggregations

ValuePartitioningPolicy (org.eclipse.persistence.descriptors.partitioning.ValuePartitioningPolicy)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CustomPartitioningPolicy (org.eclipse.persistence.descriptors.partitioning.CustomPartitioningPolicy)1 PartitioningPolicy (org.eclipse.persistence.descriptors.partitioning.PartitioningPolicy)1 RangePartitioningPolicy (org.eclipse.persistence.descriptors.partitioning.RangePartitioningPolicy)1 RoundRobinPartitioningPolicy (org.eclipse.persistence.descriptors.partitioning.RoundRobinPartitioningPolicy)1 UnionPartitioningPolicy (org.eclipse.persistence.descriptors.partitioning.UnionPartitioningPolicy)1 CollectionMapping (org.eclipse.persistence.mappings.CollectionMapping)1