Package org.openbravo.dal.xml
Class EntityResolver
- java.lang.Object
-
- org.openbravo.dal.xml.EntityResolver
-
- All Implemented Interfaces:
OBNotSingleton
,OBProvidable
- Direct Known Subclasses:
ClientImportEntityResolver
public class EntityResolver extends Object implements OBNotSingleton
The entity resolver will resolve an entity name and id to a business object. The resolver will first try to find the business object in the database in the accessible clients and organizations using the id and the content of the mapping table (AD_REF_DATA_LOADED table). If not found then unique constraints are used to find matching objects in the database. If then still no existing object is found then a new object is created and based on the accesslevel of the Entity the client and organization are set.- Author:
- mtaal
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
EntityResolver.ResolvingMode
The resolving mode determines how the EntityResolver should response if no existing object can be found for a certain entity name and id.
-
Constructor Summary
Constructors Constructor Description EntityResolver()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addObjectToCaches(String id, String entityName, BaseOBObject bob)
protected BaseOBObject
doSearch(String id, Entity entity, String clientId, boolean filterOrgs, String orgId)
protected BaseOBObject
doSearch(String id, Entity entity, String clientId, String orgId)
void
exchangeObjects(BaseOBObject prevObject, BaseOBObject newObject)
Replace an object in the cache with another one.protected BaseOBObject
findUniqueConstrainedObject(BaseOBObject obObject)
protected Client
getClient()
protected Client
getClientZero()
protected Map<Object,BaseOBObject>
getData()
static EntityResolver
getInstance()
protected String
getKey(String entityName, String id)
BaseOBObject
getObjectUsingOriginalId(String id)
protected Organization
getOrganization()
protected Organization
getOrganizationZero()
String
getOriginalId(BaseOBObject bob)
EntityResolver.ResolvingMode
getResolvingMode()
protected boolean
isOptionCreateReferencedIfNotFound()
BaseOBObject
resolve(String entityName, String id, boolean referenced)
BaseOBObject
resolve(String entityName, String id, boolean referenced, boolean filterOrgs)
Searches for an entity using the entityname and the id, first the internal cache is searched and then the database.protected BaseOBObject
search(String id, Entity entity, String orgId)
protected BaseOBObject
searchClient(String id, Entity entity)
protected BaseOBObject
searchClientOrganization(String id, Entity entity)
protected BaseOBObject
searchInstance(Entity entity, String id)
protected BaseOBObject
searchSystem(String id, Entity entity)
protected void
setClient(Client client)
protected void
setClientOrganization(BaseOBObject bob)
protected void
setClientOrganizationZero()
void
setOptionCreateReferencedIfNotFound(boolean optionCreateReferencedIfNotFound)
This option controls if referenced objects (through an association) must exist in the database.protected void
setOrganization(Organization organization)
void
setResolvingMode(EntityResolver.ResolvingMode resolvingMode)
-
-
-
Method Detail
-
getInstance
public static EntityResolver getInstance()
-
resolve
public BaseOBObject resolve(String entityName, String id, boolean referenced, boolean filterOrgs)
Searches for an entity using the entityname and the id, first the internal cache is searched and then the database. Depending if the entity is searched for as a reference or as a main object (in the root of the xml) the search is differs. If no existing object can be found then new one is created..- Parameters:
entityName
- the name of the entity searched forid
- the id, can be nullreferenced
- if the entity is searched because it is refered to or if it is in the root of the xml- Returns:
- an existing or a new entity
-
resolve
public BaseOBObject resolve(String entityName, String id, boolean referenced)
-
addObjectToCaches
protected void addObjectToCaches(String id, String entityName, BaseOBObject bob)
-
setClientOrganization
protected void setClientOrganization(BaseOBObject bob)
-
searchInstance
protected BaseOBObject searchInstance(Entity entity, String id)
-
getOriginalId
public String getOriginalId(BaseOBObject bob)
-
getObjectUsingOriginalId
public BaseOBObject getObjectUsingOriginalId(String id)
-
searchSystem
protected BaseOBObject searchSystem(String id, Entity entity)
-
searchClient
protected BaseOBObject searchClient(String id, Entity entity)
-
searchClientOrganization
protected BaseOBObject searchClientOrganization(String id, Entity entity)
-
search
protected BaseOBObject search(String id, Entity entity, String orgId)
-
doSearch
protected BaseOBObject doSearch(String id, Entity entity, String clientId, String orgId)
-
doSearch
protected BaseOBObject doSearch(String id, Entity entity, String clientId, boolean filterOrgs, String orgId)
-
setClientOrganizationZero
protected void setClientOrganizationZero()
-
getClient
protected Client getClient()
-
setClient
protected void setClient(Client client)
-
getOrganization
protected Organization getOrganization()
-
setOrganization
protected void setOrganization(Organization organization)
-
getData
protected Map<Object,BaseOBObject> getData()
-
isOptionCreateReferencedIfNotFound
protected boolean isOptionCreateReferencedIfNotFound()
-
setOptionCreateReferencedIfNotFound
public void setOptionCreateReferencedIfNotFound(boolean optionCreateReferencedIfNotFound)
This option controls if referenced objects (through an association) must exist in the database.- Parameters:
optionCreateReferencedIfNotFound
- if true then referenced objects are allowed to not exist in the database, meaning that they a new object is created for a reference
-
getResolvingMode
public EntityResolver.ResolvingMode getResolvingMode()
-
setResolvingMode
public void setResolvingMode(EntityResolver.ResolvingMode resolvingMode)
- See Also:
EntityResolver.ResolvingMode
-
findUniqueConstrainedObject
protected BaseOBObject findUniqueConstrainedObject(BaseOBObject obObject)
-
getClientZero
protected Client getClientZero()
-
getOrganizationZero
protected Organization getOrganizationZero()
-
exchangeObjects
public void exchangeObjects(BaseOBObject prevObject, BaseOBObject newObject)
Replace an object in the cache with another one. The new one is then found when using the id of the old one. The id of the previous one can be local to the xml.- Parameters:
prevObject
- the object current in the data cachenewObject
- the new object which can then be found under the old object
-
-