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 2006/07/15 16:22:36 UTC

svn commit: r422233 [2/4] - in /db/ojb/trunk/src/java/org/apache/ojb/broker: ./ metadata/ metadata/torque/ platforms/ query/ util/ util/dbhandling/

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/JdbcTypesHelper.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/JdbcTypesHelper.java?rev=422233&r1=422232&r2=422233&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/JdbcTypesHelper.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/JdbcTypesHelper.java Sat Jul 15 07:22:34 2006
@@ -1,49 +1,40 @@
 package org.apache.ojb.broker.metadata;
 
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
+/* Copyright 2003-2005 The Apache Software Foundation
+ *
+ * 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.
+ */
+
 import java.lang.reflect.Field;
 import java.math.BigDecimal;
 import java.net.URL;
 import java.sql.Blob;
-import java.sql.CallableStatement;
 import java.sql.Clob;
 import java.sql.Date;
 import java.sql.Ref;
-import java.sql.ResultSet;
-import java.sql.SQLException;
 import java.sql.Struct;
 import java.sql.Time;
 import java.sql.Timestamp;
 import java.sql.Types;
 import java.util.HashMap;
+import java.util.Locale;
 import java.util.Map;
 
-import org.apache.commons.lang.BooleanUtils;
-import org.apache.commons.lang.builder.ToStringBuilder;
 import org.apache.ojb.broker.OJBRuntimeException;
-import org.apache.ojb.broker.util.SqlHelper;
-import org.apache.ojb.broker.util.sequence.SequenceManagerException;
-
-/* Copyright 2003-2004 The Apache Software Foundation
- *
- * 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.
- */
+import org.apache.ojb.broker.metadata.fieldaccess.PersistentField;
 
 /**
- * Helper class which provide all supported {@link JdbcType} classes
- * (based on the {@link java.sql.Types}) as inner classes.
+ * Helps to manage the {@link JdbcType} implementation classes.
  *
  * @see JdbcType
  * @version $Id$
@@ -58,34 +49,35 @@
      */
     static
     {
-        setJdbcType("array", Types.ARRAY, new T_Array());
-        setJdbcType("bigint", Types.BIGINT, new T_BigInt());
-        setJdbcType("binary", Types.BINARY, new T_Binary());
-        setJdbcType("bit", Types.BIT, new T_Bit());
-        setJdbcType("blob", Types.BLOB, new T_Blob());
-        setJdbcType("char", Types.CHAR, new T_Char());
-        setJdbcType("clob", Types.CLOB, new T_Clob());
-        setJdbcType("date", Types.DATE, new T_Date());
-        setJdbcType("decimal", Types.DECIMAL, new T_Decimal());
-        setJdbcType("double", Types.DOUBLE, new T_Double());
-        setJdbcType("float", Types.FLOAT, new T_Float());
-        setJdbcType("integer", Types.INTEGER, new T_Integer());
-        setJdbcType("longvarbinary", Types.LONGVARBINARY, new T_LongVarBinary());
-        setJdbcType("longvarchar", Types.LONGVARCHAR, new T_LongVarChar());
-        setJdbcType("numeric", Types.NUMERIC, new T_Numeric());
-        setJdbcType("real", Types.REAL, new T_Real());
-        setJdbcType("ref", Types.REF, new T_Ref());
-        setJdbcType("smallint", Types.SMALLINT, new T_SmallInt());
-        setJdbcType("struct", Types.STRUCT, new T_Struct());
-        setJdbcType("time", Types.TIME, new T_Time());
-        setJdbcType("timestamp", Types.TIMESTAMP, new T_Timestamp());
-        setJdbcType("tinyint", Types.TINYINT, new T_TinyInt());
-        setJdbcType("varbinary", Types.VARBINARY, new T_VarBinary());
-        setJdbcType("varchar", Types.VARCHAR, new T_Varchar());
-        
+        setJdbcType("array", Types.ARRAY, new JdbcTypes.T_Array());
+        setJdbcType("bigint", Types.BIGINT, new JdbcTypes.T_BigInt());
+        setJdbcType("binary", Types.BINARY, new JdbcTypes.T_Binary());
+        setJdbcType("bit", Types.BIT, new JdbcTypes.T_Bit());
+        setJdbcType("blob", Types.BLOB, new JdbcTypes.T_Blob());
+        setJdbcType("char", Types.CHAR, new JdbcTypes.T_Char());
+        setJdbcType("clob", Types.CLOB, new JdbcTypes.T_Clob());
+        setJdbcType("date", Types.DATE, new JdbcTypes.T_Date());
+        setJdbcType("decimal", Types.DECIMAL, new JdbcTypes.T_Decimal());
+        setJdbcType("double", Types.DOUBLE, new JdbcTypes.T_Double());
+        setJdbcType("float", Types.FLOAT, new JdbcTypes.T_Float());
+        setJdbcType("integer", Types.INTEGER, new JdbcTypes.T_Integer());
+        setJdbcType("longvarbinary", Types.LONGVARBINARY, new JdbcTypes.T_LongVarBinary());
+        setJdbcType("longvarchar", Types.LONGVARCHAR, new JdbcTypes.T_LongVarChar());
+        setJdbcType("numeric", Types.NUMERIC, new JdbcTypes.T_Numeric());
+        setJdbcType("real", Types.REAL, new JdbcTypes.T_Real());
+        setJdbcType("ref", Types.REF, new JdbcTypes.T_Ref());
+        setJdbcType("smallint", Types.SMALLINT, new JdbcTypes.T_SmallInt());
+        setJdbcType("struct", Types.STRUCT, new JdbcTypes.T_Struct());
+        setJdbcType("time", Types.TIME, new JdbcTypes.T_Time());
+        setJdbcType("timestamp", Types.TIMESTAMP, new JdbcTypes.T_Timestamp());
+        setJdbcType("tinyint", Types.TINYINT, new JdbcTypes.T_TinyInt());
+        setJdbcType("varbinary", Types.VARBINARY, new JdbcTypes.T_VarBinary());
+        setJdbcType("varchar", Types.VARCHAR, new JdbcTypes.T_Varchar());
+        setJdbcType("java_object", Types.JAVA_OBJECT, new JdbcTypes.T_JavaObject());
+
 //#ifdef JDBC30
-        setJdbcType("boolean", Types.BOOLEAN, new T_Boolean());
-        setJdbcType("datalink", Types.DATALINK, new T_Datalink());
+        setJdbcType("boolean", Types.BOOLEAN, new JdbcTypes.T_Boolean());
+        setJdbcType("datalink", Types.DATALINK, new JdbcTypes.T_Datalink());
 //#endif
        
     }
@@ -128,11 +120,41 @@
     /**
      * Lookup the {@link JdbcType} by name. If name was not found an exception
      * is thrown.
+     *
+     * @param typeName The name of the JDBC type as String, e.g. 'bigint', 'integer'...
      */
     public static JdbcType getJdbcTypeByName(String typeName)
     {
-        JdbcType result = null;
-        result = (JdbcType) jdbcObjectTypesFromName.get(typeName.toLowerCase());
+        /*
+        arminw:
+        Some user reported problems when using OJB with non-default Localization. The
+        conversion of sql type names e.g. Turkish 'BIGINT' to lower case will not match 'bigint'
+        Hope that the specification of the localization will fix this.
+        */
+        JdbcType result = (JdbcType) jdbcObjectTypesFromName.get(typeName.toLowerCase(Locale.ENGLISH));
+        if (result == null)
+        {
+            throw new OJBRuntimeException("The type " + typeName + " can not be handled by OJB." +
+                    " Please specify only types as defined by java.sql.Types.");
+        }
+        return result;
+    }
+
+    /**
+     * Lookup the {@link JdbcType} by name. If name was not found an exception
+     * is thrown.
+     *
+     * @param typeName The name of the JDBC type as String, e.g. 'bigint', 'integer'...
+     */
+    public static JdbcType getJdbcTypeByName(String typeName, PersistentField field)
+    {
+        /*
+        arminw:
+        Some user reported problems when using OJB with non-default Localization. The
+        conversion of sql type names e.g. Turkish 'BIGINT' to lower case will not match 'bigint'
+        Hope that the specification of the localization will fix this.
+        */
+        JdbcType result = (JdbcType) jdbcObjectTypesFromName.get(typeName.toLowerCase(Locale.ENGLISH));
         if (result == null)
         {
             throw new OJBRuntimeException("The type " + typeName + " can not be handled by OJB." +
@@ -158,29 +180,34 @@
      *
      * @see FieldDescriptor#getJdbcType
      */
-    public static JdbcType getJdbcTypeByReflection(String fieldType)
+    public static JdbcType getJdbcTypeByReflection(PersistentField fld)
     {
         JdbcType result;
-        
+        String fieldType = fld.getType().getName();
+
         if (fieldType.equalsIgnoreCase(Character.class.getName()) || fieldType.equalsIgnoreCase("char"))
             result = getJdbcTypeByName("char");
-        else if (fieldType.equalsIgnoreCase(Short.class.getName()) || fieldType.equalsIgnoreCase("short"))
-            result = getJdbcTypeByName("smallint");
+        else if (fieldType.equalsIgnoreCase(String.class.getName()))
+            result = getJdbcTypeByName("varchar");
+
         else if (fieldType.equalsIgnoreCase(Integer.class.getName()) || fieldType.equalsIgnoreCase("int"))
             result = getJdbcTypeByName("integer");
         else if (fieldType.equalsIgnoreCase(Long.class.getName()) || fieldType.equalsIgnoreCase("long"))
             result = getJdbcTypeByName("bigint");
+        else if (fieldType.equalsIgnoreCase(Boolean.class.getName()) || fieldType.equalsIgnoreCase("boolean"))
+            result = getJdbcTypeByName("bit");
+        else if (fieldType.equalsIgnoreCase(BigDecimal.class.getName()))
+            result = getJdbcTypeByName("decimal");
+        else if (fieldType.equalsIgnoreCase(Short.class.getName()) || fieldType.equalsIgnoreCase("short"))
+            result = getJdbcTypeByName("smallint");
         else if (fieldType.equalsIgnoreCase(Byte.class.getName()) || fieldType.equalsIgnoreCase("byte"))
             result = getJdbcTypeByName("tinyint");
+
         else if (fieldType.equalsIgnoreCase(Float.class.getName()) || fieldType.equalsIgnoreCase("float"))
             result = getJdbcTypeByName("real");
         else if (fieldType.equalsIgnoreCase(Double.class.getName()) || fieldType.equalsIgnoreCase("double"))
             result = getJdbcTypeByName("float");
-        else if (fieldType.equalsIgnoreCase(String.class.getName()))
-            result = getJdbcTypeByName("varchar");
-        /*
-        TODO: arminw: useful? This only will work in conjunction with  a FieldConversion
-        */
+
         else if (fieldType.equalsIgnoreCase(java.util.Date.class.getName()))
             result = getJdbcTypeByName("date");
         else if (fieldType.equalsIgnoreCase(Date.class.getName()))
@@ -189,14 +216,16 @@
             result = getJdbcTypeByName("time");
         else if (fieldType.equalsIgnoreCase(Timestamp.class.getName()))
             result = getJdbcTypeByName("timestamp");
-        else if (fieldType.equalsIgnoreCase(BigDecimal.class.getName()))
-            result = getJdbcTypeByName("decimal");
+
+        else if (fieldType.equalsIgnoreCase(Blob.class.getName()))
+            result = getJdbcTypeByName("blob");
+        else if (fieldType.equalsIgnoreCase(Clob.class.getName()))
+            result = getJdbcTypeByName("clob");
+
         else if (fieldType.equalsIgnoreCase(Ref.class.getName()))
             result = getJdbcTypeByName("ref");
         else if (fieldType.equalsIgnoreCase(Struct.class.getName()))
             result = getJdbcTypeByName("struct");
-        else if (fieldType.equalsIgnoreCase(Boolean.class.getName()) || fieldType.equalsIgnoreCase("boolean"))
-            result = getJdbcTypeByName("bit");
 //#ifdef JDBC30
         else if (fieldType.equalsIgnoreCase(URL.class.getName()))
             result = getJdbcTypeByName("datalink");
@@ -208,28 +237,28 @@
     }
 
 
-    /**
-     * Returns an java object read from the specified ResultSet column.
-     */
-    public static Object getObjectFromColumn(ResultSet rs, Integer jdbcType, int columnId)
-            throws SQLException
-    {
-        return getObjectFromColumn(rs, null, jdbcType, null, columnId);
-    }
-
-    /**
-     * Returns an java object for the given jdbcType by extract from the given
-     * CallableStatement or ResultSet.
-     * NOTE: Exactly one of the arguments of type CallableStatement or ResultSet
-     * have to be non-null.
-     * If the 'columnId' argument is equals {@link JdbcType#MIN_INT}, then the given 'columnName'
-     * argument is used to lookup column. Else the given 'columnId' is used as column index.
-     */
-    private static Object getObjectFromColumn(ResultSet rs, CallableStatement stmt, Integer jdbcType, String columnName, int columnId)
-            throws SQLException
-    {
-        return getJdbcTypeByTypesIndex(jdbcType).getObjectFromColumn(rs, stmt, columnName, columnId);
-    }
+//    /**
+//     * Returns an java object read from the specified ResultSet column.
+//     */
+//    public static Object getObjectFromColumn(ResultSet rs, Integer jdbcType, int columnId)
+//            throws SQLException
+//    {
+//        return getObjectFromColumn(rs, null, jdbcType, null, columnId);
+//    }
+//
+//    /**
+//     * Returns an java object for the given jdbcType by extract from the given
+//     * CallableStatement or ResultSet.
+//     * NOTE: Exactly one of the arguments of type CallableStatement or ResultSet
+//     * have to be non-null.
+//     * If the 'columnId' argument is equals {@link JdbcType#MIN_INT}, then the given 'columnName'
+//     * argument is used to lookup column. Else the given 'columnId' is used as column index.
+//     */
+//    private static Object getObjectFromColumn(ResultSet rs, CallableStatement stmt, Integer jdbcType, String columnName, int columnId)
+//            throws SQLException
+//    {
+//        return getJdbcTypeByTypesIndex(jdbcType).getObjectFromColumn(rs, stmt, columnName, columnId);
+//    }
 
     /**
      * Returns a string representation of the given {@link java.sql.Types} value.
@@ -256,1098 +285,120 @@
         return statusName;
     }
 
-
-    //======================================================================================
-    // inner classes implementing JdbcType interface
-    //======================================================================================
-
-    public abstract static class BaseType implements JdbcType
+    /**
+     * Returns a {@link org.apache.ojb.broker.metadata.FieldType} instance for the given sql type
+     * (see {@link java.sql.Types}) as specified in JDBC 3.0 specification
+     * (see JDBC 3.0 specification <em>Appendix B, Data Type Conversion Tables</em>).
+     *
+     * @param jdbcType Specify the type to look for.
+     * @return A new specific {@link org.apache.ojb.broker.metadata.FieldType} instance.
+     */
+    static FieldType newFieldType(JdbcType jdbcType)
     {
-        private FieldType fieldType;
-
-        protected BaseType()
-        {
-            fieldType = FieldTypeClasses.newFieldType(this);
-        }
-
-        abstract Object readValueFromResultSet(ResultSet rs, String columnName) throws SQLException;
-
-        abstract Object readValueFromResultSet(ResultSet rs, int columnIndex) throws SQLException;
-
-        abstract Object readValueFromStatement(CallableStatement stmt, int columnIndex) throws SQLException;
-        /*
-        only supported by jdk >= 1.4x, maybe useful in further versions
-        */
-        // abstract Object readValueFromStatement(CallableStatement stmt, String columnName) throws SQLException;
-
-        public boolean equals(Object obj)
+        FieldType result;
+        switch(jdbcType.getType())
         {
-            if (this == obj) return true;
-            boolean result = false;
-            if (obj instanceof JdbcType)
-            {
-                result = this.getType() == ((JdbcType) obj).getType();
-            }
-            return result;
-        }
-
-        public String getTypeAsString()
-        {
-            return getSqlTypeAsString(getType());
-        }
-
-        public int hashCode()
-        {
-            return getType();
-        }
-
-        public FieldType getFieldType()
-        {
-            return fieldType;
-        }
-
-        public Object getObjectFromColumn(CallableStatement stmt, int columnId) throws SQLException
-        {
-            return getObjectFromColumn(null, stmt, null, columnId);
-        }
-
-        public Object getObjectFromColumn(ResultSet rs, String columnName) throws SQLException
-        {
-            return getObjectFromColumn(rs, null, columnName, MIN_INT);
-        }
-
-        public Object getObjectFromColumn(final ResultSet rs, final CallableStatement stmt,
-                                          final String columnName, int columnIndex) throws SQLException
-        {
-            if (stmt != null)
-            {
-                if (columnIndex == MIN_INT)
-                {
-                    throw new UnsupportedOperationException("Not implemented yet");
-                }
-                else
-                {
-                    return readValueFromStatement(stmt, columnIndex);
-                }
-            }
-            else
-            {
-                return columnIndex == MIN_INT ?
-                        readValueFromResultSet(rs, SqlHelper.stripOjbQuotes(columnName))
-                        : readValueFromResultSet(rs, columnIndex);
-            }
-        }
-
-        public String toString()
-        {
-            return new ToStringBuilder(this)
-                    .append("jdbcType", getType())
-                    .append("jdbcTypeString", getSqlTypeAsString(getType()))
-                    .append("associatedFieldType", getFieldType())
-                    .toString();
-        }
-
-//      // not used in code, but maybe useful in further versions
-//        public Object getObjectFromColumn(CallableStatement stmt, String columnName) throws SQLException
-//        {
-//            return getObjectFromColumn(null, stmt, columnName, MIN_INT);
-//        }
+            case Types.ARRAY:
+                result = new FieldTypes.ArrayFieldType();
+                break;
+            case Types.BIGINT:
+                result = new FieldTypes.LongFieldType();
+                break;
+            case Types.BINARY:
+                result = new FieldTypes.ByteArrayFieldType();
+                break;
+            case Types.BIT:
+                result = new FieldTypes.BooleanFieldType();
+                break;
+            case Types.BLOB:
+                result = new FieldTypes.BlobFieldType();
+                break;
+            case Types.CHAR:
+                result = new FieldTypes.StringFieldType();
+                break;
+            case Types.CLOB:
+                result = new FieldTypes.ClobFieldType();
+                break;
+            case Types.DATE:
+                result = new FieldTypes.DateFieldType();
+                break;
+            case Types.DECIMAL:
+                result = new FieldTypes.BigDecimalFieldType();
+                break;
+// Not needed, user have to use the underlying sql datatype in OJB mapping files
+//            case Types.DISTINCT:
+//                result = new DistinctFieldType();
+//                break;
+            case Types.DOUBLE:
+                result = new FieldTypes.DoubleFieldType();
+                break;
+            case Types.FLOAT:
+                result = new FieldTypes.FloatFieldType();
+                break;
+            case Types.INTEGER:
+                result = new FieldTypes.IntegerFieldType();
+                break;
+            case Types.JAVA_OBJECT:
+                result = new FieldTypes.JavaObjectFieldType();
+                break;
+            case Types.LONGVARBINARY:
+                result = new FieldTypes.ByteArrayFieldType();
+                break;
+            case Types.LONGVARCHAR:
+                result = new FieldTypes.StringFieldType();
+                break;
+            case Types.NUMERIC:
+                result = new FieldTypes.BigDecimalFieldType();
+                break;
+            case Types.REAL:
+                result = new FieldTypes.FloatFieldType();
+                break;
+            case Types.REF:
+                result = new FieldTypes.RefFieldType();
+                break;
+            case Types.SMALLINT:
+                result = new FieldTypes.ShortFieldType();
+                break;
+            case Types.STRUCT:
+                result = new FieldTypes.StructFieldType();
+                break;
+            case Types.TIME:
+                result = new FieldTypes.TimeFieldType();
+                break;
+            case Types.TIMESTAMP:
+                result = new FieldTypes.TimestampFieldType();
+                break;
+            case Types.TINYINT:
+                result = new FieldTypes.ByteFieldType();
+                break;
+            case Types.VARBINARY:
+                result = new FieldTypes.ByteArrayFieldType();
+                break;
+            case Types.VARCHAR:
+                result = new FieldTypes.StringFieldType();
+                break;
+            case Types.OTHER:
+                result = new FieldTypes.JavaObjectFieldType();
+                break;
 //
-//        public Object getObjectFromColumn(ResultSet rs, int columnId) throws SQLException
-//        {
-//            return getObjectFromColumn(rs, null, null, columnId);
-//        }
-
-    }
-
-
-    public static final class T_Char extends BaseType
-    {
-        public Object sequenceKeyConversion(Long identifier)
-        {
-            return identifier.toString();
-        }
-
-//        Object readValueFromStatement(CallableStatement stmt, String columnName) throws SQLException
-//        {
-//            return stmt.getString(columnName);
-//        }
-
-        Object readValueFromStatement(CallableStatement stmt, int columnIndex) throws SQLException
-        {
-            return stmt.getString(columnIndex);
-        }
-
-        Object readValueFromResultSet(ResultSet rs, String columnName) throws SQLException
-        {
-            return rs.getString(columnName);
-        }
-
-        Object readValueFromResultSet(ResultSet rs, int columnIndex) throws SQLException
-        {
-            return rs.getString(columnIndex);
-        }
-
-        public int getType()
-        {
-            return Types.CHAR;
-        }
-    }
-
-    public static final class T_Varchar extends BaseType
-    {
-        public Object sequenceKeyConversion(Long identifier)
-        {
-            return identifier.toString();
-        }
-
-//        Object readValueFromStatement(CallableStatement stmt, String columnName) throws SQLException
-//        {
-//            return stmt.getString(columnName);
-//        }
-
-        Object readValueFromStatement(CallableStatement stmt, int columnIndex) throws SQLException
-        {
-            return stmt.getString(columnIndex);
-        }
-
-        Object readValueFromResultSet(ResultSet rs, String columnName) throws SQLException
-        {
-            return rs.getString(columnName);
-        }
-
-        Object readValueFromResultSet(ResultSet rs, int columnIndex) throws SQLException
-        {
-            return rs.getString(columnIndex);
-        }
-
-        public int getType()
-        {
-            return Types.VARCHAR;
-        }
-    }
-
-    public static final class T_LongVarChar extends BaseType
-    {
-        public Object sequenceKeyConversion(Long identifier)
-        {
-            return identifier.toString();
-        }
-
-//        Object readValueFromStatement(CallableStatement stmt, String columnName) throws SQLException
-//        {
-//            return stmt.getString(columnName);
-//        }
-
-        Object readValueFromStatement(CallableStatement stmt, int columnIndex) throws SQLException
-        {
-            return stmt.getString(columnIndex);
-        }
-
-        Object readValueFromResultSet(ResultSet rs, String columnName) throws SQLException
-        {
-            return rs.getString(columnName);
-        }
-
-        Object readValueFromResultSet(ResultSet rs, int columnIndex) throws SQLException
-        {
-            return rs.getString(columnIndex);
-        }
-
-        public int getType()
-        {
-            return Types.LONGVARCHAR;
-        }
-    }
-
-    public static final class T_Numeric extends BaseType
-    {
-        public Object sequenceKeyConversion(Long identifier)
-        {
-            return new BigDecimal(identifier.longValue());
-        }
-
-//        Object readValueFromStatement(CallableStatement stmt, String columnName) throws SQLException
-//        {
-//            return stmt.getBigDecimal(columnName);
-//        }
-
-        Object readValueFromStatement(CallableStatement stmt, int columnIndex) throws SQLException
-        {
-            return stmt.getBigDecimal(columnIndex);
-        }
-
-        Object readValueFromResultSet(ResultSet rs, String columnName) throws SQLException
-        {
-            return rs.getBigDecimal(columnName);
-        }
-
-        Object readValueFromResultSet(ResultSet rs, int columnIndex) throws SQLException
-        {
-            return rs.getBigDecimal(columnIndex);
-        }
-
-        public int getType()
-        {
-            return Types.NUMERIC;
-        }
-    }
-
-    public static final class T_Decimal extends BaseType
-    {
-        public Object sequenceKeyConversion(Long identifier)
-        {
-            return new BigDecimal(identifier.longValue());
-        }
-
-//        Object readValueFromStatement(CallableStatement stmt, String columnName) throws SQLException
-//        {
-//            return stmt.getBigDecimal(columnName);
-//        }
-
-        Object readValueFromStatement(CallableStatement stmt, int columnIndex) throws SQLException
-        {
-            return stmt.getBigDecimal(columnIndex);
-        }
-
-        Object readValueFromResultSet(ResultSet rs, String columnName) throws SQLException
-        {
-            return rs.getBigDecimal(columnName);
-        }
-
-        Object readValueFromResultSet(ResultSet rs, int columnIndex) throws SQLException
-        {
-            return rs.getBigDecimal(columnIndex);
-        }
-
-        public int getType()
-        {
-            return Types.DECIMAL;
-        }
-    }
-
-    public static final class T_Bit extends BaseType
-    {
-        public Object sequenceKeyConversion(Long identifier) throws SequenceManagerException
-        {
-            throw new SequenceManagerException("Not supported sequence key type 'BIT'");
-        }
-
-//        Object readValueFromStatement(CallableStatement stmt, String columnName) throws SQLException
-//        {
-//            boolean temp = stmt.getBoolean(columnName);
-//            return (stmt.wasNull() ? null : new Boolean(temp));
-//        }
-
-        Object readValueFromStatement(CallableStatement stmt, int columnIndex) throws SQLException
-        {
-            boolean temp = stmt.getBoolean(columnIndex);
-            return (stmt.wasNull() ? null : BooleanUtils.toBooleanObject(temp));
-        }
-
-        Object readValueFromResultSet(ResultSet rs, String columnName) throws SQLException
-        {
-            boolean temp = rs.getBoolean(columnName);
-            return (rs.wasNull() ? null : BooleanUtils.toBooleanObject(temp));
-        }
-
-        Object readValueFromResultSet(ResultSet rs, int columnIndex) throws SQLException
-        {
-            boolean temp = rs.getBoolean(columnIndex);
-            return (rs.wasNull() ? null : BooleanUtils.toBooleanObject(temp));
-        }
-
-        public int getType()
-        {
-            return Types.BIT;
-        }
-    }
+//            case Types.NULL:
+//                result = new NullFieldType();
+//                break;
 
 //#ifdef JDBC30
-    public static final class T_Boolean extends BaseType
-    {
-        public Object sequenceKeyConversion(final Long identifier) throws SequenceManagerException
-        {
-            throw new SequenceManagerException("Not supported sequence key type 'BOOLEAN'");
-        }
-
-//        Object readValueFromStatement(CallableStatement stmt, String columnName) throws SQLException
-//        {
-//            boolean temp = stmt.getBoolean(columnName);
-//            return (stmt.wasNull() ? null : BooleanUtils.toBooleanObject(temp));
-//        }
-
-        Object readValueFromStatement(CallableStatement stmt, int columnIndex) throws SQLException
-        {
-            boolean temp = stmt.getBoolean(columnIndex);
-            return (stmt.wasNull() ? null : BooleanUtils.toBooleanObject(temp));
-        }
-
-        Object readValueFromResultSet(ResultSet rs, String columnName) throws SQLException
-        {
-            boolean temp = rs.getBoolean(columnName);
-            return (rs.wasNull() ? null : BooleanUtils.toBooleanObject(temp));
+            case Types.BOOLEAN:
+                result = new FieldTypes.BooleanFieldType();
+                break;
+            case Types.DATALINK:
+                result = new FieldTypes.URLFieldType();
+                break;
+//#endif
+            default:
+                throw new OJBRuntimeException("Unkown or not supported field type specified, specified jdbc type was '"
+                        + jdbcType + "', as string: " + JdbcTypesHelper.getSqlTypeAsString(jdbcType.getType()));
         }
-
-        Object readValueFromResultSet(ResultSet rs, int columnIndex) throws SQLException
-        {
-            boolean temp = rs.getBoolean(columnIndex);
-            return (rs.wasNull() ? null : BooleanUtils.toBooleanObject(temp));
+        // make sure that the sql type was set
+        //result.setSqlType(jdbcType);
+        return result;
+    }
         }
-
-        public int getType()
-        {
-            return Types.BOOLEAN;
-        }
-    }
-//#endif
-
-    public static final class T_TinyInt extends BaseType
-    {
-        public Object sequenceKeyConversion(final Long identifier)
-        {
-            return new Byte(identifier.byteValue());
-        }
-
-//        Object readValueFromStatement(CallableStatement stmt, String columnName) throws SQLException
-//        {
-//            byte temp = stmt.getByte(columnName);
-//            return (stmt.wasNull() ? null : new Byte(temp));
-//        }
-
-        Object readValueFromStatement(CallableStatement stmt, int columnIndex) throws SQLException
-        {
-            byte temp = stmt.getByte(columnIndex);
-            return (stmt.wasNull() ? null : new Byte(temp));
-        }
-
-        Object readValueFromResultSet(ResultSet rs, String columnName) throws SQLException
-        {
-            byte temp = rs.getByte(columnName);
-            return (rs.wasNull() ? null : new Byte(temp));
-        }
-
-        Object readValueFromResultSet(ResultSet rs, int columnIndex) throws SQLException
-        {
-            byte temp = rs.getByte(columnIndex);
-            return (rs.wasNull() ? null : new Byte(temp));
-        }
-
-        public int getType()
-        {
-            return Types.TINYINT;
-        }
-    }
-
-    public static final class T_SmallInt extends BaseType
-    {
-        public Object sequenceKeyConversion(Long identifier)
-        {
-            return new Short(identifier.shortValue());
-        }
-
-//        Object readValueFromStatement(CallableStatement stmt, String columnName) throws SQLException
-//        {
-//            short temp = stmt.getShort(columnName);
-//            return (stmt.wasNull() ? null : new Short(temp));
-//        }
-
-        Object readValueFromStatement(CallableStatement stmt, int columnIndex) throws SQLException
-        {
-            short temp = stmt.getShort(columnIndex);
-            return (stmt.wasNull() ? null : new Short(temp));
-        }
-
-        Object readValueFromResultSet(ResultSet rs, String columnName) throws SQLException
-        {
-            short temp = rs.getShort(columnName);
-            return (rs.wasNull() ? null : new Short(temp));
-        }
-
-        Object readValueFromResultSet(ResultSet rs, int columnIndex) throws SQLException
-        {
-            short temp = rs.getShort(columnIndex);
-            return (rs.wasNull() ? null : new Short(temp));
-        }
-
-        public int getType()
-        {
-            return Types.SMALLINT;
-        }
-    }
-
-    public static final class T_Integer extends BaseType
-    {
-        public Object sequenceKeyConversion(Long identifier)
-        {
-            return new Integer(identifier.intValue());
-        }
-
-//        Object readValueFromStatement(CallableStatement stmt, String columnName) throws SQLException
-//        {
-//            int temp = stmt.getInt(columnName);
-//            return (stmt.wasNull() ? null : new Integer(temp));
-//        }
-
-        Object readValueFromStatement(CallableStatement stmt, int columnIndex) throws SQLException
-        {
-            int temp = stmt.getInt(columnIndex);
-            return (stmt.wasNull() ? null : new Integer(temp));
-        }
-
-        Object readValueFromResultSet(ResultSet rs, String columnName) throws SQLException
-        {
-            int temp = rs.getInt(columnName);
-            return (rs.wasNull() ? null : new Integer(temp));
-        }
-
-        Object readValueFromResultSet(ResultSet rs, int columnIndex) throws SQLException
-        {
-            int temp = rs.getInt(columnIndex);
-            return (rs.wasNull() ? null : new Integer(temp));
-        }
-
-        public int getType()
-        {
-            return Types.INTEGER;
-        }
-    }
-
-    public static final class T_BigInt extends BaseType
-    {
-        public Object sequenceKeyConversion(Long identifier)
-        {
-            return identifier;
-        }
-
-//        Object readValueFromStatement(CallableStatement stmt, String columnName) throws SQLException
-//        {
-//            long temp = stmt.getLong(columnName);
-//            return (stmt.wasNull() ? null : new Long(temp));
-//        }
-
-        Object readValueFromStatement(CallableStatement stmt, int columnIndex) throws SQLException
-        {
-            long temp = stmt.getLong(columnIndex);
-            return (stmt.wasNull() ? null : new Long(temp));
-        }
-
-        Object readValueFromResultSet(ResultSet rs, String columnName) throws SQLException
-        {
-            long temp = rs.getLong(columnName);
-            return (rs.wasNull() ? null : new Long(temp));
-        }
-
-        Object readValueFromResultSet(ResultSet rs, int columnIndex) throws SQLException
-        {
-            long temp = rs.getLong(columnIndex);
-            return (rs.wasNull() ? null : new Long(temp));
-        }
-
-        public int getType()
-        {
-            return Types.BIGINT;
-        }
-    }
-
-    public static final class T_Real extends BaseType
-    {
-        public Object sequenceKeyConversion(Long identifier)
-        {
-            return new Float(identifier.floatValue());
-        }
-
-//        Object readValueFromStatement(CallableStatement stmt, String columnName) throws SQLException
-//        {
-//            float temp = stmt.getFloat(columnName);
-//            return (stmt.wasNull() ? null : new Float(temp));
-//        }
-
-        Object readValueFromStatement(CallableStatement stmt, int columnIndex) throws SQLException
-        {
-            float temp = stmt.getFloat(columnIndex);
-            return (stmt.wasNull() ? null : new Float(temp));
-        }
-
-        Object readValueFromResultSet(ResultSet rs, String columnName) throws SQLException
-        {
-            float temp = rs.getFloat(columnName);
-            return (rs.wasNull() ? null : new Float(temp));
-        }
-
-        Object readValueFromResultSet(ResultSet rs, int columnIndex) throws SQLException
-        {
-            float temp = rs.getFloat(columnIndex);
-            return (rs.wasNull() ? null : new Float(temp));
-        }
-
-        public int getType()
-        {
-            return Types.REAL;
-        }
-    }
-
-    public static final class T_Float extends BaseType
-    {
-        public Object sequenceKeyConversion(Long identifier)
-        {
-            return new Double(identifier.doubleValue());
-        }
-
-//        Object readValueFromStatement(CallableStatement stmt, String columnName) throws SQLException
-//        {
-//            double temp = stmt.getDouble(columnName);
-//            return (stmt.wasNull() ? null : new Double(temp));
-//        }
-
-        Object readValueFromStatement(CallableStatement stmt, int columnIndex) throws SQLException
-        {
-            double temp = stmt.getDouble(columnIndex);
-            return (stmt.wasNull() ? null : new Double(temp));
-        }
-
-        Object readValueFromResultSet(ResultSet rs, String columnName) throws SQLException
-        {
-            double temp = rs.getDouble(columnName);
-            return (rs.wasNull() ? null : new Double(temp));
-        }
-
-        Object readValueFromResultSet(ResultSet rs, int columnIndex) throws SQLException
-        {
-            double temp = rs.getDouble(columnIndex);
-            return (rs.wasNull() ? null : new Double(temp));
-        }
-
-        public int getType()
-        {
-            return Types.FLOAT;
-        }
-    }
-
-    public static final class T_Double extends BaseType
-    {
-        public Object sequenceKeyConversion(Long identifier)
-        {
-            return new Double(identifier.doubleValue());
-        }
-
-//        Object readValueFromStatement(CallableStatement stmt, String columnName) throws SQLException
-//        {
-//            double temp = stmt.getDouble(columnName);
-//            return (stmt.wasNull() ? null : new Double(temp));
-//        }
-
-        Object readValueFromStatement(CallableStatement stmt, int columnIndex) throws SQLException
-        {
-            double temp = stmt.getDouble(columnIndex);
-            return (stmt.wasNull() ? null : new Double(temp));
-        }
-
-        Object readValueFromResultSet(ResultSet rs, String columnName) throws SQLException
-        {
-            double temp = rs.getDouble(columnName);
-            return (rs.wasNull() ? null : new Double(temp));
-        }
-
-        Object readValueFromResultSet(ResultSet rs, int columnIndex) throws SQLException
-        {
-            double temp = rs.getDouble(columnIndex);
-            return (rs.wasNull() ? null : new Double(temp));
-        }
-
-        public int getType()
-        {
-            return Types.DOUBLE;
-        }
-    }
-
-    public static final class T_Binary extends BaseType
-    {
-        public Object sequenceKeyConversion(Long identifier)
-        {
-            return identifier.toString().getBytes();
-        }
-
-//        Object readValueFromStatement(CallableStatement stmt, String columnName) throws SQLException
-//        {
-//            return stmt.getBytes(columnName);
-//        }
-
-        Object readValueFromStatement(CallableStatement stmt, int columnIndex) throws SQLException
-        {
-            return stmt.getBytes(columnIndex);
-        }
-
-        Object readValueFromResultSet(ResultSet rs, String columnName) throws SQLException
-        {
-            return rs.getBytes(columnName);
-        }
-
-        Object readValueFromResultSet(ResultSet rs, int columnIndex) throws SQLException
-        {
-            return rs.getBytes(columnIndex);
-        }
-
-        public int getType()
-        {
-            return Types.BINARY;
-        }
-    }
-
-    public static final class T_VarBinary extends BaseType
-    {
-        public Object sequenceKeyConversion(Long identifier)
-        {
-            return identifier.toString().getBytes();
-        }
-
-//        Object readValueFromStatement(CallableStatement stmt, String columnName) throws SQLException
-//        {
-//            return stmt.getBytes(columnName);
-//        }
-
-        Object readValueFromStatement(CallableStatement stmt, int columnIndex) throws SQLException
-        {
-            return stmt.getBytes(columnIndex);
-        }
-
-        Object readValueFromResultSet(ResultSet rs, String columnName) throws SQLException
-        {
-            return rs.getBytes(columnName);
-        }
-
-        Object readValueFromResultSet(ResultSet rs, int columnIndex) throws SQLException
-        {
-            return rs.getBytes(columnIndex);
-        }
-
-        public int getType()
-        {
-            return Types.VARBINARY;
-        }
-    }
-
-    public static final class T_LongVarBinary extends BaseType
-    {
-        protected static final int BUFSZ = 2048;
-
-        /**
-         * Retrieve LONGVARBINARY InputStream data and pack into a byte array.
-         *
-         * @param is the input stream to be retrieved
-         * @return a string containing the clob data
-         * @throws java.sql.SQLException if conversion fails or the clob cannot be read
-         */
-        protected static byte[] retrieveStreamDataFromRs(InputStream is) throws SQLException
-        {
-            if (is == null)
-            {
-                return null;
-            }
-            byte[] bytes = null;
-            ByteArrayOutputStream bos = null;
-            try
-            {
-                bos = new ByteArrayOutputStream();
-                int numRead;
-                byte[] buf = new byte[BUFSZ];
-                while ((numRead = is.read(buf, 0, buf.length)) > 0)
-                {
-                    bos.write(buf, 0, numRead);
-                }
-                bytes = bos.toByteArray();
-            }
-            catch (IOException e)
-            {
-                throw new SQLException("I/O exception retrieving LONGVARBINARY: " + e.getLocalizedMessage());
-            }
-            finally
-            {
-                if (bos != null)
-                {
-                    try
-                    {
-                        bos.close();
-                    }
-                    catch (Exception ignored)
-                    {
-                        //ignore
-                    }
-                }
-            }
-            return bytes;
-        }
-
-        public Object sequenceKeyConversion(Long identifier)
-        {
-            return identifier.toString().getBytes();
-        }
-
-//        Object readValueFromStatement(CallableStatement stmt, String columnName) throws SQLException
-//        {
-//            return stmt.getBytes(columnName);
-//        }
-
-        Object readValueFromStatement(CallableStatement stmt, int columnIndex) throws SQLException
-        {
-            return stmt.getBytes(columnIndex);
-        }
-
-        Object readValueFromResultSet(ResultSet rs, String columnName) throws SQLException
-        {
-            return retrieveStreamDataFromRs(rs.getBinaryStream(columnName));
-        }
-
-        Object readValueFromResultSet(ResultSet rs, int columnIndex) throws SQLException
-        {
-            return retrieveStreamDataFromRs(rs.getBinaryStream(columnIndex));
-        }
-
-        public int getType()
-        {
-            return Types.LONGVARBINARY;
-        }
-    }
-
-    public static final class T_Date extends BaseType
-    {
-        public Object sequenceKeyConversion(Long identifier)
-        {
-            return new Date(identifier.longValue());
-        }
-
-//        Object readValueFromStatement(CallableStatement stmt, String columnName) throws SQLException
-//        {
-//            return stmt.getDate(columnName);
-//        }
-
-        Object readValueFromStatement(CallableStatement stmt, int columnIndex) throws SQLException
-        {
-            return stmt.getDate(columnIndex);
-        }
-
-        Object readValueFromResultSet(ResultSet rs, String columnName) throws SQLException
-        {
-            return rs.getDate(columnName);
-        }
-
-        Object readValueFromResultSet(ResultSet rs, int columnIndex) throws SQLException
-        {
-            return rs.getDate(columnIndex);
-        }
-
-        public int getType()
-        {
-            return Types.DATE;
-        }
-    }
-
-    public static final class T_Time extends BaseType
-    {
-        public Object sequenceKeyConversion(Long identifier)
-        {
-            return new Time(identifier.longValue());
-        }
-
-//        Object readValueFromStatement(CallableStatement stmt, String columnName) throws SQLException
-//        {
-//            return stmt.getTime(columnName);
-//        }
-
-        Object readValueFromStatement(CallableStatement stmt, int columnIndex) throws SQLException
-        {
-            return stmt.getTime(columnIndex);
-        }
-
-        Object readValueFromResultSet(ResultSet rs, String columnName) throws SQLException
-        {
-            return rs.getTime(columnName);
-        }
-
-        Object readValueFromResultSet(ResultSet rs, int columnIndex) throws SQLException
-        {
-            return rs.getTime(columnIndex);
-        }
-
-        public int getType()
-        {
-            return Types.TIME;
-        }
-    }
-
-    public static final class T_Timestamp extends BaseType
-    {
-        public Object sequenceKeyConversion(Long identifier)
-        {
-            return new Timestamp(identifier.longValue());
-        }
-
-//        Object readValueFromStatement(CallableStatement stmt, String columnName) throws SQLException
-//        {
-//            return stmt.getTimestamp(columnName);
-//        }
-
-        Object readValueFromStatement(CallableStatement stmt, int columnIndex) throws SQLException
-        {
-            return stmt.getTimestamp(columnIndex);
-        }
-
-        Object readValueFromResultSet(ResultSet rs, String columnName) throws SQLException
-        {
-            return rs.getTimestamp(columnName);
-        }
-
-        Object readValueFromResultSet(ResultSet rs, int columnIndex) throws SQLException
-        {
-            return rs.getTimestamp(columnIndex);
-        }
-
-        public int getType()
-        {
-            return Types.TIMESTAMP;
-        }
-    }
-
-    public static final class T_Clob extends BaseType
-    {
-        protected static final int BUFSZ = 32768;
-
-        /**
-         * Convert CLOB to String. Safe for very large objects.
-         *
-         * @param aClob clob with character data
-         * @return a string containing the clob data
-         * @throws java.sql.SQLException if conversion fails or the clob cannot be read
-         */
-        protected static String safeClobToString(Clob aClob) throws SQLException
-        {
-            long length = aClob.length();
-            if (length == 0)
-            {
-                return "";
-            }
-            StringBuffer sb = new StringBuffer();
-            char[] buf = new char[BUFSZ];
-            java.io.Reader stream = aClob.getCharacterStream();
-            try
-            {
-                int numRead;
-                while ((numRead = stream.read(buf)) != -1)
-                {
-                    sb.append(buf, 0, numRead);
-                }
-                stream.close();
-            }
-            catch (IOException e)
-            {
-                throw new SQLException(e.getLocalizedMessage());
-            }
-            return sb.toString();
-        }
-
-        public Object sequenceKeyConversion(Long identifier) throws SequenceManagerException
-        {
-            throw new SequenceManagerException("Not supported sequence key type 'CLOB'");
-        }
-
-//        Object readValueFromStatement(CallableStatement stmt, String columnName) throws SQLException
-//        {
-//            Clob aClob = stmt.getClob(columnName);
-//            return (stmt.wasNull() ? null : aClob.getSubString(1L, (int) aClob.length()));
-//        }
-
-        Object readValueFromStatement(CallableStatement stmt, int columnIndex) throws SQLException
-        {
-            Clob aClob = stmt.getClob(columnIndex);
-            return (stmt.wasNull() ? null : safeClobToString(aClob));
-        }
-
-        Object readValueFromResultSet(ResultSet rs, String columnName) throws SQLException
-        {
-            Clob aClob = rs.getClob(columnName);
-            return (rs.wasNull() ? null : safeClobToString(aClob));
-        }
-
-        Object readValueFromResultSet(ResultSet rs, int columnIndex) throws SQLException
-        {
-            Clob aClob = rs.getClob(columnIndex);
-            return (rs.wasNull() ? null : safeClobToString(aClob));
-        }
-
-        public int getType()
-        {
-            return Types.CLOB;
-        }
-    }
-
-    public static final class T_Blob extends BaseType
-    {
-        public Object sequenceKeyConversion(Long identifier) throws SequenceManagerException
-        {
-            throw new SequenceManagerException("Not supported sequence key type 'BLOB'");
-        }
-
-//        Object readValueFromStatement(CallableStatement stmt, String columnName) throws SQLException
-//        {
-//            Blob aBlob = stmt.getBlob(columnName);
-//            return (stmt.wasNull() ? null : aBlob.getBytes(1L, (int) aBlob.length()));
-//        }
-
-        Object readValueFromStatement(CallableStatement stmt, int columnIndex) throws SQLException
-        {
-            Blob aBlob = stmt.getBlob(columnIndex);
-            return (stmt.wasNull() ? null : aBlob.getBytes(1L, (int) aBlob.length()));
-        }
-
-        Object readValueFromResultSet(ResultSet rs, String columnName) throws SQLException
-        {
-            Blob aBlob = rs.getBlob(columnName);
-            return (rs.wasNull() ? null : aBlob.getBytes(1L, (int) aBlob.length()));
-        }
-
-        Object readValueFromResultSet(ResultSet rs, int columnIndex) throws SQLException
-        {
-            Blob aBlob = rs.getBlob(columnIndex);
-            return (rs.wasNull() ? null : aBlob.getBytes(1L, (int) aBlob.length()));
-        }
-
-        public int getType()
-        {
-            return Types.BLOB;
-        }
-    }
-
-    public static final class T_Array extends BaseType
-    {
-        public Object sequenceKeyConversion(Long identifier) throws SequenceManagerException
-        {
-            throw new SequenceManagerException("Not supported sequence key type 'ARRAY'");
-        }
-
-//        Object readValueFromStatement(CallableStatement stmt, String columnName) throws SQLException
-//        {
-//            return stmt.getArray(columnName);
-//        }
-
-        Object readValueFromStatement(CallableStatement stmt, int columnIndex) throws SQLException
-        {
-            return stmt.getArray(columnIndex);
-        }
-
-        Object readValueFromResultSet(ResultSet rs, String columnName) throws SQLException
-        {
-            return rs.getArray(columnName);
-        }
-
-        Object readValueFromResultSet(ResultSet rs, int columnIndex) throws SQLException
-        {
-            return rs.getArray(columnIndex);
-        }
-
-        public int getType()
-        {
-            return Types.ARRAY;
-        }
-    }
-
-    public static final class T_Struct extends BaseType
-    {
-        public Object sequenceKeyConversion(Long identifier) throws SequenceManagerException
-        {
-            throw new SequenceManagerException("Not supported sequence key type 'STRUCT'");
-        }
-
-//        Object readValueFromStatement(CallableStatement stmt, String columnName) throws SQLException
-//        {
-//            return stmt.getObject(columnName);
-//        }
-
-        Object readValueFromStatement(CallableStatement stmt, int columnIndex) throws SQLException
-        {
-            return stmt.getObject(columnIndex);
-        }
-
-        Object readValueFromResultSet(ResultSet rs, String columnName) throws SQLException
-        {
-            return rs.getObject(columnName);
-        }
-
-        Object readValueFromResultSet(ResultSet rs, int columnIndex) throws SQLException
-        {
-            return rs.getObject(columnIndex);
-        }
-
-        public int getType()
-        {
-            return Types.STRUCT;
-        }
-    }
-
-    public static final class T_Ref extends BaseType
-    {
-        public Object sequenceKeyConversion(Long identifier) throws SequenceManagerException
-        {
-            throw new SequenceManagerException("Not supported sequence key type 'REF'");
-        }
-
-//        Object readValueFromStatement(CallableStatement stmt, String columnName) throws SQLException
-//        {
-//            return stmt.getRef(columnName);
-//        }
-
-        Object readValueFromStatement(CallableStatement stmt, int columnIndex) throws SQLException
-        {
-            return stmt.getRef(columnIndex);
-        }
-
-        Object readValueFromResultSet(ResultSet rs, String columnName) throws SQLException
-        {
-            return rs.getRef(columnName);
-        }
-
-        Object readValueFromResultSet(ResultSet rs, int columnIndex) throws SQLException
-        {
-            return rs.getRef(columnIndex);
-        }
-
-        public int getType()
-        {
-            return Types.REF;
-        }
-    }
-
-//#ifdef JDBC30
-    public static final class T_Datalink extends BaseType
-    {
-        public Object sequenceKeyConversion(Long identifier) throws SequenceManagerException
-        {
-            throw new SequenceManagerException("Not supported sequence key type 'DATALINK'");
-        }
-
-//        Object readValueFromStatement(CallableStatement stmt, String columnName) throws SQLException
-//        {
-//            return stmt.getURL(columnName);
-//        }
-
-        Object readValueFromStatement(CallableStatement stmt, int columnIndex) throws SQLException
-        {
-            return stmt.getURL(columnIndex);
-        }
-
-        Object readValueFromResultSet(ResultSet rs, String columnName) throws SQLException
-        {
-            return rs.getURL(columnName);
-        }
-
-        Object readValueFromResultSet(ResultSet rs, int columnIndex) throws SQLException
-        {
-            return rs.getURL(columnIndex);
-        }
-
-        public int getType()
-        {
-            return Types.DATALINK;
-        }
-    }
-//#endif
-}

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/MetadataManager.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/MetadataManager.java?rev=422233&r1=422232&r2=422233&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/MetadataManager.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/MetadataManager.java Sat Jul 15 07:22:34 2006
@@ -15,8 +15,13 @@
  * limitations under the License.
  */
 
+import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
 import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Hashtable;
@@ -25,10 +30,15 @@
 import java.util.Map;
 
 import org.apache.commons.lang.SerializationUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.ojb.broker.OJB;
 import org.apache.ojb.broker.PBKey;
 import org.apache.ojb.broker.PersistenceBrokerFactory;
+import org.apache.ojb.broker.OJBException;
+import org.apache.ojb.broker.OJBRuntimeException;
 import org.apache.ojb.broker.core.configuration.NeedsInitialization;
 import org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldFactory;
+import org.apache.ojb.broker.util.ClassHelper;
 import org.apache.ojb.broker.util.logging.Logger;
 import org.apache.ojb.broker.util.logging.LoggerFactory;
 
@@ -36,9 +46,9 @@
  * Central class for metadata operations/manipulations - manages OJB's
  * metadata objects, in particular:
  * <ul>
- * <li>{@link org.apache.ojb.broker.metadata.DescriptorRepository} contains
+ * <li>{@link DescriptorRepository} contains
  * metadata of persistent objects</li>
- * <li>{@link org.apache.ojb.broker.metadata.ConnectionRepository} contains
+ * <li>{@link ConnectionRepository} contains
  * all connection metadata information</li>
  * </ul>
  *
@@ -46,8 +56,8 @@
  *
  * <p>
  * <b>How to read/merge metadata</b><br/>
- * Per default OJB loads default {@link org.apache.ojb.broker.metadata.DescriptorRepository}
- * and {@link org.apache.ojb.broker.metadata.ConnectionRepository} instances, by reading the
+ * Per default OJB loads default {@link DescriptorRepository}
+ * and {@link ConnectionRepository} instances, by reading the
  * specified repository file. This is done first time the <code>MetadataManager</code> instance
  * was used.
  * <br/>
@@ -65,16 +75,16 @@
  * <a name="perThread"/>
  * <h3>Per thread handling of metadata</h3>
  * <p>
- * Per default the manager handle one global {@link org.apache.ojb.broker.metadata.DescriptorRepository}
+ * Per default the manager handle one global {@link DescriptorRepository}
  * for all calling threads, but it is ditto possible to use different metadata <i>profiles</i> in a per thread
- * manner - <i>profiles</i> means different copies of {@link org.apache.ojb.broker.metadata.DescriptorRepository}
+ * manner - <i>profiles</i> means different copies of {@link DescriptorRepository}
  * objects.
  * <p/>
  *
  * <p>
  * <a name="enablePerThreadMode"/>
  * <b>Enable the per thread mode</b><br/>
- * To enable the 'per thread' mode for {@link org.apache.ojb.broker.metadata.DescriptorRepository}
+ * To enable the 'per thread' mode for {@link DescriptorRepository}
  * instances:
  * <pre>
  *   MetadataManager mm = MetadataManager.getInstance();
@@ -85,7 +95,7 @@
  * This could be done e.g. at start up.<br/>
  * Now it's possible to use dedicated <code>DescriptorRepository</code> instances
  * per thread:
- *  <pre>
+ * <pre>
  *   // e.g we get a coppy of the global repository
  *   DescriptorRepository dr = mm.copyOfGlobalRepository();
  *   // now we can manipulate the persistent object metadata of the copy
@@ -107,7 +117,7 @@
  * <b>How to use different metadata profiles</b><br/>
  * MetadataManager was shipped with a simple mechanism to
  * add, remove and load different persistent objects metadata
- * profiles (different {@link org.apache.ojb.broker.metadata.DescriptorRepository}
+ * profiles (different {@link DescriptorRepository}
  * instances) in a per thread manner. Use
  * <ul>
  * <li>{@link #addProfile addProfile} add different persistent object metadata profiles</li>
@@ -118,25 +128,26 @@
  * the <a href="#enablePerThreadMode">per thread mode</a> is enabled.
  * </p>
  *
- *
  * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
  * @version $Id$
  *
  *
- * TODO: This class needs adaptation to new repository.dtd with new persistence-configuration element
+ *          TODO: This class needs adaptation to new repository.dtd with new persistence-configuration element
  */
 public class MetadataManager implements NeedsInitialization
 {
+    private Logger log = LoggerFactory.getLogger(MetadataManager.class);
+
+    public static final String REPOSITORY_PROPERTY_NAME = "repository.xml";
+    private static final String SER_FILE_SUFFIX = "serialized";
+
+
     /** The default repository file */
     public static final String DEFAULT_REPOSITORY_PATH = "repository.xml";
     private static final String MSG_STR = "* Can't find DescriptorRepository for current thread, use default one *";
 
-    /** The factory for creating field objects in the metamodel*/
+    /** The factory for creating field objects in the metamodel */
     private PersistentFieldFactory fieldFactory;
-    /** The repository file i/o */
-    private RepositoryPersistor persistor;
-
-    private Logger log = LoggerFactory.getLogger(MetadataManager.class);
 
     private static ThreadLocal threadedRepository = new ThreadLocal();
     private static ThreadLocal currentProfileKey = new ThreadLocal();
@@ -149,13 +160,18 @@
     private ConnectionRepository connectionRepository;
     private boolean enablePerThreadChanges;
     private PBKey defaultPBKey;
+    private Class repositoryPersistorClass;
     private Map persistenceConfigurationDescriptorMap;
+    private String serializedRepositoryPath;
+    private boolean usingSerializedRepository;
+    private OJB ojb;
 
-    public MetadataManager(PersistentFieldFactory fieldFactory)
+    // constructor
+    public MetadataManager(OJB ojb, PersistentFieldFactory fieldFactory)
     {
+        this.ojb = ojb;
         this.persistenceConfigurationDescriptorMap = Collections.synchronizedMap(new HashMap());
         this.fieldFactory = fieldFactory;
-        this.persistor    = getRepositoryPersistor();
     }
 
     /**
@@ -184,6 +200,7 @@
 
     /**
      * Add a new {@link PersistenceConfigurationDescriptor} for use by OJB.
+     *
      * @param pcd The descriptor to use. The {@link PBKey}
      */
     public void addPersistenceConfiguration(PersistenceConfigurationDescriptor pcd)
@@ -203,105 +220,62 @@
         return (PersistenceConfigurationDescriptor) persistenceConfigurationDescriptorMap.remove(key);
     }
 
-    /**
-     * Returns the repository path.
-     * 
-     * @return The repository path
-     */
-    public String getRepositoryPath()
-    {
-        return repositoryPath;
-    }
-
-    /**
-     * Sets the repository path.
-     *
-     * @param repositoryPath The new repository path
-     */
-    public void setRepositoryPath(String repositoryPath)
-    {
-        this.repositoryPath = repositoryPath;
-    }
-
-    /**
-     * Returns whether we're using a serialized repository.
-     * 
-     * @return <code>true</code> if we're using a serialized repository
-     */
-    public boolean isUsingSerializedRepository()
-    {
-        return persistor.isUsingSerializedRepository();
-    }
-
-    /**
-     * Specifies whether we're using a serialized repository.
-     *
-     * @param usingSerializedRepository <code>true</code> if we're using
-     *                                  a serialized repository
-     */
-    public void setUsingSerializedRepository(boolean usingSerializedRepository)
-    {
-        persistor.setUsingSerializedRepository(usingSerializedRepository);
-    }
-
-    /**
-     * Returns the path of the serialized repository.
-     * 
-     * @return The path
-     */
-    public String getSerializedRepositoryPath()
-    {
-        return persistor.getSerializedRepositoryPath();
-    }
-
-    /**
-     * Sets the path of the serialized repository.
-     *
-     * @param serializedRepositoryPath The new path
-     */
-    public void setSerializedRepositoryPath(String serializedRepositoryPath)
+    /** Initializes the metadata, i.e. parses the repository file. */
+    public void initialize()
     {
-        persistor.setSerializedRepositoryPath(serializedRepositoryPath);
-    }
+        metadataProfiles = new Hashtable();
+        currentProfileKey.set(null);
 
-    /**
-     * Returns the last activated profile key.
-     *
-     * @return the last activated profile key or null if no profile has been loaded
-     * @throws MetadataException if per-thread changes has not been activated
-     * @see #loadProfile(Object)
-     */
-    public Object getCurrentProfileKey() throws MetadataException
-    {
-        if (!isEnablePerThreadChanges())
+        File serFile = null;
+        if(usingSerializedRepository)
         {
-            throw new MetadataException("Call to this method is undefined, since per-thread mode is disabled.");
+            // build File object pointing to serialized repository location
+            serFile = new File(serializedRepositoryPath + File.separator + DEFAULT_REPOSITORY_PATH
+                    + "." + SER_FILE_SUFFIX);
+
+            if(serFile.exists() && serFile.length() > 0)
+            {
+                try
+                {
+                    long duration = System.currentTimeMillis();
+                    globalRepository = deserialize(serFile);
+                    log.info("Read serialized repository in " + (System.currentTimeMillis() - duration) + " ms");
+                }
+                catch(Exception e)
+                {
+                    log.error("error in loading serialized repository. Will try to use XML version.", e);
+                }
+            }
         }
-        return currentProfileKey.get();
-    }
 
-    /**
-     * Initializes the metadata, i.e. parses the repository file. 
-     */
-    public void initialize()
-    {
-        metadataProfiles  = new Hashtable();
-        currentProfileKey.set(null);
+        URL url = buildRepositoryURL();
         try
         {
-            globalRepository     = persistor.readDescriptorRepository(repositoryPath);
-            connectionRepository = persistor.readConnectionRepository(repositoryPath);
+            if(globalRepository == null)
+            {
+                globalRepository = createRepositoryPersistor().readDescriptorRepository(url);
+                if(usingSerializedRepository)
+                {
+                    serialize(globalRepository, serFile);
+                    log.info("Write serialized repository to " + serFile);
+                }
+            }
+            connectionRepository = createRepositoryPersistor().readConnectionRepository(url);
         }
-        catch (FileNotFoundException ex)
+        catch(FileNotFoundException ex)
         {
-            globalRepository     = new DescriptorRepository();
+            log.warn("Could not access '" + url + "' or a DOCTYPE/DTD-dependency. "
+                    + "(Check letter case for file names and HTTP-access if using DOCTYPE PUBLIC)"
+                    + " Starting with empty metadata and connection configurations.", ex);
+            globalRepository = new DescriptorRepository();
             connectionRepository = new ConnectionRepository();
-            log.info("No repository.xml file found, starting with empty metadata and connection configuration");
         }
-        catch (Exception ex)
+        catch(Exception ex)
         {
-            throw new MetadataException("Can't read repository file '" + repositoryPath + "'", ex);
+            if(ex instanceof OJBRuntimeException) throw (OJBRuntimeException) ex;
+            throw new MetadataException("Can't read repository file '" + url + "'", ex);
         }
+
         defaultPBKey = buildDefaultKey();
     }
 
@@ -313,9 +287,7 @@
         metadataProfiles = null;
     }
 
-    /**
-     * Returns an instance of this class.
-     */
+    /** Returns an instance of this class. */
     public static synchronized MetadataManager getInstance()
     {
         // we use the setup'd OJB instance
@@ -324,7 +296,7 @@
 
     /**
      * Returns the field factory used by the metadata manager.
-     * 
+     *
      * @return The field factory
      */
     public PersistentFieldFactory getFieldFactory()
@@ -333,16 +305,6 @@
     }
 
     /**
-     * Returns a repository persistor instance.
-     * 
-     * @return The persistor
-     */
-    public RepositoryPersistor getRepositoryPersistor()
-    {
-        return new RepositoryPersistor(fieldFactory);
-    }
-    
-    /**
      * Returns the current valid {@link org.apache.ojb.broker.metadata.DescriptorRepository} for
      * the caller. This is the provided way to obtain the
      * {@link org.apache.ojb.broker.metadata.DescriptorRepository}.
@@ -357,10 +319,10 @@
     public DescriptorRepository getRepository()
     {
         DescriptorRepository repository;
-        if (enablePerThreadChanges)
+        if(enablePerThreadChanges)
         {
             repository = (DescriptorRepository) threadedRepository.get();
-            if (repository == null)
+            if(repository == null)
             {
                 repository = getGlobalRepository();
                 log.info(MSG_STR);
@@ -392,9 +354,7 @@
         return globalRepository;
     }
 
-    /**
-     * Returns the {@link ConnectionRepository}.
-     */
+    /** Returns the {@link ConnectionRepository}. */
     public ConnectionRepository connectionRepository()
     {
         return connectionRepository;
@@ -403,6 +363,7 @@
     /**
      * Merge the given {@link ConnectionRepository} with the existing one (without making
      * a deep copy of the containing connection descriptors).
+     *
      * @see #mergeConnectionRepository(ConnectionRepository targetRepository, ConnectionRepository sourceRepository, boolean deep)
      */
     public void mergeConnectionRepository(ConnectionRepository repository)
@@ -426,10 +387,10 @@
             ConnectionRepository targetRepository, ConnectionRepository sourceRepository, boolean deep)
     {
         List list = sourceRepository.getAllDescriptor();
-        for (Iterator iterator = list.iterator(); iterator.hasNext();)
+        for(Iterator iterator = list.iterator(); iterator.hasNext();)
         {
             JdbcConnectionDescriptor jcd = (JdbcConnectionDescriptor) iterator.next();
-            if (deep)
+            if(deep)
             {
                 //TODO: adopt copy/clone methods for metadata classes?
                 jcd = (JdbcConnectionDescriptor) SerializationUtils.clone(jcd);
@@ -458,8 +419,11 @@
      * <tt>deep</tt> is set <code>true</code> deep copies of source objects were made.
      * <br/>
      * Note: Using <tt>deep copy mode</tt> all descriptors will be serialized
-     * by using the default class loader to resolve classes. This could be problematic
-     * when classes load by a context class loader.
+     * by using the default class loader to resolve classes. This can be problematic
+     * when classes are loaded by a context class loader.
+     * <p>
+     * Note: All classes within the repository structure have to implement
+     * <code>java.io.Serializable</code> to be able to create a cloned copy.
      *
      * @see #isEnablePerThreadChanges
      * @see #setEnablePerThreadChanges
@@ -468,10 +432,10 @@
             DescriptorRepository targetRepository, DescriptorRepository sourceRepository, boolean deep)
     {
         Iterator it = sourceRepository.iterator();
-        while (it.hasNext())
+        while(it.hasNext())
         {
             ClassDescriptor cld = (ClassDescriptor) it.next();
-            if (deep)
+            if(deep)
             {
                 //TODO: adopt copy/clone methods for metadata classes?
                 cld = (ClassDescriptor) SerializationUtils.clone(cld);
@@ -483,32 +447,38 @@
 
     /**
      * Read ClassDescriptors from the given repository file.
+     *
      * @see #mergeDescriptorRepository
      */
     public DescriptorRepository readDescriptorRepository(String fileName)
     {
         try
         {
-            return getRepositoryPersistor().readDescriptorRepository(fileName);
+            RepositoryPersistor persistor = createRepositoryPersistor();
+            return persistor.readDescriptorRepository(fileName);
         }
-        catch (Exception e)
+        catch(Exception e)
         {
+            if(e instanceof OJBRuntimeException) throw (OJBRuntimeException) e;
             throw new MetadataException("Can not read repository " + fileName, e);
         }
     }
 
     /**
      * Read ClassDescriptors from the given InputStream.
+     *
      * @see #mergeDescriptorRepository
      */
     public DescriptorRepository readDescriptorRepository(InputStream inst)
     {
         try
         {
-            return getRepositoryPersistor().readDescriptorRepository(inst);
+            RepositoryPersistor persistor = createRepositoryPersistor();
+            return persistor.readDescriptorRepository(inst);
         }
-        catch (Exception e)
+        catch(Exception e)
         {
+            if(e instanceof OJBRuntimeException) throw (OJBRuntimeException) e;
             throw new MetadataException("Can not read repository " + inst, e);
         }
     }
@@ -522,10 +492,12 @@
     {
         try
         {
-            return getRepositoryPersistor().readConnectionRepository(fileName);
+            RepositoryPersistor persistor = createRepositoryPersistor();
+            return persistor.readConnectionRepository(fileName);
         }
-        catch (Exception e)
+        catch(Exception e)
         {
+            if(e instanceof OJBRuntimeException) throw (OJBRuntimeException) e;
             throw new MetadataException("Can not read repository " + fileName, e);
         }
     }
@@ -539,10 +511,12 @@
     {
         try
         {
-            return getRepositoryPersistor().readConnectionRepository(inst);
+            RepositoryPersistor persistor = createRepositoryPersistor();
+            return persistor.readConnectionRepository(inst);
         }
-        catch (Exception e)
+        catch(Exception e)
         {
+            if(e instanceof OJBRuntimeException) throw (OJBRuntimeException) e;
             throw new MetadataException("Can not read repository from " + inst, e);
         }
     }
@@ -557,14 +531,14 @@
      */
     public void setDescriptor(DescriptorRepository repository, boolean global)
     {
-        if (global)
+        if(global)
         {
-            if (log.isDebugEnabled()) log.debug("Set new global repository: " + repository);
+            if(log.isDebugEnabled()) log.debug("Set new global repository: " + repository);
             globalRepository = repository;
         }
         else
         {
-            if (log.isDebugEnabled()) log.debug("Set new threaded repository: " + repository);
+            if(log.isDebugEnabled()) log.debug("Set new threaded repository: " + repository);
             threadedRepository.set(repository);
         }
     }
@@ -582,6 +556,7 @@
     /**
      * Convenience method for
      * {@link #setDescriptor setDescriptor(repository, false)}.
+     *
      * @deprecated use {@link #setDescriptor}
      */
     public void setPerThreadDescriptor(DescriptorRepository repository)
@@ -633,29 +608,27 @@
 
     /**
      * Add a metadata profile.
+     *
      * @see #loadProfile
      */
     public void addProfile(Object key, DescriptorRepository repository)
     {
-        if (metadataProfiles.contains(key))
+        if(metadataProfiles.contains(key))
         {
             throw new MetadataException("Duplicate profile key. Key '" + key + "' already exists.");
         }
         metadataProfiles.put(key, repository);
     }
 
-    /**
-     * Load the given metadata profile for the current thread.
-     *
-     */
+    /** Load the given metadata profile for the current thread. */
     public void loadProfile(Object key)
     {
-        if (!isEnablePerThreadChanges())
+        if(!isEnablePerThreadChanges())
         {
             throw new MetadataException("Can not load profile with disabled per thread mode");
         }
         DescriptorRepository rep = (DescriptorRepository) metadataProfiles.get(key);
-        if (rep == null)
+        if(rep == null)
         {
             throw new MetadataException("Can not find profile for key '" + key + "'");
         }
@@ -664,16 +637,28 @@
     }
 
     /**
-     * Remove the given metadata profile.
+     * Returns the last activated profile key.
+     *
+     * @return the last activated profile key or null if no profile has been loaded
+     * @throws MetadataException if per-thread changes has not been activated
+     * @see #loadProfile(Object)
      */
+    public Object getCurrentProfileKey() throws MetadataException
+    {
+        if(!isEnablePerThreadChanges())
+        {
+            throw new MetadataException("Call to this method is undefined, since per-thread mode is disabled.");
+        }
+        return currentProfileKey.get();
+    }
+
+    /** Remove the given metadata profile. */
     public DescriptorRepository removeProfile(Object key)
     {
         return (DescriptorRepository) metadataProfiles.remove(key);
     }
 
-    /**
-     * Remove all metadata profiles.
-     */
+    /** Remove all metadata profiles. */
     public void clearProfiles()
     {
         metadataProfiles.clear();
@@ -694,6 +679,7 @@
 
     /**
      * Return the default {@link PBKey}.
+     *
      * @see #setDefaultPBKey
      */
     public PBKey getDefaultPBKey()
@@ -707,6 +693,7 @@
      * <br/>
      * Note: Only allowed to set once by declare a default connection
      * in configuration files, or using this method.
+     *
      * @throws MetadataException if key was set more than one time
      */
     public void setDefaultPBKey(PBKey defaultPBKey)
@@ -721,29 +708,30 @@
 
     /**
      * Try to build an default PBKey for convenience PB create method.
+     *
      * @return PBKey or <code>null</code> if default key was not declared in
-     * metadata
+     *         metadata
      */
     private PBKey buildDefaultKey()
     {
         List descriptors = connectionRepository().getAllDescriptor();
         JdbcConnectionDescriptor descriptor;
         PBKey result = null;
-        for (Iterator iterator = descriptors.iterator(); iterator.hasNext();)
+        for(Iterator iterator = descriptors.iterator(); iterator.hasNext();)
         {
             descriptor = (JdbcConnectionDescriptor) iterator.next();
-            if (descriptor.isDefaultConnection())
+            if(descriptor.isDefaultConnection())
             {
                 if(result != null)
                 {
                     log.error("Found additional connection descriptor with enabled 'default-connection' "
                             + descriptor.getPBKey() + ". This is NOT allowed. Will use the first found descriptor " + result
                             + " as default connection");
-            }
+                }
                 else
                 {
                     result = descriptor.getPBKey();
-        }
+                }
             }
         }
 
@@ -751,9 +739,196 @@
         {
             log.info("No 'default-connection' attribute set in jdbc-connection-descriptors," +
                     " thus it's currently not possible to use 'defaultPersistenceBroker()' " +
-                    " convenience method to lookup PersistenceBroker instances. But it's possible"+
+                    " convenience method to lookup PersistenceBroker instances. But it's possible" +
                     " to enable this at runtime using 'setDefaultKey' method.");
         }
         return result;
+    }
+
+    protected URL buildRepositoryURL()
+    {
+        // 1. search for system property entry
+        String repositoryPath = System.getProperties().getProperty(REPOSITORY_PROPERTY_NAME, null);
+        String repositoryPath2 = null;
+        // 2. lookup repository file path from OJB.properties file
+        if(repositoryPath == null)
+        {
+            repositoryPath = getRepositoryPath();
+        }
+        URL url = lookupURL(repositoryPath);
+        if(url == null)
+        {
+            // 3. Try to lookup repository file in same directory as OJB.properties file
+            String ojbPropertiesPath = ojb.getOjbPropertiesPath();
+            if(ojbPropertiesPath != null && ojbPropertiesPath.length() > 0)
+            {
+                ojbPropertiesPath = StringUtils.substringBeforeLast(ojbPropertiesPath, REPOSITORY_PROPERTY_NAME);
+                repositoryPath2 = ojbPropertiesPath + repositoryPath;
+                url = lookupURL(repositoryPath2);
+            }
+        }
+
+        if(url != null)
+        {
+            log.info("OJB Repository file: " + url);
+        }
+        else
+        {
+            log.warn("Can't find OJB Repository file using path '" + repositoryPath + "' and path '" + repositoryPath2 + "'");
+        }
+        return url;
+    }
+
+    private URL lookupURL(String repositoryPath)
+    {
+        //j2ee compliant lookup of resources
+        URL url = ClassHelper.getResource(repositoryPath);
+        // don't be too strict: if resource is not on the classpath, try ordinary file lookup
+        if(url == null)
+        {
+            try
+            {
+                File file = new File(repositoryPath);
+                if(file.exists())
+                {
+                    url = file.toURL();
+                }
+            }
+            catch(MalformedURLException ignore)
+            {
+                // ignore
+            }
+        }
+        return url;
+    }
+
+    protected void serialize(DescriptorRepository repository, File file)
+    {
+        try
+        {
+            FileOutputStream fos = new FileOutputStream(file);
+            // serialize repository
+            SerializationUtils.serialize(repository, fos);
+        }
+        catch(Exception e)
+        {
+            log.error("Serialization failed, using output path: " + file.getAbsolutePath(), e);
+        }
+    }
+
+    protected DescriptorRepository deserialize(File serFile)
+    {
+        DescriptorRepository result = null;
+        try
+        {
+            FileInputStream fis = new FileInputStream(serFile);
+            // deserialize repository
+            result = (DescriptorRepository) SerializationUtils.deserialize(fis);
+        }
+        catch(Exception e)
+        {
+            log.error("Deserialisation failed, using input path: " + serFile.getAbsolutePath(), e);
+        }
+        return result;
+    }
+
+    /**
+     * Create new instance of the specified {@link RepositoryPersistor} class.
+     *
+     * @return A new instance.
+     */
+    public RepositoryPersistor createRepositoryPersistor()
+    {
+        try
+        {
+            return (RepositoryPersistor) ClassHelper.newInstance(
+                    repositoryPersistorClass, PersistentFieldFactory.class, fieldFactory);
+        }
+        catch(Exception e)
+        {
+            throw new MetadataException("Can't instantiate " + repositoryPersistorClass, e);
+        }
+    }
+
+    /**
+     * Returns the path of the serialized repository.
+     *
+     * @return The path
+     */
+    public String getSerializedRepositoryPath()
+    {
+        return serializedRepositoryPath;
+    }
+
+    /**
+     * Sets the path of the serialized repository.
+     *
+     * @param serializedRepositoryPath The new path
+     */
+    public void setSerializedRepositoryPath(String serializedRepositoryPath)
+    {
+        this.serializedRepositoryPath = serializedRepositoryPath;
+    }
+
+    /**
+     * Returns whether we're using a serialized repository.
+     *
+     * @return <code>true</code> if we're using a serialized repository
+     */
+    public boolean isUsingSerializedRepository()
+    {
+        return usingSerializedRepository;
+    }
+
+    /**
+     * Specifies whether we're using a serialized repository.
+     *
+     * @param usingSerializedRepository <code>true</code> if we're using
+     * a serialized repository
+     */
+    public void setUsingSerializedRepository(boolean usingSerializedRepository)
+    {
+        this.usingSerializedRepository = usingSerializedRepository;
+    }
+
+    /**
+     * Returns the repository path.
+     *
+     * @return The repository path
+     */
+    public String getRepositoryPath()
+    {
+        return repositoryPath;
+    }
+
+    /**
+     * Sets the repository path.
+     *
+     * @param repositoryPath The new repository path
+     */
+    public void setRepositoryPath(String repositoryPath)
+    {
+        this.repositoryPath = repositoryPath;
+    }
+
+    /**
+     * Get the implementation class of {@link RepositoryPersistor}
+     * or <em>null</em> if not set.
+     *
+     * @return The class used to instatiate {@link RepositoryPersistor} instances.
+     */
+    public Class getRepositoryPersistorClass()
+    {
+        return repositoryPersistorClass;
+    }
+
+    /**
+     * Set the {@link RepositoryPersistor} class to use for read in of metadata.
+     * 
+     * @param repositoryPersistorClass
+     */
+    public void setRepositoryPersistorClass(Class repositoryPersistorClass)
+    {
+        this.repositoryPersistorClass = repositoryPersistorClass;
     }
 }

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/ObjectReferenceDescriptor.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/ObjectReferenceDescriptor.java?rev=422233&r1=422232&r2=422233&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/ObjectReferenceDescriptor.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/metadata/ObjectReferenceDescriptor.java Sat Jul 15 07:22:34 2006
@@ -361,11 +361,22 @@
      */
     public void addForeignKeyField(Object fkField, String targetField)
     {
+        addForeignKeyField(fkField, targetField, false);
+    }
+
+    /**
+     * Add a foreign key field.
+     * @param fkField the id or name of the foreign key field
+     * @param targetField the name of the target field
+     * @param inverse Flag to mark inverse foreign key fields.
+     */
+    protected void addForeignKeyField(Object fkField, String targetField, boolean inverse)
+    {
         if (m_ForeignKeyFields == null)
         {
             m_ForeignKeyFields = new Vector();
         }
-        m_ForeignKeyFields.add(new ForeignKey(fkField, targetField));
+        m_ForeignKeyFields.add(new ForeignKey(fkField, targetField, inverse));
     }
 
     /**
@@ -645,6 +656,30 @@
             return result != null && result.equalsIgnoreCase("true");
         }
 
+    /**
+     * Returns <em>true</em> if a foreign key constraint to the referenced object is
+     * declared, else <em>false</em> is returned.
+     */
+    public boolean hasConstraint()
+    {
+        /*
+        arminw: Currently we don't have a ForeignKey descriptor object and
+        a official xml-element to support FK settings. As a workaround I introduce
+        a custom-attribute to handle FK settings in collection-/reference-decriptor
+        */
+        String result = getAttribute("constraint");
+        return result != null && result.equalsIgnoreCase("true");
+    }
+
+    /**
+     * Set a foreign key constraint flag for this reference - see {@link #hasConstraint()}
+     * @param constraint If set <em>true</em>, signals a foreign key constraint in database.
+     */
+    public void setConstraint(boolean constraint)
+    {
+        addAttribute("constraint", constraint ? "true" : "false");
+    }
+
     public String toString()
     {
         return new ToStringBuilder(this)
@@ -783,14 +818,15 @@
     static class ForeignKey implements Serializable
     {
         private static final long serialVersionUID = 3256718468362482741L;
-
+        boolean inverse;
         Object fkField;
         String targetField;
 
-        ForeignKey(Object fkField, String targetField)
+        public ForeignKey(Object fkField, String targetField, boolean inverse)
         {
             this.fkField = fkField;
             this.targetField = targetField;
+            this.inverse = inverse;
         }
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org