Index: xml/src/main/java/org/exolab/castor/xml/descriptors/BaseDescriptor.java
===================================================================
--- xml/src/main/java/org/exolab/castor/xml/descriptors/BaseDescriptor.java (revision 7783)
+++ xml/src/main/java/org/exolab/castor/xml/descriptors/BaseDescriptor.java (working copy)
@@ -1,11 +1,26 @@
package org.exolab.castor.xml.descriptors;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
import org.exolab.castor.xml.UnmarshalState;
import org.exolab.castor.xml.ValidationException;
import org.exolab.castor.xml.XMLClassDescriptor;
import org.exolab.castor.xml.XMLFieldDescriptor;
public abstract class BaseDescriptor implements XMLClassDescriptor {
+
+ /**
+ * Map holding the properties set and read by Natures.
+ */
+ private Map _properties = new HashMap();
+
+ /**
+ * Map holding the available natures.
+ */
+ private Set _natures = new HashSet();
/**
* Returns true if the given object represented by this XMLClassDescriptor
@@ -50,5 +65,50 @@
public boolean isChoice() {
return false;
}
-
+
+ /**
+ * @see org.exolab.castor.builder.info.nature.PropertyHolder#
+ * getProperty(java.lang.String)
+ * @param name
+ * of the property
+ * @return value of the property
+ */
+ public Object getProperty(final String name) {
+ return _properties.get(name);
+ }
+
+ /**
+ * @see org.exolab.castor.builder.info.nature.PropertyHolder#
+ * setProperty(java.lang.String, java.lang.Object)
+ * @param name
+ * of the property
+ * @param value
+ * of the property
+ */
+ public void setProperty(final String name, final Object value) {
+ _properties.put(name, value);
+ }
+
+ /**
+ * @see org.exolab.castor.builder.info.nature.NatureExtendable#
+ * addNature(java.lang.String)
+ * @param nature
+ * ID of the Nature
+ */
+ public void addNature(final String nature) {
+ _natures.add(nature);
+ }
+
+ /**
+ * @see org.exolab.castor.builder.info.nature.NatureExtendable#
+ * hasNature(java.lang.String)
+ * @param nature
+ * ID of the Nature
+ * @return true if the Nature ID was added.
+ */
+ public boolean hasNature(final String nature) {
+ return _natures.contains(nature);
+ }
+
+
}
Index: xml/src/main/java/org/exolab/castor/xml/MarshalFramework.java
===================================================================
--- xml/src/main/java/org/exolab/castor/xml/MarshalFramework.java (revision 7783)
+++ xml/src/main/java/org/exolab/castor/xml/MarshalFramework.java (working copy)
@@ -45,7 +45,11 @@
package org.exolab.castor.xml;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
import java.util.Vector;
import org.castor.xml.BackwardCompatibilityContext;
@@ -614,6 +618,16 @@
private FieldDescriptor[] _fields = null;
/**
+ * Map holding the properties set and read by Natures.
+ */
+ private Map _properties = new HashMap();
+
+ /**
+ * Map holding the available natures.
+ */
+ private Set _natures = new HashSet();
+
+ /**
* Creates a new InternalXMLClassDescriptor for the given
* XMLClassDescriptor.
*/
@@ -825,7 +839,51 @@
public boolean isChoice() {
return false;
}
-
+
+ /**
+ * @see org.exolab.castor.builder.info.nature.PropertyHolder#
+ * getProperty(java.lang.String)
+ * @param name
+ * of the property
+ * @return value of the property
+ */
+ public Object getProperty(final String name) {
+ return _properties.get(name);
+ }
+
+ /**
+ * @see org.exolab.castor.builder.info.nature.PropertyHolder#
+ * setProperty(java.lang.String, java.lang.Object)
+ * @param name
+ * of the property
+ * @param value
+ * of the property
+ */
+ public void setProperty(final String name, final Object value) {
+ _properties.put(name, value);
+ }
+
+ /**
+ * @see org.exolab.castor.builder.info.nature.NatureExtendable#
+ * addNature(java.lang.String)
+ * @param nature
+ * ID of the Nature
+ */
+ public void addNature(final String nature) {
+ _natures.add(nature);
+ }
+
+ /**
+ * @see org.exolab.castor.builder.info.nature.NatureExtendable#
+ * hasNature(java.lang.String)
+ * @param nature
+ * ID of the Nature
+ * @return true if the Nature ID was added.
+ */
+ public boolean hasNature(final String nature) {
+ return _natures.contains(nature);
+ }
+
} //-- InternalXMLClassDescriptor
Index: xml/src/main/java/org/exolab/castor/xml/util/JDOClassDescriptorResolverImpl.java
===================================================================
--- xml/src/main/java/org/exolab/castor/xml/util/JDOClassDescriptorResolverImpl.java (revision 7783)
+++ xml/src/main/java/org/exolab/castor/xml/util/JDOClassDescriptorResolverImpl.java (working copy)
@@ -48,7 +48,7 @@
protected List _packages = new LinkedList();
/**
- * {@link JDOClassDescriptor} resolution commands.
+ * JDO-specific {@link ClassDescriptor} resolution commands.
*/
private Map _commands = new HashMap();
@@ -64,7 +64,7 @@
/**
* Registers a {@link ClassDescriptorResolutionCommand} used to resolve
- * {@link JDOClassDescriptor}s.
+ * {@link ClassDescriptor}s.
*
* @param command
* to register.
Index: xml/src/main/java/org/exolab/castor/xml/util/XMLClassDescriptorImpl.java
===================================================================
--- xml/src/main/java/org/exolab/castor/xml/util/XMLClassDescriptorImpl.java (revision 7783)
+++ xml/src/main/java/org/exolab/castor/xml/util/XMLClassDescriptorImpl.java (working copy)
@@ -52,8 +52,12 @@
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
import org.castor.xml.XMLNaming;
import org.exolab.castor.mapping.AbstractFieldHandler;
@@ -203,9 +207,15 @@
private List _substitutes = new LinkedList();
- //----------------/
- //- Constructors -/
- //----------------/
+ /**
+ * Map holding the properties set and read by Natures.
+ */
+ private Map _properties = new HashMap();
+
+ /**
+ * Map holding the available natures.
+ */
+ private Set _natures = new HashSet();
/**
* Creates an XMLClassDescriptor class used by the Marshalling Framework.
@@ -1492,4 +1502,49 @@
public boolean isChoice() {
return this._compositor == CHOICE;
}
+
+ /**
+ * @see org.exolab.castor.builder.info.nature.PropertyHolder#
+ * getProperty(java.lang.String)
+ * @param name
+ * of the property
+ * @return value of the property
+ */
+ public Object getProperty(final String name) {
+ return _properties.get(name);
+ }
+
+ /**
+ * @see org.exolab.castor.builder.info.nature.PropertyHolder#
+ * setProperty(java.lang.String, java.lang.Object)
+ * @param name
+ * of the property
+ * @param value
+ * of the property
+ */
+ public void setProperty(final String name, final Object value) {
+ _properties.put(name, value);
+ }
+
+ /**
+ * @see org.exolab.castor.builder.info.nature.NatureExtendable#
+ * addNature(java.lang.String)
+ * @param nature
+ * ID of the Nature
+ */
+ public void addNature(final String nature) {
+ _natures.add(nature);
+ }
+
+ /**
+ * @see org.exolab.castor.builder.info.nature.NatureExtendable#
+ * hasNature(java.lang.String)
+ * @param nature
+ * ID of the Nature
+ * @return true if the Nature ID was added.
+ */
+ public boolean hasNature(final String nature) {
+ return _natures.contains(nature);
+ }
+
} //-- XMLClassDescriptor
Index: xml/src/main/java/org/exolab/castor/types/BaseDescriptor.java
===================================================================
--- xml/src/main/java/org/exolab/castor/types/BaseDescriptor.java (revision 7783)
+++ xml/src/main/java/org/exolab/castor/types/BaseDescriptor.java (working copy)
@@ -44,6 +44,11 @@
*/
package org.exolab.castor.types;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
import org.exolab.castor.mapping.AccessMode;
import org.exolab.castor.mapping.ClassDescriptor;
import org.exolab.castor.mapping.FieldDescriptor;
@@ -62,6 +67,8 @@
* @version $Revision$ $Date: 2004-12-16 22:49:25 -0700 (Thu, 16 Dec 2004) $
*/
public class BaseDescriptor implements XMLClassDescriptor {
+
+
/** Used for returning no attribute and no element fields */
protected static final XMLFieldDescriptor[] noXMLFields = new XMLFieldDescriptor[0];
@@ -72,9 +79,15 @@
/** The class type for the descriptor */
private Class _class = null;
- //----------------/
- //- Constructors -/
- //----------------/
+ /**
+ * Map holding the properties set and read by Natures.
+ */
+ private Map _properties = new HashMap();
+
+ /**
+ * Map holding the available natures.
+ */
+ private Set _natures = new HashSet();
protected BaseDescriptor(String xmlName, Class type) {
super();
@@ -82,10 +95,6 @@
_class = type;
} //-- BaseDescriptor
- //------------------/
- //- Public Methods -/
- //------------------/
-
/**
* Returns the set of XMLFieldDescriptors for all members that should be
* marshalled as XML attributes.
@@ -191,10 +200,6 @@
return super.toString() + "; descriptor for class: " + className + "; xml name: " + getXMLName();
} //-- toString
- //-------------------------------------/
- //- Implementation of ClassDescriptor -/
- //-------------------------------------/
-
/**
* Returns the Java class represented by this descriptor.
*
@@ -285,4 +290,48 @@
return false;
}
+ /**
+ * @see org.exolab.castor.builder.info.nature.PropertyHolder#
+ * getProperty(java.lang.String)
+ * @param name
+ * of the property
+ * @return value of the property
+ */
+ public Object getProperty(final String name) {
+ return _properties.get(name);
+ }
+
+ /**
+ * @see org.exolab.castor.builder.info.nature.PropertyHolder#
+ * setProperty(java.lang.String, java.lang.Object)
+ * @param name
+ * of the property
+ * @param value
+ * of the property
+ */
+ public void setProperty(final String name, final Object value) {
+ _properties.put(name, value);
+ }
+
+ /**
+ * @see org.exolab.castor.builder.info.nature.NatureExtendable#
+ * addNature(java.lang.String)
+ * @param nature
+ * ID of the Nature
+ */
+ public void addNature(final String nature) {
+ _natures.add(nature);
+ }
+
+ /**
+ * @see org.exolab.castor.builder.info.nature.NatureExtendable#
+ * hasNature(java.lang.String)
+ * @param nature
+ * ID of the Nature
+ * @return true if the Nature ID was added.
+ */
+ public boolean hasNature(final String nature) {
+ return _natures.contains(nature);
+ }
+
} //-- BaseDescriptor
Index: xml/src/main/java/org/exolab/castor/core/exceptions/CastorIllegalStateException.java
===================================================================
--- xml/src/main/java/org/exolab/castor/core/exceptions/CastorIllegalStateException.java (revision 7783)
+++ xml/src/main/java/org/exolab/castor/core/exceptions/CastorIllegalStateException.java (working copy)
@@ -1,82 +0,0 @@
-package org.exolab.castor.core.exceptions;
-
-import java.io.PrintStream;
-import java.io.PrintWriter;
-
-public final class CastorIllegalStateException extends IllegalStateException {
- /** SerialVersionUID */
- private static final long serialVersionUID = 2351884252990815335L;
-
- /** The cause for this exception. */
- private Throwable _cause;
-
- public CastorIllegalStateException() {
- super();
- }
-
- public CastorIllegalStateException(final String message) {
- super(message);
- }
-
- public CastorIllegalStateException(final Throwable cause) {
- super();
- _cause = cause;
- }
-
- public CastorIllegalStateException(final String message, final Throwable cause) {
- super(message);
- _cause = cause;
- }
-
- /**
- * Match the JDK 1.4 Throwable version of getCause() on JDK<1.4 systems.
- *
- * @return The throwable cause of this exception.
- */
- public Throwable getCause() {
- return _cause;
- }
-
- /**
- * Print a stack trace to stderr.
- */
- public void printStackTrace() {
- // Print the stack trace for this exception.
- super.printStackTrace();
-
- if (_cause != null) {
- System.err.print("Caused by: ");
- _cause.printStackTrace();
- }
- }
-
- /**
- * Print a stack trace to the specified PrintStream.
- *
- * @param s The PrintStream to print a stack trace to.
- */
- public void printStackTrace(final PrintStream s) {
- // Print the stack trace for this exception.
- super.printStackTrace(s);
-
- if (_cause != null) {
- s.print("Caused by: ");
- _cause.printStackTrace(s);
- }
- }
-
- /**
- * Print a stack trace to the specified PrintWriter.
- *
- * @param w The PrintWriter to print a stack trace to.
- */
- public void printStackTrace(final PrintWriter w) {
- // Print the stack trace for this exception.
- super.printStackTrace(w);
-
- if (_cause != null) {
- w.print("Caused by: ");
- _cause.printStackTrace(w);
- }
- }
-}
Index: xml/src/main/java/org/exolab/castor/core/exceptions/CastorException.java
===================================================================
--- xml/src/main/java/org/exolab/castor/core/exceptions/CastorException.java (revision 7783)
+++ xml/src/main/java/org/exolab/castor/core/exceptions/CastorException.java (working copy)
@@ -1,210 +0,0 @@
-/**
- * Redistribution and use of this software and associated documentation
- * ("Software"), with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * 1. Redistributions of source code must retain copyright
- * statements and notices. Redistributions must also contain a
- * copy of this document.
- *
- * 2. Redistributions in binary form must reproduce the
- * above copyright notice, this list of conditions and the
- * following disclaimer in the documentation and/or other
- * materials provided with the distribution.
- *
- * 3. The name "Exolab" must not be used to endorse or promote
- * products derived from this Software without prior written
- * permission of Intalio, Inc. For written permission,
- * please contact info@exolab.org.
- *
- * 4. Products derived from this Software may not be called "Exolab"
- * nor may "Exolab" appear in their names without prior written
- * permission of Intalio, Inc. Exolab is a registered
- * trademark of Intalio, Inc.
- *
- * 5. Due credit should be given to the Exolab Project
- * (http://www.exolab.org/).
- *
- * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
- * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
- * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- * OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Copyright 1999 (C) Intalio, Inc. All Rights Reserved.
- *
- * $Id$
- */
-
-package org.exolab.castor.core.exceptions;
-
-import java.io.PrintStream;
-import java.io.PrintWriter;
-
-/**
- * The base exception for Castor (or at least Castor XML)
- *
- * @author Keith Visco
- * @version $Revision$ $Date: 2006-04-25 15:08:23 -0600 (Tue, 25 Apr 2006) $
- */
-public class CastorException extends Exception {
- /** SerialVersionUID */
- private static final long serialVersionUID = -5963804406955523505L;
-
- /** The cause for this exception. */
- private Throwable cause;
-
- /**
- * Creates a new CastorException with no message, or nested Exception
- */
- public CastorException() {
- super();
- }
-
- /**
- * Creates a new CastorException with the given message.
- *
- * @param message the message for this Exception
- */
- public CastorException(String message) {
- super(message);
- }
-
- /**
- * Creates a new CastorException with the given message and cause.
- * @param message The message for this exception.
- * @param cause A Throwable instance.
- */
- public CastorException(String message, Throwable cause) {
- super (message);
- this.cause = cause;
- }
-
- /**
- * Creates a new CastorException with the given cause.
- * @param cause A Throwable instance.
- */
- public CastorException(Throwable cause) {
- this.cause = cause;
- }
-
- /**
- * Match the JDK 1.4 Throwable version of initCause() on JDK<1.4 systems.
- * @param cause The throwable you wish to attach to this exception as the 'cause' of the exception.
- * @return This exception. (Throwable also returns this, not the cause.)
- */
- public synchronized Throwable initCause(Throwable cause) {
- this.cause = cause;
- return this;
- }
-
- /**
- * Match the JDK 1.4 Throwable version of getCause() on JDK<1.4 systems.
- * @return The throwable cause of this exception.
- */
- public Throwable getCause() {
- return cause;
- }
-
- /**
- * Retrieve the cause of a specific exception. This is a nice, safe, easy
- * thing to call internally to ensure we never call getCause on something
- * that shouldn't have it. More hand-holding than anything else, really, but
- * it makes it easy to read.
- *
- * @param e
- * The exception you wish to extract a cause from.
- * @return The throwable attached to that exception as a cause.
- */
- private static Throwable getNestedException(Throwable e) {
- // Deal with the myriad ways of getting a nested exception.
- if (e instanceof CastorException) return ((CastorException) e).getCause();
- return null;
- }
-
- /**
- * Return the detailed message from this Exception. Chain message
- * information from child exceptions into it, so that the message shows the
- * chain of message information available.
- * @return the detailed message from this Exception.
- */
- public String getMessage() {
- // Get this exception's message.
- String msg = super.getMessage();
-
- Throwable parent = this;
- Throwable child = getNestedException(parent);
-
- if (child!=null) {
- // Get the child's message.
- String msg2 = child.getMessage();
-
- // If we found a message for the child exception,
- // we append it.
- if (msg2 != null) {
- if (msg != null) {
- msg += ": " + msg2;
- } else {
- msg = msg2;
- }
- }
- }
-
- // Return the completed message.
- return msg;
- }
-
- /**
- * Print a stack trace to stderr.
- */
- public void printStackTrace() {
- // Print the stack trace for this exception.
- super.printStackTrace();
-
- Throwable child = getNestedException(this);
-
- if (child != null) {
- System.err.print("Caused by: ");
- child.printStackTrace();
- }
- }
-
- /**
- * Print a stack trace to the specified PrintStream.
- * @param s The PrintStream to print a stack trace to.
- */
- public void printStackTrace(PrintStream s) {
- // Print the stack trace for this exception.
- super.printStackTrace(s);
-
- Throwable child = getNestedException(this);
-
- if (child != null) {
- s.print("Caused by: ");
- child.printStackTrace(s);
- }
- }
-
- /**
- * Print a stack trace to the specified PrintWriter.
- * @param w The PrintWriter to print a stack trace to.
- */
- public void printStackTrace(PrintWriter w) {
- // Print the stack trace for this exception.
- super.printStackTrace(w);
-
- Throwable child = getNestedException(this);
- if (child != null) {
- w.print("Caused by: ");
- child.printStackTrace(w);
- }
- }
-
-}
Index: xml/src/main/java/org/exolab/castor/mapping/ClassDescriptor.java
===================================================================
--- xml/src/main/java/org/exolab/castor/mapping/ClassDescriptor.java (revision 7783)
+++ xml/src/main/java/org/exolab/castor/mapping/ClassDescriptor.java (working copy)
@@ -44,6 +44,8 @@
*/
package org.exolab.castor.mapping;
+import org.castor.core.nature.PropertyHolder;
+
/**
* Describes the properties of a class and its fields. Implementations
* will extend this inteface to provide additional properties.
@@ -52,7 +54,7 @@
* @version $Revision$ $Date: 2003-03-03 00:05:44 -0700 (Mon, 03 Mar 2003) $
* @see FieldDescriptor
*/
-public interface ClassDescriptor {
+public interface ClassDescriptor extends PropertyHolder {
/**
* Returns the Java class represented by this descriptor.
@@ -81,6 +83,7 @@
* @return The identity field
*/
FieldDescriptor getIdentity();
+
}
Index: xml/src/main/java/org/exolab/castor/mapping/loader/ClassDescriptorImpl.java
===================================================================
--- xml/src/main/java/org/exolab/castor/mapping/loader/ClassDescriptorImpl.java (revision 7783)
+++ xml/src/main/java/org/exolab/castor/mapping/loader/ClassDescriptorImpl.java (working copy)
@@ -44,9 +44,12 @@
*/
package org.exolab.castor.mapping.loader;
-import java.util.Collection;
-import java.util.LinkedList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import org.castor.core.nature.PropertyHolder;
import org.exolab.castor.mapping.ClassDescriptor;
import org.exolab.castor.mapping.FieldDescriptor;
import org.exolab.castor.mapping.xml.ClassMapping;
@@ -59,8 +62,7 @@
* @author Ralf Joachim
* @version $Revision$ $Date: 2006-01-07 15:48:31 -0700 (Sat, 07 Jan 2006) $
*/
-public class ClassDescriptorImpl implements ClassDescriptor {
- //-----------------------------------------------------------------------------------
+public class ClassDescriptorImpl implements ClassDescriptor, PropertyHolder {
/**
* {@link ClassMapping} instance holding class mapping information required
@@ -79,12 +81,6 @@
*/
private ClassDescriptor _extends;
- /**
- * A collection of class descriptors that extend this class, or
- * an empty collection if this is a leaf class.
- */
- private final Collection _extended = new LinkedList();
-
/**
* The {@link ClassDescriptor} of the class which this class
* depends upon.
@@ -96,9 +92,19 @@
*/
private FieldDescriptor[] _fields;
- /**
- * The field of the identity for this class.
+ /**
+ * Map holding the properties set and read by Natures.
*/
+ private Map _properties = new HashMap();
+
+ /**
+ * Map holding the available natures.
+ */
+ private Set _natures = new HashSet();
+
+ /**
+ * Identity {@link FieldDescriptor}s.
+ */
private FieldDescriptor[] _identities;
/**
@@ -152,14 +158,6 @@
}
/**
- * Adds a {@link ClassDescriptor} that extends this class.
- * @param classDesc A {@link ClassDescriptor} that extends this class.
- */
- public void addExtended(final ClassDescriptor classDesc) {
- _extended.add(classDesc);
- }
-
- /**
* Sets the {@link ClassDescriptor} of the class which this class
* depends upon.
* @param depends the {@link ClassDescriptor} of the class which this class
@@ -196,6 +194,59 @@
}
/**
+ * {@inheritDoc}
+ * @see java.lang.Object#toString()
+ */
+ public String toString() {
+ return _javaClass.getName();
+ }
+
+ /**
+ * @see org.exolab.castor.builder.info.nature.PropertyHolder#
+ * getProperty(java.lang.String)
+ * @param name
+ * of the property
+ * @return value of the property
+ */
+ public Object getProperty(final String name) {
+ return _properties.get(name);
+ }
+
+ /**
+ * @see org.exolab.castor.builder.info.nature.PropertyHolder#
+ * setProperty(java.lang.String, java.lang.Object)
+ * @param name
+ * of the property
+ * @param value
+ * of the property
+ */
+ public void setProperty(final String name, final Object value) {
+ _properties.put(name, value);
+ }
+
+ /**
+ * @see org.exolab.castor.builder.info.nature.NatureExtendable#
+ * addNature(java.lang.String)
+ * @param nature
+ * ID of the Nature
+ */
+ public void addNature(final String nature) {
+ _natures.add(nature);
+ }
+
+ /**
+ * @see org.exolab.castor.builder.info.nature.NatureExtendable#
+ * hasNature(java.lang.String)
+ * @param nature
+ * ID of the Nature
+ * @return true if the Nature ID was added.
+ */
+ public boolean hasNature(final String nature) {
+ return _natures.contains(nature);
+
+ }
+
+ /**
* Sets the {@link FieldDescriptor}s that describe the identities as defined for this class.
* @param identities the {@link FieldDescriptor}s that describe the identities as defined
* for this class.
@@ -213,29 +264,18 @@
}
/**
- * {@inheritDoc}
- * @see org.exolab.castor.mapping.ClassDescriptor#getIdentity()
+ * Returns the first {@link FieldDescriptor} instance.
+ * @return the first {@link FieldDescriptor} instance
*/
public FieldDescriptor getIdentity() {
- return (_identities == null) ? null : _identities[0];
+ FieldDescriptor[] identities = getIdentities();
+ if (identities == null) {
+ return null;
+ }
+ return identities[0];
}
- /**
- * Returns a collection of {@link ClassDescriptor}s that extend this class (descriptor).
- * @return A collection of {@link ClassDescriptor}s that extend this class.
- */
- public Collection getExtended() {
- return _extended;
- }
- /**
- * {@inheritDoc}
- * @see java.lang.Object#toString()
- */
- public String toString() {
- return _javaClass.getName();
- }
-
}
Index: cpactf/src/main/java/harness/BaseHarnessDescriptor.java
===================================================================
--- cpactf/src/main/java/harness/BaseHarnessDescriptor.java (revision 7783)
+++ cpactf/src/main/java/harness/BaseHarnessDescriptor.java (working copy)
@@ -1,5 +1,10 @@
package harness;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
import org.exolab.castor.mapping.FieldDescriptor;
import org.exolab.castor.xml.NodeType;
import org.exolab.castor.xml.TypeValidator;
@@ -53,6 +58,16 @@
private org.exolab.castor.xml.XMLFieldDescriptor _identity;
/**
+ * Map holding the properties set and read by Natures.
+ */
+ private Map _properties = new HashMap();
+
+ /**
+ * Map holding the available natures.
+ */
+ private Set _natures = new HashSet();
+
+ /**
* {@inheritDoc}
* @see org.exolab.castor.xml.XMLClassDescriptor#getAttributeDescriptors()
*/
@@ -258,6 +273,50 @@
public boolean isChoice() {
return false;
}
-
+
+ /**
+ * @see org.exolab.castor.builder.info.nature.PropertyHolder#
+ * getProperty(java.lang.String)
+ * @param name
+ * of the property
+ * @return value of the property
+ */
+ public Object getProperty(final String name) {
+ return _properties.get(name);
+ }
+
+ /**
+ * @see org.exolab.castor.builder.info.nature.PropertyHolder#
+ * setProperty(java.lang.String, java.lang.Object)
+ * @param name
+ * of the property
+ * @param value
+ * of the property
+ */
+ public void setProperty(final String name, final Object value) {
+ _properties.put(name, value);
+ }
+
+ /**
+ * @see org.exolab.castor.builder.info.nature.NatureExtendable#
+ * addNature(java.lang.String)
+ * @param nature
+ * ID of the Nature
+ */
+ public void addNature(final String nature) {
+ _natures.add(nature);
+ }
+
+ /**
+ * @see org.exolab.castor.builder.info.nature.NatureExtendable#
+ * hasNature(java.lang.String)
+ * @param nature
+ * ID of the Nature
+ * @return true if the Nature ID was added.
+ */
+ public boolean hasNature(final String nature) {
+ return _natures.contains(nature);
+ }
+
}
Index: cpa/src/test/java/org/exolab/castor/jdo/engine/jdo_descriptors/AddressJDODescriptor.java
===================================================================
--- cpa/src/test/java/org/exolab/castor/jdo/engine/jdo_descriptors/AddressJDODescriptor.java (revision 7783)
+++ cpa/src/test/java/org/exolab/castor/jdo/engine/jdo_descriptors/AddressJDODescriptor.java (working copy)
@@ -7,13 +7,14 @@
import org.apache.commons.logging.LogFactory;
import org.castor.jdo.engine.SQLTypeInfos;
import org.exolab.castor.jdo.engine.Address;
-import org.exolab.castor.jdo.engine.JDOClassDescriptorImpl;
import org.exolab.castor.jdo.engine.JDOFieldDescriptor;
import org.exolab.castor.jdo.engine.JDOFieldDescriptorImpl;
+import org.exolab.castor.jdo.engine.nature.ClassDescriptorJDONature;
import org.exolab.castor.mapping.AccessMode;
import org.exolab.castor.mapping.FieldDescriptor;
import org.exolab.castor.mapping.FieldHandler;
import org.exolab.castor.mapping.MappingException;
+import org.exolab.castor.mapping.loader.ClassDescriptorImpl;
import org.exolab.castor.mapping.loader.FieldHandlerImpl;
import org.exolab.castor.mapping.loader.TypeInfo;
import org.exolab.castor.mapping.xml.ClassChoice;
@@ -31,7 +32,7 @@
* @author Tobias Hochwallner, Lukas Lang
*
*/
-public class AddressJDODescriptor extends JDOClassDescriptorImpl {
+public class AddressJDODescriptor extends ClassDescriptorImpl {
/**
* Logger.
@@ -44,6 +45,7 @@
*/
public AddressJDODescriptor() {
super();
+ addNature(ClassDescriptorJDONature.class.getName());
ClassMapping mapping = new ClassMapping();
ClassChoice choice = new ClassChoice();
MapTo mapTo = new MapTo();
@@ -51,13 +53,13 @@
LOG.debug("Constructor invoked");
// Set DB table name
- setTableName("address");
+ new ClassDescriptorJDONature(this).setTableName("address");
// Set corresponding Java class
setJavaClass(Address.class);
// Set access mode
- setAccessMode(AccessMode.Shared);
+ new ClassDescriptorJDONature(this).setAccessMode(AccessMode.Shared);
// Set cache key
- addCacheParam("name", "org.castor.cpa.functional.onetoone.Address");
+ new ClassDescriptorJDONature(this).addCacheParam("name", "org.castor.cpa.functional.onetoone.Address");
// Configure class mapping
mapping.setAccess(ClassMappingAccessType.SHARED);
@@ -77,7 +79,7 @@
// Set fields
setFields(new FieldDescriptor[] {});
// Set identity
- setIdentities(new FieldDescriptor[] { idFieldDescr });
+ setIdentities((new FieldDescriptor[] { idFieldDescr }));
LOG.debug("Instantiation finished");
}
Index: cpa/src/test/java/org/exolab/castor/jdo/util/ClassToBeResolved.java
===================================================================
--- cpa/src/test/java/org/exolab/castor/jdo/util/ClassToBeResolved.java (revision 7783)
+++ cpa/src/test/java/org/exolab/castor/jdo/util/ClassToBeResolved.java (working copy)
@@ -16,7 +16,7 @@
package org.exolab.castor.jdo.util;
/**
- * Empty class to test resolving of a {@link JDOClassDescriptor} from a package
+ * Empty class to test resolving of a {@link ClassDescriptor} from a package
* which contains a .jdo.castor.cdr file.
*
* @see org.exolab.castor.xml.util.ClassResolutionByCDR
Index: cpa/src/test/java/org/exolab/castor/jdo/util/ClassNotToBeResolved.java
===================================================================
--- cpa/src/test/java/org/exolab/castor/jdo/util/ClassNotToBeResolved.java (revision 7783)
+++ cpa/src/test/java/org/exolab/castor/jdo/util/ClassNotToBeResolved.java (working copy)
@@ -16,7 +16,7 @@
package org.exolab.castor.jdo.util;
/**
- * Empty class to test resolving of a {@link JDOClassDescriptor} from a package
+ * Empty class to test resolving of a {@link ClassDescriptor} from a package
* which contains a .jdo.castor.cdr file.
*
* This class should not be resolved as it is not associated with a
Index: cpa/src/test/java/org/exolab/castor/jdo/util/jdo_descriptors/ClassToBeResolvedJDODescriptor.java
===================================================================
--- cpa/src/test/java/org/exolab/castor/jdo/util/jdo_descriptors/ClassToBeResolvedJDODescriptor.java (revision 7783)
+++ cpa/src/test/java/org/exolab/castor/jdo/util/jdo_descriptors/ClassToBeResolvedJDODescriptor.java (working copy)
@@ -15,10 +15,10 @@
*/
package org.exolab.castor.jdo.util.jdo_descriptors;
-import org.exolab.castor.jdo.engine.JDOClassDescriptorImpl;
+import org.exolab.castor.mapping.loader.ClassDescriptorImpl;
/**
- * Empty class to test resolving of a {@link JDOClassDescriptor} from a package
+ * Empty class to test resolving of a {@link ClassDescriptor} from a package
* which contains a .jdo.castor.cdr file.
*
* @see org.exolab.castor.xml.util.ClassResolutionByCDR
@@ -27,7 +27,7 @@
* @since 1.2.1
*
*/
-public class ClassToBeResolvedJDODescriptor extends JDOClassDescriptorImpl {
+public class ClassToBeResolvedJDODescriptor extends ClassDescriptorImpl {
public ClassToBeResolvedJDODescriptor() {
super();
Index: cpa/src/main/java/org/exolab/castor/persist/ClassMolder.java
===================================================================
--- cpa/src/main/java/org/exolab/castor/persist/ClassMolder.java (revision 7783)
+++ cpa/src/main/java/org/exolab/castor/persist/ClassMolder.java (working copy)
@@ -64,8 +64,8 @@
import org.exolab.castor.jdo.Persistent;
import org.exolab.castor.jdo.TimeStampable;
import org.exolab.castor.jdo.engine.JDOCallback;
-import org.exolab.castor.jdo.engine.JDOClassDescriptor;
import org.exolab.castor.jdo.engine.JDOFieldDescriptor;
+import org.exolab.castor.jdo.engine.nature.ClassDescriptorJDONature;
import org.exolab.castor.mapping.AccessMode;
import org.exolab.castor.mapping.ClassDescriptor;
import org.exolab.castor.mapping.FieldDescriptor;
@@ -219,10 +219,9 @@
ds.pairExtends(this, extendsClassMapping.getName());
}
- if (clsDesc instanceof JDOClassDescriptor) {
- _cacheParams = ((JDOClassDescriptor) clsDesc).getCacheParams();
- _isKeyGenUsed = (((JDOClassDescriptor) clsDesc)
- .getKeyGeneratorDescriptor() != null);
+ if (clsDesc.hasNature(ClassDescriptorJDONature.class.getName())) {
+ _cacheParams = new ClassDescriptorJDONature(clsDesc).getCacheParams();
+ _isKeyGenUsed = new ClassDescriptorJDONature(clsDesc).getKeyGeneratorDescriptor() != null;
}
// construct FieldMolders for each of the identity fields of
@@ -291,8 +290,8 @@
+ fmFields.getClass(), e);
}
- if (relDesc instanceof JDOClassDescriptor) {
- FieldDescriptor[] relatedIds = ((JDOClassDescriptor) relDesc).getIdentities();
+ if (relDesc.hasNature(ClassDescriptorJDONature.class.getName())) {
+ FieldDescriptor[] relatedIds = ((ClassDescriptorImpl) relDesc).getIdentities();
relatedIdSQL = new String[relatedIds.length];
relatedIdType = new int[relatedIds.length];
relatedIdConvertTo = new TypeConvertor[relatedIds.length];
@@ -1354,6 +1353,6 @@
* @return The actual (OQL) statement
*/
public String getNamedQuery(final String name) {
- return (String) ((JDOClassDescriptor) _clsDesc).getNamedQueries().get(name);
+ return (String) new ClassDescriptorJDONature(_clsDesc).getNamedQueries().get(name);
}
}
Index: cpa/src/main/java/org/exolab/castor/jdo/oql/ParseTreeWalker.java
===================================================================
--- cpa/src/main/java/org/exolab/castor/jdo/oql/ParseTreeWalker.java (revision 7783)
+++ cpa/src/main/java/org/exolab/castor/jdo/oql/ParseTreeWalker.java (working copy)
@@ -23,11 +23,11 @@
import org.exolab.castor.jdo.DbMetaInfo;
import org.exolab.castor.jdo.QueryException;
-import org.exolab.castor.jdo.engine.JDOClassDescriptor;
-import org.exolab.castor.jdo.engine.JDOClassDescriptorImpl;
import org.exolab.castor.jdo.engine.JDOFieldDescriptor;
import org.exolab.castor.jdo.engine.SQLEngine;
import org.exolab.castor.jdo.engine.SQLHelper;
+import org.exolab.castor.jdo.engine.nature.ClassDescriptorJDONature;
+import org.exolab.castor.mapping.ClassDescriptor;
import org.exolab.castor.mapping.loader.Types;
import org.exolab.castor.persist.LockEngine;
import org.exolab.castor.persist.spi.QueryExpression;
@@ -62,7 +62,7 @@
private HashMap _allPaths;
private SQLEngine _engine;
- private JDOClassDescriptor _clsDesc;
+ private ClassDescriptor _clsDesc;
//projection types
public static final int AGGREGATE = 1;
@@ -152,7 +152,7 @@
*
* @return The _clsDesc member.
*/
- public JDOClassDescriptor getClassDescriptor() {
+ public ClassDescriptor getClassDescriptor() {
return _clsDesc;
}
@@ -320,16 +320,16 @@
* @return JDOFieldDescriptor for the specified field, null if not found.
*/
private JDOFieldDescriptor getFieldDesc(final String fieldName,
- final JDOClassDescriptor clsDesc) {
+ final ClassDescriptor clsDesc) {
- JDOClassDescriptor classDescriptor = clsDesc;
+ ClassDescriptor classDescriptor = clsDesc;
JDOFieldDescriptor fieldDescriptor;
while (classDescriptor != null) {
- fieldDescriptor = classDescriptor.getField(fieldName);
+ fieldDescriptor = new ClassDescriptorJDONature(classDescriptor).getField(fieldName);
if (fieldDescriptor != null) {
return fieldDescriptor;
}
- classDescriptor = (JDOClassDescriptor) classDescriptor.getExtends();
+ classDescriptor = classDescriptor.getExtends();
}
return null;
}
@@ -344,23 +344,23 @@
* @param tableIndex Field index in the path info
*/
private Object[] getFieldAndClassDesc(final String fieldName,
- final JDOClassDescriptor clsDesc,
+ final ClassDescriptor clsDesc,
final QueryExpression expr,
final Vector path, final int tableIndex) {
JDOFieldDescriptor field = null;
- JDOClassDescriptor cd = clsDesc;
+ ClassDescriptor cd = clsDesc;
JDOFieldDescriptor tempField = null;
- JDOClassDescriptor tempCd = clsDesc;
+ ClassDescriptor tempCd = clsDesc;
Object[] retVal;
while (tempCd != null) {
- tempField = tempCd.getField(fieldName);
+ tempField = new ClassDescriptorJDONature(tempCd).getField(fieldName);
if (tempField != null) {
field = tempField;
cd = tempCd;
}
- tempCd = (JDOClassDescriptor) tempCd.getExtends();
+ tempCd = tempCd.getExtends();
}
if (field == null) { return null; }
@@ -369,18 +369,18 @@
retVal = new Object[] {field, cd};
if (cd != clsDesc) {
// now add inner join for "extends"
- String tableAlias1 = clsDesc.getTableName();
- String tableAlias2 = cd.getTableName();
+ String tableAlias1 = new ClassDescriptorJDONature(clsDesc).getTableName();
+ String tableAlias2 = new ClassDescriptorJDONature(cd).getTableName();
if (tableIndex > 0) {
tableAlias1 = buildTableAlias(tableAlias1, path, tableIndex);
tableAlias2 = buildTableAlias(tableAlias2, path, tableIndex);
}
- expr.addTable(cd.getTableName(), tableAlias2);
+ expr.addTable(new ClassDescriptorJDONature(cd).getTableName(), tableAlias2);
String[] clsDescIdNames = SQLHelper.getIdentitySQLNames(clsDesc);
String[] cdIdNames = SQLHelper.getIdentitySQLNames(cd);
expr.addInnerJoin(
- clsDesc.getTableName(), clsDescIdNames, tableAlias1,
- cd.getTableName(), cdIdNames, tableAlias2);
+ new ClassDescriptorJDONature(clsDesc).getTableName(), clsDescIdNames, tableAlias1,
+ new ClassDescriptorJDONature(cd).getTableName(), cdIdNames, tableAlias2);
}
return retVal;
}
@@ -456,7 +456,7 @@
}
//use the ClassDescriptor to check that the rest of the path is valid.
- JDOClassDescriptor curClassDesc = _clsDesc;
+ ClassDescriptor curClassDesc = _clsDesc;
JDOFieldDescriptor curField = null;
int count = 0;
String curToken;
@@ -480,7 +480,7 @@
}
projectionName.append(".").append(curName);
projectionInfo.addElement(curName);
- curClassDesc = (JDOClassDescriptor) curField.getClassDescriptor();
+ curClassDesc = curField.getClassDescriptor();
if ((curClassDesc == null) && iter.hasNext()) {
throw new QueryException("An non-reference field was requested: "
+ curName + " (" + curClassDesc + ")");
@@ -990,24 +990,24 @@
selectPart = _parseTree.getChild(0);
}
- _queryExpr.addTable(_clsDesc.getTableName());
+ _queryExpr.addTable(new ClassDescriptorJDONature(_clsDesc).getTableName());
// add table names and joins for all base classes
- JDOClassDescriptor oldDesc = _clsDesc;
- JDOClassDescriptor tempDesc = (JDOClassDescriptor) _clsDesc.getExtends();
+ ClassDescriptor oldDesc = _clsDesc;
+ ClassDescriptor tempDesc = _clsDesc.getExtends();
while (tempDesc != null) {
- String tableName = tempDesc.getTableName();
+ String tableName = new ClassDescriptorJDONature(tempDesc).getTableName();
_queryExpr.addTable(tableName);
JDOFieldDescriptor leftField = (JDOFieldDescriptor) oldDesc.getIdentity();
JDOFieldDescriptor rightField = (JDOFieldDescriptor) tempDesc.getIdentity();
_queryExpr.addInnerJoin(
- oldDesc.getTableName(), leftField.getSQLName(),
- tempDesc.getTableName(), rightField.getSQLName());
+ new ClassDescriptorJDONature(oldDesc).getTableName(), leftField.getSQLName(),
+ new ClassDescriptorJDONature(tempDesc).getTableName(), rightField.getSQLName());
oldDesc = tempDesc;
- tempDesc = (JDOClassDescriptor) tempDesc.getExtends();
+ tempDesc = tempDesc.getExtends();
}
_queryExpr.addSelect(getSQLExpr(selectPart));
}
@@ -1079,7 +1079,7 @@
}
// the class for the join is even this class or one of the base classes
- JDOClassDescriptor sourceClass = _clsDesc;
+ ClassDescriptor sourceClass = _clsDesc;
for (int i = 1; i < path.size() - 1; i++) {
JDOFieldDescriptor fieldDesc = null;
@@ -1091,40 +1091,41 @@
throw new IllegalStateException("Field not found:" + path.elementAt(i));
}
fieldDesc = (JDOFieldDescriptor) fieldAndClass[0];
- sourceClass = (JDOClassDescriptor) fieldAndClass[1];
+ sourceClass = (ClassDescriptor) fieldAndClass[1];
- JDOClassDescriptor clsDesc =
- (JDOClassDescriptor) fieldDesc.getClassDescriptor();
+ ClassDescriptor clsDesc = fieldDesc.getClassDescriptor();
if (clsDesc != null) {
//we must add this table as a join
+ ClassDescriptorJDONature sourceClassJDONature =
+ new ClassDescriptorJDONature(sourceClass);
if (fieldDesc.getManyKey() == null) {
//a many -> one relationship
JDOFieldDescriptor foreignKey =
(JDOFieldDescriptor) clsDesc.getIdentity();
- String sourceTableAlias = sourceClass.getTableName();
+ String sourceTableAlias = sourceClassJDONature.getTableName();
if (i > 1) {
sourceTableAlias = buildTableAlias(sourceTableAlias, path, i - 1);
}
_queryExpr.addInnerJoin(
- sourceClass.getTableName(), fieldDesc.getSQLName(),
+ sourceClassJDONature.getTableName(), fieldDesc.getSQLName(),
sourceTableAlias,
- clsDesc.getTableName(), foreignKey.getSQLName(),
- buildTableAlias(clsDesc.getTableName(), path, i));
+ new ClassDescriptorJDONature(clsDesc).getTableName(), foreignKey.getSQLName(),
+ buildTableAlias(new ClassDescriptorJDONature(clsDesc).getTableName(), path, i));
} else if (fieldDesc.getManyTable() == null) {
//a one -> many relationship
JDOFieldDescriptor identity =
(JDOFieldDescriptor) sourceClass.getIdentity();
- String sourceTableAlias = sourceClass.getTableName();
+ String sourceTableAlias = sourceClassJDONature.getTableName();
if (i > 1) {
sourceTableAlias = buildTableAlias(sourceTableAlias, path, i - 1);
}
_queryExpr.addInnerJoin(
- sourceClass.getTableName(), identity.getSQLName(),
+ sourceClassJDONature.getTableName(), identity.getSQLName(),
sourceTableAlias,
- clsDesc.getTableName(), fieldDesc.getManyKey(),
- buildTableAlias(clsDesc.getTableName(), path, i));
+ new ClassDescriptorJDONature(clsDesc).getTableName(), fieldDesc.getManyKey(),
+ buildTableAlias(new ClassDescriptorJDONature(clsDesc).getTableName(), path, i));
} else {
//a many -> many relationship
JDOFieldDescriptor identity =
@@ -1132,14 +1133,14 @@
JDOFieldDescriptor foreignKey =
(JDOFieldDescriptor) clsDesc.getIdentity();
String manyTableAlias = fieldDesc.getManyTable();
- String sourceTableAlias = sourceClass.getTableName();
+ String sourceTableAlias = sourceClassJDONature.getTableName();
if (i > 1) {
manyTableAlias = buildTableAlias(manyTableAlias, path, i - 1);
sourceTableAlias = buildTableAlias(sourceTableAlias, path, i - 1);
}
_queryExpr.addInnerJoin(
- sourceClass.getTableName(), identity.getSQLName(),
+ sourceClassJDONature.getTableName(), identity.getSQLName(),
sourceTableAlias,
fieldDesc.getManyTable(), fieldDesc.getManyKey(),
manyTableAlias);
@@ -1147,8 +1148,8 @@
_queryExpr.addInnerJoin(
fieldDesc.getManyTable(), fieldDesc.getSQLName(),
manyTableAlias,
- clsDesc.getTableName(), foreignKey.getSQLName(),
- buildTableAlias(clsDesc.getTableName(), path, i));
+ new ClassDescriptorJDONature(clsDesc).getTableName(), foreignKey.getSQLName(),
+ buildTableAlias(new ClassDescriptorJDONature(clsDesc).getTableName(), path, i));
}
sourceClass = clsDesc;
}
@@ -1324,18 +1325,19 @@
"fieldInfo for " + exprTree.toStringEx() + " not found");
}
- JDOClassDescriptor clsDesc =
- (JDOClassDescriptor) field.getContainingClassDescriptor();
+ ClassDescriptor clsDesc = field.getContainingClassDescriptor();
if (clsDesc == null) {
throw new IllegalStateException(
"ContainingClass of " + field.toString() + " is null !");
}
String clsTableAlias;
- if (tokenType == TokenType.DOT && path != null && path.size() > 2) {
+ ClassDescriptorJDONature classDescriptorJDONature =
+ new ClassDescriptorJDONature(clsDesc);
+ if (tokenType == TokenType.DOT && path != null && path.size() > 2) {
clsTableAlias = buildTableAlias(
- clsDesc.getTableName(), path, path.size() - 2);
- JDOClassDescriptor srcDesc = _clsDesc;
+ classDescriptorJDONature.getTableName(), path, path.size() - 2);
+ ClassDescriptor srcDesc = _clsDesc;
for (int i = 1; i < path.size(); i++) {
Object[] fieldAndClass = getFieldAndClassDesc(
(String) path.elementAt(i),
@@ -1347,10 +1349,10 @@
}
JDOFieldDescriptor fieldDesc =
(JDOFieldDescriptor) fieldAndClass[0];
- srcDesc = (JDOClassDescriptor) fieldDesc.getClassDescriptor();
+ srcDesc = fieldDesc.getClassDescriptor();
}
} else {
- clsTableAlias = buildTableAlias(clsDesc.getTableName(), path, 9999);
+ clsTableAlias = buildTableAlias(classDescriptorJDONature.getTableName(), path, 9999);
}
return _queryExpr.encodeColumn(clsTableAlias, field.getSQLName()[0]);
Index: cpa/src/main/java/org/exolab/castor/jdo/engine/SQLHelper.java
===================================================================
--- cpa/src/main/java/org/exolab/castor/jdo/engine/SQLHelper.java (revision 7783)
+++ cpa/src/main/java/org/exolab/castor/jdo/engine/SQLHelper.java (working copy)
@@ -26,7 +26,10 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.castor.jdo.engine.SQLTypeInfos;
+import org.exolab.castor.jdo.engine.nature.ClassDescriptorJDONature;
+import org.exolab.castor.mapping.ClassDescriptor;
import org.exolab.castor.mapping.FieldDescriptor;
+import org.exolab.castor.mapping.loader.ClassDescriptorImpl;
import org.exolab.castor.persist.spi.Identity;
/**
@@ -47,26 +50,26 @@
final int numberOfIdentityColumns, final int numberOfFields,
final int numberOfExtendLevels, final ResultSet rs) throws SQLException {
- JDOClassDescriptor potentialLeafDescriptor = null;
+ ClassDescriptor potentialLeafDescriptor = null;
int suggestedNumberOfFields = numberOfFields;
Collection potentialActualClassDescriptor = new LinkedList();
int numberOfIdentitiesToAnalyze = 0;
addExtendingClassDescriptors(potentialActualClassDescriptor, extendingClassDescriptors);
- JDOClassDescriptor potentialClassDescriptor = null;
- JDOClassDescriptor potentialClassDescriptorPrevious = null;
+ ClassDescriptor potentialClassDescriptor = null;
+ ClassDescriptor potentialClassDescriptorPrevious = null;
int initialColumnIndex =
numberOfFields + numberOfIdentityColumns * numberOfExtendLevels + 1;
int columnIndex = initialColumnIndex;
int numberOfExtendingClassDescriptors = 0;
for (Iterator iter = potentialActualClassDescriptor.iterator(); iter.hasNext(); ) {
- potentialClassDescriptor = (JDOClassDescriptor) iter.next();
+ potentialClassDescriptor = (ClassDescriptor) iter.next();
numberOfExtendingClassDescriptors += 1;
if (LOG.isDebugEnabled()) {
LOG.debug ("Potential extending class descriptor: "
+ potentialClassDescriptor.getJavaClass().getName());
}
- FieldDescriptor[] identityDescriptors = potentialClassDescriptor.getIdentities();
+ FieldDescriptor[] identityDescriptors = ((ClassDescriptorImpl) potentialClassDescriptor).getIdentities();
boolean isNull = true;
for (int i = 0; i < identityDescriptors.length; i++) {
@@ -138,11 +141,11 @@
return new Object[] {potentialLeafDescriptor, new Integer (suggestedNumberOfFields) };
}
- public static int numberOfExtendingClassDescriptors(final JDOClassDescriptor classDescriptor) {
+ public static int numberOfExtendingClassDescriptors(final ClassDescriptor classDescriptor) {
int numberOfExtendLevels = 1;
- JDOClassDescriptor currentClassDescriptor = classDescriptor;
+ ClassDescriptor currentClassDescriptor = classDescriptor;
while (currentClassDescriptor.getExtends() != null) {
- currentClassDescriptor = (JDOClassDescriptor) currentClassDescriptor.getExtends();
+ currentClassDescriptor = currentClassDescriptor.getExtends();
numberOfExtendLevels++;
}
return numberOfExtendLevels;
@@ -151,16 +154,16 @@
public static void addExtendingClassDescriptors(
final Collection classDescriptorsToAdd, final Collection extendingClassDescriptors) {
- JDOClassDescriptor classDescriptor = null;
+ ClassDescriptor classDescriptor = null;
for (Iterator iter = extendingClassDescriptors.iterator(); iter.hasNext(); ) {
- classDescriptor = (JDOClassDescriptor) iter.next();
+ classDescriptor = (ClassDescriptor) iter.next();
classDescriptorsToAdd.add (classDescriptor);
- addExtendingClassDescriptors(classDescriptorsToAdd, classDescriptor.getExtended());
+ addExtendingClassDescriptors(classDescriptorsToAdd, new ClassDescriptorJDONature(classDescriptor).getExtended());
}
}
- public static String[] getIdentitySQLNames(final JDOClassDescriptor desc) {
- FieldDescriptor[] identities = desc.getIdentities();
+ public static String[] getIdentitySQLNames(final ClassDescriptor desc) {
+ FieldDescriptor[] identities = ((ClassDescriptorImpl) desc).getIdentities();
String[] sqlNames = new String[identities.length];
for (int i = 0; i < identities.length; i++) {
sqlNames[i] = ((JDOFieldDescriptor) identities[i]).getSQLName()[0];
Index: cpa/src/main/java/org/exolab/castor/jdo/engine/SQLStatementStore.java
===================================================================
--- cpa/src/main/java/org/exolab/castor/jdo/engine/SQLStatementStore.java (revision 7783)
+++ cpa/src/main/java/org/exolab/castor/jdo/engine/SQLStatementStore.java (working copy)
@@ -30,6 +30,7 @@
import org.exolab.castor.jdo.ObjectDeletedException;
import org.exolab.castor.jdo.ObjectModifiedException;
import org.exolab.castor.jdo.PersistenceException;
+import org.exolab.castor.jdo.engine.nature.ClassDescriptorJDONature;
import org.exolab.castor.persist.spi.Identity;
import org.exolab.castor.persist.spi.PersistenceFactory;
import org.exolab.castor.persist.spi.QueryExpression;
@@ -64,7 +65,7 @@
_engine = engine;
_factory = factory;
_type = engine.getDescriptor().getJavaClass().getName();
- _mapTo = engine.getDescriptor().getTableName();
+ _mapTo = new ClassDescriptorJDONature(engine.getDescriptor()).getTableName();
// iterate through all fields to check whether there is a field
// to persist at all; in the case of extend relationships where no
@@ -157,7 +158,7 @@
SQLEngine extended = _engine.getExtends();
if (extended != null) {
// | quick and very dirty hack to try to make multiple class on the same table work
- if (!extended.getDescriptor().getTableName().equals(_mapTo)) {
+ if (!new ClassDescriptorJDONature(extended.getDescriptor()).getTableName().equals(_mapTo)) {
extended.store(conn, identity, newentity, oldentity);
}
}
Index: cpa/src/main/java/org/exolab/castor/jdo/engine/JDOClassDescriptor.java
===================================================================
--- cpa/src/main/java/org/exolab/castor/jdo/engine/JDOClassDescriptor.java (revision 7783)
+++ cpa/src/main/java/org/exolab/castor/jdo/engine/JDOClassDescriptor.java (working copy)
@@ -1,94 +0,0 @@
-/*
- * Copyright 2008 Werner Guttmann
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.exolab.castor.jdo.engine;
-
-import java.util.Collection;
-import java.util.Map;
-import java.util.Properties;
-
-import org.exolab.castor.mapping.AccessMode;
-import org.exolab.castor.mapping.ClassDescriptor;
-import org.exolab.castor.mapping.FieldDescriptor;
-
-/**
- * JDO class descriptor.
- *
- * Extends and augments {@link ClassDescriptor} to include persistence-specific data such as
- * e.g. the table name and other SQL-related information.
- *
- * @author Werner Guttmann
- * @version $Revision: 7099 $ $Date: 2006-04-10 16:39:24 -0600 (Mon, 10 Apr 2006) $
- * @since 1.2.1
- */
-public interface JDOClassDescriptor extends ClassDescriptor {
-
- /**
- * Returns the table name to which this object maps.
- *
- * @return Table name
- */
- String getTableName();
-
- /**
- * Return the access mode specified for this class.
- * @return the access mode specified for this class
- */
- AccessMode getAccessMode();
-
- /**
- * {@link Properties} defining cache type and parameters.
- * @return Cache-related properties for this class.
- */
- Properties getCacheParams();
-
- /**
- * Get map of named query strings associated with their names.
- *
- * @return Map of named query strings associated with their names.
- */
- Map getNamedQueries();
-
- /**
- * Get key generator specified for this class.
- *
- * @return Key generator descriptor.
- */
- KeyGeneratorDescriptor getKeyGeneratorDescriptor();
-
- /**
- * Returns the identity fields ({@link FieldDescriptor}) of this class.
- * @return the identity fields of this class.
- */
- FieldDescriptor[] getIdentities();
-
- /**
- * Returns a collection of class descriptors that extend this class descriptor.
- *
- * @return A collection of class descriptors.
- */
- Collection getExtended();
-
- /**
- * Returns a JDOFieldDescriptor for the field with the name passed. null
- * if named field does not exist.
- *
- * @param name Name of the field to return.
- * @return Field if it exists, otherwise null.
- */
- JDOFieldDescriptor getField(String name);
-
-
-}
\ No newline at end of file
Index: cpa/src/main/java/org/exolab/castor/jdo/engine/SQLStatementRemove.java
===================================================================
--- cpa/src/main/java/org/exolab/castor/jdo/engine/SQLStatementRemove.java (revision 7783)
+++ cpa/src/main/java/org/exolab/castor/jdo/engine/SQLStatementRemove.java (working copy)
@@ -25,6 +25,7 @@
import org.apache.commons.logging.LogFactory;
import org.castor.util.Messages;
import org.exolab.castor.jdo.PersistenceException;
+import org.exolab.castor.jdo.engine.nature.ClassDescriptorJDONature;
import org.exolab.castor.persist.spi.Identity;
import org.exolab.castor.persist.spi.PersistenceFactory;
import org.exolab.castor.persist.spi.QueryExpression;
@@ -48,7 +49,7 @@
_engine = engine;
_factory = factory;
_type = engine.getDescriptor().getJavaClass().getName();
- _mapTo = engine.getDescriptor().getTableName();
+ _mapTo = new ClassDescriptorJDONature(engine.getDescriptor()).getTableName();
buildStatement();
}
Index: cpa/src/main/java/org/exolab/castor/jdo/engine/OQLQueryImpl.java
===================================================================
--- cpa/src/main/java/org/exolab/castor/jdo/engine/OQLQueryImpl.java (revision 7783)
+++ cpa/src/main/java/org/exolab/castor/jdo/engine/OQLQueryImpl.java (working copy)
@@ -63,12 +63,14 @@
import org.exolab.castor.jdo.Query;
import org.exolab.castor.jdo.QueryException;
import org.exolab.castor.jdo.QueryResults;
+import org.exolab.castor.jdo.engine.nature.ClassDescriptorJDONature;
import org.exolab.castor.jdo.oql.Lexer;
import org.exolab.castor.jdo.oql.ParamInfo;
import org.exolab.castor.jdo.oql.ParseTreeNode;
import org.exolab.castor.jdo.oql.ParseTreeWalker;
import org.exolab.castor.jdo.oql.Parser;
import org.exolab.castor.mapping.AccessMode;
+import org.exolab.castor.mapping.ClassDescriptor;
import org.exolab.castor.mapping.FieldHandler;
import org.exolab.castor.mapping.MappingException;
import org.exolab.castor.mapping.TypeConvertor;
@@ -93,7 +95,7 @@
private Class _objClass;
- private JDOClassDescriptor _clsDesc;
+ private ClassDescriptor _clsDesc;
private QueryExpression _expr;
@@ -565,11 +567,11 @@
* execution of the OQL query.
*/
class OQLEnumeration implements QueryResults, Enumeration {
- private Object _lastObject;
+ private Object _lastObject;
- private Vector _pathInfo;
+ private Vector _pathInfo;
- private JDOClassDescriptor _classDescriptor;
+ private ClassDescriptor _classDescriptor;
private org.exolab.castor.persist.QueryResults _results;
@@ -580,7 +582,7 @@
* @param clsDesc
*/
OQLEnumeration(final org.exolab.castor.persist.QueryResults results,
- final Vector pathInfo, final JDOClassDescriptor clsDesc) {
+ final Vector pathInfo, final ClassDescriptor clsDesc) {
_results = results;
_pathInfo = pathInfo;
_classDescriptor = clsDesc;
@@ -754,15 +756,15 @@
}
private Object followPath(final Object parent) {
- JDOClassDescriptor curClassDesc = _classDescriptor;
+ ClassDescriptor curClassDesc = _classDescriptor;
Object curObject = parent;
for (int i = 1; i < _pathInfo.size(); i++) {
String curFieldName = (String) _pathInfo.elementAt(i);
try {
- JDOFieldDescriptor curFieldDesc = curClassDesc.getField(curFieldName);
+ JDOFieldDescriptor curFieldDesc = new ClassDescriptorJDONature(curClassDesc).getField(curFieldName);
FieldHandler handler = curFieldDesc.getHandler();
curObject = handler.getValue(curObject);
- curClassDesc = (JDOClassDescriptor) curFieldDesc.getClassDescriptor();
+ curClassDesc = curFieldDesc.getClassDescriptor();
} catch (Exception ex) {
throw new NoSuchElementException(
"An exception was thrown trying to access get methods to follow "
Index: cpa/src/main/java/org/exolab/castor/jdo/engine/SQLStatementCreate.java
===================================================================
--- cpa/src/main/java/org/exolab/castor/jdo/engine/SQLStatementCreate.java (revision 7783)
+++ cpa/src/main/java/org/exolab/castor/jdo/engine/SQLStatementCreate.java (working copy)
@@ -43,6 +43,7 @@
import org.exolab.castor.jdo.Database;
import org.exolab.castor.jdo.DuplicateIdentityException;
import org.exolab.castor.jdo.PersistenceException;
+import org.exolab.castor.jdo.engine.nature.ClassDescriptorJDONature;
import org.exolab.castor.mapping.FieldDescriptor;
import org.exolab.castor.mapping.MappingException;
import org.exolab.castor.persist.spi.Identity;
@@ -75,7 +76,7 @@
_engine = engine;
_factory = factory;
_type = engine.getDescriptor().getJavaClass().getName();
- _mapTo = engine.getDescriptor().getTableName();
+ _mapTo = new ClassDescriptorJDONature(engine.getDescriptor()).getTableName();
_keyGen = getKeyGenerator(engine, factory);
@@ -91,7 +92,8 @@
final PersistenceFactory factory) throws MappingException {
KeyGenerator keyGen = null;
if (engine.getDescriptor().getExtends() == null) {
- KeyGeneratorDescriptor keyGenDesc = engine.getDescriptor().getKeyGeneratorDescriptor();
+ KeyGeneratorDescriptor keyGenDesc =
+ new ClassDescriptorJDONature(engine.getDescriptor()).getKeyGeneratorDescriptor();
if (keyGenDesc != null) {
FieldDescriptor fldDesc = engine.getDescriptor().getIdentity();
int[] tempType = ((JDOFieldDescriptor) fldDesc).getSQLType();
@@ -264,7 +266,7 @@
// must create record in the parent table first. all other dependents
// are created afterwards. quick and very dirty hack to try to make
// multiple class on the same table work.
- if ((extended != null) && !extended.getDescriptor().getTableName().equals(_mapTo)) {
+ if ((extended != null) && !new ClassDescriptorJDONature(extended.getDescriptor()).getTableName().equals(_mapTo)) {
internalIdentity = extended.create(database, conn, entity, internalIdentity);
}
@@ -337,7 +339,7 @@
// must create record in the parent table first. all other dependents
// are created afterwards. quick and very dirty hack to try to make
// multiple class on the same table work.
- if ((extended != null) && !extended.getDescriptor().getTableName().equals(_mapTo)) {
+ if ((extended != null) && !new ClassDescriptorJDONature(extended.getDescriptor()).getTableName().equals(_mapTo)) {
internalIdentity = extended.create(database, conn, entity, internalIdentity);
}
@@ -413,7 +415,7 @@
// must create record in the parent table first. all other dependents
// are created afterwards. quick and very dirty hack to try to make
// multiple class on the same table work.
- if ((extended != null) && !extended.getDescriptor().getTableName().equals(_mapTo)) {
+ if ((extended != null) && !new ClassDescriptorJDONature(extended.getDescriptor()).getTableName().equals(_mapTo)) {
internalIdentity = extended.create(database, conn, entity, internalIdentity);
}
@@ -500,7 +502,7 @@
// must create record in the parent table first. all other dependents
// are created afterwards. quick and very dirty hack to try to make
// multiple class on the same table work.
- if ((extended != null) && !extended.getDescriptor().getTableName().equals(_mapTo)) {
+ if ((extended != null) && !new ClassDescriptorJDONature(extended.getDescriptor()).getTableName().equals(_mapTo)) {
internalIdentity = extended.create(database, conn, entity, internalIdentity);
}
Index: cpa/src/main/java/org/exolab/castor/jdo/engine/SQLStatementLookup.java
===================================================================
--- cpa/src/main/java/org/exolab/castor/jdo/engine/SQLStatementLookup.java (revision 7783)
+++ cpa/src/main/java/org/exolab/castor/jdo/engine/SQLStatementLookup.java (working copy)
@@ -27,6 +27,7 @@
import org.exolab.castor.jdo.DuplicateIdentityException;
import org.exolab.castor.jdo.PersistenceException;
import org.exolab.castor.jdo.QueryException;
+import org.exolab.castor.jdo.engine.nature.ClassDescriptorJDONature;
import org.exolab.castor.mapping.MappingException;
import org.exolab.castor.persist.spi.Identity;
import org.exolab.castor.persist.spi.PersistenceFactory;
@@ -52,7 +53,7 @@
_engine = engine;
_factory = factory;
_type = engine.getDescriptor().getJavaClass().getName();
- _mapTo = engine.getDescriptor().getTableName();
+ _mapTo = new ClassDescriptorJDONature(engine.getDescriptor()).getTableName();
buildStatement();
}
Index: cpa/src/main/java/org/exolab/castor/jdo/engine/nature/ClassDescriptorJDONature.java
===================================================================
--- cpa/src/main/java/org/exolab/castor/jdo/engine/nature/ClassDescriptorJDONature.java (revision 0)
+++ cpa/src/main/java/org/exolab/castor/jdo/engine/nature/ClassDescriptorJDONature.java (revision 0)
@@ -0,0 +1,237 @@
+/*
+ * Copyright 2008 Werner Guttmann
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.exolab.castor.jdo.engine.nature;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.castor.core.nature.BaseNature;
+import org.castor.core.nature.PropertyHolder;
+import org.exolab.castor.jdo.engine.JDOFieldDescriptor;
+import org.exolab.castor.jdo.engine.KeyGeneratorDescriptor;
+import org.exolab.castor.mapping.AccessMode;
+import org.exolab.castor.mapping.ClassDescriptor;
+import org.exolab.castor.mapping.FieldDescriptor;
+import org.exolab.castor.mapping.loader.ClassDescriptorImpl;
+
+/**
+ * JDO-specific nature for {@link ClassDescriptor}.
+ *
+ * Augments {@link ClassDescriptor} to include persistence-specific data such as
+ * e.g. the table name and other SQL-related information.
+ *
+ * @author Werner Guttmann
+ * @since 1.2.1
+ */
+public class ClassDescriptorJDONature extends BaseNature {
+
+ /**
+ * Nature property name for table name.
+ */
+ private static final String TABLE_NAME = "tableName";
+
+ /**
+ * Nature property name for table name.
+ */
+ private static final String ACCESS_MODE = "accessMode";
+
+ /**
+ * Nature property name for key generator descriptor.
+ */
+ private static final String KEY_GENERATOR_DESCRIPTOR = "keyGeneratorDescriptor";
+
+ /**
+ * Nature property name for cache parameters.
+ */
+ private static final String CACHE_PARAMETERS = "cacheParameters";
+
+ /**
+ * Nature property name for named queries.
+ */
+ private static final String NAMED_QUERIES = "namedQueries";
+
+ /**
+ * Nature property name for {@link ClassDescriptor}s that extend this {@link ClassDescriptor}.
+ */
+ private static final String EXTENDED = "extended";
+
+ /**
+ * Creates an instance of {@link ClassDescriptorJDONature}.
+ * @param holder The {@link PropertyHolder} to 'view upon'.
+ */
+ public ClassDescriptorJDONature(final PropertyHolder holder) {
+ super(holder);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.castor.core.nature.Nature#getId()
+ */
+ public String getId() {
+ return getClass().getName();
+ }
+
+ public void setTableName(final String tableName) {
+ setProperty(TABLE_NAME, tableName);
+ }
+
+ /**
+ * Returns the table name to which this object maps.
+ *
+ * @return Table name
+ */
+ public String getTableName() {
+ return (String) getProperty(TABLE_NAME);
+ }
+
+
+ /**
+ * Sets the access mode to which this {@link ClassDescriptor} maps.
+ * @param accessMode The access mode to be used.
+ */
+ public void setAccessMode(final AccessMode accessMode) {
+ setProperty(ACCESS_MODE, accessMode);
+ }
+
+ /**
+ * Returns the access mode to which this object maps.
+ *
+ * @return Access mode
+ */
+ public AccessMode getAccessMode() {
+ return (AccessMode) getProperty(ACCESS_MODE);
+ }
+
+ /**
+ * Set key generator specified for this class.
+ *
+ * @param keyGenDesc Key generator descriptor.
+ */
+ public void setKeyGeneratorDescriptor(final KeyGeneratorDescriptor keyGenDesc) {
+ setProperty(KEY_GENERATOR_DESCRIPTOR, keyGenDesc);
+ }
+
+ /**
+ * Get key generator specified for this class.
+ *
+ * @return Key generator descriptor.
+ */
+ public KeyGeneratorDescriptor getKeyGeneratorDescriptor() {
+ return (KeyGeneratorDescriptor) getProperty(KEY_GENERATOR_DESCRIPTOR);
+ }
+
+ /**
+ * Adds a cache parameter to this {@link ClassDescriptor}.
+ * @param key The cache parameter key.
+ * @param value The cache parameter value.
+ */
+ public void addCacheParam(final String key, final String value) {
+ Properties cacheParameters = (Properties) getProperty(CACHE_PARAMETERS);
+ if (cacheParameters == null) {
+ cacheParameters = new Properties();
+ }
+ cacheParameters.put(key, value);
+ setProperty(CACHE_PARAMETERS, cacheParameters);
+ }
+
+ /**
+ * Returns the cache parameters defined for this {@link ClassDescriptor}.
+ * @return the defined cache parameters
+ */
+ public Properties getCacheParams() {
+ return (Properties) getProperty(CACHE_PARAMETERS);
+ }
+
+ /**
+ * Adds a named query to this {@link ClassDescriptor}.
+ * @param name The name of the named query.
+ * @param value The query string
+ */
+ public void addNamedQuery(final String name, final String query) {
+ Map namedQueries = (Map) getProperty(NAMED_QUERIES);
+ if (namedQueries == null) {
+ namedQueries = new HashMap();
+ }
+ namedQueries.put(name, query);
+ setProperty(NAMED_QUERIES, namedQueries);
+ }
+
+ /**
+ * Get map of named query strings associated with their names.
+ *
+ * @return Map of named query strings associated with their names.
+ */
+ public Map getNamedQueries() {
+ return getPropertyAsMap(NAMED_QUERIES);
+ }
+
+ /**
+ * Returns the {@link JDOFieldDescriptor} for the given name.
+ * @param name A field name.
+ * @return The associated {@link JDOFieldDescriptor}.
+ */
+ public JDOFieldDescriptor getField(final String name) {
+ FieldDescriptor[] fields = ((ClassDescriptor) getHolder()).getFields();
+ for (int i = 0; i < fields.length; ++i) {
+ FieldDescriptor field = fields[i];
+ if ((field instanceof JDOFieldDescriptor)
+ && (field.getFieldName().equals(name))) {
+
+ return (JDOFieldDescriptor) field;
+ }
+ }
+
+ FieldDescriptor[] identities = ((ClassDescriptorImpl) getHolder()).getIdentities();
+ for (int i = 0; i < identities.length; ++i) {
+ FieldDescriptor field = identities[i];
+ if ((field instanceof JDOFieldDescriptor)
+ && (field.getFieldName().equals(name))) {
+
+ return (JDOFieldDescriptor) field;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Adds a {@link ClassDescriptor} that extends this class.
+ * @param classDesc A {@link ClassDescriptor} that extends this class.
+ */
+ public void addExtended(final ClassDescriptor classDesc) {
+ List extendeds = getPropertyAsList(EXTENDED);
+ if (extendeds == null) {
+ extendeds = new ArrayList();
+ }
+ extendeds.add(classDesc);
+ setProperty(EXTENDED, extendeds);
+ }
+
+
+ /**
+ * Returns a collection of {@link ClassDescriptor}s that extend this class (descriptor).
+ * @return A collection of {@link ClassDescriptor}s that extend this class.
+ */
+ public Collection getExtended() {
+ return getPropertyAsList(EXTENDED);
+ }
+
+}
Index: cpa/src/main/java/org/exolab/castor/jdo/engine/JDOMappingLoader.java
===================================================================
--- cpa/src/main/java/org/exolab/castor/jdo/engine/JDOMappingLoader.java (revision 7783)
+++ cpa/src/main/java/org/exolab/castor/jdo/engine/JDOMappingLoader.java (working copy)
@@ -61,7 +61,6 @@
import org.castor.cache.Cache;
import org.castor.cache.simple.CountLimited;
import org.castor.cache.simple.TimeLimited;
-import org.castor.core.constants.cpa.JDOConstants;
import org.castor.core.util.Configuration;
import org.castor.cpa.CPAConfiguration;
import org.castor.cpa.persistence.convertor.AbstractSimpleTypeConvertor;
@@ -70,6 +69,7 @@
import org.castor.mapping.BindingType;
import org.castor.util.Messages;
import org.exolab.castor.jdo.TimeStampable;
+import org.exolab.castor.jdo.engine.nature.ClassDescriptorJDONature;
import org.exolab.castor.mapping.AccessMode;
import org.exolab.castor.mapping.ClassDescriptor;
import org.exolab.castor.mapping.CollectionHandler;
@@ -81,6 +81,7 @@
import org.exolab.castor.mapping.TypeConvertor;
import org.exolab.castor.mapping.loader.AbstractFieldDescriptor;
import org.exolab.castor.mapping.loader.AbstractMappingLoader;
+import org.exolab.castor.mapping.loader.ClassDescriptorImpl;
import org.exolab.castor.mapping.loader.CollectionHandlers;
import org.exolab.castor.mapping.loader.FieldDescriptorImpl;
import org.exolab.castor.mapping.loader.FieldHandlerFriend;
@@ -98,7 +99,6 @@
import org.exolab.castor.persist.spi.PersistenceFactory;
import org.exolab.castor.xml.util.ClassLoaderNature;
import org.exolab.castor.xml.util.ClassResolutionByFile;
-import org.exolab.castor.xml.util.resolvers.ResolveHelpers;
/**
* A JDO implementation of mapping helper. Creates JDO class descriptors
@@ -250,7 +250,9 @@
}
// Create the class descriptor.
- JDOClassDescriptorImpl clsDesc = new JDOClassDescriptorImpl();
+ ClassDescriptorImpl clsDesc = new ClassDescriptorImpl();
+ // add JDO nature
+ clsDesc.addNature(ClassDescriptorJDONature.class.getName());
// Set reference to class mapping on class descriptor.
clsDesc.setMapping(clsMap);
@@ -267,12 +269,12 @@
// class and make sure this class indeed extends it.
ClassDescriptor extDesc = getExtended(clsMap, javaClass);
if (extDesc != null) {
- if (!(extDesc instanceof JDOClassDescriptor)) {
+ if (!(extDesc.hasNature(ClassDescriptorJDONature.class.getName()))) {
throw new IllegalArgumentException(
"Extended class does not have a JDO descriptor");
}
- ((JDOClassDescriptorImpl) extDesc).addExtended(clsDesc);
+ new ClassDescriptorJDONature(extDesc).addExtended(clsDesc);
}
clsDesc.setExtends(extDesc);
@@ -328,7 +330,7 @@
for (int i = 0; i < allFields.length; i++) { fieldList.add(allFields[i]); }
// Add all identities of extended class to identity list.
- FieldDescriptor[] extIds = ((JDOClassDescriptor) extDesc).getIdentities();
+ FieldDescriptor[] extIds = ((ClassDescriptorImpl) extDesc).getIdentities();
for (int i = 0; i < extIds.length; i++) { idList.add(extIds[i]); }
// Search redefined identities in extending class.
@@ -342,13 +344,16 @@
// Set identities on class descriptor.
FieldDescriptor[] ids = new FieldDescriptor[idList.size()];
- clsDesc.setIdentities((FieldDescriptor[]) idList.toArray(ids));
+ ((ClassDescriptorImpl) clsDesc).setIdentities(((FieldDescriptor[]) idList.toArray(ids)));
// Set fields on class descriptor.
FieldDescriptor[] fields = new FieldDescriptor[fieldList.size()];
clsDesc.setFields((FieldDescriptor[]) fieldList.toArray(fields));
- clsDesc.setTableName(clsMap.getMapTo().getTable());
+ clsDesc.addNature(ClassDescriptorJDONature.class.getName());
+ ClassDescriptorJDONature jdoNature = new ClassDescriptorJDONature(clsDesc);
+ // clsDesc.setTableName(clsMap.getMapTo().getTable());
+ jdoNature.setTableName(clsMap.getMapTo().getTable());
extractAndSetAccessMode(clsDesc, clsMap);
extractAndAddCacheParams(clsDesc, clsMap, javaClass);
@@ -364,10 +369,10 @@
* @param clsDesc JDO class descriptor to set the access mode on.
* @param clsMap Class mapping to extract the access mode from.
*/
- private void extractAndSetAccessMode(final JDOClassDescriptorImpl clsDesc,
+ private void extractAndSetAccessMode(final ClassDescriptorImpl clsDesc,
final ClassMapping clsMap) {
if (clsMap.getAccess() != null) {
- clsDesc.setAccessMode(AccessMode.valueOf(clsMap.getAccess().toString()));
+ new ClassDescriptorJDONature(clsDesc).setAccessMode(AccessMode.valueOf(clsMap.getAccess().toString()));
}
}
@@ -380,10 +385,10 @@
* @throws MappingException If cache type none has been specified for
* a class that implements TimeStampable interface.
*/
- private void extractAndAddCacheParams(final JDOClassDescriptorImpl clsDesc,
+ private void extractAndAddCacheParams(final ClassDescriptorImpl clsDesc,
final ClassMapping clsMap, final Class javaClass)
throws MappingException {
- clsDesc.addCacheParam(Cache.PARAM_NAME, clsMap.getName());
+ new ClassDescriptorJDONature(clsDesc).addCacheParam(Cache.PARAM_NAME, clsMap.getName());
CacheTypeMapping cacheMapping = clsMap.getCacheTypeMapping();
if (cacheMapping != null) {
@@ -394,19 +399,19 @@
"persist.wrongCacheTypeSpecified", clsMap.getName()));
}
}
- clsDesc.addCacheParam(Cache.PARAM_TYPE, type);
+ new ClassDescriptorJDONature(clsDesc).addCacheParam(Cache.PARAM_TYPE, type);
Param[] params = cacheMapping.getParam();
for (int i = 0; i < params.length; i++) {
- clsDesc.addCacheParam(params[i].getName(), params[i].getValue());
+ new ClassDescriptorJDONature(clsDesc).addCacheParam(params[i].getName(), params[i].getValue());
}
String debug = new Boolean(cacheMapping.getDebug()).toString();
- clsDesc.addCacheParam(Cache.PARAM_DEBUG, debug);
+ new ClassDescriptorJDONature(clsDesc).addCacheParam(Cache.PARAM_DEBUG, debug);
String capacity = Long.toString(cacheMapping.getCapacity());
- clsDesc.addCacheParam(CountLimited.PARAM_CAPACITY, capacity);
- clsDesc.addCacheParam(TimeLimited.PARAM_TTL, capacity);
+ new ClassDescriptorJDONature(clsDesc).addCacheParam(CountLimited.PARAM_CAPACITY, capacity);
+ new ClassDescriptorJDONature(clsDesc).addCacheParam(TimeLimited.PARAM_TTL, capacity);
}
}
@@ -417,7 +422,7 @@
* @param clsMap Class mapping to extract the named queries from.
* @throws MappingException On duplicate query names.
*/
- private void extractAndAddNamedQueries(final JDOClassDescriptorImpl clsDesc,
+ private void extractAndAddNamedQueries(final ClassDescriptorImpl clsDesc,
final ClassMapping clsMap)
throws MappingException {
Enumeration namedQueriesEnum = clsMap.enumerateNamedQuery();
@@ -430,7 +435,7 @@
}
_queryNames.add(queryName);
- clsDesc.addNamedQuery(queryName, query.getQuery());
+ new ClassDescriptorJDONature(clsDesc).addNamedQuery(queryName, query.getQuery());
}
}
@@ -444,7 +449,7 @@
* @param clsDesc JDO class descriptor to set the key generator descriptor at.
* @param clsMap Class mapping name of key generator.
*/
- private void extractAndSetKeyGeneratorDescriptor(final JDOClassDescriptorImpl clsDesc,
+ private void extractAndSetKeyGeneratorDescriptor(final ClassDescriptorImpl clsDesc,
final ClassMapping clsMap) {
KeyGeneratorDescriptor keyGenDesc = null;
@@ -458,7 +463,7 @@
}
}
- clsDesc.setKeyGeneratorDescriptor(keyGenDesc);
+ new ClassDescriptorJDONature(clsDesc).setKeyGeneratorDescriptor(keyGenDesc);
}
protected FieldDescriptor findIdentityByName(
@@ -489,7 +494,7 @@
* Walks through all fields of a descriptor and resolves relation
* {@link ClassDescriptor}s by using mapping information or, if not
* present, resolution by file to support generated
- * {@link JDOClassDescriptor}s. Resolved {@link ClassDescriptor}s will be
+ * {@link ClassDescriptor}s. Resolved {@link ClassDescriptor}s will be
* set as a field's descriptor.
*
* @param clsDesc
Index: cpa/src/main/java/org/exolab/castor/jdo/engine/SQLFieldInfo.java
===================================================================
--- cpa/src/main/java/org/exolab/castor/jdo/engine/SQLFieldInfo.java (revision 7783)
+++ cpa/src/main/java/org/exolab/castor/jdo/engine/SQLFieldInfo.java (working copy)
@@ -17,9 +17,11 @@
*/
package org.exolab.castor.jdo.engine;
+import org.exolab.castor.jdo.engine.nature.ClassDescriptorJDONature;
import org.exolab.castor.mapping.ClassDescriptor;
import org.exolab.castor.mapping.FieldDescriptor;
import org.exolab.castor.mapping.MappingException;
+import org.exolab.castor.mapping.loader.ClassDescriptorImpl;
import org.exolab.castor.mapping.loader.FieldHandlerImpl;
/**
@@ -48,7 +50,7 @@
private final FieldDescriptor _fieldDescriptor;
- public SQLFieldInfo(final JDOClassDescriptor clsDesc,
+ public SQLFieldInfo(final ClassDescriptor clsDesc,
final FieldDescriptor fieldDesc,
final String classTable, final boolean ext)
throws MappingException {
@@ -56,11 +58,11 @@
ClassDescriptor related = fieldDesc.getClassDescriptor();
if (related != null) {
- if (!(related instanceof JDOClassDescriptor)) {
+ if (!(related.hasNature(ClassDescriptorJDONature.class.getName()))) {
throw new MappingException("Related class is not JDOClassDescriptor");
}
- FieldDescriptor[] relids = ((JDOClassDescriptor) related).getIdentities();
+ FieldDescriptor[] relids = ((ClassDescriptorImpl) related).getIdentities();
String[] relnames = new String[relids.length];
for (int i = 0; i < relids.length; i++) {
relnames[i] = ((JDOFieldDescriptor) relids[i]).getSQLName()[0];
@@ -70,7 +72,7 @@
}
}
- FieldDescriptor[] classids = clsDesc.getIdentities();
+ FieldDescriptor[] classids = ((ClassDescriptorImpl) clsDesc).getIdentities();
String[] classnames = new String[classids.length];
for (int i = 0; i < classids.length; i++) {
classnames[i] = ((JDOFieldDescriptor) classids[i]).getSQLName()[0];
@@ -82,7 +84,7 @@
String[] names = relnames;
if (!(fieldDesc instanceof JDOFieldDescriptor)) {
- _tableName = ((JDOClassDescriptor) related).getTableName();
+ _tableName = new ClassDescriptorJDONature(related).getTableName();
_store = false;
_multi = fieldDesc.isMultivalued();
_joined = true;
@@ -117,7 +119,7 @@
_joined = false;
_joinFields = classnames;
} else {
- _tableName = ((JDOClassDescriptor) related).getTableName();
+ _tableName = new ClassDescriptorJDONature(related).getTableName();
_store = false;
_multi = jdoFieldDesc.isMultivalued();
_joined = true;
Index: cpa/src/main/java/org/exolab/castor/jdo/engine/JDOClassDescriptorImpl.java
===================================================================
--- cpa/src/main/java/org/exolab/castor/jdo/engine/JDOClassDescriptorImpl.java (revision 7783)
+++ cpa/src/main/java/org/exolab/castor/jdo/engine/JDOClassDescriptorImpl.java (working copy)
@@ -1,183 +0,0 @@
-/**
- * Redistribution and use of this software and associated documentation
- * ("Software"), with or without modification, are permitted provided
- * that the following conditions are met:
- *
- * 1. Redistributions of source code must retain copyright
- * statements and notices. Redistributions must also contain a
- * copy of this document.
- *
- * 2. Redistributions in binary form must reproduce the
- * above copyright notice, this list of conditions and the
- * following disclaimer in the documentation and/or other
- * materials provided with the distribution.
- *
- * 3. The name "Exolab" must not be used to endorse or promote
- * products derived from this Software without prior written
- * permission of Intalio, Inc. For written permission,
- * please contact info@exolab.org.
- *
- * 4. Products derived from this Software may not be called "Exolab"
- * nor may "Exolab" appear in their names without prior written
- * permission of Intalio, Inc. Exolab is a registered
- * trademark of Intalio, Inc.
- *
- * 5. Due credit should be given to the Exolab Project
- * (http://www.exolab.org/).
- *
- * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
- * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
- * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- * OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Copyright 1999 (C) Intalio, Inc. All Rights Reserved.
- *
- * $Id$
- */
-package org.exolab.castor.jdo.engine;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
-import org.exolab.castor.mapping.AccessMode;
-import org.exolab.castor.mapping.FieldDescriptor;
-import org.exolab.castor.mapping.loader.ClassDescriptorImpl;
-
-/**
- * JDO class descriptors. Extends {@link ClassDescriptor} to include the table name and
- * other SQL-related information. All fields are of type {@link JDOFieldDescriptor},
- * identity field is not included in the returned field list, and contained fields are
- * flattened out for efficiency (thus all fields are directly accessible).
- *
- * @author Assaf Arkin
- * @author Ralf Joachim
- * @version $Revision$ $Date: 2006-04-10 16:39:24 -0600 (Mon, 10 Apr 2006) $
- */
-public class JDOClassDescriptorImpl extends ClassDescriptorImpl
- implements JDOClassDescriptor {
-
- /** The name of the SQL table. */
- private String _tableName;
-
- /** The access mode specified for this class. */
- private AccessMode _accessMode = AccessMode.Shared;
-
- /** The properties defining cache type and parameters. */
- private final Properties _cacheParams = new Properties();
-
- /** Associated named queries, keyed by their name. */
- private final Map _namedQueries = new HashMap();
-
- /** The key generator specified for this class. */
- private KeyGeneratorDescriptor _keyGenDesc;
-
- public JDOClassDescriptorImpl() {
- super();
- }
-
- protected void setTableName(final String tableName) {
- _tableName = tableName;
- }
-
- /**
- * Returns the table name to which this object maps.
- *
- * @return Table name
- */
- public String getTableName() {
- return _tableName;
- }
-
- protected void setAccessMode(final AccessMode accessMode) {
- _accessMode = accessMode;
- }
-
- public AccessMode getAccessMode() {
- return _accessMode;
- }
-
- protected void addCacheParam(final String key, final String value) {
- _cacheParams.put(key, value);
- }
-
- public Properties getCacheParams() {
- return _cacheParams;
- }
-
- protected void addNamedQuery(final String name, final String query) {
- _namedQueries.put(name, query);
- }
-
- /**
- * Get map of named query strings associated with their names.
- *
- * @return Map of named query strings associated with their names.
- */
- public Map getNamedQueries() {
- return _namedQueries;
- }
-
- /**
- * Set key generator specified for this class.
- *
- * @param keyGenDesc Key generator descriptor.
- */
- protected void setKeyGeneratorDescriptor(final KeyGeneratorDescriptor keyGenDesc) {
- _keyGenDesc = keyGenDesc;
- }
-
- /**
- * Get key generator specified for this class.
- *
- * @return Key generator descriptor.
- */
- public KeyGeneratorDescriptor getKeyGeneratorDescriptor() {
- return _keyGenDesc;
- }
-
-
- /**
- * {@inheritDoc}
- * @see org.exolab.castor.jdo.engine.JDOClassDescriptor#getField(java.lang.String)
- */
- public JDOFieldDescriptor getField(final String name) {
- FieldDescriptor[] fields = getFields();
- for (int i = 0; i < fields.length; ++i) {
- FieldDescriptor field = fields[i];
- if ((field instanceof JDOFieldDescriptor)
- && (field.getFieldName().equals(name))) {
-
- return (JDOFieldDescriptor) field;
- }
- }
-
- FieldDescriptor[] identities = getIdentities();
- for (int i = 0; i < identities.length; ++i) {
- FieldDescriptor field = identities[i];
- if ((field instanceof JDOFieldDescriptor)
- && (field.getFieldName().equals(name))) {
-
- return (JDOFieldDescriptor) field;
- }
- }
-
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- public String toString() {
- return getJavaClass().getName() + " AS " + _tableName;
- }
-
-}
Index: cpa/src/main/java/org/exolab/castor/jdo/engine/SQLStatementLoad.java
===================================================================
--- cpa/src/main/java/org/exolab/castor/jdo/engine/SQLStatementLoad.java (revision 7783)
+++ cpa/src/main/java/org/exolab/castor/jdo/engine/SQLStatementLoad.java (working copy)
@@ -41,7 +41,9 @@
import org.exolab.castor.jdo.ObjectNotFoundException;
import org.exolab.castor.jdo.PersistenceException;
import org.exolab.castor.jdo.QueryException;
+import org.exolab.castor.jdo.engine.nature.ClassDescriptorJDONature;
import org.exolab.castor.mapping.AccessMode;
+import org.exolab.castor.mapping.ClassDescriptor;
import org.exolab.castor.mapping.MappingException;
import org.exolab.castor.persist.spi.Identity;
import org.exolab.castor.persist.spi.Persistence;
@@ -78,12 +80,12 @@
_engine = engine;
_factory = factory;
_type = engine.getDescriptor().getJavaClass().getName();
- _mapTo = engine.getDescriptor().getTableName();
+ _mapTo = new ClassDescriptorJDONature(engine.getDescriptor()).getTableName();
// obtain the number of ClassDescriptor that extend this one.
_numberOfExtendLevels = SQLHelper.numberOfExtendingClassDescriptors(engine.getDescriptor());
_extendingClassDescriptors =
- ((JDOClassDescriptorImpl) engine.getDescriptor()).getExtended();
+ new ClassDescriptorJDONature(engine.getDescriptor()).getExtended();
buildStatement();
}
@@ -96,15 +98,15 @@
Vector joinTables = new Vector();
// join all the extended table
- JDOClassDescriptor curDesc = _engine.getDescriptor();
- JDOClassDescriptor baseDesc;
+ ClassDescriptor curDesc = _engine.getDescriptor();
+ ClassDescriptor baseDesc;
while (curDesc.getExtends() != null) {
- baseDesc = (JDOClassDescriptor) curDesc.getExtends();
+ baseDesc = curDesc.getExtends();
String[] curDescIdNames = SQLHelper.getIdentitySQLNames(curDesc);
String[] baseDescIdNames = SQLHelper.getIdentitySQLNames(baseDesc);
- expr.addInnerJoin(curDesc.getTableName(), curDescIdNames,
- baseDesc.getTableName(), baseDescIdNames);
- joinTables.add(baseDesc.getTableName());
+ expr.addInnerJoin(new ClassDescriptorJDONature(curDesc).getTableName(), curDescIdNames,
+ new ClassDescriptorJDONature(baseDesc).getTableName(), baseDescIdNames);
+ joinTables.add(new ClassDescriptorJDONature(baseDesc).getTableName());
curDesc = baseDesc;
}
@@ -125,23 +127,23 @@
if ((i == 0) && field.isJoined()) {
String[] identities = SQLHelper.getIdentitySQLNames(_engine.getDescriptor());
for (int j = 0; j < identities.length; j++) {
- expr.addColumn(curDesc.getTableName(), identities[j]);
+ expr.addColumn(new ClassDescriptorJDONature(curDesc).getTableName(), identities[j]);
}
- identitiesUsedForTable.put(curDesc.getTableName(), Boolean.TRUE);
+ identitiesUsedForTable.put(new ClassDescriptorJDONature(curDesc).getTableName(), Boolean.TRUE);
}
// add id columns to select statement
if (!alias.equals(aliasOld) && !field.isJoined()) {
- JDOClassDescriptor classDescriptor = (JDOClassDescriptor)
+ ClassDescriptor classDescriptor =
field.getFieldDescriptor().getContainingClassDescriptor();
boolean isTableNameAlreadyAdded = identitiesUsedForTable.containsKey(
- classDescriptor.getTableName());
+ new ClassDescriptorJDONature(classDescriptor).getTableName());
if (!isTableNameAlreadyAdded) {
String[] identities = SQLHelper.getIdentitySQLNames(classDescriptor);
for (int j = 0; j < identities.length; j++) {
expr.addColumn(alias, identities[j]);
}
- identitiesUsedForTable.put(classDescriptor.getTableName(), Boolean.TRUE);
+ identitiesUsedForTable.put(new ClassDescriptorJDONature(classDescriptor).getTableName(), Boolean.TRUE);
}
}
@@ -153,7 +155,7 @@
leftCol[j] = ids[j + offset].getName();
}
if (joinTables.contains(field.getTableName())
- || _engine.getDescriptor().getTableName().equals(
+ || new ClassDescriptorJDONature(_engine.getDescriptor()).getTableName().equals(
field.getTableName())) {
// should not mix with aliases in ParseTreeWalker
@@ -174,25 +176,26 @@
// 'join' all the extending tables
List classDescriptorsToAdd = new LinkedList();
- JDOClassDescriptor classDescriptor = null;
+ ClassDescriptor classDescriptor = null;
SQLHelper.addExtendingClassDescriptors(classDescriptorsToAdd,
- ((JDOClassDescriptorImpl) _engine.getDescriptor()).getExtended());
+ new ClassDescriptorJDONature(_engine.getDescriptor()).getExtended());
if (classDescriptorsToAdd.size() > 0) {
for (Iterator iter = classDescriptorsToAdd.iterator(); iter.hasNext(); ) {
- classDescriptor = (JDOClassDescriptor) iter.next();
-
+ classDescriptor = (ClassDescriptor) iter.next();
+ ClassDescriptorJDONature classDescriptorJDONature =
+ new ClassDescriptorJDONature(classDescriptor);
if (LOG.isTraceEnabled()) {
LOG.trace("Adding outer left join for "
+ classDescriptor.getJavaClass().getName() + " on table "
- + classDescriptor.getTableName());
+ + classDescriptorJDONature.getTableName());
}
String[] engDescIdNames = SQLHelper.getIdentitySQLNames(
_engine.getDescriptor());
String[] clsDescIdNames = SQLHelper.getIdentitySQLNames(classDescriptor);
expr.addOuterJoin(_mapTo, engDescIdNames,
- classDescriptor.getTableName(), clsDescIdNames);
+ classDescriptorJDONature.getTableName(), clsDescIdNames);
Persistence persistenceEngine;
try {
@@ -206,23 +209,23 @@
SQLEngine engine = (SQLEngine) persistenceEngine;
SQLColumnInfo[] idInfos = engine.getColumnInfoForIdentities();
for (int i = 0; i < idInfos.length; i++) {
- expr.addColumn (classDescriptor.getTableName(), idInfos[i].getName());
+ expr.addColumn (classDescriptorJDONature.getTableName(), idInfos[i].getName());
}
SQLFieldInfo[] fieldInfos = ((SQLEngine) persistenceEngine).getInfo();
for (int i = 0; i < fieldInfos.length; i++) {
boolean hasFieldToAdd = false;
SQLColumnInfo[] columnInfos = fieldInfos[i].getColumnInfo();
- if (classDescriptor.getTableName().equals(fieldInfos[i].getTableName())) {
+ if (classDescriptorJDONature.getTableName().equals(fieldInfos[i].getTableName())) {
for (int j = 0; j < columnInfos.length; j++) {
- expr.addColumn(classDescriptor.getTableName(),
+ expr.addColumn(classDescriptorJDONature.getTableName(),
fieldInfos[i].getColumnInfo()[j].getName());
}
hasFieldToAdd = true;
}
if (hasFieldToAdd) {
- expr.addTable(classDescriptor.getTableName());
+ expr.addTable(classDescriptorJDONature.getTableName());
}
}
}
@@ -320,7 +323,7 @@
Object[] returnValues =
SQLHelper.calculateNumberOfFields(_extendingClassDescriptors,
ids.length, fields.length, _numberOfExtendLevels, rs);
- JDOClassDescriptor potentialLeafDescriptor = (JDOClassDescriptor) returnValues[0];
+ ClassDescriptor potentialLeafDescriptor = (ClassDescriptor) returnValues[0];
if ((potentialLeafDescriptor != null)
&& !potentialLeafDescriptor.getJavaClass().getName().equals(_type)) {
@@ -344,7 +347,7 @@
Set processedTables = new HashSet();
if (fields.length > 0 && fields[0].isJoined()) {
- processedTables.add(_engine.getDescriptor().getTableName());
+ processedTables.add(new ClassDescriptorJDONature(_engine.getDescriptor()).getTableName());
}
boolean notNull;
// index in fields[] for storing result of SQLTypes.getObject()
@@ -394,7 +397,7 @@
columnIndex = ids.length + 1;
processedTables.clear();
if (fields[0].isJoined()) {
- processedTables.add(_engine.getDescriptor().getTableName());
+ processedTables.add(new ClassDescriptorJDONature(_engine.getDescriptor()).getTableName());
}
for (int i = 0; i < fields.length; ++i) {
Index: cpa/src/main/java/org/exolab/castor/jdo/engine/SQLEngine.java
===================================================================
--- cpa/src/main/java/org/exolab/castor/jdo/engine/SQLEngine.java (revision 7783)
+++ cpa/src/main/java/org/exolab/castor/jdo/engine/SQLEngine.java (working copy)
@@ -28,9 +28,12 @@
import org.exolab.castor.jdo.Database;
import org.exolab.castor.jdo.PersistenceException;
import org.exolab.castor.jdo.QueryException;
+import org.exolab.castor.jdo.engine.nature.ClassDescriptorJDONature;
import org.exolab.castor.mapping.AccessMode;
+import org.exolab.castor.mapping.ClassDescriptor;
import org.exolab.castor.mapping.FieldDescriptor;
import org.exolab.castor.mapping.MappingException;
+import org.exolab.castor.mapping.loader.ClassDescriptorImpl;
import org.exolab.castor.mapping.loader.FieldHandlerImpl;
import org.exolab.castor.persist.spi.Identity;
import org.exolab.castor.persist.spi.KeyGenerator;
@@ -68,7 +71,7 @@
private final PersistenceFactory _factory;
- private final JDOClassDescriptor _clsDesc;
+ private final ClassDescriptor _clsDesc;
private KeyGenerator _keyGen;
@@ -80,7 +83,7 @@
private final SQLStatementStore _storeStatement;
- public SQLEngine(final JDOClassDescriptor clsDesc, final PersistenceFactory factory,
+ public SQLEngine(final ClassDescriptor clsDesc, final PersistenceFactory factory,
final String stampField) throws MappingException {
_clsDesc = clsDesc;
@@ -88,7 +91,7 @@
_keyGen = null;
if (_clsDesc.getExtends() == null) {
- KeyGeneratorDescriptor keyGenDesc = clsDesc.getKeyGeneratorDescriptor();
+ KeyGeneratorDescriptor keyGenDesc = new ClassDescriptorJDONature(clsDesc).getKeyGeneratorDescriptor();
if (keyGenDesc != null) {
int[] tempType = ((JDOFieldDescriptor) _clsDesc.getIdentity()).getSQLType();
_keyGen = keyGenDesc.getKeyGeneratorRegistry().getKeyGenerator(
@@ -122,7 +125,7 @@
* No loop or circle should exist
*/
// then, we put depended class ids in the back
- JDOClassDescriptor base = clsDesc;
+ ClassDescriptor base = clsDesc;
// walk until the base class which this class extends
base = clsDesc;
@@ -133,7 +136,7 @@
// throw new MappingException(
// "Class should not both depends on and extended other classes");
// }
- base = (JDOClassDescriptor) base.getExtends();
+ base = base.getExtends();
stack.push(base);
// do we need to add loop detection?
}
@@ -142,8 +145,8 @@
// clsDesc
// we always put the original id info in front
// [oleg] except for SQL name, it may differ.
- FieldDescriptor[] baseIdDescriptors = base.getIdentities();
- FieldDescriptor[] idDescriptors = clsDesc.getIdentities();
+ FieldDescriptor[] baseIdDescriptors = ((ClassDescriptorImpl) base).getIdentities();
+ FieldDescriptor[] idDescriptors = ((ClassDescriptorImpl) clsDesc).getIdentities();
for (int i = 0; i < baseIdDescriptors.length; i++) {
if (baseIdDescriptors[i] instanceof JDOFieldDescriptor) {
@@ -169,7 +172,7 @@
// then do the fields
while (!stack.empty()) {
- base = (JDOClassDescriptor) stack.pop();
+ base = (ClassDescriptor) stack.pop();
FieldDescriptor[] fieldDescriptors = base.getFields();
for (int i = 0; i < fieldDescriptors.length; i++) {
// fieldDescriptors[i] is persistent in db if it is not transient
@@ -179,7 +182,7 @@
|| (fieldDescriptors[i].getClassDescriptor() != null)) {
fieldsInfo.add(new SQLFieldInfo(clsDesc, fieldDescriptors[i],
- base.getTableName(), !stack.empty()));
+ new ClassDescriptorJDONature(base).getTableName(), !stack.empty()));
}
}
}
@@ -220,14 +223,14 @@
* Used by {@link org.exolab.castor.jdo.OQLQuery} to retrieve the class descriptor.
* @return the JDO class descriptor.
*/
- public JDOClassDescriptor getDescriptor() {
+ public ClassDescriptor getDescriptor() {
return _clsDesc;
}
public PersistenceQuery createQuery(final QueryExpression query, final Class[] types,
final AccessMode accessMode)
throws QueryException {
- AccessMode mode = (accessMode != null) ? accessMode : _clsDesc.getAccessMode();
+ AccessMode mode = (accessMode != null) ? accessMode : new ClassDescriptorJDONature(_clsDesc).getAccessMode();
String sql = query.getStatement(mode == AccessMode.DbLocked);
if (LOG.isDebugEnabled()) {
Index: cpa/src/main/java/org/exolab/castor/jdo/engine/SQLQuery.java
===================================================================
--- cpa/src/main/java/org/exolab/castor/jdo/engine/SQLQuery.java (revision 7783)
+++ cpa/src/main/java/org/exolab/castor/jdo/engine/SQLQuery.java (working copy)
@@ -32,9 +32,12 @@
import org.castor.persist.ProposedEntity;
import org.castor.util.Messages;
import org.exolab.castor.jdo.PersistenceException;
+import org.exolab.castor.jdo.engine.nature.ClassDescriptorJDONature;
import org.exolab.castor.mapping.AccessMode;
+import org.exolab.castor.mapping.ClassDescriptor;
import org.exolab.castor.mapping.FieldDescriptor;
import org.exolab.castor.mapping.MappingException;
+import org.exolab.castor.mapping.loader.ClassDescriptorImpl;
import org.exolab.castor.persist.spi.Identity;
import org.exolab.castor.persist.spi.Persistence;
import org.exolab.castor.persist.spi.PersistenceFactory;
@@ -99,9 +102,9 @@
_types = types;
_values = new Object[ _types.length ];
_sql = sql;
- _identSqlType = new int[_engine.getDescriptor().getIdentities().length];
+ _identSqlType = new int[((ClassDescriptorImpl) _engine.getDescriptor()).getIdentities().length];
for (int i = 0; i < _identSqlType.length; i++) {
- FieldDescriptor fldDesc = _engine.getDescriptor().getIdentities()[i];
+ FieldDescriptor fldDesc = ((ClassDescriptorImpl) _engine.getDescriptor()).getIdentities()[i];
_identSqlType[i] = ((JDOFieldDescriptor) fldDesc).getSQLType()[0];
}
@@ -471,11 +474,11 @@
int originalFieldNumber = _requestedEngine.getInfo().length;
Collection extendingClassDescriptors =
- ((JDOClassDescriptorImpl) _requestedEngine.getDescriptor()).getExtended();
+ new ClassDescriptorJDONature(_requestedEngine.getDescriptor()).getExtended();
if (extendingClassDescriptors.size() > 0) {
int numberOfExtendLevels = SQLHelper.numberOfExtendingClassDescriptors(
_requestedEngine.getDescriptor());
- JDOClassDescriptor leafDescriptor = null;
+ ClassDescriptor leafDescriptor = null;
Object[] returnValues = null;
try {
returnValues = SQLHelper.calculateNumberOfFields(extendingClassDescriptors,
@@ -486,7 +489,7 @@
throw new PersistenceException("Problem calculating number of concrete fields.", e);
}
- leafDescriptor = (JDOClassDescriptor) returnValues[0];
+ leafDescriptor = (ClassDescriptor) returnValues[0];
if (leafDescriptor != null) {
if (!leafDescriptor.getJavaClass().getName().equals(
Index: cpa/src/main/java/org/exolab/castor/jdo/engine/KeyGeneratorDescriptor.java
===================================================================
--- cpa/src/main/java/org/exolab/castor/jdo/engine/KeyGeneratorDescriptor.java (revision 7783)
+++ cpa/src/main/java/org/exolab/castor/jdo/engine/KeyGeneratorDescriptor.java (working copy)
@@ -57,7 +57,7 @@
* @author Oleg Nitz
* @version $Revision$ $Date: 2003-03-03 00:05:44 -0700 (Mon, 03 Mar 2003) $
*/
-final class KeyGeneratorDescriptor {
+final public class KeyGeneratorDescriptor {
private final String _name;
private final String _keyGenFactoryName;
Index: cpa/src/main/java/org/castor/cpa/persistence/sql/driver/BaseFactory.java
===================================================================
--- cpa/src/main/java/org/castor/cpa/persistence/sql/driver/BaseFactory.java (revision 7783)
+++ cpa/src/main/java/org/castor/cpa/persistence/sql/driver/BaseFactory.java (working copy)
@@ -50,8 +50,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.castor.util.Messages;
-import org.exolab.castor.jdo.engine.JDOClassDescriptor;
import org.exolab.castor.jdo.engine.SQLEngine;
+import org.exolab.castor.jdo.engine.nature.ClassDescriptorJDONature;
import org.exolab.castor.mapping.ClassDescriptor;
import org.exolab.castor.mapping.MappingException;
import org.exolab.castor.persist.spi.Persistence;
@@ -77,12 +77,14 @@
* {@inheritDoc}
*/
public Persistence getPersistence(final ClassDescriptor clsDesc) {
- if (!(clsDesc instanceof JDOClassDescriptor)) { return null; }
+ if (!(clsDesc.hasNature(ClassDescriptorJDONature.class.getName()))) {
+ return null;
+ }
try {
Persistence sqlEngine = (SQLEngine) _classDescriptorToPersistence.get(clsDesc);
if (sqlEngine == null) {
- sqlEngine = new SQLEngine((JDOClassDescriptor) clsDesc, this, null);
+ sqlEngine = new SQLEngine(clsDesc, this, null);
_classDescriptorToPersistence.put(clsDesc, sqlEngine);
}
return sqlEngine;