Search in sources :

Example 36 with DataMap

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);
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) ValidationException(org.apache.cayenne.validation.ValidationException) DataMapDefaults(org.apache.cayenne.modeler.pref.DataMapDefaults) DataMapEvent(org.apache.cayenne.configuration.event.DataMapEvent) DataMap(org.apache.cayenne.map.DataMap)

Example 37 with DataMap

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));
}
Also used : DataMapEvent(org.apache.cayenne.configuration.event.DataMapEvent) DataMap(org.apache.cayenne.map.DataMap)

Example 38 with 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.");
    }
}
Also used : QueryDescriptor(org.apache.cayenne.map.QueryDescriptor) ValidationException(org.apache.cayenne.validation.ValidationException) QueryEvent(org.apache.cayenne.configuration.event.QueryEvent) DataMap(org.apache.cayenne.map.DataMap)

Example 39 with DataMap

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);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Logger(org.slf4j.Logger) ToolsModule(org.apache.cayenne.dbsync.reverse.configuration.ToolsModule) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) DataMap(org.apache.cayenne.map.DataMap) ClientClassGenerationAction(org.apache.cayenne.gen.ClientClassGenerationAction) ClassGenerationAction(org.apache.cayenne.gen.ClassGenerationAction)

Example 40 with DataMap

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);
    }
}
Also used : DriverDataSource(org.apache.cayenne.datasource.DriverDataSource) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Logger(org.slf4j.Logger) NoopJdbcEventLogger(org.apache.cayenne.log.NoopJdbcEventLogger) ToolsModule(org.apache.cayenne.dbsync.reverse.configuration.ToolsModule) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) DataMap(org.apache.cayenne.map.DataMap) DbAdapter(org.apache.cayenne.dba.DbAdapter) Injector(org.apache.cayenne.di.Injector) DbSyncModule(org.apache.cayenne.dbsync.DbSyncModule) AdhocObjectFactory(org.apache.cayenne.di.AdhocObjectFactory) DbGenerator(org.apache.cayenne.access.DbGenerator)

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