Package com.mckoi.database.jdbc
Class SQLQuery
- java.lang.Object
-
- com.mckoi.database.jdbc.SQLQuery
-
public final class SQLQuery extends java.lang.Object
Represents an SQL Query to the database. This includes the query string itself plus any data types that are part of the query.FUTURE ENHANCEMENTS: This could do some preliminary parsing of the query string for faster translation by the database.
-
-
Field Summary
Fields Modifier and Type Field Description private int
parameter_count
private java.lang.Object[]
parameters
The list of all variable substitutions that are in the query.private int
parameters_index
private boolean
prepared
Set to true when this query is prepared via the prepare method.private java.lang.String
query
The SQL String.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addVar(java.lang.Object ob)
Adds a variable to the query.void
clear()
Clears all the parameters.SQLQuery
copy()
Creates an exact copy of this object.static SQLQuery
deserializeFromBlob(ByteLongObject ob)
Deserializes an SQLQuery object from a ByteLongObject.private void
doEscapeSubstitutions()
Performs any JDBC escape processing on the query.boolean
equals(java.lang.Object ob)
Returns true if this query is equal to another.private java.lang.String
escapeJDBCSubstitution(java.lang.String jdbc_code)
Given a JDBC escape code of the form {keyword ...java.lang.String
getQuery()
Returns the query string.java.lang.Object[]
getVars()
Returns the array of all objects that are to be used as substitutions for '?' in the query.private void
growParametersList(int new_size)
Grows the parameters list to the given size.void
prepare(boolean do_escape_processing)
Prepares the query by parsing the query string and performing any updates that are required before being passed down to the lower layers of the database engine for processing.static SQLQuery
readFrom(java.io.DataInputStream in)
Reads an SQLQuery object from the data input stream.ByteLongObject
serializeToBlob()
Serializes an SQLQuery object to a ByteLongObject.void
setVar(int i, java.lang.Object ob)
Sets a variable at the given index.java.lang.String
toString()
Outputs the query as text (for debugging)private java.lang.Object
translateObjectType(java.lang.Object ob)
Translates the given object to a type the object can process.void
writeTo(java.io.DataOutputStream out)
Writes the SQL query to the data output stream.
-
-
-
Field Detail
-
query
private java.lang.String query
The SQL String. For example, "select * from Part".
-
prepared
private boolean prepared
Set to true when this query is prepared via the prepare method.
-
parameters
private java.lang.Object[] parameters
The list of all variable substitutions that are in the query. A variable substitution is set up in a prepared statement.
-
parameters_index
private int parameters_index
-
parameter_count
private int parameter_count
-
-
Method Detail
-
growParametersList
private void growParametersList(int new_size)
Grows the parameters list to the given size.
-
translateObjectType
private java.lang.Object translateObjectType(java.lang.Object ob)
Translates the given object to a type the object can process.
-
addVar
public void addVar(java.lang.Object ob)
Adds a variable to the query. If the object is not a type that is a database 'primitive' type (BigDecimal, ByteLongObject, Boolean, Date, String) then it is serialized and the serialized form is wrapped in a ByteLongObject.
-
setVar
public void setVar(int i, java.lang.Object ob)
Sets a variable at the given index. Grows if necessary. If the object is not a type that is a database 'primitive' type (BigDecimal, ByteLongObject, Boolean, Date, String) then it is serialized and the serialized form is wrapped in a ByteLongObject.
-
clear
public void clear()
Clears all the parameters.
-
getQuery
public java.lang.String getQuery()
Returns the query string.
-
getVars
public java.lang.Object[] getVars()
Returns the array of all objects that are to be used as substitutions for '?' in the query.NOTE: Array returned references internal Object[] here so don't change!
-
escapeJDBCSubstitution
private java.lang.String escapeJDBCSubstitution(java.lang.String jdbc_code) throws java.sql.SQLException
Given a JDBC escape code of the form {keyword ... parameters ...} this will return the most optimal Mckoi SQL query for the code.- Throws:
java.sql.SQLException
-
doEscapeSubstitutions
private void doEscapeSubstitutions() throws java.sql.SQLException
Performs any JDBC escape processing on the query. For example, the code {d 'yyyy-mm-dd'} is converted to 'DATE 'yyyy-mm-dd'.- Throws:
java.sql.SQLException
-
prepare
public void prepare(boolean do_escape_processing) throws java.sql.SQLException
Prepares the query by parsing the query string and performing any updates that are required before being passed down to the lower layers of the database engine for processing. For example, JDBC escape code processing.- Throws:
java.sql.SQLException
-
equals
public boolean equals(java.lang.Object ob)
Returns true if this query is equal to another.- Overrides:
equals
in classjava.lang.Object
-
copy
public SQLQuery copy()
Creates an exact copy of this object.
-
toString
public java.lang.String toString()
Outputs the query as text (for debugging)- Overrides:
toString
in classjava.lang.Object
-
writeTo
public void writeTo(java.io.DataOutputStream out) throws java.io.IOException
Writes the SQL query to the data output stream.- Throws:
java.io.IOException
-
readFrom
public static SQLQuery readFrom(java.io.DataInputStream in) throws java.io.IOException
Reads an SQLQuery object from the data input stream.- Throws:
java.io.IOException
-
serializeToBlob
public ByteLongObject serializeToBlob()
Serializes an SQLQuery object to a ByteLongObject.
-
deserializeFromBlob
public static SQLQuery deserializeFromBlob(ByteLongObject ob)
Deserializes an SQLQuery object from a ByteLongObject.
-
-