org.apache.ojb.broker.util
Class BrokerHelper

java.lang.Object
  extended byorg.apache.ojb.broker.util.BrokerHelper

public class BrokerHelper
extends java.lang.Object

Version:
$Id: BrokerHelper.java,v 1.37 2004/02/13 18:59:15 arminw Exp $
Author:
Armin Waibel

Field Summary
static java.lang.String REPOSITORY_NAME_SEPARATOR
           
 
Constructor Summary
BrokerHelper(PersistenceBroker broker)
           
 
Method Summary
 boolean assertValidPkFields(FieldDescriptor[] fieldDescriptors, java.lang.Object[] pkValues)
          returns true if the primary key fields are valid, 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 the Objects attribute (READ/WRITE only)
protected  java.lang.Object getAutoIncrementValue(FieldDescriptor fd, java.lang.Object obj, java.lang.Object cv)
          Get an autoincremented value that has already had a field conversion run on it.
 Query getCountQuery(Query aQuery)
          Build a Count-Query based on aQuery
 ValueContainer[] getKeyValues(ClassDescriptor cld, Identity oid)
          Return key Values of an Identity
 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 with an Objects NON-PK VALUES (READ/WRITE only)
 ValueContainer[] getValuesForObject(FieldDescriptor[] fields, java.lang.Object obj, boolean convertToSql)
          Get the values of the fields for an obj
 boolean hasNullPKField(ClassDescriptor cld, java.lang.Object obj)
          Detect if the given object has a PK field represents a 'null' value.
 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 is a primary key and 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REPOSITORY_NAME_SEPARATOR

public static final java.lang.String REPOSITORY_NAME_SEPARATOR
See Also:
Constant Field Values
Constructor Detail

BrokerHelper

public BrokerHelper(PersistenceBroker broker)
Method Detail

extractAllTokens

public 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.

Throws:
PersistenceBrokerException - if given name was null

crossCheckPBKey

public 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().


getKeyValues

public ValueContainer[] getKeyValues(ClassDescriptor cld,
                                     java.lang.Object objectOrProxy,
                                     boolean convertToSql)
                              throws PersistenceBrokerException
returns an Array with an Objects PK VALUES if convertToSql is true, any associated java-to-sql conversions are applied. If the Object is a Proxy or a VirtualProxy NO conversion is necessary.

Parameters:
objectOrProxy -
convertToSql -
Returns:
Object[]
Throws:
PersistenceBrokerException

getKeyValues

public ValueContainer[] getKeyValues(ClassDescriptor cld,
                                     Identity oid)
                              throws PersistenceBrokerException
Return key Values of an Identity

Parameters:
cld -
oid -
Returns:
Object[]
Throws:
PersistenceBrokerException

getKeyValues

public ValueContainer[] getKeyValues(ClassDescriptor cld,
                                     Identity oid,
                                     boolean convertToSql)
                              throws PersistenceBrokerException
Return key Values of an Identity

Parameters:
cld -
oid -
convertToSql -
Returns:
Object[]
Throws:
PersistenceBrokerException

getKeyValues

public ValueContainer[] getKeyValues(ClassDescriptor cld,
                                     java.lang.Object objectOrProxy)
                              throws PersistenceBrokerException
returns an Array with an Objects PK VALUES, with any java-to-sql FieldConversion applied. If the Object is a Proxy or a VirtualProxy NO conversion is necessary.

Parameters:
objectOrProxy -
Returns:
Object[]
Throws:
PersistenceBrokerException

representsNull

public 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 is a primary key and 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


hasNullPKField

public boolean hasNullPKField(ClassDescriptor cld,
                              java.lang.Object obj)
Detect if the given object has a PK field represents a 'null' value.


getAutoIncrementValue

protected java.lang.Object getAutoIncrementValue(FieldDescriptor fd,
                                                 java.lang.Object obj,
                                                 java.lang.Object cv)
Get an autoincremented value that has already had a field conversion run on it.

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.

Throws:
MetadataException - if there is an erros accessing obj field values

getValuesForObject

public ValueContainer[] getValuesForObject(FieldDescriptor[] fields,
                                           java.lang.Object obj,
                                           boolean convertToSql)
                                    throws PersistenceBrokerException
Get the values of the fields for an obj

Parameters:
fields -
obj -
Throws:
PersistenceBrokerException

getNonKeyRwValues

public ValueContainer[] getNonKeyRwValues(ClassDescriptor cld,
                                          java.lang.Object obj)
                                   throws PersistenceBrokerException
returns an Array with an Objects NON-PK VALUES (READ/WRITE only)

Throws:
MetadataException - if there is an erros accessing o field values
PersistenceBrokerException

getAllRwValues

public ValueContainer[] getAllRwValues(ClassDescriptor cld,
                                       java.lang.Object obj)
                                throws PersistenceBrokerException
returns an array containing values for all the Objects attribute (READ/WRITE only)

Throws:
MetadataException - if there is an erros accessing obj field values
PersistenceBrokerException

extractValueArray

public java.lang.Object[] extractValueArray(ValueContainer[] containers)
Extract an value array of the given ValueContainer array.

Parameters:
containers -
Returns:

assertValidPkFields

public boolean assertValidPkFields(FieldDescriptor[] fieldDescriptors,
                                   java.lang.Object[] pkValues)
returns true if the primary key fields are valid, else false. PK fields are valid if each of them is either an OJB managed attribute (autoincrement or locking) or if it contains a valid non-null value

Parameters:
fieldDescriptors - the array of PK fielddescriptors
pkValues - the array of PK values
Returns:
boolean

getCountQuery

public Query getCountQuery(Query aQuery)
Build a Count-Query based on aQuery

Parameters:
aQuery -
Returns:

doesExist

public boolean doesExist(ClassDescriptor cld,
                         Identity oid,
                         java.lang.Object obj)
TODO: This method should be moved to JdbcAccess before 1.1 release. This method only checks if the requested object can be found in DB (without full object materialization).



Authors: Thomas Mahler and others. (C) 2000 - 2003 Apache Software Foundation
All rights reserved. Published under the Apache License.
http://db.apache.org/ojb
Version: 1.0.rc5, 2003-12-14