Search in sources :

Example 6 with DataMap

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

the class CreateIfNoSchemaStrategy method generate.

private void generate(DataNode dataNode) {
    Collection<DataMap> map = dataNode.getDataMaps();
    Iterator<DataMap> iterator = map.iterator();
    while (iterator.hasNext()) {
        DbGenerator gen = new DbGenerator(dataNode.getAdapter(), iterator.next(), dataNode.getJdbcEventLogger());
        gen.setShouldCreateTables(true);
        gen.setShouldDropTables(false);
        gen.setShouldCreateFKConstraints(true);
        gen.setShouldCreatePKSupport(true);
        gen.setShouldDropPKSupport(false);
        try {
            gen.runGenerator(dataNode.getDataSource());
        } catch (Exception e) {
            throw new CayenneRuntimeException(e);
        }
    }
}
Also used : CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) DbGenerator(org.apache.cayenne.access.DbGenerator) SQLException(java.sql.SQLException) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) DataMap(org.apache.cayenne.map.DataMap)

Example 7 with DataMap

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

the class EntityUtilsTest method setUp.

@Before
public void setUp() throws Exception {
    dataMap = new DataMap();
    objEntity = new ObjEntity();
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) DataMap(org.apache.cayenne.map.DataMap) Before(org.junit.Before)

Example 8 with DataMap

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

the class CayenneContextIT method testCommitChangesNew.

@Test
public void testCommitChangesNew() {
    final CompoundDiff diff = new CompoundDiff();
    final Object newObjectId = new ObjectId("test", "key", "generated");
    eventManager = new DefaultEventManager(0);
    // test that ids that are passed back are actually propagated to the
    // right
    // objects...
    MockDataChannel channel = new MockDataChannel() {

        @Override
        public GraphDiff onSync(ObjectContext originatingContext, GraphDiff changes, int syncType) {
            return diff;
        }

        // must provide a channel with working event manager
        @Override
        public EventManager getEventManager() {
            return eventManager;
        }
    };
    CayenneContext context = new CayenneContext(channel);
    ObjEntity entity = new ObjEntity("test_entity");
    entity.setClassName(MockPersistentObject.class.getName());
    DataMap dataMap = new DataMap("test");
    dataMap.addObjEntity(entity);
    Collection<DataMap> entities = Collections.singleton(dataMap);
    context.setEntityResolver(new EntityResolver(entities));
    Persistent object = context.newObject(MockPersistentObject.class);
    // record change here to make it available to the anonymous connector
    // method..
    diff.add(new NodeIdChangeOperation(object.getObjectId(), newObjectId));
    // check that a generated object ID is assigned back to the object...
    assertNotSame(newObjectId, object.getObjectId());
    context.commitChanges();
    assertSame(newObjectId, object.getObjectId());
    assertSame(object, context.graphManager.getNode(newObjectId));
}
Also used : NodeIdChangeOperation(org.apache.cayenne.graph.NodeIdChangeOperation) GraphDiff(org.apache.cayenne.graph.GraphDiff) DefaultEventManager(org.apache.cayenne.event.DefaultEventManager) EntityResolver(org.apache.cayenne.map.EntityResolver) DataMap(org.apache.cayenne.map.DataMap) ObjEntity(org.apache.cayenne.map.ObjEntity) CompoundDiff(org.apache.cayenne.graph.CompoundDiff) Test(org.junit.Test)

Example 9 with DataMap

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

the class DataMapValidator method validateName.

private void validateName(DataMap map, ValidationResult validationResult) {
    String name = map.getName();
    if (Util.isEmptyString(name)) {
        addFailure(validationResult, map, "Unnamed DataMap");
        return;
    }
    DataChannelDescriptor domain = map.getDataChannelDescriptor();
    if (domain == null) {
        return;
    }
    // check for duplicate names in the parent context
    for (DataMap otherMap : domain.getDataMaps()) {
        if (otherMap == map) {
            continue;
        }
        if (name.equals(otherMap.getName())) {
            addFailure(validationResult, map, "Duplicate DataMap name: %s", name);
            return;
        }
    }
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DataMap(org.apache.cayenne.map.DataMap)

Example 10 with DataMap

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

the class ProcedureValidator method validateName.

void validateName(Procedure procedure, ValidationResult validationResult) {
    String name = procedure.getName();
    // Must have name
    if (Util.isEmptyString(name)) {
        addFailure(validationResult, procedure, "Unnamed Procedure");
        return;
    }
    DataMap map = procedure.getDataMap();
    if (map == null) {
        return;
    }
    // check for duplicate names in the parent context
    for (final Procedure otherProcedure : map.getProcedures()) {
        if (otherProcedure == procedure) {
            continue;
        }
        if (name.equals(otherProcedure.getName())) {
            addFailure(validationResult, procedure, "Duplicate Procedure name: %s", procedure.getName());
            break;
        }
    }
}
Also used : Procedure(org.apache.cayenne.map.Procedure) DataMap(org.apache.cayenne.map.DataMap)

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