Object-Relational Mapping: Background
OUAF uses an Object-Relational Mapping (ORM) engine, which maps tables to entities using the system's table, table/field, field, and constraint metadata to guide the creation of mapping definitions during artifact generation.
Entities represent database tables. They are created as Java objects during a database "session", which has the lifetime of a single DB transaction.
DONT: Entities are not safe to use for reference, calling methods, etc., after the session that created them has ended. For example, don't copy entities into application caches. DO: Instead, let the application cache do the data retrieval and return the data to the session. ID objects are safe to store across sessions. Note in the following example that the entity AlgorithmType is not stored:
public class AlgorithmTypeInfoCache implements ApplicationCache {
private static final AlgorithmTypeInfoCache INSTANCE = new AlgorithmTypeInfoCache();
private final ConcurrentMap<AlgorithmType_Id, AlgorithmTypeInfo> algorithmTypeInfoById = new ConcurrentHashMap<AlgorithmType_Id, AlgorithmTypeInfo>();
protected AlgorithmTypeInfoCache() { ContextHolder.getContext().registerCache(this); }
public String getName() { return "AlgorithmTypeInfoCache"; }
public void flush() {algorithmTypeInfoById.clear(); }
public static AlgorithmTypeInfo getAlgorithmTypeInfo(AlgorithmType_Id algTypeId) {
return INSTANCE.privateGetAlgorithmTypeInfo(algTypeId);
}
private AlgorithmTypeInfo privateGetAlgorithmTypeInfo(AlgorithmType_Id algTypeId) {
AlgorithmTypeInfo algTypeInfo = algorithmTypeInfoById.get(algTypeId);
if (algTypeInfo != null) return algTypeInfo;
AlgorithmType type = algTypeId.getEntity();
if (type == null) return null;
AlgorithmTypeInfo info = new AlgorithmTypeInfo(type);
AlgorithmTypeInfo prev = algorithmTypeInfoById.putIfAbsent(algTypeId, info);
if (prev != null) return prev;
return info;
}
}
DO: it is safe to use XML documents (to be consumed by BOs, BSs, or SSs) for moving data between sessions.
Every entity has a unique corresponding "id" class, e.g. BatchControl has BachControlId. The ORM framework automatically generates correct SQL to perform the following essential tasks:
• Read, update, insert, delete one entity (row) from the database.
• Navigate between related entities as per their key/constraint relationships, for example from a parent entity to a collection of children.
Parent topic