Search in sources :

Example 31 with PersistenceUnitInfo

use of org.apache.openejb.assembler.classic.PersistenceUnitInfo in project tomee by apache.

the class AutoConfigPersistenceUnitsTest method testEmptyUnitOneAvailableJtaDataSource.

/**
     * Existing data source "Orange", jta managed
     * <p/>
     * Persistence xml like so:
     * <p/>
     * <persistence-unit name="orange-unit">
     * </persistence-unit>
     * <p/>
     * The <jta-data-source> should be auto linked
     * to the Orange data source
     * <p/>
     * We should generate a <non-jta-data-source> based on
     * the <jta-data-source>
     *
     * @throws Exception
     */
public void testEmptyUnitOneAvailableJtaDataSource() throws Exception {
    final ResourceInfo supplied = addDataSource("Orange", OrangeDriver.class, "jdbc:orange:some:stuff", true);
    assertSame(supplied, resources.get(0));
    final PersistenceUnitInfo unitInfo = addPersistenceUnit("orange-unit", null, null);
    assertNotNull(unitInfo);
    final ResourceInfo generated = resources.get(1);
    assertEquals(supplied.id, unitInfo.jtaDataSource);
    assertEquals(generated.id, unitInfo.nonJtaDataSource);
    assertEquals(supplied.id + "NonJta", generated.id);
    assertEquals(supplied.service, generated.service);
    assertEquals(supplied.className, generated.className);
    assertEquals(supplied.properties.get("JdbcDriver"), generated.properties.get("JdbcDriver"));
    assertEquals(supplied.properties.get("JdbcUrl"), generated.properties.get("JdbcUrl"));
    assertEquals("false", generated.properties.get("JtaManaged"));
}
Also used : ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) PersistenceUnitInfo(org.apache.openejb.assembler.classic.PersistenceUnitInfo)

Example 32 with PersistenceUnitInfo

use of org.apache.openejb.assembler.classic.PersistenceUnitInfo in project tomee by apache.

the class AutoConfigPersistenceUnitsTest method testSameDataSourceForBoth3.

/**
     * Existing data source "OrangeOne", jta managed
     * Existing data source "OrangeTwo", not jta managed
     * <p/>
     * Persistence xml like so:
     * <p/>
     * <persistence-unit name="orange-unit">
     * <jta-data-source>OrangeOne</jta-data-source>
     * <non-jta-data-source>OrangeOne</non-jta-data-source>
     * </persistence-unit>
     * <p/>
     * They used the same data source for both the
     * jta-data-source and non-jta-data-source and we
     * can determine the data source will not work as
     * a non-jta-data-source
     * BUT
     * they have explicitly configured a data source
     * that nearly matches the named datasource and
     * would be identical to what we would auto-create
     *
     * @throws Exception
     */
public void testSameDataSourceForBoth3() throws Exception {
    final ResourceInfo jta = addDataSource("OrangeOne", OrangeDriver.class, "jdbc:orange:some:stuff", true);
    final ResourceInfo nonJta = addDataSource("OrangeTwo", OrangeDriver.class, "jdbc:orange:some:stuff", false);
    assertSame(jta, resources.get(0));
    assertSame(nonJta, resources.get(1));
    final PersistenceUnitInfo unitInfo = addPersistenceUnit("orange-unit", "orangeOne", "orangeOne");
    assertNotNull(unitInfo);
    assertEquals(jta.id, unitInfo.jtaDataSource);
    assertEquals(nonJta.id, unitInfo.nonJtaDataSource);
}
Also used : ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) PersistenceUnitInfo(org.apache.openejb.assembler.classic.PersistenceUnitInfo)

Example 33 with PersistenceUnitInfo

use of org.apache.openejb.assembler.classic.PersistenceUnitInfo in project tomee by apache.

the class AutoConfigPersistenceUnitsTest method testPossiblyAmbiguousJtaOptions.

// ---
/**
     * Existing data source "Orange", not jta managed
     * Existing data source "Lime", jta managed
     * Existing data source "JtaOrange", jta managed
     * <p/>
     * Persistence xml like so:
     * <p/>
     * <persistence-unit name="orange-unit">
     * <non-jta-data-source>Orange</non-jta-data-source>
     * </persistence-unit>
     * <p/>
     * We should select the <jta-data-source> based on
     * the closest match to the <non-jta-data-source>
     *
     * @throws Exception
     */
public void testPossiblyAmbiguousJtaOptions() throws Exception {
    final ResourceInfo supplied = addDataSource("Orange", OrangeDriver.class, "jdbc:orange:some:stuff", false);
    final ResourceInfo badMatch = addDataSource("Lime", LimeDriver.class, "jdbc:lime:some:stuff", true);
    final ResourceInfo goodMatch = addDataSource("JtaOrange", OrangeDriver.class, "jdbc:orange:some:stuff", true);
    assertSame(supplied, resources.get(0));
    assertSame(badMatch, resources.get(1));
    assertSame(goodMatch, resources.get(2));
    final PersistenceUnitInfo unitInfo = addPersistenceUnit("orange-unit", null, "orange");
    assertNotNull(unitInfo);
    assertEquals(goodMatch.id, unitInfo.jtaDataSource);
    assertEquals(supplied.id, unitInfo.nonJtaDataSource);
}
Also used : ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) PersistenceUnitInfo(org.apache.openejb.assembler.classic.PersistenceUnitInfo)

Example 34 with PersistenceUnitInfo

use of org.apache.openejb.assembler.classic.PersistenceUnitInfo in project tomee by apache.

the class AutoConfigPersistenceUnitsTest method testThirdPartyDataSources4.

/**
     * Existing data source "Orange", not controlled by us
     * <p/>
     * Persistence xml like so:
     * <p/>
     * <persistence-unit name="orange-unit">
     * <jta-data-source>Orange</jta-data-source>
     * <non-jta-data-source>Orange</non-jta-data-source>
     * </persistence-unit>
     * <p/>
     * Here we should just let them try and get by with
     * both jta and non-jta references pointed at the same
     * data source.
     *
     * @throws Exception
     */
public void testThirdPartyDataSources4() throws Exception {
    final ResourceInfo dataSource = addDataSource("Orange", OrangeDriver.class, "jdbc:orange:some:stuff", null);
    assertSame(dataSource, resources.get(0));
    final PersistenceUnitInfo unitInfo = addPersistenceUnit("orange-unit", "orange", "orange");
    assertNotNull(unitInfo);
    assertEquals(dataSource.id, unitInfo.jtaDataSource);
    assertEquals(dataSource.id, unitInfo.nonJtaDataSource);
}
Also used : ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) PersistenceUnitInfo(org.apache.openejb.assembler.classic.PersistenceUnitInfo)

Example 35 with PersistenceUnitInfo

use of org.apache.openejb.assembler.classic.PersistenceUnitInfo in project tomee by apache.

the class AutoConfigPersistenceUnitsTest method testShortName.

/**
     * Existing data source "Orange", jta managed
     * Existing data source "OrangeUnmanaged", not jta managed
     * <p/>
     * Persistence xml like so:
     * <p/>
     * <persistence-unit name="orange-unit">
     * <jta-data-source>java:foo/bar/baz/Orange</jta-data-source>
     * <non-jta-data-source>java:foo/bar/baz/OrangeUnamanged</non-jta-data-source>
     * </persistence-unit>
     * <p/>
     * The datasources should be mapped correctly despite the
     * vendor specific prefix.
     *
     * @throws Exception
     */
public void testShortName() throws Exception {
    final ResourceInfo jta = addDataSource("Orange", OrangeDriver.class, "jdbc:orange:some:stuff", true);
    final ResourceInfo nonJta = addDataSource("OrangeUnmanaged", OrangeDriver.class, "jdbc:orange:some:stuff", false);
    assertSame(jta, resources.get(0));
    assertSame(nonJta, resources.get(1));
    final PersistenceUnitInfo unitInfo = addPersistenceUnit("orange-unit", "java:foo/bar/baz/orange", "java:foo/bar/baz/orangeUnmanaged");
    assertNotNull(unitInfo);
    assertEquals(jta.id, unitInfo.jtaDataSource);
    assertEquals(nonJta.id, unitInfo.nonJtaDataSource);
}
Also used : ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) PersistenceUnitInfo(org.apache.openejb.assembler.classic.PersistenceUnitInfo)

Aggregations

PersistenceUnitInfo (org.apache.openejb.assembler.classic.PersistenceUnitInfo)35 ResourceInfo (org.apache.openejb.assembler.classic.ResourceInfo)31 AppInfo (org.apache.openejb.assembler.classic.AppInfo)5 File (java.io.File)3 URL (java.net.URL)3 Assembler (org.apache.openejb.assembler.classic.Assembler)3 Persistence (org.apache.openejb.jee.jpa.unit.Persistence)3 PersistenceUnit (org.apache.openejb.jee.jpa.unit.PersistenceUnit)3 WebAppInfo (org.apache.openejb.assembler.classic.WebAppInfo)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Properties (java.util.Properties)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Context (javax.naming.Context)1 InitialContext (javax.naming.InitialContext)1 NameNotFoundException (javax.naming.NameNotFoundException)1