Search in sources :

Example 71 with DataMap

use of org.apache.cayenne.map.DataMap in project cayenne by apache.

the class ObjEntityHandlerTest method testLoad.

@Test
public void testLoad() throws Exception {
    final DataMap map = new DataMap();
    assertEquals(0, map.getObjEntities().size());
    parse("obj-entity", new HandlerFactory() {

        @Override
        public NamespaceAwareNestedTagHandler createHandler(NamespaceAwareNestedTagHandler parent) {
            return new ObjEntityHandler(parent, map);
        }
    });
    assertEquals(1, map.getObjEntities().size());
    ObjEntity entity = map.getObjEntity("ArtistCallback");
    assertNotNull(entity);
    assertTrue(entity.isAbstract());
    assertTrue(entity.isReadOnly());
    assertTrue(entity.isServerOnly());
    assertFalse(entity.isClientAllowed());
    assertEquals(3, entity.getAttributes().size());
    assertEquals(8, entity.getCallbackMethods().size());
    assertEquals(ObjEntity.LOCK_TYPE_OPTIMISTIC, entity.getDeclaredLockType());
    assertEquals("org.apache.cayenne.testdo.testmap.ArtistCallback", entity.getClassName());
    assertNull("super.class should be suppressed by super entity", entity.getSuperClassName());
    assertEquals("Artist", entity.getSuperEntityName());
    assertEquals("client.class", entity.getClientClassName());
    assertNull("client.super.class should be suppressed by super entity", entity.getClientSuperClassName());
    assertEquals("ARTIST_CT", entity.getDbEntityName());
    ObjAttribute attribute = entity.getAttribute("artistName");
    assertNotNull(attribute);
    assertEquals("NAME", attribute.getDbAttributeName());
    assertEquals("java.lang.String", attribute.getType());
    assertTrue(attribute.isUsedForLocking());
    attribute = entity.getAttribute("dateOfBirth");
    assertNotNull(attribute);
    assertNull(attribute.getDbAttributeName());
    assertEquals("java.util.Date", attribute.getType());
    assertFalse(attribute.isUsedForLocking());
    attribute = entity.getAttribute("embeddable1");
    assertNotNull(attribute);
    assertNull(attribute.getDbAttributeName());
    assertEquals("org.apache.cayenne.testdo.embeddable.Embeddable1", attribute.getType());
    assertFalse(attribute.isUsedForLocking());
    String override = entity.getDeclaredAttributeOverrides().get("name");
    assertEquals("parent.child.name", override);
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) ObjAttribute(org.apache.cayenne.map.ObjAttribute) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Example 72 with DataMap

use of org.apache.cayenne.map.DataMap in project cayenne by apache.

the class PrefetchTypeForSelectQueryHandlerTest method testLoad.

@Test
public void testLoad() throws Exception {
    final DataMap map = new DataMap();
    parse("query", new HandlerFactory() {

        @Override
        public NamespaceAwareNestedTagHandler createHandler(NamespaceAwareNestedTagHandler parent) {
            return new QueryDescriptorHandler(parent, map);
        }
    });
    SelectQueryDescriptor selectQueryDescriptor = (SelectQueryDescriptor) map.getQueryDescriptor("query");
    assertEquals(3, selectQueryDescriptor.getPrefetchesMap().size());
    assertEquals(1, (int) selectQueryDescriptor.getPrefetchesMap().get("paintings"));
    assertEquals(2, (int) selectQueryDescriptor.getPrefetchesMap().get("paintings.artist"));
    assertEquals(3, (int) selectQueryDescriptor.getPrefetchesMap().get("paintings.gallery"));
}
Also used : SelectQueryDescriptor(org.apache.cayenne.map.SelectQueryDescriptor) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Example 73 with DataMap

use of org.apache.cayenne.map.DataMap in project cayenne by apache.

the class XMLDataMapLoaderTest method loadFullDataMap.

@Test
public void loadFullDataMap() {
    URL url = getClass().getResource("testConfigMap4.map.xml");
    DataMap map = loader.load(new URLResource(url));
    assertNotNull(map);
    assertEquals("testConfigMap4", map.getName());
    // check general state
    assertEquals(12, map.getDbEntities().size());
    assertEquals(17, map.getObjEntities().size());
    assertEquals(4, map.getProcedures().size());
    assertEquals(14, map.getQueryDescriptors().size());
    assertEquals(1, map.getEmbeddables().size());
    assertEquals("TEST_CATALOG", map.getDefaultCatalog());
    assertNull(map.getDefaultSchema());
    assertEquals("org.apache.cayenne.testdo.testmap", map.getDefaultPackage());
    assertTrue(map.isClientSupported());
    // check some loaded content
    assertEquals("org.apache.cayenne.testdo.testmap.Artist", map.getObjEntity("Artist").getClassName());
    assertEquals(5, map.getObjEntity("CompoundPainting").getAttributes().size());
    assertEquals(3, map.getObjEntity("Artist").getRelationships().size());
    assertEquals(7, map.getObjEntity("ArtistCallback").getCallbackMethods().size());
    assertEquals("name = \"test\"", map.getDbEntity("ARTGROUP").getQualifier().toString());
    assertEquals(4, map.getDbEntity("EXHIBIT").getAttributes().size());
    assertEquals(3, map.getDbEntity("PAINTING").getRelationships().size());
    assertEquals("gallery_seq", map.getDbEntity("GALLERY").getPrimaryKeyGenerator().getGeneratorName());
    DbAttribute pk1 = map.getDbEntity("EXHIBIT").getAttribute("EXHIBIT_ID");
    assertFalse(pk1.isGenerated());
    assertTrue(pk1.isPrimaryKey());
    DbAttribute pk2 = map.getDbEntity("GENERATED_COLUMN").getAttribute("GENERATED_COLUMN");
    assertTrue(pk2.isGenerated());
    assertTrue(pk2.isPrimaryKey());
    assertEquals(true, map.getProcedure("cayenne_tst_out_proc").isReturningValue());
    assertEquals(1, map.getProcedure("cayenne_tst_out_proc").getCallOutParameters().size());
    assertEquals(2, map.getProcedure("cayenne_tst_out_proc").getCallParameters().size());
    assertEquals("true", map.getQueryDescriptor("EjbqlQueryTest").getProperty("cayenne.GenericSelectQuery.fetchingDataRows"));
    SQLTemplateDescriptor descriptor = (SQLTemplateDescriptor) map.getQueryDescriptor("NonSelectingQuery");
    assertEquals("INSERT INTO PAINTING (PAINTING_ID, PAINTING_TITLE, ESTIMATED_PRICE) " + "VALUES (512, 'No Painting Like This', 12.5)", descriptor.getAdapterSql().get("org.apache.cayenne.dba.db2.DB2Adapter"));
    assertEquals("TEST", map.getEmbeddable("org.apache.cayenne.testdo.Embeddable").getAttribute("test").getDbAttributeName());
}
Also used : URLResource(org.apache.cayenne.resource.URLResource) SQLTemplateDescriptor(org.apache.cayenne.map.SQLTemplateDescriptor) DbAttribute(org.apache.cayenne.map.DbAttribute) URL(java.net.URL) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Example 74 with DataMap

use of org.apache.cayenne.map.DataMap in project cayenne by apache.

the class ConcurrentPkGeneratorIT method testConcurrentInserts.

/*
     * Attempts to discover any problems regarding thread locking in the PkGenerator
     */
@Test
public void testConcurrentInserts() {
    if (!unitDbAdapter.supportsPKGeneratorConcurrency()) {
        return;
    }
    final DataMap dataMap = runtime.getDataDomain().getDataMap("qualified");
    // clear out the table
    ObjectContext context = runtime.newContext();
    List<Qualified1> qualified1s = context.select(SelectQuery.query(Qualified1.class, null));
    context.deleteObjects(qualified1s);
    context.commitChanges();
    // perform concurrent inserts
    int numThreads = 2;
    int insertsPerThread = 100;
    ExecutorService executor = Executors.newFixedThreadPool(numThreads);
    Runnable task = () -> {
        try {
            ObjectContext context1 = runtime.newContext();
            for (ObjEntity entity : dataMap.getObjEntities()) {
                context1.newObject(entity.getJavaClass());
            }
            context1.commitChanges();
        } catch (Exception e) {
            e.printStackTrace();
        }
    };
    for (int j = 0; j < insertsPerThread; j++) {
        for (int i = 0; i < numThreads; i++) {
            executor.submit(task);
        }
    }
    // check for completion or deadlock
    executor.shutdown();
    try {
        // normally this completes in less than 2 seconds. If it takes 30 then it failed.
        boolean didFinish = executor.awaitTermination(30, TimeUnit.SECONDS);
        if (!didFinish) {
            fail("Concurrent inserts either deadlocked or contended over the lock too long.");
        }
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }
    // check for gaps in the generated sequence numbers
    qualified1s = context.select(SelectQuery.query(Qualified1.class, null));
    assertEquals(insertsPerThread * numThreads, qualified1s.size());
// PKs will be used in order most of the time, but the implementation doesn't guarantee it.
// qualified1s.sort(Comparator.comparing(Cayenne::intPKForObject));
// 
// int lastPk = Cayenne.intPKForObject(qualified1s.get(0)) - 1;
// for (Qualified1 qualified1 : qualified1s) {
// if (lastPk+1 != Cayenne.intPKForObject(qualified1)) {
// fail("Found gap in sequence number: " + lastPk + " - " + Cayenne.intPKForObject(qualified1));
// }
// lastPk++;
// }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) Qualified1(org.apache.cayenne.testdo.qualified.Qualified1) ExecutorService(java.util.concurrent.ExecutorService) ObjectContext(org.apache.cayenne.ObjectContext) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Example 75 with DataMap

use of org.apache.cayenne.map.DataMap in project cayenne by apache.

the class OracleAdapterIT method testUpdatesLOBColumns.

@Test
public void testUpdatesLOBColumns() throws Exception {
    DataMap map = runtime.getDataDomain().getDataMap("lob");
    assertTrue(OracleAdapter.updatesLOBColumns(new InsertBatchQuery(map.getDbEntity("BLOB_TEST"), 1)));
    assertTrue(OracleAdapter.updatesLOBColumns(new InsertBatchQuery(map.getDbEntity("CLOB_TEST"), 1)));
    assertFalse(OracleAdapter.updatesLOBColumns(new InsertBatchQuery(map.getDbEntity("TEST"), 1)));
}
Also used : InsertBatchQuery(org.apache.cayenne.query.InsertBatchQuery) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Aggregations

DataMap (org.apache.cayenne.map.DataMap)233 Test (org.junit.Test)88 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)48 DbEntity (org.apache.cayenne.map.DbEntity)48 ObjEntity (org.apache.cayenne.map.ObjEntity)45 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)22 URL (java.net.URL)21 URLResource (org.apache.cayenne.resource.URLResource)20 ArrayList (java.util.ArrayList)19 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)19 MergerToken (org.apache.cayenne.dbsync.merge.token.MergerToken)17 QueryDescriptor (org.apache.cayenne.map.QueryDescriptor)16 DataMapEvent (org.apache.cayenne.configuration.event.DataMapEvent)15 File (java.io.File)14 Procedure (org.apache.cayenne.map.Procedure)14 Embeddable (org.apache.cayenne.map.Embeddable)13 Injector (org.apache.cayenne.di.Injector)12 DbAttribute (org.apache.cayenne.map.DbAttribute)11 EntityResolver (org.apache.cayenne.map.EntityResolver)11 Entity (org.apache.cayenne.map.Entity)10