De-DOS'd these files, from Dave Hoover.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2122 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -1,234 +1,234 @@
|
|||||||
//
|
//
|
||||||
// $Id$
|
// $Id$
|
||||||
//
|
//
|
||||||
// samskivert library - useful routines for java programs
|
// samskivert library - useful routines for java programs
|
||||||
// Copyright (C) 2001-6 Konstantin Knizhnik, Michael Bayne
|
// Copyright (C) 2001-6 Konstantin Knizhnik, Michael Bayne
|
||||||
//
|
//
|
||||||
// This library is free software; you can redistribute it and/or modify it
|
// This library is free software; you can redistribute it and/or modify it
|
||||||
// under the terms of the GNU Lesser General Public License as published
|
// under the terms of the GNU Lesser General Public License as published
|
||||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// This library is distributed in the hope that it will be useful,
|
// This library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
// Lesser General Public License for more details.
|
// Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
// License along with this library; if not, write to the Free Software
|
// License along with this library; if not, write to the Free Software
|
||||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
package com.samskivert.jdbc.jora;
|
package com.samskivert.jdbc.jora;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
|
|
||||||
import com.samskivert.Log;
|
import com.samskivert.Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cursor is used for successive access to records fetched by SELECT statement.
|
* Cursor is used for successive access to records fetched by SELECT statement.
|
||||||
* As far as records can be retrived from several derived tables (polymorphic
|
* As far as records can be retrived from several derived tables (polymorphic
|
||||||
* form of select), this class can issue several requests to database. Cursor
|
* form of select), this class can issue several requests to database. Cursor
|
||||||
* also provides methods for updating/deleting current record.
|
* also provides methods for updating/deleting current record.
|
||||||
*/
|
*/
|
||||||
public class Cursor<V>
|
public class Cursor<V>
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* A cursor is initially positioned before its first row; the first call to
|
* A cursor is initially positioned before its first row; the first call to
|
||||||
* next makes the first row the current row; the second call makes the
|
* next makes the first row the current row; the second call makes the
|
||||||
* second row the current row, etc.
|
* second row the current row, etc.
|
||||||
*
|
*
|
||||||
* <P> If an input stream from the previous row is open, it is implicitly
|
* <P> If an input stream from the previous row is open, it is implicitly
|
||||||
* closed. The ResultSet's warning chain is cleared when a new row is read.
|
* closed. The ResultSet's warning chain is cleared when a new row is read.
|
||||||
*
|
*
|
||||||
* @return object constructed from fetched record or null if there are no
|
* @return object constructed from fetched record or null if there are no
|
||||||
* more rows
|
* more rows
|
||||||
*/
|
*/
|
||||||
public V next ()
|
public V next ()
|
||||||
throws SQLException
|
throws SQLException
|
||||||
{
|
{
|
||||||
// if we closed everything up after the last call to next(),
|
// if we closed everything up after the last call to next(),
|
||||||
// table will be null here and we should bail immediately
|
// table will be null here and we should bail immediately
|
||||||
if (_table == null) {
|
if (_table == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_result == null) {
|
if (_result == null) {
|
||||||
if (_qbeObject != null) {
|
if (_qbeObject != null) {
|
||||||
PreparedStatement qbeStmt = _conn.prepareStatement(_query);
|
PreparedStatement qbeStmt = _conn.prepareStatement(_query);
|
||||||
_table.bindQueryVariables(qbeStmt, _qbeObject, _qbeMask);
|
_table.bindQueryVariables(qbeStmt, _qbeObject, _qbeMask);
|
||||||
_result = qbeStmt.executeQuery();
|
_result = qbeStmt.executeQuery();
|
||||||
_stmt = qbeStmt;
|
_stmt = qbeStmt;
|
||||||
} else {
|
} else {
|
||||||
if (_stmt == null) {
|
if (_stmt == null) {
|
||||||
_stmt = _conn.createStatement();
|
_stmt = _conn.createStatement();
|
||||||
}
|
}
|
||||||
_result = _stmt.executeQuery(_query);
|
_result = _stmt.executeQuery(_query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (_result.next()) {
|
if (_result.next()) {
|
||||||
return _currObject = _table.load(_result);
|
return _currObject = _table.load(_result);
|
||||||
}
|
}
|
||||||
|
|
||||||
_result.close();
|
_result.close();
|
||||||
_result = null;
|
_result = null;
|
||||||
_currObject = null;
|
_currObject = null;
|
||||||
_table = null;
|
_table = null;
|
||||||
|
|
||||||
if (_stmt != null) {
|
if (_stmt != null) {
|
||||||
_stmt.close();
|
_stmt.close();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the first element matched by this cursor or null if no elements
|
* Returns the first element matched by this cursor or null if no elements
|
||||||
* were matched. Checks to ensure that no subsequent elements were matched
|
* were matched. Checks to ensure that no subsequent elements were matched
|
||||||
* by the query, logs a warning if there were spurious additional matches.
|
* by the query, logs a warning if there were spurious additional matches.
|
||||||
*/
|
*/
|
||||||
public V get ()
|
public V get ()
|
||||||
throws SQLException
|
throws SQLException
|
||||||
{
|
{
|
||||||
V result = next();
|
V result = next();
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
int spurious = 0;
|
int spurious = 0;
|
||||||
while (next() != null) {
|
while (next() != null) {
|
||||||
spurious++;
|
spurious++;
|
||||||
}
|
}
|
||||||
if (spurious > 0) {
|
if (spurious > 0) {
|
||||||
Log.warning("Cursor.get() quietly tossed " + spurious +
|
Log.warning("Cursor.get() quietly tossed " + spurious +
|
||||||
" spurious additional records. " +
|
" spurious additional records. " +
|
||||||
"[query=" + _query + "].");
|
"[query=" + _query + "].");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update current record pointed by cursor. This method can be called only
|
* Update current record pointed by cursor. This method can be called only
|
||||||
* after next() method, which returns non-null object. This objects is used
|
* after next() method, which returns non-null object. This objects is used
|
||||||
* to update current record fields.
|
* to update current record fields.
|
||||||
*
|
*
|
||||||
* <P> If you are going to update or delete selected records, you should
|
* <P> If you are going to update or delete selected records, you should
|
||||||
* add "for update" clause to select statement. So parameter of
|
* add "for update" clause to select statement. So parameter of
|
||||||
* <CODE>jora.Table.select()</CODE> statement should contain "for update"
|
* <CODE>jora.Table.select()</CODE> statement should contain "for update"
|
||||||
* clause: <CODE>record.table.Select("where name='xyz' for
|
* clause: <CODE>record.table.Select("where name='xyz' for
|
||||||
* update");</CODE><P>
|
* update");</CODE><P>
|
||||||
*
|
*
|
||||||
* <I><B>Attention!</I></B> Not all database drivers support update
|
* <I><B>Attention!</I></B> Not all database drivers support update
|
||||||
* operation with cursor. This method will not work with such database
|
* operation with cursor. This method will not work with such database
|
||||||
* drivers.
|
* drivers.
|
||||||
*/
|
*/
|
||||||
public void update ()
|
public void update ()
|
||||||
throws SQLException
|
throws SQLException
|
||||||
{
|
{
|
||||||
if (_currObject == null) {
|
if (_currObject == null) {
|
||||||
throw new IllegalStateException("No current object");
|
throw new IllegalStateException("No current object");
|
||||||
}
|
}
|
||||||
_table.updateVariables(_result, _currObject);
|
_table.updateVariables(_result, _currObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete current record pointed by cursor. This method can be called only
|
* Delete current record pointed by cursor. This method can be called only
|
||||||
* after next() method, which returns non-null object.
|
* after next() method, which returns non-null object.
|
||||||
*
|
*
|
||||||
* <P> If you are going to update or delete selected records, you should
|
* <P> If you are going to update or delete selected records, you should
|
||||||
* add "for update" clause to select statement. So parameter of
|
* add "for update" clause to select statement. So parameter of
|
||||||
* <CODE>jora.Table.select()</CODE> statement should contain "for update"
|
* <CODE>jora.Table.select()</CODE> statement should contain "for update"
|
||||||
* clause: <CODE>record.table.Select("where name='xyz' for
|
* clause: <CODE>record.table.Select("where name='xyz' for
|
||||||
* update");</CODE><P>
|
* update");</CODE><P>
|
||||||
*
|
*
|
||||||
* <I><B>Attention!</I></B> Not all database drivers support delete
|
* <I><B>Attention!</I></B> Not all database drivers support delete
|
||||||
* operation with cursor. This method will not work with such database
|
* operation with cursor. This method will not work with such database
|
||||||
* drivers.
|
* drivers.
|
||||||
*/
|
*/
|
||||||
public void delete ()
|
public void delete ()
|
||||||
throws SQLException
|
throws SQLException
|
||||||
{
|
{
|
||||||
if (_currObject == null) {
|
if (_currObject == null) {
|
||||||
throw new IllegalStateException("No current object");
|
throw new IllegalStateException("No current object");
|
||||||
}
|
}
|
||||||
_result.deleteRow();
|
_result.deleteRow();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Close the Cursor, even if we haven't read all the possible objects.
|
* Close the Cursor, even if we haven't read all the possible objects.
|
||||||
*/
|
*/
|
||||||
public void close ()
|
public void close ()
|
||||||
throws SQLException
|
throws SQLException
|
||||||
{
|
{
|
||||||
if (_result != null) {
|
if (_result != null) {
|
||||||
_result.close();
|
_result.close();
|
||||||
_result = null;
|
_result = null;
|
||||||
}
|
}
|
||||||
if (_stmt != null) {
|
if (_stmt != null) {
|
||||||
_stmt.close();
|
_stmt.close();
|
||||||
_stmt = null;
|
_stmt = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts no more than <I>maxElements</I> records from database and store
|
* Extracts no more than <I>maxElements</I> records from database and store
|
||||||
* them into array. It is possible to extract rest records by successive
|
* them into array. It is possible to extract rest records by successive
|
||||||
* next() or toArray() calls. Selected objects should have now components
|
* next() or toArray() calls. Selected objects should have now components
|
||||||
* of InputStream, Blob or Clob type, because their data will be not
|
* of InputStream, Blob or Clob type, because their data will be not
|
||||||
* available after fetching next record.
|
* available after fetching next record.
|
||||||
*
|
*
|
||||||
* @param maxElements limitation for result array size (and also for number
|
* @param maxElements limitation for result array size (and also for number
|
||||||
* of fetched records)
|
* of fetched records)
|
||||||
* @return List with objects constructed from fetched records.
|
* @return List with objects constructed from fetched records.
|
||||||
*/
|
*/
|
||||||
public ArrayList<V> toArrayList (int maxElements)
|
public ArrayList<V> toArrayList (int maxElements)
|
||||||
throws SQLException
|
throws SQLException
|
||||||
{
|
{
|
||||||
ArrayList<V> al = new ArrayList<V>(Math.min(maxElements, 100));
|
ArrayList<V> al = new ArrayList<V>(Math.min(maxElements, 100));
|
||||||
V o;
|
V o;
|
||||||
while (--maxElements >= 0 && (o = next()) != null) {
|
while (--maxElements >= 0 && (o = next()) != null) {
|
||||||
al.add(o);
|
al.add(o);
|
||||||
}
|
}
|
||||||
return al;
|
return al;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store all objects returned by SELECT query into a list of Object.
|
* Store all objects returned by SELECT query into a list of Object.
|
||||||
* Selected objects should have now components of InputStream, Blob or Clob
|
* Selected objects should have now components of InputStream, Blob or Clob
|
||||||
* type, because their data will be not available after fetching next
|
* type, because their data will be not available after fetching next
|
||||||
* record.
|
* record.
|
||||||
*
|
*
|
||||||
* @return Array with objects constructed from fetched records.
|
* @return Array with objects constructed from fetched records.
|
||||||
*/
|
*/
|
||||||
public ArrayList<V> toArrayList ()
|
public ArrayList<V> toArrayList ()
|
||||||
throws SQLException
|
throws SQLException
|
||||||
{
|
{
|
||||||
return toArrayList(Integer.MAX_VALUE);
|
return toArrayList(Integer.MAX_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Cursor (Table<V> table, Connection conn, String query)
|
protected Cursor (Table<V> table, Connection conn, String query)
|
||||||
{
|
{
|
||||||
_table = table;
|
_table = table;
|
||||||
_conn = conn;
|
_conn = conn;
|
||||||
_query = query;
|
_query = query;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Cursor (Table<V> table, Connection conn, V obj,
|
protected Cursor (Table<V> table, Connection conn, V obj,
|
||||||
FieldMask mask, boolean like)
|
FieldMask mask, boolean like)
|
||||||
{
|
{
|
||||||
_table = table;
|
_table = table;
|
||||||
_conn = conn;
|
_conn = conn;
|
||||||
_like = like;
|
_like = like;
|
||||||
_qbeObject = obj;
|
_qbeObject = obj;
|
||||||
_qbeMask = mask;
|
_qbeMask = mask;
|
||||||
_query = table.buildQueryList(obj, mask, like);
|
_query = table.buildQueryList(obj, mask, like);
|
||||||
_stmt = null;
|
_stmt = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Table<V> _table;
|
protected Table<V> _table;
|
||||||
protected Connection _conn;
|
protected Connection _conn;
|
||||||
protected ResultSet _result;
|
protected ResultSet _result;
|
||||||
protected String _query;
|
protected String _query;
|
||||||
protected Statement _stmt;
|
protected Statement _stmt;
|
||||||
protected V _currObject, _qbeObject;
|
protected V _currObject, _qbeObject;
|
||||||
protected FieldMask _qbeMask;
|
protected FieldMask _qbeMask;
|
||||||
protected boolean _like;
|
protected boolean _like;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,451 +1,451 @@
|
|||||||
//
|
//
|
||||||
// $Id$
|
// $Id$
|
||||||
//
|
//
|
||||||
// samskivert library - useful routines for java programs
|
// samskivert library - useful routines for java programs
|
||||||
// Copyright (C) 2001-6 Konstantin Knizhnik, Michael Bayne
|
// Copyright (C) 2001-6 Konstantin Knizhnik, Michael Bayne
|
||||||
//
|
//
|
||||||
// This library is free software; you can redistribute it and/or modify it
|
// This library is free software; you can redistribute it and/or modify it
|
||||||
// under the terms of the GNU Lesser General Public License as published
|
// under the terms of the GNU Lesser General Public License as published
|
||||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// This library is distributed in the hope that it will be useful,
|
// This library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
// Lesser General Public License for more details.
|
// Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
// License along with this library; if not, write to the Free Software
|
// License along with this library; if not, write to the Free Software
|
||||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
package com.samskivert.jdbc.jora;
|
package com.samskivert.jdbc.jora;
|
||||||
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.math.*;
|
import java.math.*;
|
||||||
import java.lang.reflect.*;
|
import java.lang.reflect.*;
|
||||||
|
|
||||||
class FieldDescriptor
|
class FieldDescriptor
|
||||||
{
|
{
|
||||||
protected FieldDescriptor (Field field, String name)
|
protected FieldDescriptor (Field field, String name)
|
||||||
{
|
{
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.field = field;
|
this.field = field;
|
||||||
this.scale = -1;
|
this.scale = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final boolean isAtomic ()
|
protected final boolean isAtomic ()
|
||||||
{
|
{
|
||||||
return inType < tClosure;
|
return inType < tClosure;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final boolean isCompound ()
|
protected final boolean isCompound ()
|
||||||
{
|
{
|
||||||
return inType >= tCompound;
|
return inType >= tCompound;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final boolean isBuiltin ()
|
protected final boolean isBuiltin ()
|
||||||
{
|
{
|
||||||
return inType <= t_boolean;
|
return inType <= t_boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final boolean bindVariable (
|
protected final boolean bindVariable (
|
||||||
PreparedStatement pstmt, Object obj, int column)
|
PreparedStatement pstmt, Object obj, int column)
|
||||||
throws SQLException
|
throws SQLException
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
switch (outType) {
|
switch (outType) {
|
||||||
case t_byte:
|
case t_byte:
|
||||||
pstmt.setByte(column, field.getByte(obj));
|
pstmt.setByte(column, field.getByte(obj));
|
||||||
break;
|
break;
|
||||||
case t_short:
|
case t_short:
|
||||||
pstmt.setShort(column, field.getShort(obj));
|
pstmt.setShort(column, field.getShort(obj));
|
||||||
break;
|
break;
|
||||||
case t_int:
|
case t_int:
|
||||||
pstmt.setInt(column, field.getInt(obj));
|
pstmt.setInt(column, field.getInt(obj));
|
||||||
break;
|
break;
|
||||||
case t_long:
|
case t_long:
|
||||||
pstmt.setLong(column, field.getLong(obj));
|
pstmt.setLong(column, field.getLong(obj));
|
||||||
break;
|
break;
|
||||||
case t_float:
|
case t_float:
|
||||||
pstmt.setFloat(column, field.getFloat(obj));
|
pstmt.setFloat(column, field.getFloat(obj));
|
||||||
break;
|
break;
|
||||||
case t_double:
|
case t_double:
|
||||||
pstmt.setDouble(column, field.getDouble(obj));
|
pstmt.setDouble(column, field.getDouble(obj));
|
||||||
break;
|
break;
|
||||||
case t_boolean:
|
case t_boolean:
|
||||||
pstmt.setBoolean(column, field.getBoolean(obj));
|
pstmt.setBoolean(column, field.getBoolean(obj));
|
||||||
break;
|
break;
|
||||||
case tByte:
|
case tByte:
|
||||||
pstmt.setByte(column, ((Byte)field.get(obj)).byteValue());
|
pstmt.setByte(column, ((Byte)field.get(obj)).byteValue());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case tShort:
|
case tShort:
|
||||||
pstmt.setShort(column, ((Short)field.get(obj)).shortValue());
|
pstmt.setShort(column, ((Short)field.get(obj)).shortValue());
|
||||||
break;
|
break;
|
||||||
case tInteger:
|
case tInteger:
|
||||||
pstmt.setInt(column, ((Integer)field.get(obj)).intValue());
|
pstmt.setInt(column, ((Integer)field.get(obj)).intValue());
|
||||||
break;
|
break;
|
||||||
case tLong:
|
case tLong:
|
||||||
pstmt.setLong(column, ((Long)field.get(obj)).longValue());
|
pstmt.setLong(column, ((Long)field.get(obj)).longValue());
|
||||||
break;
|
break;
|
||||||
case tFloat:
|
case tFloat:
|
||||||
pstmt.setFloat(column, ((Float)field.get(obj)).floatValue());
|
pstmt.setFloat(column, ((Float)field.get(obj)).floatValue());
|
||||||
break;
|
break;
|
||||||
case tDouble:
|
case tDouble:
|
||||||
pstmt.setDouble(column,((Double)field.get(obj)).doubleValue());
|
pstmt.setDouble(column,((Double)field.get(obj)).doubleValue());
|
||||||
break;
|
break;
|
||||||
case tBoolean:
|
case tBoolean:
|
||||||
pstmt.setBoolean(column,
|
pstmt.setBoolean(column,
|
||||||
((Boolean)field.get(obj)).booleanValue());
|
((Boolean)field.get(obj)).booleanValue());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case tDecimal:
|
case tDecimal:
|
||||||
pstmt.setBigDecimal(column, (BigDecimal)field.get(obj));
|
pstmt.setBigDecimal(column, (BigDecimal)field.get(obj));
|
||||||
break;
|
break;
|
||||||
case tString:
|
case tString:
|
||||||
pstmt.setString(column, (String)field.get(obj));
|
pstmt.setString(column, (String)field.get(obj));
|
||||||
break;
|
break;
|
||||||
case tBytes:
|
case tBytes:
|
||||||
pstmt.setBytes(column, (byte[])field.get(obj));
|
pstmt.setBytes(column, (byte[])field.get(obj));
|
||||||
break;
|
break;
|
||||||
case tDate:
|
case tDate:
|
||||||
pstmt.setDate(column, (java.sql.Date)field.get(obj));
|
pstmt.setDate(column, (java.sql.Date)field.get(obj));
|
||||||
break;
|
break;
|
||||||
case tTime:
|
case tTime:
|
||||||
pstmt.setTime(column, (java.sql.Time)field.get(obj));
|
pstmt.setTime(column, (java.sql.Time)field.get(obj));
|
||||||
break;
|
break;
|
||||||
case tTimestamp:
|
case tTimestamp:
|
||||||
pstmt.setTimestamp(column, (java.sql.Timestamp)field.get(obj));
|
pstmt.setTimestamp(column, (java.sql.Timestamp)field.get(obj));
|
||||||
break;
|
break;
|
||||||
case tStream:
|
case tStream:
|
||||||
java.io.InputStream in = (java.io.InputStream)field.get(obj);
|
java.io.InputStream in = (java.io.InputStream)field.get(obj);
|
||||||
pstmt.setBinaryStream(column, in, in.available());
|
pstmt.setBinaryStream(column, in, in.available());
|
||||||
break;
|
break;
|
||||||
case tBlob:
|
case tBlob:
|
||||||
pstmt.setBlob(column, (Blob)field.get(obj));
|
pstmt.setBlob(column, (Blob)field.get(obj));
|
||||||
break;
|
break;
|
||||||
case tClob:
|
case tClob:
|
||||||
pstmt.setClob(column, (Clob)field.get(obj));
|
pstmt.setClob(column, (Clob)field.get(obj));
|
||||||
break;
|
break;
|
||||||
case tAsString:
|
case tAsString:
|
||||||
pstmt.setString(column, field.get(obj).toString());
|
pstmt.setString(column, field.get(obj).toString());
|
||||||
break;
|
break;
|
||||||
case tClosure:
|
case tClosure:
|
||||||
// There is no reason to use piped streams because
|
// There is no reason to use piped streams because
|
||||||
// we need to pass total number of bytes to JDBC driver
|
// we need to pass total number of bytes to JDBC driver
|
||||||
java.io.ByteArrayOutputStream out =
|
java.io.ByteArrayOutputStream out =
|
||||||
new java.io.ByteArrayOutputStream();
|
new java.io.ByteArrayOutputStream();
|
||||||
java.io.ObjectOutputStream clu =
|
java.io.ObjectOutputStream clu =
|
||||||
new java.io.ObjectOutputStream(out);
|
new java.io.ObjectOutputStream(out);
|
||||||
clu.writeObject(field.get(obj));
|
clu.writeObject(field.get(obj));
|
||||||
clu.close();
|
clu.close();
|
||||||
pstmt.setBytes(column, out.toByteArray());
|
pstmt.setBytes(column, out.toByteArray());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch(SQLException ex) {
|
} catch(SQLException ex) {
|
||||||
if (outType != tClosure && outType != tAsString) {
|
if (outType != tClosure && outType != tAsString) {
|
||||||
outType = tAsString;
|
outType = tAsString;
|
||||||
return bindVariable(pstmt, obj, column);
|
return bindVariable(pstmt, obj, column);
|
||||||
} else {
|
} else {
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
} catch(IllegalAccessException ex) {
|
} catch(IllegalAccessException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
throw new IllegalAccessError();
|
throw new IllegalAccessError();
|
||||||
} catch(java.io.IOException ex) {
|
} catch(java.io.IOException ex) {
|
||||||
throw new DataTransferError(ex);
|
throw new DataTransferError(ex);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final boolean updateVariable (
|
protected final boolean updateVariable (
|
||||||
ResultSet result, Object obj, int column)
|
ResultSet result, Object obj, int column)
|
||||||
throws SQLException
|
throws SQLException
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
switch (outType) {
|
switch (outType) {
|
||||||
case t_byte:
|
case t_byte:
|
||||||
result.updateByte(column, field.getByte(obj));
|
result.updateByte(column, field.getByte(obj));
|
||||||
break;
|
break;
|
||||||
case t_short:
|
case t_short:
|
||||||
result.updateShort(column, field.getShort(obj));
|
result.updateShort(column, field.getShort(obj));
|
||||||
break;
|
break;
|
||||||
case t_int:
|
case t_int:
|
||||||
result.updateInt(column, field.getInt(obj));
|
result.updateInt(column, field.getInt(obj));
|
||||||
break;
|
break;
|
||||||
case t_long:
|
case t_long:
|
||||||
result.updateLong(column, field.getLong(obj));
|
result.updateLong(column, field.getLong(obj));
|
||||||
break;
|
break;
|
||||||
case t_float:
|
case t_float:
|
||||||
result.updateFloat(column, field.getFloat(obj));
|
result.updateFloat(column, field.getFloat(obj));
|
||||||
break;
|
break;
|
||||||
case t_double:
|
case t_double:
|
||||||
result.updateDouble(column, field.getDouble(obj));
|
result.updateDouble(column, field.getDouble(obj));
|
||||||
break;
|
break;
|
||||||
case t_boolean:
|
case t_boolean:
|
||||||
result.updateBoolean(column, field.getBoolean(obj));
|
result.updateBoolean(column, field.getBoolean(obj));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case tByte:
|
case tByte:
|
||||||
result.updateByte(column, ((Byte)field.get(obj)).byteValue());
|
result.updateByte(column, ((Byte)field.get(obj)).byteValue());
|
||||||
break;
|
break;
|
||||||
case tShort:
|
case tShort:
|
||||||
result.updateShort(column,
|
result.updateShort(column,
|
||||||
((Short)field.get(obj)).shortValue());
|
((Short)field.get(obj)).shortValue());
|
||||||
break;
|
break;
|
||||||
case tInteger:
|
case tInteger:
|
||||||
result.updateInt(column, ((Integer)field.get(obj)).intValue());
|
result.updateInt(column, ((Integer)field.get(obj)).intValue());
|
||||||
break;
|
break;
|
||||||
case tLong:
|
case tLong:
|
||||||
result.updateLong(column, ((Long)field.get(obj)).longValue());
|
result.updateLong(column, ((Long)field.get(obj)).longValue());
|
||||||
break;
|
break;
|
||||||
case tFloat:
|
case tFloat:
|
||||||
result.updateFloat(column,
|
result.updateFloat(column,
|
||||||
((Float)field.get(obj)).floatValue());
|
((Float)field.get(obj)).floatValue());
|
||||||
break;
|
break;
|
||||||
case tDouble:
|
case tDouble:
|
||||||
result.updateDouble(column,
|
result.updateDouble(column,
|
||||||
((Double)field.get(obj)).doubleValue());
|
((Double)field.get(obj)).doubleValue());
|
||||||
break;
|
break;
|
||||||
case tBoolean:
|
case tBoolean:
|
||||||
result.updateBoolean(column,
|
result.updateBoolean(column,
|
||||||
((Boolean)field.get(obj)).booleanValue());
|
((Boolean)field.get(obj)).booleanValue());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case tDecimal:
|
case tDecimal:
|
||||||
result.updateBigDecimal(column, (BigDecimal)field.get(obj));
|
result.updateBigDecimal(column, (BigDecimal)field.get(obj));
|
||||||
break;
|
break;
|
||||||
case tString:
|
case tString:
|
||||||
result.updateString(column, (String)field.get(obj));
|
result.updateString(column, (String)field.get(obj));
|
||||||
break;
|
break;
|
||||||
case tBytes:
|
case tBytes:
|
||||||
result.updateBytes(column, (byte[])field.get(obj));
|
result.updateBytes(column, (byte[])field.get(obj));
|
||||||
break;
|
break;
|
||||||
case tDate:
|
case tDate:
|
||||||
result.updateDate(column, (java.sql.Date)field.get(obj));
|
result.updateDate(column, (java.sql.Date)field.get(obj));
|
||||||
break;
|
break;
|
||||||
case tTime:
|
case tTime:
|
||||||
result.updateTime(column, (java.sql.Time)field.get(obj));
|
result.updateTime(column, (java.sql.Time)field.get(obj));
|
||||||
break;
|
break;
|
||||||
case tTimestamp:
|
case tTimestamp:
|
||||||
result.updateTimestamp(column,
|
result.updateTimestamp(column,
|
||||||
(java.sql.Timestamp)field.get(obj));
|
(java.sql.Timestamp)field.get(obj));
|
||||||
break;
|
break;
|
||||||
case tStream:
|
case tStream:
|
||||||
java.io.InputStream in = (java.io.InputStream)field.get(obj);
|
java.io.InputStream in = (java.io.InputStream)field.get(obj);
|
||||||
result.updateBinaryStream(column, in, in.available());
|
result.updateBinaryStream(column, in, in.available());
|
||||||
break;
|
break;
|
||||||
case tBlob:
|
case tBlob:
|
||||||
Blob blob = (Blob)field.get(obj);
|
Blob blob = (Blob)field.get(obj);
|
||||||
result.updateBinaryStream(column,
|
result.updateBinaryStream(column,
|
||||||
blob.getBinaryStream(),
|
blob.getBinaryStream(),
|
||||||
(int)blob.length());
|
(int)blob.length());
|
||||||
break;
|
break;
|
||||||
case tClob:
|
case tClob:
|
||||||
Clob clob = (Clob)field.get(obj);
|
Clob clob = (Clob)field.get(obj);
|
||||||
result.updateCharacterStream(column,
|
result.updateCharacterStream(column,
|
||||||
clob.getCharacterStream(),
|
clob.getCharacterStream(),
|
||||||
(int)clob.length());
|
(int)clob.length());
|
||||||
break;
|
break;
|
||||||
case tAsString:
|
case tAsString:
|
||||||
result.updateString(column, field.get(obj).toString());
|
result.updateString(column, field.get(obj).toString());
|
||||||
break;
|
break;
|
||||||
case tClosure:
|
case tClosure:
|
||||||
// There is no reason to use piped streams because
|
// There is no reason to use piped streams because
|
||||||
// we need to pass total number of bytes to JDBC driver
|
// we need to pass total number of bytes to JDBC driver
|
||||||
java.io.ByteArrayOutputStream out =
|
java.io.ByteArrayOutputStream out =
|
||||||
new java.io.ByteArrayOutputStream();
|
new java.io.ByteArrayOutputStream();
|
||||||
java.io.ObjectOutputStream clu =
|
java.io.ObjectOutputStream clu =
|
||||||
new java.io.ObjectOutputStream(out);
|
new java.io.ObjectOutputStream(out);
|
||||||
clu.writeObject(field.get(obj));
|
clu.writeObject(field.get(obj));
|
||||||
clu.close();
|
clu.close();
|
||||||
result.updateBytes(column, out.toByteArray());
|
result.updateBytes(column, out.toByteArray());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch(SQLException ex) {
|
} catch(SQLException ex) {
|
||||||
if (outType != tClosure && outType != tAsString) {
|
if (outType != tClosure && outType != tAsString) {
|
||||||
outType = tAsString;
|
outType = tAsString;
|
||||||
return updateVariable(result, obj, column);
|
return updateVariable(result, obj, column);
|
||||||
} else {
|
} else {
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
} catch(IllegalAccessException ex) {
|
} catch(IllegalAccessException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
throw new IllegalAccessError();
|
throw new IllegalAccessError();
|
||||||
} catch(java.io.IOException ex) {
|
} catch(java.io.IOException ex) {
|
||||||
throw new DataTransferError(ex);
|
throw new DataTransferError(ex);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final boolean loadVariable (
|
protected final boolean loadVariable (
|
||||||
ResultSet result, Object obj, int column)
|
ResultSet result, Object obj, int column)
|
||||||
throws SQLException, IllegalAccessException
|
throws SQLException, IllegalAccessException
|
||||||
{
|
{
|
||||||
switch (inType) {
|
switch (inType) {
|
||||||
case t_byte:
|
case t_byte:
|
||||||
field.setByte(obj, result.getByte(column));
|
field.setByte(obj, result.getByte(column));
|
||||||
break;
|
break;
|
||||||
case t_short:
|
case t_short:
|
||||||
field.setShort(obj, result.getShort(column));
|
field.setShort(obj, result.getShort(column));
|
||||||
break;
|
break;
|
||||||
case t_int:
|
case t_int:
|
||||||
field.setInt(obj, result.getInt(column));
|
field.setInt(obj, result.getInt(column));
|
||||||
break;
|
break;
|
||||||
case t_long:
|
case t_long:
|
||||||
field.setLong(obj, result.getLong(column));
|
field.setLong(obj, result.getLong(column));
|
||||||
break;
|
break;
|
||||||
case t_float:
|
case t_float:
|
||||||
field.setFloat(obj, result.getFloat(column));
|
field.setFloat(obj, result.getFloat(column));
|
||||||
break;
|
break;
|
||||||
case t_double:
|
case t_double:
|
||||||
field.setDouble(obj, result.getDouble(column));
|
field.setDouble(obj, result.getDouble(column));
|
||||||
break;
|
break;
|
||||||
case t_boolean:
|
case t_boolean:
|
||||||
field.setBoolean(obj, result.getBoolean(column));
|
field.setBoolean(obj, result.getBoolean(column));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case tByte:
|
case tByte:
|
||||||
byte b = result.getByte(column);
|
byte b = result.getByte(column);
|
||||||
field.set(obj, result.wasNull() ? null : Byte.valueOf(b));
|
field.set(obj, result.wasNull() ? null : Byte.valueOf(b));
|
||||||
break;
|
break;
|
||||||
case tShort:
|
case tShort:
|
||||||
short s = result.getShort(column);
|
short s = result.getShort(column);
|
||||||
field.set(obj, result.wasNull() ? null : Short.valueOf(s));
|
field.set(obj, result.wasNull() ? null : Short.valueOf(s));
|
||||||
break;
|
break;
|
||||||
case tInteger:
|
case tInteger:
|
||||||
int i = result.getInt(column);
|
int i = result.getInt(column);
|
||||||
field.set(obj, result.wasNull() ? null : Integer.valueOf(i));
|
field.set(obj, result.wasNull() ? null : Integer.valueOf(i));
|
||||||
break;
|
break;
|
||||||
case tLong:
|
case tLong:
|
||||||
long l = result.getLong(column);
|
long l = result.getLong(column);
|
||||||
field.set(obj, result.wasNull() ? null : Long.valueOf(l));
|
field.set(obj, result.wasNull() ? null : Long.valueOf(l));
|
||||||
break;
|
break;
|
||||||
case tFloat:
|
case tFloat:
|
||||||
float f = result.getFloat(column);
|
float f = result.getFloat(column);
|
||||||
field.set(obj, result.wasNull() ? null : Float.valueOf(f));
|
field.set(obj, result.wasNull() ? null : Float.valueOf(f));
|
||||||
field.setFloat(obj, result.getFloat(column));
|
field.setFloat(obj, result.getFloat(column));
|
||||||
break;
|
break;
|
||||||
case tDouble:
|
case tDouble:
|
||||||
double d = result.getDouble(column);
|
double d = result.getDouble(column);
|
||||||
field.set(obj, result.wasNull() ? null : Double.valueOf(d));
|
field.set(obj, result.wasNull() ? null : Double.valueOf(d));
|
||||||
break;
|
break;
|
||||||
case tBoolean:
|
case tBoolean:
|
||||||
boolean bl = result.getBoolean(column);
|
boolean bl = result.getBoolean(column);
|
||||||
field.set(obj, result.wasNull() ? null : Boolean.valueOf(bl));
|
field.set(obj, result.wasNull() ? null : Boolean.valueOf(bl));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case tDecimal:
|
case tDecimal:
|
||||||
field.set(obj, result.getBigDecimal(column));
|
field.set(obj, result.getBigDecimal(column));
|
||||||
break;
|
break;
|
||||||
case tString:
|
case tString:
|
||||||
field.set(obj, result.getString(column));
|
field.set(obj, result.getString(column));
|
||||||
break;
|
break;
|
||||||
case tBytes:
|
case tBytes:
|
||||||
field.set(obj, result.getBytes(column));
|
field.set(obj, result.getBytes(column));
|
||||||
break;
|
break;
|
||||||
case tDate:
|
case tDate:
|
||||||
field.set(obj, result.getDate(column));
|
field.set(obj, result.getDate(column));
|
||||||
break;
|
break;
|
||||||
case tTime:
|
case tTime:
|
||||||
field.set(obj, result.getTime(column));
|
field.set(obj, result.getTime(column));
|
||||||
break;
|
break;
|
||||||
case tTimestamp:
|
case tTimestamp:
|
||||||
field.set(obj, result.getTimestamp(column));
|
field.set(obj, result.getTimestamp(column));
|
||||||
break;
|
break;
|
||||||
case tStream:
|
case tStream:
|
||||||
field.set(obj, result.getBinaryStream(column));
|
field.set(obj, result.getBinaryStream(column));
|
||||||
break;
|
break;
|
||||||
case tBlob:
|
case tBlob:
|
||||||
field.set(obj, result.getBlob(column));
|
field.set(obj, result.getBlob(column));
|
||||||
break;
|
break;
|
||||||
case tClob:
|
case tClob:
|
||||||
field.set(obj, result.getClob(column));
|
field.set(obj, result.getClob(column));
|
||||||
break;
|
break;
|
||||||
case tClosure:
|
case tClosure:
|
||||||
try {
|
try {
|
||||||
java.io.InputStream input = result.getBinaryStream(column);
|
java.io.InputStream input = result.getBinaryStream(column);
|
||||||
java.io.ObjectInputStream in =
|
java.io.ObjectInputStream in =
|
||||||
new java.io.ObjectInputStream(input);
|
new java.io.ObjectInputStream(input);
|
||||||
field.set(obj, in.readObject());
|
field.set(obj, in.readObject());
|
||||||
in.close();
|
in.close();
|
||||||
} catch(ClassNotFoundException ex) {
|
} catch(ClassNotFoundException ex) {
|
||||||
throw new DataTransferError(ex);
|
throw new DataTransferError(ex);
|
||||||
} catch(java.io.IOException ex) {
|
} catch(java.io.IOException ex) {
|
||||||
throw new DataTransferError(ex);
|
throw new DataTransferError(ex);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int inType; // type tag for field input (see constants below)
|
protected int inType; // type tag for field input (see constants below)
|
||||||
protected int outType; // type tag for field output
|
protected int outType; // type tag for field output
|
||||||
protected int scale; // scale for tDecimal type,
|
protected int scale; // scale for tDecimal type,
|
||||||
protected String name; // full (compound) name of component
|
protected String name; // full (compound) name of component
|
||||||
protected Field field; // field info from java.lang.reflect
|
protected Field field; // field info from java.lang.reflect
|
||||||
|
|
||||||
protected Constructor constructor; // constructor of object component
|
protected Constructor constructor; // constructor of object component
|
||||||
|
|
||||||
protected static final int t_byte = 0;
|
protected static final int t_byte = 0;
|
||||||
protected static final int t_short = 1;
|
protected static final int t_short = 1;
|
||||||
protected static final int t_int = 2;
|
protected static final int t_int = 2;
|
||||||
protected static final int t_long = 3;
|
protected static final int t_long = 3;
|
||||||
protected static final int t_float = 4;
|
protected static final int t_float = 4;
|
||||||
protected static final int t_double = 5;
|
protected static final int t_double = 5;
|
||||||
protected static final int t_boolean = 6;
|
protected static final int t_boolean = 6;
|
||||||
protected static final int tByte = 7;
|
protected static final int tByte = 7;
|
||||||
protected static final int tShort = 8;
|
protected static final int tShort = 8;
|
||||||
protected static final int tInteger = 9;
|
protected static final int tInteger = 9;
|
||||||
protected static final int tLong = 10;
|
protected static final int tLong = 10;
|
||||||
protected static final int tFloat = 11;
|
protected static final int tFloat = 11;
|
||||||
protected static final int tDouble = 12;
|
protected static final int tDouble = 12;
|
||||||
protected static final int tBoolean = 13;
|
protected static final int tBoolean = 13;
|
||||||
protected static final int tDecimal = 14;
|
protected static final int tDecimal = 14;
|
||||||
protected static final int tString = 15;
|
protected static final int tString = 15;
|
||||||
protected static final int tBytes = 16;
|
protected static final int tBytes = 16;
|
||||||
protected static final int tDate = 17;
|
protected static final int tDate = 17;
|
||||||
protected static final int tTime = 18;
|
protected static final int tTime = 18;
|
||||||
protected static final int tTimestamp = 19;
|
protected static final int tTimestamp = 19;
|
||||||
protected static final int tStream = 20;
|
protected static final int tStream = 20;
|
||||||
protected static final int tBlob = 21;
|
protected static final int tBlob = 21;
|
||||||
protected static final int tClob = 22;
|
protected static final int tClob = 22;
|
||||||
protected static final int tAsString = 23;
|
protected static final int tAsString = 23;
|
||||||
|
|
||||||
protected static final int tClosure = 24;
|
protected static final int tClosure = 24;
|
||||||
protected static final int tCompound = 25;
|
protected static final int tCompound = 25;
|
||||||
|
|
||||||
protected static final int[] sqlTypeMapping = {
|
protected static final int[] sqlTypeMapping = {
|
||||||
Types.INTEGER, // t_byte
|
Types.INTEGER, // t_byte
|
||||||
Types.INTEGER, // t_short
|
Types.INTEGER, // t_short
|
||||||
Types.INTEGER, // t_int
|
Types.INTEGER, // t_int
|
||||||
Types.BIGINT, // t_long
|
Types.BIGINT, // t_long
|
||||||
Types.FLOAT, // t_float
|
Types.FLOAT, // t_float
|
||||||
Types.DOUBLE, // t_double
|
Types.DOUBLE, // t_double
|
||||||
Types.BIT, // t_boolean
|
Types.BIT, // t_boolean
|
||||||
Types.INTEGER, // tByte
|
Types.INTEGER, // tByte
|
||||||
Types.INTEGER, // tShort
|
Types.INTEGER, // tShort
|
||||||
Types.INTEGER, // tInteger
|
Types.INTEGER, // tInteger
|
||||||
Types.BIGINT, // tLong
|
Types.BIGINT, // tLong
|
||||||
Types.FLOAT, // tFloat
|
Types.FLOAT, // tFloat
|
||||||
Types.DOUBLE, // tDouble
|
Types.DOUBLE, // tDouble
|
||||||
Types.BIT, // tBoolean
|
Types.BIT, // tBoolean
|
||||||
Types.NUMERIC, // tDecimal
|
Types.NUMERIC, // tDecimal
|
||||||
Types.VARCHAR, // tString
|
Types.VARCHAR, // tString
|
||||||
Types.VARBINARY,// tBytes
|
Types.VARBINARY,// tBytes
|
||||||
Types.DATE, // tDate
|
Types.DATE, // tDate
|
||||||
Types.TIME, // tTime
|
Types.TIME, // tTime
|
||||||
Types.TIMESTAMP, // tTimestamp
|
Types.TIMESTAMP, // tTimestamp
|
||||||
Types.LONGVARBINARY, // tStream
|
Types.LONGVARBINARY, // tStream
|
||||||
Types.LONGVARBINARY, // tBlob
|
Types.LONGVARBINARY, // tBlob
|
||||||
Types.LONGVARCHAR, // tClob
|
Types.LONGVARCHAR, // tClob
|
||||||
Types.VARCHAR, // tAsString
|
Types.VARCHAR, // tAsString
|
||||||
Types.LONGVARBINARY // tClosure
|
Types.LONGVARBINARY // tClosure
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user