001: /**
002: * Objective Database Abstraction Layer (ODAL)
003: * Copyright (c) 2004, The ODAL Development Group
004: * All rights reserved.
005: * For definition of the ODAL Development Group please refer to LICENCE.txt file
006: *
007: * Distributable under LGPL license.
008: * See terms of license at gnu.org.
009: */package com.completex.objective.components.persistency.type;
010:
011: import com.completex.objective.components.persistency.PersistentObject;
012: import com.completex.objective.components.persistency.ColumnType;
013: import com.completex.objective.components.persistency.OdalPersistencyException;
014: import com.completex.objective.components.persistency.core.DatabasePolicy;
015:
016: import java.sql.CallableStatement;
017: import java.sql.PreparedStatement;
018: import java.sql.ResultSet;
019: import java.sql.SQLException;
020:
021: /**
022: * Class to handle database reads and binds
023: *
024: * @author Gennady Krizhevsky
025: */
026: public interface TypeHandler {
027:
028: final static int DEFAULT_CHUNK_SIZE = 2048;
029:
030: final static byte[] MINIMAL_BYTE_ARRAY = new byte[1];
031: final static String MINIMAL_CLOB_STRING = " ";
032:
033: /**
034: * Defines how to extract value from ResultSet by column index
035: *
036: * @param resultSet ResultSet
037: * @param jdbcColIndex 1-based ResultSet column index
038: * @param databasePolicy database policy
039: * @return a <code>java.lang.Object</code> holding the column value
040: * @throws SQLException
041: * @see DatabasePolicy
042: */
043: Object handleRead(ResultSet resultSet, int jdbcColIndex,
044: DatabasePolicy databasePolicy) throws SQLException;
045:
046: /**
047: * Defines how to extract value from ResultSet by column name
048: *
049: * @param resultSet
050: * @param columnName ResultSet column name
051: * @param databasePolicy database policy
052: * @return a <code>java.lang.Object</code> holding the column value
053: * @throws SQLException
054: * @see DatabasePolicy
055: */
056: Object handleRead(ResultSet resultSet, String columnName,
057: DatabasePolicy databasePolicy) throws SQLException;
058:
059: /**
060: * Defines how to bind values for column of specific type. It is used for not null values only
061: *
062: * @param statement PreparedStatement
063: * @param parameterIndex 1-based binding index
064: * @param value value to bind
065: * @throws SQLException
066: */
067: void handleBind(PreparedStatement statement, int parameterIndex,
068: Object value) throws SQLException;
069:
070: /**
071: * Defines how to bind values of PersistentObject in update/insert operations. It is used for not null values only
072: *
073: * @param statement PreparedStatement
074: * @param jdbcColIndex 1-based binding index
075: * @param value value to bind
076: * @param databasePolicy database policy
077: * @param postProcessings post processings used for LOBs for example
078: * @param persistentObject object being persisted
079: * @param columnIndex column index in persistentObject
080: * @throws SQLException
081: * @see CallableStatement
082: * @see DatabasePolicy
083: * @see LobPostProcessings
084: */
085: void handleBind(PreparedStatement statement, int jdbcColIndex,
086: Object value, DatabasePolicy databasePolicy,
087: LobPostProcessings postProcessings,
088: PersistentObject persistentObject, int columnIndex)
089: throws SQLException;
090:
091: /**
092: * Defines how to extract OUT parameter from CallableStatement by parameter index
093: *
094: * @param statement CallableStatement
095: * @param parameterIndex 1-based out parameter index
096: * @param databasePolicy database policy
097: * @return out parameter value
098: * @throws SQLException
099: */
100: Object handleOutParamRead(CallableStatement statement,
101: int parameterIndex, DatabasePolicy databasePolicy)
102: throws SQLException;
103:
104: /**
105: * Defines how to extract OUT parameter from CallableStatement by parameter name
106: *
107: * @param statement CallableStatement
108: * @param parameterName the name of the parameter
109: * @param databasePolicy database policy
110: * @return out parameter value
111: * @throws SQLException
112: * @see CallableStatement
113: * @see DatabasePolicy
114: */
115: Object handleOutParamRead(CallableStatement statement,
116: String parameterName, DatabasePolicy databasePolicy)
117: throws SQLException;
118:
119: /**
120: * Used for binding null values in PreparedStatement
121: *
122: * @param statement PreparedStatement
123: * @param parameterIndex 1-based binding index
124: * @param columnType column type
125: * @param columnIdentifier string identifying the column. It is used in error message if bind fails
126: */
127: void handleBindNull(PreparedStatement statement,
128: int parameterIndex, ColumnType columnType,
129: String columnIdentifier) throws OdalPersistencyException;
130:
131: /**
132: * Returns true if update has to be done as 2-step bynary update:
133: * 1st step - saving a minimal size byte array,
134: * 2nd step - retrieving the binary object and update it through its stream
135: *
136: * @param databasePolicy
137: * @return true if update has to be done as 2-step bynary update:
138: * 1st step - saving a minimal size byte array,
139: * 2nd step - retrieving the binary object and update it through its stream
140: */
141: boolean useTwoStepBinaryUpdate(DatabasePolicy databasePolicy);
142: }
|