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);
}
}
}
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();
}
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));
}
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;
}
}
}
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;
}
}
}
Aggregations