use of org.apache.cayenne.map.DataMap in project cayenne by apache.
the class DataMapView method setDataMapName.
void setDataMapName(String newName) {
if (newName == null || newName.trim().length() == 0) {
throw new ValidationException("Enter name for DataMap");
}
DataMap map = eventController.getCurrentDataMap();
// search for matching map name across domains, as currently they have to be
// unique globally
DataChannelDescriptor dataChannelDescriptor = (DataChannelDescriptor) Application.getInstance().getProject().getRootNode();
DataMap matchingMap = dataChannelDescriptor.getDataMap(newName);
if (matchingMap != null && !matchingMap.equals(map)) {
// there is an entity with the same name
throw new ValidationException("There is another DataMap named '" + newName + "'. Use a different name.");
}
String oldName = map.getName();
if (Util.nullSafeEquals(newName, oldName)) {
return;
}
// completely new name, set new name for domain
DataMapDefaults pref = eventController.getDataMapPreferences("");
DataMapEvent e = new DataMapEvent(this, map, map.getName());
ProjectUtil.setDataMapName((DataChannelDescriptor) eventController.getProject().getRootNode(), map, newName);
pref.copyPreferences(newName);
eventController.fireDataMapEvent(e);
}
use of org.apache.cayenne.map.DataMap in project cayenne by apache.
the class DataMapView method updateComment.
void updateComment(String comment) {
DataMap dataMap = eventController.getCurrentDataMap();
if (dataMap == null) {
return;
}
ObjectInfo.putToMetaData(eventController.getApplication().getMetaData(), dataMap, ObjectInfo.COMMENT, comment);
eventController.fireDataMapEvent(new DataMapEvent(this, dataMap));
}
use of org.apache.cayenne.map.DataMap in project cayenne by apache.
the class EjbqlQueryMainTab method setQueryName.
/**
* Initializes Query name from string.
*/
void setQueryName(String newName) {
if (newName != null && newName.trim().length() == 0) {
newName = null;
}
QueryDescriptor query = getQuery();
if (query == null) {
return;
}
if (Util.nullSafeEquals(newName, query.getName())) {
return;
}
if (newName == null) {
throw new ValidationException("Query name is required.");
}
DataMap map = mediator.getCurrentDataMap();
if (map.getQueryDescriptor(newName) == null) {
// completely new name, set new name for entity
QueryEvent e = new QueryEvent(this, query, query.getName());
ProjectUtil.setQueryName(map, query, newName);
mediator.fireQueryEvent(e);
} else {
// there is a query with the same name
throw new ValidationException("There is another query named '" + newName + "'. Use a different name.");
}
}
use of org.apache.cayenne.map.DataMap in project cayenne by apache.
the class CayenneGeneratorMojo method execute.
public void execute() throws MojoExecutionException, MojoFailureException {
// compilation resource for maven.
if (!destDir.exists()) {
destDir.mkdirs();
}
injector = DIBootstrap.createInjector(new ToolsModule(LoggerFactory.getLogger(CayenneGeneratorMojo.class)));
Logger logger = new MavenLogger(this);
CayenneGeneratorMapLoaderAction loaderAction = new CayenneGeneratorMapLoaderAction(injector);
loaderAction.setMainDataMapFile(map);
CayenneGeneratorEntityFilterAction filterAction = new CayenneGeneratorEntityFilterAction();
filterAction.setClient(client);
filterAction.setNameFilter(NamePatternMatcher.build(logger, includeEntities, excludeEntities));
try {
loaderAction.setAdditionalDataMapFiles(convertAdditionalDataMaps());
DataMap dataMap = loaderAction.getMainDataMap();
ClassGenerationAction generator = createGenerator();
generator.setLogger(logger);
if (force) {
// will (re-)generate all files
generator.setForce(true);
}
generator.setTimestamp(map.lastModified());
generator.setDataMap(dataMap);
generator.addEntities(filterAction.getFilteredEntities(dataMap));
generator.addEmbeddables(dataMap.getEmbeddables());
generator.addQueries(dataMap.getQueryDescriptors());
generator.execute();
} catch (Exception e) {
throw new MojoExecutionException("Error generating classes: ", e);
}
}
use of org.apache.cayenne.map.DataMap in project cayenne by apache.
the class DbGeneratorMojo method execute.
public void execute() throws MojoExecutionException, MojoFailureException {
Logger logger = new MavenLogger(this);
// check missing data source parameters
dataSource.validate();
Injector injector = DIBootstrap.createInjector(new DbSyncModule(), new ToolsModule(logger));
AdhocObjectFactory objectFactory = injector.getInstance(AdhocObjectFactory.class);
logger.info(String.format("connection settings - [driver: %s, url: %s, username: %s]", dataSource.getDriver(), dataSource.getUrl(), dataSource.getUsername()));
logger.info(String.format("generator options - [dropTables: %s, dropPK: %s, createTables: %s, createPK: %s, createFK: %s]", dropTables, dropPK, createTables, createPK, createFK));
try {
final DbAdapter adapterInst = (adapter == null) ? objectFactory.newInstance(DbAdapter.class, JdbcAdapter.class.getName()) : objectFactory.newInstance(DbAdapter.class, adapter);
// Load the data map and run the db generator.
DataMap dataMap = loadDataMap(injector);
DbGenerator generator = new DbGenerator(adapterInst, dataMap, NoopJdbcEventLogger.getInstance());
generator.setShouldCreateFKConstraints(createFK);
generator.setShouldCreatePKSupport(createPK);
generator.setShouldCreateTables(createTables);
generator.setShouldDropPKSupport(dropPK);
generator.setShouldDropTables(dropTables);
// load driver taking custom CLASSPATH into account...
DriverDataSource driverDataSource = new DriverDataSource((Driver) Class.forName(dataSource.getDriver()).newInstance(), dataSource.getUrl(), dataSource.getUsername(), dataSource.getPassword());
generator.runGenerator(driverDataSource);
} catch (Exception ex) {
Throwable th = Util.unwindException(ex);
String message = "Error generating database";
if (th.getLocalizedMessage() != null) {
message += ": " + th.getLocalizedMessage();
}
logger.error(message);
throw new MojoExecutionException(message, th);
}
}
Aggregations