use of org.apache.cayenne.map.DataMap in project cayenne by apache.
the class SQLTemplateIT method testSQLTemplateForDataMap.
@Test
public void testSQLTemplateForDataMap() {
DataMap testDataMap = context.getEntityResolver().getDataMap("testmap");
SQLTemplate q1 = new SQLTemplate(testDataMap, "SELECT * FROM ARTIST", true);
List<DataRow> result = context.performQuery(q1);
assertEquals(0, result.size());
}
use of org.apache.cayenne.map.DataMap in project cayenne by apache.
the class CayenneGeneratorTask method execute.
/**
* Executes the task. It will be called by ant framework.
*/
@Override
public void execute() throws BuildException {
validateAttributes();
Injector injector = DIBootstrap.createInjector(new ToolsModule(LoggerFactory.getLogger(CayenneGeneratorTask.class)));
AntLogger logger = new AntLogger(this);
CayenneGeneratorMapLoaderAction loadAction = new CayenneGeneratorMapLoaderAction(injector);
loadAction.setMainDataMapFile(map);
loadAction.setAdditionalDataMapFiles(additionalMaps);
CayenneGeneratorEntityFilterAction filterAction = new CayenneGeneratorEntityFilterAction();
filterAction.setClient(client);
filterAction.setNameFilter(NamePatternMatcher.build(logger, includeEntitiesPattern, excludeEntitiesPattern));
try {
DataMap dataMap = loadAction.getMainDataMap();
ClassGenerationAction generatorAction = createGeneratorAction();
generatorAction.setLogger(logger);
generatorAction.setTimestamp(map.lastModified());
generatorAction.setDataMap(dataMap);
generatorAction.addEntities(filterAction.getFilteredEntities(dataMap));
generatorAction.addEmbeddables(filterAction.getFilteredEmbeddables(dataMap));
generatorAction.addQueries(dataMap.getQueryDescriptors());
generatorAction.execute();
} catch (Exception e) {
throw new BuildException(e);
}
}
use of org.apache.cayenne.map.DataMap in project cayenne by apache.
the class DbGeneratorTask method execute.
@Override
public void execute() {
Logger logger = new AntLogger(this);
log(String.format("connection settings - [driver: %s, url: %s, username: %s]", driver, url, userName), Project.MSG_VERBOSE);
log(String.format("generator options - [dropTables: %s, dropPK: %s, createTables: %s, createPK: %s, createFK: %s]", dropTables, dropPK, createTables, createPK, createFK), Project.MSG_VERBOSE);
validateAttributes();
ClassLoader loader = null;
Injector injector = DIBootstrap.createInjector(new DbSyncModule(), new ToolsModule(logger));
try {
loader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(DbGeneratorTask.class.getClassLoader());
// Load the data map and run the db generator.
DataMap dataMap = loadDataMap(injector);
// load driver taking custom CLASSPATH into account...
DriverDataSource dataSource = new DriverDataSource((Driver) Class.forName(driver).newInstance(), url, userName, password);
DbAdapter adapter = getAdapter(injector, dataSource);
DbGenerator generator = new DbGenerator(adapter, dataMap, Collections.<DbEntity>emptyList(), null, NoopJdbcEventLogger.getInstance());
generator.setShouldCreateFKConstraints(createFK);
generator.setShouldCreatePKSupport(createPK);
generator.setShouldCreateTables(createTables);
generator.setShouldDropPKSupport(dropPK);
generator.setShouldDropTables(dropTables);
generator.runGenerator(dataSource);
} catch (Exception ex) {
Throwable th = Util.unwindException(ex);
String message = "Error generating database";
if (th.getLocalizedMessage() != null) {
message += ": " + th.getLocalizedMessage();
}
log(message, Project.MSG_ERR);
throw new BuildException(message, th);
} finally {
Thread.currentThread().setContextClassLoader(loader);
injector.shutdown();
}
}
use of org.apache.cayenne.map.DataMap in project cayenne by apache.
the class DataChannelDescriptor method encodeAsXML.
@Override
public void encodeAsXML(XMLEncoder encoder, ConfigurationNodeVisitor delegate) {
encoder.start("domain").attribute("xmlns", SCHEMA_XSD).attribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance", true).attribute("xsi:schemaLocation", SCHEMA_XSD + " " + SCHEMA_XSD + ".xsd", true).projectVersion();
if (!properties.isEmpty()) {
List<String> keys = new ArrayList<>(properties.keySet());
Collections.sort(keys);
for (String key : keys) {
encoder.property(key, properties.get(key));
}
}
if (!dataMaps.isEmpty()) {
List<DataMap> maps = new ArrayList<>(this.dataMaps);
Collections.sort(maps);
for (DataMap dataMap : maps) {
encoder.start("map").attribute("name", dataMap.getName().trim()).end();
}
}
if (!nodeDescriptors.isEmpty()) {
List<DataNodeDescriptor> nodes = new ArrayList<>(nodeDescriptors);
Collections.sort(nodes);
encoder.nested(nodes, delegate);
}
delegate.visitDataChannelDescriptor(this);
encoder.end();
}
use of org.apache.cayenne.map.DataMap in project cayenne by apache.
the class DefaultDataChannelDescriptorMerger method merge.
public DataChannelDescriptor merge(DataChannelDescriptor... descriptors) {
if (descriptors == null || descriptors.length == 0) {
throw new IllegalArgumentException("Null or empty descriptors");
}
if (descriptors.length == 1) {
return descriptors[0];
}
int len = descriptors.length;
// merge into a new descriptor; do not alter source descriptors
DataChannelDescriptor merged = new DataChannelDescriptor();
merged.setName(descriptors[len - 1].getName());
merged.getProperties().putAll(descriptors[len - 1].getProperties());
// iterate in reverse order to reduce add/remove operations
for (int i = len - 1; i >= 0; i--) {
DataChannelDescriptor descriptor = descriptors[i];
// TODO: they still have a link to the unmerged descriptor, is it bad?
for (DataMap map : descriptor.getDataMaps()) {
// report conflicting DataMap and leave the existing copy
DataMap existing = merged.getDataMap(map.getName());
if (existing != null) {
logger.info("Discarding overridden DataMap '" + map.getName() + "' from descriptor '" + descriptor.getName() + "'");
} else {
logger.info("Using DataMap '" + map.getName() + "' from descriptor '" + descriptor.getName() + "' in merged descriptor");
merged.getDataMaps().add(map);
}
}
// DataNodes are merged by copy as we may modify them (changing map linking)
for (DataNodeDescriptor node : descriptor.getNodeDescriptors()) {
DataNodeDescriptor existing = merged.getNodeDescriptor(node.getName());
if (existing != null) {
logger.info("Discarding overridden DataNode '" + node.getName() + "' from descriptor '" + descriptor.getName() + "'");
for (String mapName : node.getDataMapNames()) {
if (!existing.getDataMapNames().contains(mapName)) {
existing.getDataMapNames().add(mapName);
}
}
} else {
logger.info("Using DataNode '" + node.getName() + "' from descriptor '" + descriptor.getName() + "' in merged descriptor");
merged.getNodeDescriptors().add(cloneDataNodeDescriptor(node, merged));
}
}
}
return merged;
}
Aggregations