Author: tomdz
Date: Mon Dec 26 07:53:30 2005
New Revision: 359070
URL: http://svn.apache.org/viewcvs?rev=359070&view=rev
Log:
Enhanced handling of binary columns
Added helper class for serialization and Base64 encoding of objects
Added:
db/ddlutils/trunk/lib/commons-codec-1.3.jar (with props)
db/ddlutils/trunk/src/java/org/apache/ddlutils/io/BinaryObjectsHelper.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/io/converters/ByteArrayBase64Converter.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/model/JdbcTypeCategoryEnum.java
Modified:
db/ddlutils/trunk/src/java/org/apache/ddlutils/dynabean/DynaSqlIterator.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Column.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/model/TypeMap.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java
Added: db/ddlutils/trunk/lib/commons-codec-1.3.jar
URL:
http://svn.apache.org/viewcvs/db/ddlutils/trunk/lib/commons-codec-1.3.jar?rev=359070&view=auto
==============================================================================
Binary file - no diff available.
Propchange: db/ddlutils/trunk/lib/commons-codec-1.3.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Modified:
db/ddlutils/trunk/src/java/org/apache/ddlutils/dynabean/DynaSqlIterator.java
URL:
http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/dynabean/DynaSqlIterator.java?rev=359070&r1=359069&r2=359070&view=diff
==============================================================================
---
db/ddlutils/trunk/src/java/org/apache/ddlutils/dynabean/DynaSqlIterator.java
(original)
+++
db/ddlutils/trunk/src/java/org/apache/ddlutils/dynabean/DynaSqlIterator.java
Mon Dec 26 07:53:30 2005
@@ -16,6 +16,8 @@
* limitations under the License.
*/
+import java.sql.Blob;
+import java.sql.Clob;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
@@ -319,10 +321,28 @@
value = resultSet.getTimestamp(columnName);
break;
case Types.CLOB:
- value = resultSet.getClob(columnName);
+ Clob clob = resultSet.getClob(columnName);
+
+ if ((clob == null) || (clob.length() > Integer.MAX_VALUE))
+ {
+ value = clob;
+ }
+ else
+ {
+ value = clob.getSubString(1l, (int)clob.length());
+ }
break;
case Types.BLOB:
- value = resultSet.getBlob(columnName);
+ Blob blob = resultSet.getBlob(columnName);
+
+ if ((blob == null) || (blob.length() > Integer.MAX_VALUE))
+ {
+ value = blob;
+ }
+ else
+ {
+ value = blob.getBytes(1l, (int)blob.length());
+ }
break;
case Types.ARRAY:
value = resultSet.getArray(columnName);
Added:
db/ddlutils/trunk/src/java/org/apache/ddlutils/io/BinaryObjectsHelper.java
URL:
http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/io/BinaryObjectsHelper.java?rev=359070&view=auto
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/io/BinaryObjectsHelper.java
(added)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/io/BinaryObjectsHelper.java
Mon Dec 26 07:53:30 2005
@@ -0,0 +1,129 @@
+package org.apache.ddlutils.io;
+
+/*
+ * Copyright 1999-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.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.sql.Types;
+
+import org.apache.ddlutils.DdlUtilsException;
+import org.apache.ddlutils.io.converters.ByteArrayBase64Converter;
+
+/**
+ * Helper class for dealing with the serialization and Base64 encoding of
objects.
+ *
+ * @author tomdz
+ * @version $Revision: $
+ */
+public class BinaryObjectsHelper
+{
+ /**
+ * Serializes the given object to a byte array representation.
+ *
+ * @param obj The object to serialize
+ * @return The byte array containing the serialized form of the object
+ */
+ public byte[] serialize(Object obj)
+ {
+ try
+ {
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
+ ObjectOutputStream objOut = new ObjectOutputStream(output);
+
+ objOut.writeObject(obj);
+ objOut.close();
+
+ return output.toByteArray();
+ }
+ catch (IOException ex)
+ {
+ throw new DdlUtilsException("Could not serialize object", ex);
+ }
+ }
+
+ /**
+ * Deserializes the object from its byte array representation.
+ *
+ * @param serializedForm The byte array containing the serialized form of
the object
+ * @return The object
+ */
+ public Object deserialize(byte[] serializedForm)
+ {
+ try
+ {
+ ByteArrayInputStream input = new
ByteArrayInputStream(serializedForm);
+ ObjectInputStream objIn = new ObjectInputStream(input);
+
+ return objIn.readObject();
+ }
+ catch (IOException ex)
+ {
+ throw new DdlUtilsException("Could not deserialize object", ex);
+ }
+ catch (ClassNotFoundException ex)
+ {
+ throw new DdlUtilsException("Could find class for deserialized
object", ex);
+ }
+ }
+
+ /**
+ * Encodes the serialized form of the given object to its Base64 form.
+ *
+ * @param obj The object
+ * @return The Base64 string
+ */
+ public String encode(Object obj)
+ {
+ return encodeByteArray(serialize(obj));
+ }
+
+ /**
+ * Encodes the given byte array to its Base64 form.
+ *
+ * @param data The data to encode
+ * @return The Base64 string
+ */
+ public String encodeByteArray(byte[] data)
+ {
+ return new ByteArrayBase64Converter().convertToString(data,
Types.BINARY);
+ }
+
+ /**
+ * Decodes an object from the serialized form encoded in the given Base64
string.
+ *
+ * @param base64Rep The serialized form encoded in Base64
+ * @return The object
+ */
+ public Object decode(String base64Rep)
+ {
+ return deserialize(decodeByteArray(base64Rep));
+ }
+
+ /**
+ * Decodes the given Base64 form to a byte array.
+ *
+ * @param base64Rep The Base64 string to decode
+ * @return The byte array
+ */
+ public byte[] decodeByteArray(String base64Rep)
+ {
+ return (byte[])new
ByteArrayBase64Converter().convertFromString(base64Rep, Types.BINARY);
+ }
+}
Added:
db/ddlutils/trunk/src/java/org/apache/ddlutils/io/converters/ByteArrayBase64Converter.java
URL:
http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/io/converters/ByteArrayBase64Converter.java?rev=359070&view=auto
==============================================================================
---
db/ddlutils/trunk/src/java/org/apache/ddlutils/io/converters/ByteArrayBase64Converter.java
(added)
+++
db/ddlutils/trunk/src/java/org/apache/ddlutils/io/converters/ByteArrayBase64Converter.java
Mon Dec 26 07:53:30 2005
@@ -0,0 +1,45 @@
+package org.apache.ddlutils.io.converters;
+
+/*
+ * Copyright 1999-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 org.apache.commons.codec.binary.Base64;
+
+/**
+ * Converts between a byte array and its Base64 encoded string representation
(e.g. for use in XML).
+ *
+ * @author Thomas Dudziak
+ * @version $Revision: $
+ */
+public class ByteArrayBase64Converter implements SqlTypeConverter
+{
+ /**
+ * [EMAIL PROTECTED]
+ */
+ public Object convertFromString(String textRep, int sqlTypeCode) throws
ConversionException
+ {
+ return Base64.encodeBase64(textRep.getBytes());
+ }
+
+ /**
+ * [EMAIL PROTECTED]
+ */
+ public String convertToString(Object obj, int sqlTypeCode) throws
ConversionException
+ {
+ return new String(Base64.decodeBase64((byte[])obj));
+ }
+
+}
Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Column.java
URL:
http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Column.java?rev=359070&r1=359069&r2=359070&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Column.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Column.java Mon Dec 26
07:53:30 2005
@@ -17,6 +17,7 @@
*/
import java.io.Serializable;
+import java.sql.Types;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
@@ -436,12 +437,16 @@
comparator.append(_required, other._required);
comparator.append(_autoIncrement, other._autoIncrement);
comparator.append(_typeCode, other._typeCode);
- comparator.append(_type, other._type);
- comparator.append(_scale, other._scale);
comparator.append(_defaultValue, other._defaultValue);
// comparing the size makes only sense for types where it is
relevant
- if (!TypeMap.isNumericType(_typeCode) &&
TypeMap.isNumericType(other._typeCode))
+ if ((_typeCode == Types.NUMERIC) || (_typeCode == Types.DECIMAL))
+ {
+ comparator.append(_scale, other._scale);
+ comparator.append(_scale, other._scale);
+ }
+ else if ((_typeCode == Types.CHAR) || (_typeCode == Types.VARCHAR)
||
+ (_typeCode == Types.BINARY) || (_typeCode ==
Types.VARBINARY))
{
comparator.append(_size, other._size);
}
Added:
db/ddlutils/trunk/src/java/org/apache/ddlutils/model/JdbcTypeCategoryEnum.java
URL:
http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/model/JdbcTypeCategoryEnum.java?rev=359070&view=auto
==============================================================================
---
db/ddlutils/trunk/src/java/org/apache/ddlutils/model/JdbcTypeCategoryEnum.java
(added)
+++
db/ddlutils/trunk/src/java/org/apache/ddlutils/model/JdbcTypeCategoryEnum.java
Mon Dec 26 07:53:30 2005
@@ -0,0 +1,110 @@
+package org.apache.ddlutils.model;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.lang.enums.ValuedEnum;
+
+/**
+ * Represents the different categories of jdbc types.
+ *
+ * @author tomdz
+ * @version $Revision: $
+ */
+public class JdbcTypeCategoryEnum extends ValuedEnum
+{
+ /** The integer value for the enum value for numeric jdbc types. */
+ public static final int VALUE_NUMERIC = 1;
+ /** The integer value for the enum value for date/time jdbc types. */
+ public static final int VALUE_DATETIME = 2;
+ /** The integer value for the enum value for textual jdbc types. */
+ public static final int VALUE_TEXTUAL = 3;
+ /** The integer value for the enum value for binary jdbc types. */
+ public static final int VALUE_BINARY = 4;
+ /** The integer value for the enum value for special jdbc types. */
+ public static final int VALUE_SPECIAL = 5;
+ /** The integer value for the enum value for all other jdbc types. */
+ public static final int VALUE_OTHER = 6;
+
+ /** The enum value for numeric jdbc types. */
+ public static final JdbcTypeCategoryEnum NUMERIC = new
JdbcTypeCategoryEnum("numeric", VALUE_NUMERIC);
+ /** The enum value for date/time jdbc types. */
+ public static final JdbcTypeCategoryEnum DATETIME = new
JdbcTypeCategoryEnum("datetime", VALUE_DATETIME);
+ /** The enum value for textual jdbc types. */
+ public static final JdbcTypeCategoryEnum TEXTUAL = new
JdbcTypeCategoryEnum("textual", VALUE_TEXTUAL);
+ /** The enum value for binary jdbc types. */
+ public static final JdbcTypeCategoryEnum BINARY = new
JdbcTypeCategoryEnum("binary", VALUE_BINARY);
+ /** The enum value for special jdbc types. */
+ public static final JdbcTypeCategoryEnum SPECIAL = new
JdbcTypeCategoryEnum("special", VALUE_SPECIAL);
+ /** The enum value for other jdbc types. */
+ public static final JdbcTypeCategoryEnum OTHER = new
JdbcTypeCategoryEnum("other", VALUE_OTHER);
+
+ /** Version id for this class as relevant for serialization. */
+ private static final long serialVersionUID = -2695615907467866410L;
+
+ /**
+ * Creates a new enum object.
+ *
+ * @param defaultTextRep The textual representation
+ * @param value The corresponding integer value
+ */
+ private JdbcTypeCategoryEnum(String defaultTextRep, int value)
+ {
+ super(defaultTextRep, value);
+ }
+
+ /**
+ * Returns the enum value that corresponds to the given textual
+ * representation.
+ *
+ * @param defaultTextRep The textual representation
+ * @return The enum value
+ */
+ public static JdbcTypeCategoryEnum getEnum(String defaultTextRep)
+ {
+ return (JdbcTypeCategoryEnum)getEnum(JdbcTypeCategoryEnum.class,
defaultTextRep);
+ }
+
+ /**
+ * Returns the enum value that corresponds to the given integer
+ * representation.
+ *
+ * @param intValue The integer value
+ * @return The enum value
+ */
+ public static JdbcTypeCategoryEnum getEnum(int intValue)
+ {
+ return (JdbcTypeCategoryEnum)getEnum(JdbcTypeCategoryEnum.class,
intValue);
+ }
+
+ /**
+ * Returns the map of enum values.
+ *
+ * @return The map of enum values
+ */
+ public static Map getEnumMap()
+ {
+ return getEnumMap(JdbcTypeCategoryEnum.class);
+ }
+
+ /**
+ * Returns a list of all enum values.
+ *
+ * @return The list of enum values
+ */
+ public static List getEnumList()
+ {
+ return getEnumList(JdbcTypeCategoryEnum.class);
+ }
+
+ /**
+ * Returns an iterator of all enum values.
+ *
+ * @return The iterator
+ */
+ public static Iterator iterator()
+ {
+ return iterator(JdbcTypeCategoryEnum.class);
+ }
+}
Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/model/TypeMap.java
URL:
http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/model/TypeMap.java?rev=359070&r1=359069&r2=359070&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/model/TypeMap.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/model/TypeMap.java Mon Dec
26 07:53:30 2005
@@ -19,6 +19,7 @@
import java.sql.Types;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Set;
import org.apache.ddlutils.util.Jdbc3Utils;
@@ -98,51 +99,45 @@
private static HashMap _typeNameToTypeCode = new HashMap();
/** Maps [EMAIL PROTECTED] java.sql.Types} type code constants to the
corresponding type names. */
private static HashMap _typeCodeToTypeName = new HashMap();
- /** Contains the type codes of the numeric types. */
- private static HashSet _numericTypes = new HashSet();
- /** Contains the type codes of the text types. */
- private static HashSet _textTypes = new HashSet();
- /** Contains the type codes of the binary types. */
- private static HashSet _binaryTypes = new HashSet();
- /** Contains the type codes of the special types (eg. OTHER, REF etc.). */
- private static HashSet _specialTypes = new HashSet();
+ /** Conatins the types per category. */
+ private static HashMap _typesPerCategory = new HashMap();
static
{
- registerJdbcType(Types.ARRAY, ARRAY, false, false,
false, true);
- registerJdbcType(Types.BIGINT, BIGINT, true, false,
false, false);
- registerJdbcType(Types.BINARY, BINARY, false, false,
true, false);
- registerJdbcType(Types.BIT, BIT, true, false,
false, false);
- registerJdbcType(Types.BLOB, BLOB, false, false,
true, false);
- registerJdbcType(Types.CHAR, CHAR, false, true,
false, false);
- registerJdbcType(Types.CLOB, CLOB, false, true,
false, false);
- registerJdbcType(Types.DATE, DATE, false, false,
false, false);
- registerJdbcType(Types.DECIMAL, DECIMAL, true, false,
false, false);
- registerJdbcType(Types.DISTINCT, DISTINCT, false, false,
false, true);
- registerJdbcType(Types.DOUBLE, DOUBLE, true, false,
false, false);
- registerJdbcType(Types.FLOAT, FLOAT, true, false,
false, false);
- registerJdbcType(Types.INTEGER, INTEGER, true, false,
false, false);
- registerJdbcType(Types.JAVA_OBJECT, JAVA_OBJECT, false, false,
false, true);
- registerJdbcType(Types.LONGVARBINARY, LONGVARBINARY, false, false,
true, false);
- registerJdbcType(Types.LONGVARCHAR, LONGVARCHAR, false, true,
false, false);
- registerJdbcType(Types.NULL, NULL, false, false,
false, true);
- registerJdbcType(Types.NUMERIC, NUMERIC, true, false,
false, false);
- registerJdbcType(Types.OTHER, OTHER, false, false,
false, true);
- registerJdbcType(Types.REAL, REAL, true, false,
false, false);
- registerJdbcType(Types.REF, REF, false, false,
false, true);
- registerJdbcType(Types.SMALLINT, SMALLINT, true, false,
false, false);
- registerJdbcType(Types.STRUCT, STRUCT, false, false,
false, true);
- registerJdbcType(Types.TIME, TIME, false, false,
false, false);
- registerJdbcType(Types.TIMESTAMP, TIMESTAMP, false, false,
false, false);
- registerJdbcType(Types.TINYINT, TINYINT, true, false,
false, false);
- registerJdbcType(Types.VARBINARY, VARBINARY, false, false,
true, false);
- registerJdbcType(Types.VARCHAR, VARCHAR, false, true,
false, false);
+ registerJdbcType(Types.ARRAY, ARRAY,
JdbcTypeCategoryEnum.SPECIAL);
+ registerJdbcType(Types.BIGINT, BIGINT,
JdbcTypeCategoryEnum.NUMERIC);
+ registerJdbcType(Types.BINARY, BINARY,
JdbcTypeCategoryEnum.BINARY);
+ registerJdbcType(Types.BIT, BIT,
JdbcTypeCategoryEnum.NUMERIC);
+ registerJdbcType(Types.BLOB, BLOB,
JdbcTypeCategoryEnum.BINARY);
+ registerJdbcType(Types.CHAR, CHAR,
JdbcTypeCategoryEnum.TEXTUAL);
+ registerJdbcType(Types.CLOB, CLOB,
JdbcTypeCategoryEnum.TEXTUAL);
+ registerJdbcType(Types.DATE, DATE,
JdbcTypeCategoryEnum.DATETIME);
+ registerJdbcType(Types.DECIMAL, DECIMAL,
JdbcTypeCategoryEnum.NUMERIC);
+ registerJdbcType(Types.DISTINCT, DISTINCT,
JdbcTypeCategoryEnum.SPECIAL);
+ registerJdbcType(Types.DOUBLE, DOUBLE,
JdbcTypeCategoryEnum.NUMERIC);
+ registerJdbcType(Types.FLOAT, FLOAT,
JdbcTypeCategoryEnum.NUMERIC);
+ registerJdbcType(Types.INTEGER, INTEGER,
JdbcTypeCategoryEnum.NUMERIC);
+ registerJdbcType(Types.JAVA_OBJECT, JAVA_OBJECT,
JdbcTypeCategoryEnum.SPECIAL);
+ registerJdbcType(Types.LONGVARBINARY, LONGVARBINARY,
JdbcTypeCategoryEnum.BINARY);
+ registerJdbcType(Types.LONGVARCHAR, LONGVARCHAR,
JdbcTypeCategoryEnum.TEXTUAL);
+ registerJdbcType(Types.NULL, NULL,
JdbcTypeCategoryEnum.SPECIAL);
+ registerJdbcType(Types.NUMERIC, NUMERIC,
JdbcTypeCategoryEnum.NUMERIC);
+ registerJdbcType(Types.OTHER, OTHER,
JdbcTypeCategoryEnum.SPECIAL);
+ registerJdbcType(Types.REAL, REAL,
JdbcTypeCategoryEnum.NUMERIC);
+ registerJdbcType(Types.REF, REF,
JdbcTypeCategoryEnum.SPECIAL);
+ registerJdbcType(Types.SMALLINT, SMALLINT,
JdbcTypeCategoryEnum.NUMERIC);
+ registerJdbcType(Types.STRUCT, STRUCT,
JdbcTypeCategoryEnum.SPECIAL);
+ registerJdbcType(Types.TIME, TIME,
JdbcTypeCategoryEnum.DATETIME);
+ registerJdbcType(Types.TIMESTAMP, TIMESTAMP,
JdbcTypeCategoryEnum.DATETIME);
+ registerJdbcType(Types.TINYINT, TINYINT,
JdbcTypeCategoryEnum.NUMERIC);
+ registerJdbcType(Types.VARBINARY, VARBINARY,
JdbcTypeCategoryEnum.BINARY);
+ registerJdbcType(Types.VARCHAR, VARCHAR,
JdbcTypeCategoryEnum.TEXTUAL);
// only available in JDK 1.4 and above:
if (Jdbc3Utils.supportsJava14JdbcTypes())
{
- registerJdbcType(Jdbc3Utils.determineBooleanTypeCode(), BOOLEAN,
true, false, false, false);
- registerJdbcType(Jdbc3Utils.determineDatalinkTypeCode(), DATALINK,
false, false, false, true);
+ registerJdbcType(Jdbc3Utils.determineBooleanTypeCode(), BOOLEAN,
JdbcTypeCategoryEnum.NUMERIC);
+ registerJdbcType(Jdbc3Utils.determineDatalinkTypeCode(), DATALINK,
JdbcTypeCategoryEnum.SPECIAL);
}
// Torque/Turbine extensions which we only support when reading from
an XML schema
@@ -176,84 +171,96 @@
}
/**
- * Registers a JDBC type.
+ * Registers a jdbc type.
*
- * @param typeCode The type code (one of the [EMAIL PROTECTED]
java.sql.Types} constants)
- * @param typeName The type name (case is ignored)
- * @param isNumericType Whether the type is a numeric type
- * @param isTextType Whether the type is a text type
- * @param isBinaryType Whether the type is a binary type
- * @param isSpecialType Whether the type is a special type
+ * @param typeCode The type code (one of the [EMAIL PROTECTED]
java.sql.Types} constants)
+ * @param typeName The type name (case is ignored)
+ * @param category The type category
*/
- protected static void registerJdbcType(int typeCode, String typeName,
boolean isNumericType, boolean isTextType, boolean isBinaryType, boolean
isSpecialType)
+ protected static void registerJdbcType(int typeCode, String typeName,
JdbcTypeCategoryEnum category)
{
Integer typeId = new Integer(typeCode);
_typeNameToTypeCode.put(typeName.toUpperCase(), typeId);
_typeCodeToTypeName.put(typeId, typeName.toUpperCase());
- if (isNumericType)
- {
- _numericTypes.add(typeId);
- }
- if (isTextType)
- {
- _textTypes.add(typeId);
- }
- if (isBinaryType)
- {
- _binaryTypes.add(typeId);
- }
- if (isSpecialType)
+
+ Set typesInCategory = (Set)_typesPerCategory.get(category);
+
+ if (typesInCategory == null)
{
- _specialTypes.add(typeId);
+ typesInCategory = new HashSet();
+ _typesPerCategory.put(category, typesInCategory);
}
+ typesInCategory.add(typeId);
}
/**
- * Determines whether the given sql type (one of the [EMAIL PROTECTED]
java.sql.Types} constants)
+ * Determines whether the given jdbc type (one of the [EMAIL PROTECTED]
java.sql.Types} constants)
* is a numeric type.
*
- * @param sqlTypeID The type code
+ * @param jdbcTypeCode The type code
* @return <code>true</code> if the type is a numeric one
*/
- public static boolean isNumericType(int sqlTypeID)
+ public static boolean isNumericType(int jdbcTypeCode)
{
- return _numericTypes.contains(new Integer(sqlTypeID));
+ Set typesInCategory =
(Set)_typesPerCategory.get(JdbcTypeCategoryEnum.NUMERIC);
+
+ return typesInCategory == null ? false : typesInCategory.contains(new
Integer(jdbcTypeCode));
}
/**
- * Determines whether the given sql type (one of the [EMAIL PROTECTED]
java.sql.Types} constants)
+ * Determines whether the given jdbc type (one of the [EMAIL PROTECTED]
java.sql.Types} constants)
+ * is a date/time type.
+ *
+ * @param jdbcTypeCode The type code
+ * @return <code>true</code> if the type is a numeric one
+ */
+ public static boolean isDateTimeType(int jdbcTypeCode)
+ {
+ Set typesInCategory =
(Set)_typesPerCategory.get(JdbcTypeCategoryEnum.DATETIME);
+
+ return typesInCategory == null ? false : typesInCategory.contains(new
Integer(jdbcTypeCode));
+ }
+
+ /**
+ * Determines whether the given jdbc type (one of the [EMAIL PROTECTED]
java.sql.Types} constants)
* is a text type.
*
- * @param sqlTypeID The type code
+ * @param jdbcTypeCode The type code
* @return <code>true</code> if the type is a text one
*/
- public static boolean isTextType(int sqlTypeID)
+ public static boolean isTextType(int jdbcTypeCode)
{
- return _textTypes.contains(new Integer(sqlTypeID));
+ Set typesInCategory =
(Set)_typesPerCategory.get(JdbcTypeCategoryEnum.TEXTUAL);
+
+ return typesInCategory == null ? false : typesInCategory.contains(new
Integer(jdbcTypeCode));
}
/**
- * Determines whether the given sql type (one of the [EMAIL PROTECTED]
java.sql.Types} constants)
+ * Determines whether the given jdbc type (one of the [EMAIL PROTECTED]
java.sql.Types} constants)
* is a binary type.
*
- * @param sqlTypeID The type code
+ * @param jdbcTypeCode The type code
* @return <code>true</code> if the type is a binary one
*/
- public static boolean isBinaryType(int sqlTypeID)
+ public static boolean isBinaryType(int jdbcTypeCode)
{
- return _binaryTypes.contains(new Integer(sqlTypeID));
+ Set typesInCategory =
(Set)_typesPerCategory.get(JdbcTypeCategoryEnum.BINARY);
+
+ return typesInCategory == null ? false : typesInCategory.contains(new
Integer(jdbcTypeCode));
}
/**
* Determines whether the given sql type (one of the [EMAIL PROTECTED]
java.sql.Types} constants)
* is a special type.
*
- * @param sqlTypeID The type code
+ * @param jdbcTypeCode The type code
* @return <code>true</code> if the type is a special one
*/
- public static boolean isSpecialType(int sqlTypeID)
+ public static boolean isSpecialType(int jdbcTypeCode)
{
- return _specialTypes.contains(new Integer(sqlTypeID));
+ Set typesInCategory =
(Set)_typesPerCategory.get(JdbcTypeCategoryEnum.SPECIAL);
+
+ return typesInCategory == null ? false : typesInCategory.contains(new
Integer(jdbcTypeCode));
}
}
Modified:
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java
URL:
http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java?rev=359070&r1=359069&r2=359070&view=diff
==============================================================================
---
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java
(original)
+++
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java
Mon Dec 26 07:53:30 2005
@@ -1429,7 +1429,8 @@
{
Column column = table.getColumn(columnIdx);
- if (TypeMap.isTextType(column.getTypeCode()))
+ if (TypeMap.isTextType(column.getTypeCode()) ||
+ TypeMap.isDateTimeType(column.getTypeCode()))
{
String defaultValue = column.getDefaultValue();
@@ -1479,6 +1480,10 @@
if (value == null)
{
statement.setNull(sqlIndex, typeCode);
+ }
+ else if (value instanceof byte[])
+ {
+ statement.setBytes(sqlIndex, (byte[])value);
}
else if (value instanceof String)
{