© 2005 BEA Systems, Inc.

com.bea.p13n.content.document.ref.loader
Class ColumnSizes

java.lang.Object
  extended bycom.bea.p13n.content.document.ref.loader.ColumnSizes

public class ColumnSizes
extends Object

Utility class to help determine JDBC table column sizes and to truncate data for inserting.

The general usage of this class should be truncate data fields before sending them to the database to avoid extraneous errors when data truncation would be a valid solution. For example,

 String id = request.getParameter("id");
 String name = request.getParameter("name");
 String value = request.getParameter("value");
 Connection con =
     DriverManager.getConnection("jdbc:weblogic:jts:commercePool");
 String sql = "INSERT INTO MYTABLE (ID, NAME, VALUE) VALUES (?, ?, ?)";
 PreparedStatement stmt = con.prepareStatment(sql);
 id = ColumnSizes.truncate(id, con, "MYTABLE", "ID");
 stmt.setString(1, id);
 name = ColumnSizes.truncate(name, con, "MYTABLE", "NAME");
 stmt.setString(2, name);
 value = ColumnSizes.truncate(value, con, "MYTABLE", "VALUE");
 stmt.setString(3, value);
 stmt.executeUpdate();
 stmt.close();
 con.close();
 

Additionally, you can use the getColumnInfo() method to determine the size of a table column. In this manner, you could warn the user about the max size or about data truncation.
When determining the size of columns, the following logic is used:

  1. If the property "p13n.jdbc.maxsize.<table>.<column>" in the loader.properties file is set to a numeric value, then it is assumed the column is a TEXT column with that maximum length.
  2. If the property "p13n.jdbc.maxsize.checkMetaData" in the loader.properties file is set to "true" and the specified Connection is not null, then the Connection's DatabaseMetaData will be used to determine the column information.
  3. If the column is not found or "p13n.jdbc.maxsize.checkMetaData" is not "true", then null is returned.
Additionally, the column information is cached to avoid extraneous database activity. Therefore, if the tables in the database are altered, the server will need to be restarted.

Note: Setting p13n.jdbc.maxsize.checkMetaData to true will cause the java.sql.DatabaseMetaData.getColumns() method to be invoked. Some JDBC drivers do not support this method correctly. Some Type 2 drivers might core dump on this method call.

Since:
3.1.0

Nested Class Summary
static class ColumnSizes.ColumnInfo
          Deprecated. Object describing a column.
 
Field Summary
static int BOOLEAN
          Deprecated. The constant for a boolean type (0).
static boolean CHECK_META_DATA
          Deprecated. Should we check with the DatabaseMetaData for getting column sizes.
static int DATETIME
          Deprecated. The constant for a datetime type (4).
static int FLOAT
          Deprecated. The constant for the floating-point numeric type (2).
static int INTEGER
          Deprecated. The constant for a numeric type (1).
static int MULTI_VALUED
          Deprecated. The constant for a multivalued type (6).
static int TEXT
          Deprecated. The constant for a text type (3).
static int USER_DEFINED
          Deprecated. The constant for a user defined type (5).
 
Constructor Summary
ColumnSizes()
          Deprecated.  
 
Method Summary
static int fromSQLType(int sqlType)
          Deprecated. Convert a java.sql.Types constant into one of ours.
static ColumnSizes.ColumnInfo getColumnInfo(Connection con, String table, String column)
          Deprecated. Get the ColumnInfo for the specified column.
static String getTypeName(int type)
          Deprecated. Get the default descriptive type name.
static Object truncate(Object in, Connection con, String table, String column)
          Deprecated. Truncate the specified object to the size of the specified table/column.
static String truncate(String in, Connection con, String table, String column)
          Deprecated. Truncate the specified String to the size of the specified table/column.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BOOLEAN

public static final int BOOLEAN
Deprecated. 
The constant for a boolean type (0).

See Also:
Constant Field Values

CHECK_META_DATA

public static boolean CHECK_META_DATA
Deprecated. 
Should we check with the DatabaseMetaData for getting column sizes.

This is initialized from the "p13n.jdbc.maxsize.checkMetaData" property in the weblogiccommerce.properties.


DATETIME

public static final int DATETIME
Deprecated. 
The constant for a datetime type (4).

See Also:
Constant Field Values

FLOAT

public static final int FLOAT
Deprecated. 
The constant for the floating-point numeric type (2).

See Also:
Constant Field Values

INTEGER

public static final int INTEGER
Deprecated. 
The constant for a numeric type (1).

See Also:
Constant Field Values

MULTI_VALUED

public static final int MULTI_VALUED
Deprecated. 
The constant for a multivalued type (6).

See Also:
Constant Field Values

TEXT

public static final int TEXT
Deprecated. 
The constant for a text type (3).

See Also:
Constant Field Values

USER_DEFINED

public static final int USER_DEFINED
Deprecated. 
The constant for a user defined type (5).

See Also:
Constant Field Values
Constructor Detail

ColumnSizes

public ColumnSizes()
Deprecated. 
Method Detail

fromSQLType

public static int fromSQLType(int sqlType)
Deprecated. 
Convert a java.sql.Types constant into one of ours.

Parameters:
sqlType - value from java.sql.Types.
Returns:
the corresponding attribute type (BOOLEAN, NUMERIC, TEXT, DATETIME, MULTI_VALUED, or USER_DEFINED).

getColumnInfo

public static ColumnSizes.ColumnInfo getColumnInfo(Connection con,
                                                   String table,
                                                   String column)
                                            throws SQLException
Deprecated. 
Get the ColumnInfo for the specified column.

If the column information is not found in the cache, it will be loaded (see class comments for details on how it is loaded).

Parameters:
con - the connection to use, null to not.
table - the table name.
column - the column name.
Returns:
the ColumnInfo or null if the column doesn't exist.
Throws:
SQLException - if the information cannot be loaded.

getTypeName

public static String getTypeName(int type)
Deprecated. 
Get the default descriptive type name.


truncate

public static Object truncate(Object in,
                              Connection con,
                              String table,
                              String column)
Deprecated. 
Truncate the specified object to the size of the specified table/column.


truncate

public static String truncate(String in,
                              Connection con,
                              String table,
                              String column)
Deprecated. 
Truncate the specified String to the size of the specified table/column.

See Also:
truncate(java.lang.Object, java.sql.Connection, java.lang.String, java.lang.String)

© 2005 BEA Systems, Inc.

Copyright © 2005 BEA Systems, Inc. All Rights Reserved