|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.ojb.broker.util.BrokerHelper
public class BrokerHelper
This class contains helper methods primarily used by the PersistenceBroker
implementation (e.g. contains methods to assign the the values of 'autoincrement' fields).
Furthermore it was used to introduce new features related to PersistenceBroker
- these
new features and services (if they stand the test of time) will be moved to separate services in future.
Field Summary | |
---|---|
private PersistenceBrokerImpl |
m_broker
|
static String |
REPOSITORY_NAME_SEPARATOR
|
private Map |
sqlSelectMap
|
Constructor Summary | |
---|---|
BrokerHelper(PersistenceBrokerImpl broker)
|
Method Summary | |
---|---|
boolean |
assertValidPkForDelete(ClassDescriptor cld,
Object obj)
returns true if the primary key fields are valid for delete, else false. |
boolean |
assertValidPksForStore(FieldDescriptor[] fieldDescriptors,
Object[] pkValues)
returns true if the primary key fields are valid for store, else false. |
static PBKey |
crossCheckPBKey(PBKey key)
Check if the user of the given PBKey was null , if so we try to
get user/password from the jdbc-connection-descriptor matching the given
PBKey.getAlias(). |
boolean |
doesExist(ClassDescriptor cld,
Identity oid,
Object obj)
TODO: This method should be moved to JdbcAccess
before 1.1 release. |
static PBKey |
extractAllTokens(String name)
splits up the name string and extract db url, user name and password and build a new PBKey instance - the token '#' is used to separate the substrings. |
Object[] |
extractValueArray(ValueContainer[] containers)
Extract an value array of the given ValueContainer array. |
ValueContainer[] |
getAllRwValues(ClassDescriptor cld,
Object obj)
Returns an array containing values for all READ/WRITE attributes of the object based on the specified ClassDescriptor . |
static Object[] |
getCollectionArray(Object collectionOrArray)
Returns an object array for Collection , array or
ManageableCollection instances. |
static Iterator |
getCollectionIterator(Object collectionOrArray)
Returns an Iterator instance for Collection , object Array or
ManageableCollection instances. |
Query |
getCountQuery(Query aQuery)
Build a Count-Query based on aQuery |
ValueContainer[] |
getKeyValues(ClassDescriptor cld,
Identity oid)
Return primary key values of given Identity object. |
ValueContainer[] |
getKeyValues(ClassDescriptor cld,
Identity oid,
boolean convertToSql)
Return key Values of an Identity |
ValueContainer[] |
getKeyValues(ClassDescriptor cld,
Object objectOrProxy)
returns an Array with an Objects PK VALUES, with any java-to-sql FieldConversion applied. |
ValueContainer[] |
getKeyValues(ClassDescriptor cld,
Object objectOrProxy,
boolean convertToSql)
Returns an Array with an Objects PK VALUES if convertToSql is true, any associated java-to-sql conversions are applied. |
ValueContainer[] |
getNonKeyRwValues(ClassDescriptor cld,
Object obj)
Returns an array containing values for all non PK field READ/WRITE attributes of the object based on the specified ClassDescriptor . |
private Platform |
getPlatform()
answer the platform |
private Query |
getQueryByCriteriaCount(QueryByCriteria aQuery)
Create a Count-Query for QueryByCriteria |
private Query |
getQueryBySqlCount(QueryBySQL aQuery)
Create a Count-Query for QueryBySQL |
private ClassDescriptor |
getRealClassDescriptor(ClassDescriptor aCld,
Object anObj)
Answer the real ClassDescriptor for anObj ie. |
private Query |
getReportQueryByCriteriaCount(ReportQueryByCriteria aQuery)
Create a Count-Query for ReportQueryByCriteria |
ValueContainer[] |
getValuesForObject(FieldDescriptor[] fields,
Object obj,
boolean convertToSql)
|
ValueContainer[] |
getValuesForObject(FieldDescriptor[] fields,
Object obj,
boolean convertToSql,
boolean assignAutoincrement)
Get the values of the fields for an obj Autoincrement values are automatically set. |
static boolean |
hasAnonymousKeyReference(ClassDescriptor cld,
ObjectReferenceDescriptor rds)
Returns true if one or more anonymous FK fields are used. |
boolean |
hasNullPKField(ClassDescriptor cld,
Object obj)
Detect if the given object has a PK field represents a 'null' value. |
void |
link(Object obj,
boolean insert)
This method concatenate the main object with all reference objects (1:1, 1:n and m:n) by hand. |
void |
link(Object source,
CollectionDescriptor cds,
List referencesToLink)
Link a bunch of 1:n or m:n objects. |
void |
link(Object source,
CollectionDescriptor cds,
Object referenceToLink)
Link a single 1:n or m:n object. |
void |
link(Object obj,
ObjectReferenceDescriptor ord,
boolean insert)
This method concatenate the main object and the specified reference object (1:1 reference a referenced object, 1:n and m:n reference a collection of referenced objects) by hand. |
boolean |
link(Object obj,
String attributeName,
boolean insert)
This method concatenate the main object and the specified reference object (1:1 reference a referenced object, 1:n and m:n reference a collection of referenced objects) by hand. |
boolean |
link(Object obj,
String attributeName,
Object reference,
boolean insert)
This method concatenate the main object and the specified reference object (1:1 reference a referenced object, 1:n and m:n reference a collection of referenced objects) by hand. |
private void |
linkOrUnlink(boolean doLink,
Object obj,
boolean insert)
|
private void |
linkOrUnlink(boolean doLink,
Object obj,
ObjectReferenceDescriptor ord,
boolean insert)
|
private boolean |
linkOrUnlink(boolean doLink,
Object obj,
String attributeName,
boolean insert)
|
private void |
linkOrUnlinkOneToOne(boolean doLink,
Object obj,
ObjectReferenceDescriptor ord,
boolean insert)
|
private void |
linkOrUnlinkXToMany(boolean doLink,
Object obj,
CollectionDescriptor cod,
boolean insert)
|
boolean |
representsNull(FieldDescriptor fld,
Object aValue)
Decide if the given object value represents 'null'. - If given value is 'null' itself, true will be returned - If given value is instance of Number with value 0 and the field-descriptor represents a primitive field, true will be returned - If given value is instance of String with length 0 and the field-descriptor is a primary key, true will be returned |
private Object |
setAutoIncrementValue(FieldDescriptor fd,
Object obj)
Set an autoincremented value in given object field that has already had a field conversion run on it, if an value for the given field is already set, it will be overridden - no further checks are done. |
void |
unlink(Object obj)
Unlink all references from this object. |
void |
unlink(Object source,
CollectionDescriptor cds,
List referencesToUnlink)
Unlink a bunch of 1:n or m:n objects. |
void |
unlink(Object source,
CollectionDescriptor cds,
Object referenceToUnlink)
Unlink a single 1:n or m:n object. |
void |
unlink(Object obj,
ObjectReferenceDescriptor ord,
boolean insert)
Unlink the specified reference from this object. |
boolean |
unlink(Object source,
String attributeName)
Unlink all referenced objects of the specified field. |
boolean |
unlink(Object source,
String attributeName,
Object target)
Unlink the specified reference object. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String REPOSITORY_NAME_SEPARATOR
private PersistenceBrokerImpl m_broker
private Map sqlSelectMap
Constructor Detail |
---|
public BrokerHelper(PersistenceBrokerImpl broker)
Method Detail |
---|
public static PBKey extractAllTokens(String name)
PersistenceBrokerException
- if given name was null
public static PBKey crossCheckPBKey(PBKey key)
null
, if so we try to
get user/password from the jdbc-connection-descriptor matching the given
PBKey.getAlias().
private ClassDescriptor getRealClassDescriptor(ClassDescriptor aCld, Object anObj)
public ValueContainer[] getKeyValues(ClassDescriptor cld, Object objectOrProxy, boolean convertToSql) throws PersistenceBrokerException
objectOrProxy
- convertToSql
-
PersistenceBrokerException
public ValueContainer[] getKeyValues(ClassDescriptor cld, Identity oid) throws PersistenceBrokerException
cld
- oid
-
PersistenceBrokerException
public ValueContainer[] getKeyValues(ClassDescriptor cld, Identity oid, boolean convertToSql) throws PersistenceBrokerException
cld
- oid
- convertToSql
-
PersistenceBrokerException
public ValueContainer[] getKeyValues(ClassDescriptor cld, Object objectOrProxy) throws PersistenceBrokerException
objectOrProxy
-
PersistenceBrokerException
public boolean representsNull(FieldDescriptor fld, Object aValue)
public boolean hasNullPKField(ClassDescriptor cld, Object obj)
private Object setAutoIncrementValue(FieldDescriptor fd, Object obj)
The data type of the value that is returned by this method is compatible with the java-world. The return value has NOT been run through a field conversion and converted to a corresponding sql-type.
PersistenceBrokerException
- if there is an erros accessing obj field valuespublic ValueContainer[] getValuesForObject(FieldDescriptor[] fields, Object obj, boolean convertToSql, boolean assignAutoincrement) throws PersistenceBrokerException
fields
- obj
-
PersistenceBrokerException
public ValueContainer[] getValuesForObject(FieldDescriptor[] fields, Object obj, boolean convertToSql) throws PersistenceBrokerException
PersistenceBrokerException
public ValueContainer[] getNonKeyRwValues(ClassDescriptor cld, Object obj) throws PersistenceBrokerException
ClassDescriptor
.
ClassDescriptor
the caller is reponsible to pass a valid descriptor.
cld
- The ClassDescriptor
to extract the RW-fieldsobj
- The object with target fields to extract.
MetadataException
- if there is an erros accessing obj field values
PersistenceBrokerException
public ValueContainer[] getAllRwValues(ClassDescriptor cld, Object obj) throws PersistenceBrokerException
ClassDescriptor
.
ClassDescriptor
the caller is reponsible to pass a valid descriptor.
cld
- The ClassDescriptor
to extract the RW-fieldsobj
- The object with target fields to extract.
MetadataException
- if there is an erros accessing obj field values
PersistenceBrokerException
public Object[] extractValueArray(ValueContainer[] containers)
ValueContainer
array.
containers
-
public boolean assertValidPksForStore(FieldDescriptor[] fieldDescriptors, Object[] pkValues)
fieldDescriptors
- the array of PK fielddescriptorspkValues
- the array of PK values
public boolean assertValidPkForDelete(ClassDescriptor cld, Object obj)
cld
- the ClassDescriptorobj
- the object
public Query getCountQuery(Query aQuery)
aQuery
-
private Query getQueryBySqlCount(QueryBySQL aQuery)
aQuery
-
private Query getQueryByCriteriaCount(QueryByCriteria aQuery)
private Query getReportQueryByCriteriaCount(ReportQueryByCriteria aQuery)
private Platform getPlatform()
public boolean doesExist(ClassDescriptor cld, Identity oid, Object obj)
JdbcAccess
before 1.1 release.
This method checks if the requested object can be
found in database (without object materialization).
cld
- The ClassDescriptor
of the
object/Identity
to check.obj
- The object to check.oid
- The associated Identity
.
Identity
of the object
public void link(Object obj, boolean insert)
public void unlink(Object obj)
obj
- Object with referenceprivate void linkOrUnlink(boolean doLink, Object obj, boolean insert)
public void link(Object obj, ObjectReferenceDescriptor ord, boolean insert)
obj
- Object with referenceord
- the ObjectReferenceDescriptor of the referenceinsert
- flag signals insert operationpublic boolean link(Object obj, String attributeName, boolean insert)
obj
- Object with referenceattributeName
- field name of the referenceinsert
- flag signals insert operation
public boolean link(Object obj, String attributeName, Object reference, boolean insert)
obj
- Object with referenceattributeName
- field name of the referencereference
- The referenced objectinsert
- flag signals insert operation
public boolean unlink(Object source, String attributeName, Object target)
source
- The source object with the specified reference field.attributeName
- The field name of the reference to unlink.target
- The referenced object to unlink.public boolean unlink(Object source, String attributeName)
source
- The source object with the specified reference.attributeName
- The field name of the reference to unlink.public void unlink(Object obj, ObjectReferenceDescriptor ord, boolean insert)
obj
- Object with referenceord
- the ObjectReferenceDescriptor of the referenceinsert
- flag signals insert operationprivate boolean linkOrUnlink(boolean doLink, Object obj, String attributeName, boolean insert)
private void linkOrUnlink(boolean doLink, Object obj, ObjectReferenceDescriptor ord, boolean insert)
private void linkOrUnlinkXToMany(boolean doLink, Object obj, CollectionDescriptor cod, boolean insert)
private void linkOrUnlinkOneToOne(boolean doLink, Object obj, ObjectReferenceDescriptor ord, boolean insert)
public void unlink(Object source, CollectionDescriptor cds, List referencesToUnlink)
source
- The source object with reference.cds
- The CollectionDescriptor
of the relation.referencesToUnlink
- List of referenced objects to unlink.public void unlink(Object source, CollectionDescriptor cds, Object referenceToUnlink)
source
- The source object with reference.cds
- The CollectionDescriptor
of the relation.referenceToUnlink
- The referenced object to link.public void link(Object source, CollectionDescriptor cds, List referencesToLink)
source
- The source object with reference.cds
- The CollectionDescriptor
of the relation.referencesToLink
- List of referenced objects to link.public void link(Object source, CollectionDescriptor cds, Object referenceToLink)
source
- The source object with the declared reference.cds
- The CollectionDescriptor
of the relation declared in source object.referenceToLink
- The referenced object to link.public static Iterator getCollectionIterator(Object collectionOrArray)
Collection
, object Array or
ManageableCollection
instances.
collectionOrArray
- a none null object of type Collection
,
Array or ManageableCollection
.
public static Object[] getCollectionArray(Object collectionOrArray)
Collection
, array or
ManageableCollection
instances.
collectionOrArray
- a none null object of type Collection
,
Array or ManageableCollection
.
public static boolean hasAnonymousKeyReference(ClassDescriptor cld, ObjectReferenceDescriptor rds)
cld
- The ClassDescriptor
of the main object.rds
- The ObjectReferenceDescriptor
of the referenced object.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |