public class BrokerHelper
extends java.lang.Object
PersistenceBroker
implementation (e.g. contains methods to assign the the values of 'autoincrement' fields).
PersistenceBroker
- these
new features and services (if they stand the test of time) will be moved to separate services in future.Modifier and Type | Field and Description |
---|---|
static java.lang.String |
REPOSITORY_NAME_SEPARATOR |
Constructor and Description |
---|
BrokerHelper(PersistenceBrokerImpl broker) |
Modifier and Type | Method and Description |
---|---|
boolean |
assertValidPkForDelete(ClassDescriptor cld,
java.lang.Object obj)
returns true if the primary key fields are valid for delete, else false.
|
boolean |
assertValidPksForStore(FieldDescriptor[] fieldDescriptors,
java.lang.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,
java.lang.Object obj)
TODO: This method should be moved to
JdbcAccess
before 1.1 release. |
static PBKey |
extractAllTokens(java.lang.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.
|
java.lang.Object[] |
extractValueArray(ValueContainer[] containers)
Extract an value array of the given
ValueContainer array. |
ValueContainer[] |
getAllRwValues(ClassDescriptor cld,
java.lang.Object obj)
Returns an array containing values for all READ/WRITE attributes of the object
based on the specified
ClassDescriptor . |
static java.lang.Object[] |
getCollectionArray(java.lang.Object collectionOrArray)
Returns an object array for
Collection , array or
ManageableCollection instances. |
static java.util.Iterator |
getCollectionIterator(java.lang.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,
java.lang.Object objectOrProxy)
returns an Array with an Objects PK VALUES, with any java-to-sql
FieldConversion applied.
|
ValueContainer[] |
getKeyValues(ClassDescriptor cld,
java.lang.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,
java.lang.Object obj)
Returns an array containing values for all non PK field READ/WRITE attributes of the object
based on the specified
ClassDescriptor . |
ValueContainer[] |
getValuesForObject(FieldDescriptor[] fields,
java.lang.Object obj,
boolean convertToSql) |
ValueContainer[] |
getValuesForObject(FieldDescriptor[] fields,
java.lang.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,
java.lang.Object obj)
Detect if the given object has a PK field represents a 'null' value.
|
void |
link(java.lang.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(java.lang.Object source,
CollectionDescriptor cds,
java.util.List referencesToLink)
Link a bunch of 1:n or m:n objects.
|
void |
link(java.lang.Object source,
CollectionDescriptor cds,
java.lang.Object referenceToLink)
Link a single 1:n or m:n object.
|
void |
link(java.lang.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(java.lang.Object obj,
java.lang.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(java.lang.Object obj,
java.lang.String attributeName,
java.lang.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.
|
boolean |
representsNull(FieldDescriptor fld,
java.lang.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 |
void |
unlink(java.lang.Object obj)
Unlink all references from this object.
|
void |
unlink(java.lang.Object source,
CollectionDescriptor cds,
java.util.List referencesToUnlink)
Unlink a bunch of 1:n or m:n objects.
|
void |
unlink(java.lang.Object source,
CollectionDescriptor cds,
java.lang.Object referenceToUnlink)
Unlink a single 1:n or m:n object.
|
void |
unlink(java.lang.Object obj,
ObjectReferenceDescriptor ord,
boolean insert)
Unlink the specified reference from this object.
|
boolean |
unlink(java.lang.Object source,
java.lang.String attributeName)
Unlink all referenced objects of the specified field.
|
boolean |
unlink(java.lang.Object source,
java.lang.String attributeName,
java.lang.Object target)
Unlink the specified reference object.
|
public static final java.lang.String REPOSITORY_NAME_SEPARATOR
public BrokerHelper(PersistenceBrokerImpl broker)
public static PBKey extractAllTokens(java.lang.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().public ValueContainer[] getKeyValues(ClassDescriptor cld, java.lang.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, java.lang.Object objectOrProxy) throws PersistenceBrokerException
objectOrProxy
- PersistenceBrokerException
public boolean representsNull(FieldDescriptor fld, java.lang.Object aValue)
public boolean hasNullPKField(ClassDescriptor cld, java.lang.Object obj)
public ValueContainer[] getValuesForObject(FieldDescriptor[] fields, java.lang.Object obj, boolean convertToSql, boolean assignAutoincrement) throws PersistenceBrokerException
fields
- obj
- PersistenceBrokerException
public ValueContainer[] getValuesForObject(FieldDescriptor[] fields, java.lang.Object obj, boolean convertToSql) throws PersistenceBrokerException
PersistenceBrokerException
public ValueContainer[] getNonKeyRwValues(ClassDescriptor cld, java.lang.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 valuesPersistenceBrokerException
public ValueContainer[] getAllRwValues(ClassDescriptor cld, java.lang.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 valuesPersistenceBrokerException
public java.lang.Object[] extractValueArray(ValueContainer[] containers)
ValueContainer
array.containers
- public boolean assertValidPksForStore(FieldDescriptor[] fieldDescriptors, java.lang.Object[] pkValues)
fieldDescriptors
- the array of PK fielddescriptorspkValues
- the array of PK valuespublic boolean assertValidPkForDelete(ClassDescriptor cld, java.lang.Object obj)
cld
- the ClassDescriptorobj
- the objectpublic Query getCountQuery(Query aQuery)
aQuery
- public boolean doesExist(ClassDescriptor cld, Identity oid, java.lang.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 objectpublic void link(java.lang.Object obj, boolean insert)
public void unlink(java.lang.Object obj)
obj
- Object with referencepublic void link(java.lang.Object obj, ObjectReferenceDescriptor ord, boolean insert)
obj
- Object with referenceord
- the ObjectReferenceDescriptor of the referenceinsert
- flag signals insert operationpublic boolean link(java.lang.Object obj, java.lang.String attributeName, boolean insert)
obj
- Object with referenceattributeName
- field name of the referenceinsert
- flag signals insert operationpublic boolean link(java.lang.Object obj, java.lang.String attributeName, java.lang.Object reference, boolean insert)
obj
- Object with referenceattributeName
- field name of the referencereference
- The referenced objectinsert
- flag signals insert operationpublic boolean unlink(java.lang.Object source, java.lang.String attributeName, java.lang.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(java.lang.Object source, java.lang.String attributeName)
source
- The source object with the specified reference.attributeName
- The field name of the reference to unlink.public void unlink(java.lang.Object obj, ObjectReferenceDescriptor ord, boolean insert)
obj
- Object with referenceord
- the ObjectReferenceDescriptor of the referenceinsert
- flag signals insert operationpublic void unlink(java.lang.Object source, CollectionDescriptor cds, java.util.List referencesToUnlink)
source
- The source object with reference.cds
- The CollectionDescriptor
of the relation.referencesToUnlink
- List of referenced objects to unlink.public void unlink(java.lang.Object source, CollectionDescriptor cds, java.lang.Object referenceToUnlink)
source
- The source object with reference.cds
- The CollectionDescriptor
of the relation.referenceToUnlink
- The referenced object to link.public void link(java.lang.Object source, CollectionDescriptor cds, java.util.List referencesToLink)
source
- The source object with reference.cds
- The CollectionDescriptor
of the relation.referencesToLink
- List of referenced objects to link.public void link(java.lang.Object source, CollectionDescriptor cds, java.lang.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 java.util.Iterator getCollectionIterator(java.lang.Object collectionOrArray)
Collection
, object Array or
ManageableCollection
instances.collectionOrArray
- a none null object of type Collection
,
Array or ManageableCollection
.public static java.lang.Object[] getCollectionArray(java.lang.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.(C) 2002 - 2005 Apache Software Foundation
All rights reserved. Published under the Apache License 2.0.
http://db.apache.org/ojb
Version: 1.0.4, 2005-12-30