Search in sources :

Example 1 with MappingNamespace

use of org.apache.cayenne.map.MappingNamespace 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 2 with MappingNamespace

use of org.apache.cayenne.map.MappingNamespace 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 3 with MappingNamespace

use of org.apache.cayenne.map.MappingNamespace 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 4 with MappingNamespace

use of org.apache.cayenne.map.MappingNamespace 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)

Aggregations

EntityResolver (org.apache.cayenne.map.EntityResolver)4 MappingNamespace (org.apache.cayenne.map.MappingNamespace)4 DataMap (org.apache.cayenne.map.DataMap)1