use of org.eclipse.persistence.descriptors.partitioning.UnionPartitioningPolicy in project eclipselink by eclipse-ee4j.
the class UnionPartitioningMetadata method buildPolicy.
@Override
public PartitioningPolicy buildPolicy() {
UnionPartitioningPolicy policy = new UnionPartitioningPolicy();
super.buildPolicy(policy);
if (this.replicateWrites != null) {
policy.setReplicateWrites(this.replicateWrites);
}
return policy;
}
use of org.eclipse.persistence.descriptors.partitioning.UnionPartitioningPolicy 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();
}
Aggregations