Author: arminw
Date: Thu Oct 5 13:37:20 2006
New Revision: 453372
URL: http://svn.apache.org/viewvc?view=rev&rev=453372
Log:
support for configurable collection classes (defined in OJB.properties file)
Modified:
db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/CollectionFactory.java
db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/CollectionFactoryDefaultImpl.java
Modified:
db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/CollectionFactory.java
URL:
http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/CollectionFactory.java?view=diff&rev=453372&r1=453371&r2=453372
==============================================================================
---
db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/CollectionFactory.java
(original)
+++
db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/CollectionFactory.java
Thu Oct 5 13:37:20 2006
@@ -18,9 +18,8 @@
import java.io.Serializable;
import org.apache.ojb.broker.ManageableCollection;
-import org.apache.ojb.broker.metadata.CollectionDescriptor;
+import org.apache.ojb.broker.core.CollectionTypes;
import org.apache.ojb.broker.metadata.MetadataException;
-import org.apache.ojb.broker.query.Query;
import org.odmg.OQLQuery;
/**
@@ -69,4 +68,17 @@
* be loaded or instantiated
*/
public ManageableCollection createCollection(OQLQuery query, Class
collectionType) throws MetadataException;
+
+ /**
+ * Get the default collection types to create collection instances used
for 1:n, m:n
+ * references and query results.
+ * @return The collection types.
+ */
+ public CollectionTypes getCollectionTypes();
+
+ /**
+ * Set the default collection types to create collection instances used
for 1:n, m:n
+ * references and query results.
+ */
+ public void setCollectionTypes(CollectionTypes types);
}
Modified:
db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/CollectionFactoryDefaultImpl.java
URL:
http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/CollectionFactoryDefaultImpl.java?view=diff&rev=453372&r1=453371&r2=453372
==============================================================================
---
db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/CollectionFactoryDefaultImpl.java
(original)
+++
db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/CollectionFactoryDefaultImpl.java
Thu Oct 5 13:37:20 2006
@@ -16,17 +16,17 @@
*/
import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+import java.util.Vector;
import org.apache.ojb.broker.ManageableCollection;
+import org.apache.ojb.broker.PersistenceBrokerException;
+import org.apache.ojb.broker.core.CollectionTypes;
import org.apache.ojb.broker.metadata.CollectionDescriptor;
import org.apache.ojb.broker.metadata.MetadataException;
import org.apache.ojb.broker.query.Query;
import org.apache.ojb.broker.util.ClassHelper;
-import org.apache.ojb.broker.util.collections.ManageableListImpl;
-import org.apache.ojb.broker.util.collections.ManageableSetImpl;
-import org.apache.ojb.broker.util.collections.RemovalAwareCollection;
-import org.apache.ojb.broker.util.collections.RemovalAwareList;
-import org.apache.ojb.broker.util.collections.RemovalAwareSet;
import org.odmg.OQLQuery;
/**
@@ -40,6 +40,8 @@
/** Serialization id; should be changed if a new version of this class
breaks state compatibility */
private static final long serialVersionUID = 3617850859254200626L;
+ private CollectionTypes types;
+
/* (non-Javadoc)
* @see
org.apache.ojb.broker.accesslayer.CollectionFactory#createCollection(org.apache.ojb.broker.accesslayer.CollectionCreationContext)
@@ -149,43 +151,51 @@
}
}
- /* (non-Javadoc)
- * @see
org.apache.ojb.broker.accesslayer.CollectionFactory#getCollectionClass(org.apache.ojb.broker.metadata.CollectionDescriptor)
- */
- public Class getCollectionClass(CollectionDescriptor collDesc) throws
MetadataException
+ public void setCollectionTypes(CollectionTypes types)
{
- // BRJ: do not use RemovalAwareCollection for m:n relationships
- // see
http://db.apache.org/ojb/docu/guides/basic-technique.html#Mapping+m%3An+associations
-
- Class fieldType = collDesc.getPersistentField().getType();
- Class collClass = collDesc.getCollectionClass();
+ this.types = types;
+ }
- if (collClass != null)
- {
- return collClass;
- }
- else if (fieldType.isArray() ||
fieldType.isAssignableFrom(RemovalAwareCollection.class))
- {
- return collDesc.isMtoNRelation() ? ManageableListImpl.class :
RemovalAwareCollection.class;
- }
- else if (fieldType.isAssignableFrom(RemovalAwareList.class))
- {
- return collDesc.isMtoNRelation() ? ManageableListImpl.class :
RemovalAwareList.class;
- }
- else if (fieldType.isAssignableFrom(RemovalAwareSet.class))
- {
- return collDesc.isMtoNRelation() ? ManageableSetImpl.class :
RemovalAwareSet.class;
- }
- else if (ManageableCollection.class.isAssignableFrom(fieldType))
- {
- return fieldType;
- }
- else
- {
- throw new MetadataException("Cannot determine a default collection
type for collection "+
- collDesc.getAttributeName()+" in type
"+
-
collDesc.getClassDescriptor().getClassNameOfObject());
+ public Class getCollectionClass(CollectionDescriptor cds) throws
PersistenceBrokerException
+ {
+ Class result = cds.getCollectionClass();
+ if(result == null)
+ {
+ Class fieldType = cds.getPersistentField().getType();
+
+ if (ManageableCollection.class.isAssignableFrom(fieldType))
+ {
+ result = fieldType;
+ }
+ else if(fieldType.isAssignableFrom(Collection.class))
+ {
+ result = cds.isMtoNRelation() ?
types.getManyToManyCollection() : types.getOneToManyCollection();
+ }
+ else if(fieldType.isAssignableFrom(List.class))
+ {
+ result = cds.isMtoNRelation() ? types.getManyToManyList() :
types.getOneToManyList();
+ }
+ else if(fieldType.isAssignableFrom(Set.class))
+ {
+ result = cds.isMtoNRelation() ? types.getManyToManySet() :
types.getOneToManySet();
+ }
+ else if(fieldType.isAssignableFrom(Vector.class))
+ {
+ result = cds.isMtoNRelation() ? types.getManyToManyVector() :
types.getOneToManyVector();
+ }
+ else if(fieldType.isArray())
+ {
+ result = cds.isMtoNRelation() ? types.getManyToManyArray() :
types.getOneToManyArray();
+ }
+ else
+ {
+ throw new MetadataException(
+ "Cannot determine a collection type for
collection/list/set/array field '"
+ + cds.getAttributeName() + "' of type '" + fieldType +
"' in persistence capable class '"
+ + cds.getClassDescriptor().getClassNameOfObject() +
"'");
+ }
}
+ return result;
}
/* (non-Javadoc)
@@ -193,7 +203,7 @@
*/
public Class getCollectionClass(Query query) throws MetadataException
{
- return RemovalAwareCollection.class;
+ return types.getQuery();
}
/* (non-Javadoc)
@@ -201,7 +211,11 @@
*/
public Class getCollectionClass(OQLQuery query) throws MetadataException
{
- return ManageableListImpl.class;
+ return types.getOQLQuery();
}
+ public CollectionTypes getCollectionTypes()
+ {
+ return types;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]