Search in sources :

Example 26 with EntityResolver

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

the class ProjectUtil method setDbEntityName.

/**
 * Renames a DbEntity and changes the name of all references.
 */
public static void setDbEntityName(DbEntity entity, String newName) {
    String oldName = entity.getName();
    // If name hasn't changed, just return
    if (Util.nullSafeEquals(oldName, newName)) {
        return;
    }
    entity.setName(newName);
    DataMap map = entity.getDataMap();
    if (map != null) {
        map.removeDbEntity(oldName, false);
        map.addDbEntity(entity);
        // important - clear parent namespace:
        MappingNamespace ns = map.getNamespace();
        if (ns instanceof EntityResolver) {
            ((EntityResolver) ns).refreshMappingCache();
        }
    }
}
Also used : EntityResolver(org.apache.cayenne.map.EntityResolver) MappingNamespace(org.apache.cayenne.map.MappingNamespace) DataMap(org.apache.cayenne.map.DataMap)

Example 27 with EntityResolver

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

the class ProjectUtil method setObjEntityName.

public static void setObjEntityName(DataMap map, ObjEntity entity, String newName) {
    String oldName = entity.getName();
    // If name hasn't changed, just return
    if (Util.nullSafeEquals(oldName, newName)) {
        return;
    }
    entity.setName(newName);
    map.removeObjEntity(oldName, false);
    map.addObjEntity(entity);
    // important - clear parent namespace:
    MappingNamespace ns = map.getNamespace();
    if (ns instanceof EntityResolver) {
        ((EntityResolver) ns).refreshMappingCache();
    }
}
Also used : EntityResolver(org.apache.cayenne.map.EntityResolver) MappingNamespace(org.apache.cayenne.map.MappingNamespace)

Example 28 with EntityResolver

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

the class ProjectUtil method setQueryName.

public static void setQueryName(DataMap map, QueryDescriptor query, String newName) {
    String oldName = query.getName();
    // If name hasn't changed, just return
    if (Util.nullSafeEquals(oldName, newName)) {
        return;
    }
    query.setName(newName);
    query.setDataMap(map);
    map.removeQueryDescriptor(oldName);
    map.addQueryDescriptor(query);
    // important - clear parent namespace:
    MappingNamespace ns = map.getNamespace();
    if (ns instanceof EntityResolver) {
        ((EntityResolver) ns).refreshMappingCache();
    }
}
Also used : EntityResolver(org.apache.cayenne.map.EntityResolver) MappingNamespace(org.apache.cayenne.map.MappingNamespace)

Example 29 with EntityResolver

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

the class ProjectUtil method setProcedureName.

public static void setProcedureName(DataMap map, Procedure procedure, String newName) {
    String oldName = procedure.getName();
    // If name hasn't changed, just return
    if (Util.nullSafeEquals(oldName, newName)) {
        return;
    }
    procedure.setName(newName);
    map.removeProcedure(oldName);
    map.addProcedure(procedure);
    // important - clear parent namespace:
    MappingNamespace ns = map.getNamespace();
    if (ns instanceof EntityResolver) {
        ((EntityResolver) ns).refreshMappingCache();
    }
}
Also used : EntityResolver(org.apache.cayenne.map.EntityResolver) MappingNamespace(org.apache.cayenne.map.MappingNamespace)

Example 30 with EntityResolver

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

the class CayenneGeneratorMapLoaderAction method getMainDataMap.

DataMap getMainDataMap() throws MalformedURLException {
    if (mainDataMap == null) {
        DataMapLoader loader = createLoader();
        DataMap mainDataMap = loadDataMap(loader, mainDataMapFile);
        if (additionalDataMapFiles != null) {
            EntityResolver entityResolver = new EntityResolver();
            entityResolver.addDataMap(mainDataMap);
            mainDataMap.setNamespace(entityResolver);
            for (File additionalDataMapFile : additionalDataMapFiles) {
                DataMap dataMap = loadDataMap(loader, additionalDataMapFile);
                entityResolver.addDataMap(dataMap);
                dataMap.setNamespace(entityResolver);
            }
        }
        this.mainDataMap = mainDataMap;
    }
    return mainDataMap;
}
Also used : DataMapLoader(org.apache.cayenne.configuration.DataMapLoader) EntityResolver(org.apache.cayenne.map.EntityResolver) File(java.io.File) DataMap(org.apache.cayenne.map.DataMap)

Aggregations

EntityResolver (org.apache.cayenne.map.EntityResolver)78 Test (org.junit.Test)53 ObjectId (org.apache.cayenne.ObjectId)13 ObjEntity (org.apache.cayenne.map.ObjEntity)13 DataMap (org.apache.cayenne.map.DataMap)11 ClientMtTable1 (org.apache.cayenne.testdo.mt.ClientMtTable1)7 DataNode (org.apache.cayenne.access.DataNode)6 RowReaderFactory (org.apache.cayenne.access.jdbc.reader.RowReaderFactory)6 JdbcAdapter (org.apache.cayenne.dba.JdbcAdapter)6 DbEntity (org.apache.cayenne.map.DbEntity)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 QueryResponse (org.apache.cayenne.QueryResponse)5 MockEventManager (org.apache.cayenne.event.MockEventManager)5 SelectQuery (org.apache.cayenne.query.SelectQuery)5 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)5 GenericResponse (org.apache.cayenne.util.GenericResponse)5 MappingNamespace (org.apache.cayenne.map.MappingNamespace)4 ObjRelationship (org.apache.cayenne.map.ObjRelationship)4 List (java.util.List)3