Jive Forums API (5.5.20.2-oracle) Developer Javadocs

com.jivesoftware.base.database
Class CachedPreparedStatement

java.lang.Object
  extended by com.jivesoftware.base.database.CachedPreparedStatement
All Implemented Interfaces:
Cacheable, com.tangosol.io.ExternalizableLite, java.io.Serializable

public class CachedPreparedStatement
extends java.lang.Object
implements com.tangosol.io.ExternalizableLite, Cacheable

Allows PreparedStatement information to be cached. A prepared statement consists of a SQL statement containing bind variables as well as variable values. For example, the SQL statement "SELECT * FROM person WHERE age > ?" would have the integer variable 18 (which replaces the "?" chracter) to find all adults. This class encapsulates both the SQL string and bind variable values so that actual PreparedStatement can be created from that information later.

See Also:
Serialized Form

Constructor Summary
CachedPreparedStatement()
          Constructs a new CachedPreparedStatement.
CachedPreparedStatement(java.lang.String sql)
          Constructs a new CachedPreparedStatement
 
Method Summary
 void addBoolean(boolean value)
          Adds a boolean parameter to the prepared statement.
 void addInt(int value)
          Adds an integer parameter to the prepared statement.
 void addLong(long value)
          Adds a long parameter to the prepared statement.
 void addString(java.lang.String value)
          Adds a String parameter to the prepared statement.
 boolean equals(java.lang.Object object)
           
 int getCachedSize()
          Returns the approximate size of the Object in bytes.
 java.lang.String getSQL()
          Returns the SQL.
 int hashCode()
           
 void readExternal(java.io.DataInput in)
           
 void setParams(java.sql.PreparedStatement pstmt)
          Sets all parameters on the given PreparedStatement.
 void setSQL(java.lang.String sql)
          Sets the SQL.
 java.lang.String toString()
           
 void writeExternal(java.io.DataOutput out)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CachedPreparedStatement

public CachedPreparedStatement()
Constructs a new CachedPreparedStatement.


CachedPreparedStatement

public CachedPreparedStatement(java.lang.String sql)
Constructs a new CachedPreparedStatement

Parameters:
sql -
Method Detail

getSQL

public java.lang.String getSQL()
Returns the SQL.

Returns:
the SQL.

setSQL

public void setSQL(java.lang.String sql)
Sets the SQL.

Parameters:
sql - the SQL.

addBoolean

public void addBoolean(boolean value)
Adds a boolean parameter to the prepared statement.

Parameters:
value - the boolean value.

addInt

public void addInt(int value)
Adds an integer parameter to the prepared statement.

Parameters:
value - the int value.

addLong

public void addLong(long value)
Adds a long parameter to the prepared statement.

Parameters:
value - the long value.

addString

public void addString(java.lang.String value)
Adds a String parameter to the prepared statement.

Parameters:
value - the String value.

setParams

public void setParams(java.sql.PreparedStatement pstmt)
               throws java.sql.SQLException
Sets all parameters on the given PreparedStatement. The standard code block for turning a CachedPreparedStatement into a PreparedStatement is as follows:
 PreparedStatement pstmt = con.prepareStatement(cachedPstmt.getSQL());
 cachedPstmt.setParams(pstmt);
 

Parameters:
pstmt - the prepared statement.
Throws:
java.sql.SQLException - if an SQL Exception occurs.

equals

public boolean equals(java.lang.Object object)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

getCachedSize

public int getCachedSize()
Description copied from interface: Cacheable
Returns the approximate size of the Object in bytes. The size should be considered to be a best estimate of how much memory the Object occupies and may be based on empirical trials or dynamic calculations.

Specified by:
getCachedSize in interface Cacheable
Returns:
the size of the Object in bytes.

readExternal

public void readExternal(java.io.DataInput in)
                  throws java.io.IOException
Specified by:
readExternal in interface com.tangosol.io.ExternalizableLite
Throws:
java.io.IOException

writeExternal

public void writeExternal(java.io.DataOutput out)
                   throws java.io.IOException
Specified by:
writeExternal in interface com.tangosol.io.ExternalizableLite
Throws:
java.io.IOException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

Jive Forums Project Page

Copyright © 1999-2006 Jive Software.