You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by ar...@apache.org on 2003/01/16 18:15:10 UTC
cvs commit: jakarta-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess PersistentFieldMaxPerformanceImpl.java PersistentFieldDefaultImpl.java
arminw 2003/01/16 09:15:10
Modified: src/java/org/apache/ojb/broker/metadata
ConnectionRepository.java
src/java/org/apache/ojb/broker/metadata/fieldaccess
PersistentFieldMaxPerformanceImpl.java
PersistentFieldDefaultImpl.java
Log:
add more logging
Revision Changes Path
1.5 +2 -2 jakarta-ojb/src/java/org/apache/ojb/broker/metadata/ConnectionRepository.java
Index: ConnectionRepository.java
===================================================================
RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/metadata/ConnectionRepository.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ConnectionRepository.java 12 Jan 2003 14:29:08 -0000 1.4
+++ ConnectionRepository.java 16 Jan 2003 17:15:10 -0000 1.5
@@ -51,7 +51,7 @@
}
else
{
- log.info("Could not found " + JdbcConnectionDescriptor.class.getName() + " for alias '" + pbKey + "'");
+ log.info("Could not found " + JdbcConnectionDescriptor.class.getName() + " for PBKey " + pbKey);
}
}
return result;
1.13 +174 -168 jakarta-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentFieldMaxPerformanceImpl.java
Index: PersistentFieldMaxPerformanceImpl.java
===================================================================
RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentFieldMaxPerformanceImpl.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- PersistentFieldMaxPerformanceImpl.java 20 Dec 2002 01:53:32 -0000 1.12
+++ PersistentFieldMaxPerformanceImpl.java 16 Jan 2003 17:15:10 -0000 1.13
@@ -54,13 +54,14 @@
* <http://www.apache.org/>.
*/
-import java.lang.reflect.Field;
-
import org.apache.ojb.broker.metadata.MetadataException;
+import org.apache.ojb.broker.util.BrokerHelper;
import org.apache.ojb.broker.util.ProxyHelper;
import org.apache.ojb.broker.util.logging.Logger;
import org.apache.ojb.broker.util.logging.LoggerFactory;
+import java.lang.reflect.Field;
+
/**
* This class is a wrapper around java.lang.reflect.Field objects.
* @author <a href="mailto:thma@apache.org">Thomas Mahler<a>
@@ -68,169 +69,174 @@
*/
public class PersistentFieldMaxPerformanceImpl implements PersistentField
{
- private transient Field field;
- private Class clazz;
- private String fieldname;
- private Logger logger = LoggerFactory.getLogger(this.getClass());
-
- public PersistentFieldMaxPerformanceImpl(Field f)
- {
- this.field = f;
- }
-
- public PersistentFieldMaxPerformanceImpl(Class c, String fieldname)
- {
- this.clazz = c;
- this.fieldname = fieldname;
- this.field = computeField(c, fieldname);
- }
-
- public Class getType()
- {
- return getField().getType();
- }
-
- public String getName()
- {
- return getField().getName();
- }
-
- public Class getDeclaringClass()
- {
- return getField().getDeclaringClass();
- }
-
- /**
- * Sets the field represented by this PersistentField object on the specified object argument to the specified new value.
- * The new value is automatically unwrapped if the underlying field has a primitive type.
- * This implementation invokes set() on its underlying Field object if the argument <b>is not null</b>.
- * OBS IllegalArgumentExceptions are wrapped as PersistenceBrokerExceptions.
- *
- * @throws MetadataException if there is an error setting this field value on obj
- * @see java.lang.reflect.Field
- */
- public void set(Object obj, Object value) throws MetadataException
- {
- Field f = getField();
- Class type = f.getType();
- try
- {
- /**
- * MBAIRD
- * we need to be able to set values to null. We can only set something to null if
- * the type is not a primitive (assignable from Object).
- */
- // thanks to Tomasz Wysocki for this trick
- if ((value != null) || !type.isPrimitive())
- {
- f.set(ProxyHelper.getRealObject(obj), value);
- }
- }
- catch (NullPointerException ignored)
- {
- logger.info("Value for field " + f.getName() + " of type " + type.getName() + " is null. Can't write into null.");
- }
- catch (IllegalAccessException e)
- {
- throw new MetadataException("IllegalAccess error setting field:" + f.getName() + " in object:" + obj.getClass().getName(), e);
- }
- catch (Throwable e)
- {
- throw new MetadataException("Error setting field:" + field.getName() + " in object:" + obj.getClass().getName(), e);
- }
- }
-
- /**
- * Returns the value of the field represented by this PersistentField, on the specified object.
- * This implementation invokes get() on its underlying Field object.
- *
- * @param obj - the object instance which we are trying to get the field value from
- * @throws MetadataException if there is an error getting this field value from obj
- * @see java.lang.reflect.Field
- */
- public Object get(Object obj) throws MetadataException
- {
- try
- {
- Field field = getField();
- Object result = field.get(ProxyHelper.getRealObject(obj));
- return result;
- }
- catch (IllegalAccessException e)
- {
- throw new MetadataException(
- "IllegalAccess error getting field:" + field.getName() + " in object:" + obj.getClass().getName(),
- e);
- }
- catch (Throwable e)
- {
- throw new MetadataException("Error getting field:" + field.getName() + " in object:" + obj.getClass().getName(), e);
- }
- }
-
- /**
- * Tries to compute a Field object using getFieldRecursive.
- *
- * @throws MetadataException if there is an error computing the field ( No Field was found into the class hierarchy)
- */
- protected Field computeField(Class c, String fieldname)
- {
- Field f = null;
- try
- {
- f = getFieldRecursive(c, fieldname);
- f.setAccessible(true); // allow access to private members
- return f;
- }
- catch (NoSuchFieldException t)
- {
- throw new MetadataException("Can't find member " + fieldname + " in " + c.getName(), t);
- }
- }
-
- /**
- * try to find a field in class c, recurse through class hierarchy if necessary
- *
- * @throws NoSuchFieldException if no Field was found into the class hierarchy
- */
- protected Field getFieldRecursive(Class c, String fieldname) throws NoSuchFieldException
- {
- try
- {
- Field f = c.getDeclaredField(fieldname);
- return f;
- }
- catch (NoSuchFieldException e)
- {
- // if field could not be found in the inheritance hierarchy, signal error
- if (c == Object.class)
- {
- throw e;
- }
- // if field could not be found in class c try in superclass
- else
- {
- return getFieldRecursive(c.getSuperclass(), fieldname);
- }
- }
- }
-
- /**
- * Returns the underlying Field object.
- *
- * @throws MetadataException if there is an error computing the field ( No Field was found into the class hierarchy)
- */
- protected Field getField()
- {
- if (field == null)
- {
- field = computeField(clazz, fieldname);
- }
- return field;
- }
-
- public boolean usesAccessorsAndMutators()
- {
- return false;
- }
+ private transient Field field;
+ private Class clazz;
+ private String fieldname;
+ private Logger logger = LoggerFactory.getLogger(this.getClass());
+
+ public PersistentFieldMaxPerformanceImpl(Field f)
+ {
+ this.field = f;
+ }
+
+ public PersistentFieldMaxPerformanceImpl(Class c, String fieldname)
+ {
+ this.clazz = c;
+ this.fieldname = fieldname;
+ this.field = computeField(c, fieldname);
+ }
+
+ public Class getType()
+ {
+ return getField().getType();
+ }
+
+ public String getName()
+ {
+ return getField().getName();
+ }
+
+ public Class getDeclaringClass()
+ {
+ return getField().getDeclaringClass();
+ }
+
+ /**
+ * Sets the field represented by this PersistentField object on the specified object argument to the specified new value.
+ * The new value is automatically unwrapped if the underlying field has a primitive type.
+ * This implementation invokes set() on its underlying Field object if the argument <b>is not null</b>.
+ * OBS IllegalArgumentExceptions are wrapped as PersistenceBrokerExceptions.
+ *
+ * @throws MetadataException if there is an error setting this field value on obj
+ * @see java.lang.reflect.Field
+ */
+ public void set(Object obj, Object value) throws MetadataException
+ {
+ Field f = getField();
+ Class type = f.getType();
+ try
+ {
+ /**
+ * MBAIRD
+ * we need to be able to set values to null. We can only set something to null if
+ * the type is not a primitive (assignable from Object).
+ */
+ // thanks to Tomasz Wysocki for this trick
+ if ((value != null) || !type.isPrimitive())
+ {
+ f.set(ProxyHelper.getRealObject(obj), value);
+ }
+ }
+ catch (NullPointerException ignored)
+ {
+ logger.info("Value for field " + f.getName() + " of type " + type.getName() +
+ " is null. Can't write into null.");
+ }
+ catch (IllegalAccessException e)
+ {
+ logger.error("while set field: " + BrokerHelper.buildMessageString(obj, value, f));
+ throw new MetadataException("IllegalAccess error setting field:" + f.getName() +
+ " in object:" + obj.getClass().getName(), e);
+ }
+ catch (Exception e)
+ {
+ logger.error("while set field: " + BrokerHelper.buildMessageString(obj, value, f));
+ throw new MetadataException("Error setting field:" + field.getName() +
+ " in object:" + obj.getClass().getName(), e);
+ }
+ }
+
+ /**
+ * Returns the value of the field represented by this PersistentField, on the specified object.
+ * This implementation invokes get() on its underlying Field object.
+ *
+ * @param obj - the object instance which we are trying to get the field value from
+ * @throws MetadataException if there is an error getting this field value from obj
+ * @see java.lang.reflect.Field
+ */
+ public Object get(Object obj) throws MetadataException
+ {
+ try
+ {
+ Field field = getField();
+ Object result = field.get(ProxyHelper.getRealObject(obj));
+ return result;
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new MetadataException(
+ "IllegalAccess error getting field:" + field.getName() + " in object:" + obj.getClass().getName(),
+ e);
+ }
+ catch (Throwable e)
+ {
+ throw new MetadataException("Error getting field:" + field.getName() + " in object:" + obj.getClass().getName(), e);
+ }
+ }
+
+ /**
+ * Tries to compute a Field object using getFieldRecursive.
+ *
+ * @throws MetadataException if there is an error computing the field ( No Field was found into the class hierarchy)
+ */
+ protected Field computeField(Class c, String fieldname)
+ {
+ Field f = null;
+ try
+ {
+ f = getFieldRecursive(c, fieldname);
+ f.setAccessible(true); // allow access to private members
+ return f;
+ }
+ catch (NoSuchFieldException t)
+ {
+ throw new MetadataException("Can't find member " + fieldname + " in " + c.getName(), t);
+ }
+ }
+
+ /**
+ * try to find a field in class c, recurse through class hierarchy if necessary
+ *
+ * @throws NoSuchFieldException if no Field was found into the class hierarchy
+ */
+ protected Field getFieldRecursive(Class c, String fieldname) throws NoSuchFieldException
+ {
+ try
+ {
+ Field f = c.getDeclaredField(fieldname);
+ return f;
+ }
+ catch (NoSuchFieldException e)
+ {
+ // if field could not be found in the inheritance hierarchy, signal error
+ if (c == Object.class)
+ {
+ throw e;
+ }
+ // if field could not be found in class c try in superclass
+ else
+ {
+ return getFieldRecursive(c.getSuperclass(), fieldname);
+ }
+ }
+ }
+
+ /**
+ * Returns the underlying Field object.
+ *
+ * @throws MetadataException if there is an error computing the field ( No Field was found into the class hierarchy)
+ */
+ protected Field getField()
+ {
+ if (field == null)
+ {
+ field = computeField(clazz, fieldname);
+ }
+ return field;
+ }
+
+ public boolean usesAccessorsAndMutators()
+ {
+ return false;
+ }
}
1.15 +205 -202 jakarta-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentFieldDefaultImpl.java
Index: PersistentFieldDefaultImpl.java
===================================================================
RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentFieldDefaultImpl.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- PersistentFieldDefaultImpl.java 24 Dec 2002 13:08:35 -0000 1.14
+++ PersistentFieldDefaultImpl.java 16 Jan 2003 17:15:10 -0000 1.15
@@ -54,16 +54,17 @@
* <http://www.apache.org/>.
*/
-import java.io.Serializable;
-import java.lang.reflect.Field;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-
import org.apache.ojb.broker.metadata.MetadataException;
+import org.apache.ojb.broker.util.BrokerHelper;
import org.apache.ojb.broker.util.ProxyHelper;
import org.apache.ojb.broker.util.logging.Logger;
import org.apache.ojb.broker.util.logging.LoggerFactory;
+import java.io.Serializable;
+import java.lang.reflect.Field;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
/**
* This class is a wrapper around java.lang.reflect.Field objects.
* @author <a href="mailto:thma@apache.org">Thomas Mahler<a>
@@ -71,222 +72,224 @@
*/
public class PersistentFieldDefaultImpl implements PersistentField
{
- private SetAccessibleAction setAccessibleAction = new SetAccessibleAction();
+ private SetAccessibleAction setAccessibleAction = new SetAccessibleAction();
+
+ private transient Field field;
+ private Class clazz;
+ private String fieldname;
+ private Logger logger = LoggerFactory.getLogger(this.getClass());
+
+ /**
+ * Make the newInstace with no constructor call happy!
+ */
+ public PersistentFieldDefaultImpl()
+ {
+
+ }
+
+ public PersistentFieldDefaultImpl(Field f)
+ {
+ this.field = f;
+ }
+
+ public PersistentFieldDefaultImpl(Class c, String fieldname)
+ {
+ this.clazz = c;
+ this.fieldname = fieldname;
+ this.field = computeField(c, fieldname);
+ }
+
+ public Class getType()
+ {
+ return getField().getType();
+ }
+
+ public String getName()
+ {
+ return getField().getName();
+ }
+
+ public Class getDeclaringClass()
+ {
+ return getField().getDeclaringClass();
+ }
+
+ /**
+ * Sets the field represented by this PersistentField object on the specified object argument to the specified new value.
+ * The new value is automatically unwrapped if the underlying field has a primitive type.
+ * This implementation invokes set() on its underlying Field object if the argument <b>is not null</b>.
+ * OBS IllegalArgumentExceptions are wrapped as PersistenceBrokerExceptions.
+ *
+ * @throws MetadataException if there is an error setting this field value on obj
+ * @see java.lang.reflect.Field
+ */
+ public synchronized void set(Object obj, Object value) throws MetadataException
+ {
+ Field f = getField();
+ boolean before = f.isAccessible();
+ AccessController.doPrivileged(setAccessibleAction);
+ Class type = f.getType();
+ /**
+ * MBAIRD
+ * used to check for value equal to null, meaning we could never set a value to null.
+ * being able to set a field to NULL is important.
+ */
- private transient Field field;
- private Class clazz;
- private String fieldname;
- private Logger logger = LoggerFactory.getLogger(this.getClass());
-
- /**
- * Make the newInstace with no constructor call happy!
- */
- public PersistentFieldDefaultImpl()
- {
-
- }
-
- public PersistentFieldDefaultImpl(Field f)
- {
- this.field = f;
- }
-
- public PersistentFieldDefaultImpl(Class c, String fieldname)
- {
- this.clazz = c;
- this.fieldname = fieldname;
- this.field = computeField(c, fieldname);
- }
-
- public Class getType()
- {
- return getField().getType();
- }
-
- public String getName()
- {
- return getField().getName();
- }
-
- public Class getDeclaringClass()
- {
- return getField().getDeclaringClass();
- }
-
- /**
- * Sets the field represented by this PersistentField object on the specified object argument to the specified new value.
- * The new value is automatically unwrapped if the underlying field has a primitive type.
- * This implementation invokes set() on its underlying Field object if the argument <b>is not null</b>.
- * OBS IllegalArgumentExceptions are wrapped as PersistenceBrokerExceptions.
- *
- * @throws MetadataException if there is an error setting this field value on obj
- * @see java.lang.reflect.Field
- */
- public synchronized void set(Object obj, Object value) throws MetadataException
- {
- Field f = getField();
- boolean before = f.isAccessible();
- AccessController.doPrivileged(setAccessibleAction);
- Class type = f.getType();
- /**
- * MBAIRD
- * used to check for value equal to null, meaning we could never set a value to null.
- * being able to set a field to NULL is important.
- */
-
- try
- {
- /**
- * MBAIRD
- * we need to be able to set values to null. We can only set something to null if
- * the type is not a primitive (assignable from Object).
- */
- if ((value != null) || !type.isPrimitive())
- {
- f.set(ProxyHelper.getRealObject(obj), value);
- }
- }
+ try
+ {
+ /**
+ * MBAIRD
+ * we need to be able to set values to null. We can only set something to null if
+ * the type is not a primitive (assignable from Object).
+ */
+ if ((value != null) || !type.isPrimitive())
+ {
+ f.set(ProxyHelper.getRealObject(obj), value);
+ }
+ }
catch (NullPointerException ignored)
{
logger.info(
- "Value for field" + f.getName() + " of type " + type.getName() + " is null. Can't write into null.");
+ "Value for field" + f.getName() + " of type " + type.getName() + " is null. Can't write into null.");
}
catch (IllegalAccessException e)
{
+ logger.error("while set field: " + BrokerHelper.buildMessageString(obj, value, f));
throw new MetadataException(
- "IllegalAccess error setting field:" + f.getName() + " in object:" + obj.getClass().getName(),
- e);
+ "IllegalAccess error setting field:" + f.getName() + " in object:" + obj.getClass().getName(),
+ e);
}
catch (Throwable e)
{
+ logger.error("while set field: " + BrokerHelper.buildMessageString(obj, value, f));
throw new MetadataException(
- "Error setting field:" + field.getName() + " in object:" + obj.getClass().getName(),
- e);
+ "Error setting field:" + field.getName() + " in object:" + obj.getClass().getName(),
+ e);
+ }
+ finally
+ {
+ getField().setAccessible(before);
+ }
+ }
+
+ /**
+ * Returns the value of the field represented by this PersistentField, on the specified object.
+ * This implementation invokes get() on its underlying Field object.
+ *
+ * @param obj - the object instance which we are trying to get the field value from
+ * @throws MetadataException if there is an error getting this field value from obj
+ * @see java.lang.reflect.Field
+ */
+ public synchronized Object get(Object obj) throws MetadataException
+ {
+ boolean before = getField().isAccessible();
+ AccessController.doPrivileged(setAccessibleAction);
+
+ try
+ {
+ Field field = getField();
+ Object result = field.get(ProxyHelper.getRealObject(obj));
+
+ return result;
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new MetadataException(
+ "IllegalAccess error getting field:" + field.getName() + " in object:" + obj.getClass().getName(),
+ e);
}
- finally
- {
- getField().setAccessible(before);
- }
- }
-
- /**
- * Returns the value of the field represented by this PersistentField, on the specified object.
- * This implementation invokes get() on its underlying Field object.
- *
- * @param obj - the object instance which we are trying to get the field value from
- * @throws MetadataException if there is an error getting this field value from obj
- * @see java.lang.reflect.Field
- */
- public synchronized Object get(Object obj) throws MetadataException
- {
- boolean before = getField().isAccessible();
- AccessController.doPrivileged(setAccessibleAction);
-
- try
- {
- Field field = getField();
- Object result = field.get(ProxyHelper.getRealObject(obj));
-
- return result;
- }
- catch (IllegalAccessException e)
- {
- throw new MetadataException(
- "IllegalAccess error getting field:" + field.getName() + " in object:" + obj.getClass().getName(),
- e);
- }
catch (Exception e)
{
throw new MetadataException(
- "Error getting field:" + field.getName() + " in object:" + obj.getClass().getName(),
- e);
+ "Error getting field:" + field.getName() + " in object:" + obj.getClass().getName(),
+ e);
}
finally
{
field.setAccessible(before);
}
- }
+ }
+
+ /**
+ * Tries to compute a Field object using getFieldRecursive.
+ *
+ * @throws MetadataException if there is an error computing the field ( No Field was found into the class hierarchy)
+ */
+ protected Field computeField(Class c, String fieldname)
+ {
+ Field f = null;
+ try
+ {
+ f = getFieldRecursive(c, fieldname);
+ //f.setAccessible(true); // allow access to private members
+ return f;
+ }
+ catch (NoSuchFieldException t)
+ {
+ // logger.error("Can't find member "
+ // + fieldname
+ // + " in "
+ // + c.getName() );
+ // logger.error(t);
+ throw new MetadataException("Can't find member " + fieldname + " in " + c.getName(), t);
+ }
+ }
+
+ /**
+ * try to find a field in class c, recurse through class hierarchy if necessary
+ *
+ * @throws NoSuchFieldException if no Field was found into the class hierarchy
+ */
+ protected Field getFieldRecursive(Class c, String fieldname) throws NoSuchFieldException
+ {
+ try
+ {
+ Field f = c.getDeclaredField(fieldname);
+ return f;
+ }
+ catch (NoSuchFieldException e)
+ {
+ // if field could not be found in the inheritance hierarchy, signal error
+ if (c == Object.class)
+ {
+ throw e;
+ }
+ // if field could not be found in class c try in superclass
+ else
+ {
+ return getFieldRecursive(c.getSuperclass(), fieldname);
+ }
+ }
+ }
+
+ /**
+ * Returns the underlying Field object.
+ *
+ * @throws MetadataException if there is an error computing the field ( No Field was found into the class hierarchy)
+ */
+ protected Field getField()
+ {
+ if (field == null)
+ {
+ field = computeField(clazz, fieldname);
+ }
+ return field;
+ }
+
+ /**
+ *
+ */
+ private class SetAccessibleAction implements PrivilegedAction, Serializable
+ {
+ public Object run()
+ {
+ getField().setAccessible(true);
+ return null;
+ }
+ }
- /**
- * Tries to compute a Field object using getFieldRecursive.
- *
- * @throws MetadataException if there is an error computing the field ( No Field was found into the class hierarchy)
- */
- protected Field computeField(Class c, String fieldname)
- {
- Field f = null;
- try
- {
- f = getFieldRecursive(c, fieldname);
- //f.setAccessible(true); // allow access to private members
- return f;
- }
- catch (NoSuchFieldException t)
- {
- // logger.error("Can't find member "
- // + fieldname
- // + " in "
- // + c.getName() );
- // logger.error(t);
- throw new MetadataException("Can't find member " + fieldname + " in " + c.getName(), t);
- }
- }
-
- /**
- * try to find a field in class c, recurse through class hierarchy if necessary
- *
- * @throws NoSuchFieldException if no Field was found into the class hierarchy
- */
- protected Field getFieldRecursive(Class c, String fieldname) throws NoSuchFieldException
- {
- try
- {
- Field f = c.getDeclaredField(fieldname);
- return f;
- }
- catch (NoSuchFieldException e)
- {
- // if field could not be found in the inheritance hierarchy, signal error
- if (c == Object.class)
- {
- throw e;
- }
- // if field could not be found in class c try in superclass
- else
- {
- return getFieldRecursive(c.getSuperclass(), fieldname);
- }
- }
- }
-
- /**
- * Returns the underlying Field object.
- *
- * @throws MetadataException if there is an error computing the field ( No Field was found into the class hierarchy)
- */
- protected Field getField()
- {
- if (field == null)
- {
- field = computeField(clazz, fieldname);
- }
- return field;
- }
-
- /**
- *
- */
- private class SetAccessibleAction implements PrivilegedAction, Serializable
- {
- public Object run()
- {
- getField().setAccessible(true);
- return null;
- }
- }
-
- public boolean usesAccessorsAndMutators()
- {
- return false;
- }
+ public boolean usesAccessorsAndMutators()
+ {
+ return false;
+ }
}