Top Description Fields Constructors Methods
org.h2.command

public abstract Class Prepared

extends Object
Class Inheritance
Known Direct Subclasses
org.h2.command.ddl.DefineCommand, org.h2.command.dml.BackupCommand, org.h2.command.dml.Call, org.h2.command.dml.DataChangeStatement, org.h2.command.dml.ExecuteImmediate, org.h2.command.dml.ExecuteProcedure, org.h2.command.dml.Explain, org.h2.command.dml.Help, org.h2.command.dml.NoOperation, org.h2.command.dml.ScriptBase, org.h2.command.dml.Set, org.h2.command.dml.SetSessionCharacteristics, org.h2.command.dml.TransactionCommand, org.h2.command.query.Query
Imports
java.util.ArrayList, .HashSet, org.h2.api.DatabaseEventListener, .ErrorCode, org.h2.engine.Database, .DbObject, .SessionLocal, org.h2.expression.Expression, .Parameter, org.h2.message.DbException, .Trace, org.h2.result.ResultInterface, org.h2.util.HasSQL

A prepared statement.

Field Summary

Modifier and TypeField and Description
private Command
protected boolean
create

Whether to create a new object (for indexes).

private long
private long
protected ArrayList<Parameter>
parameters

The list of parameters.

private int
persistedObjectId

Used to preserve object identities on database startup.

protected boolean
prepareAlways

If the query should be prepared before each execution.

private int
protected SessionLocal
session

The session.

protected String
sqlStatement

The SQL string.

protected ArrayList<Token>
sqlTokens

The SQL tokens.

private boolean

Constructor Summary

AccessConstructor and Description
public
Prepared(SessionLocal
the session
session
)

Create a new object.

Method Summary

Modifier and TypeMethod and Description
public void
checkCanceled()

Check if this statement was canceled.

protected void
checkParameters()

Check if all parameters have been set.

public void
collectDependencies(HashSet<DbObject>
collection of dependencies to populate
dependencies
)

Find and collect all DbObjects, this Prepared depends on.

public long

Returns:

the row number
getCurrentRowNumber
()

Get the current row number.

protected final Database
pack-priv long

Returns:

the meta data modification id
getModificationMetaId
()

Get the meta data modification id of the database when this statement was compiled.

protected int

Returns:

the object id
getObjectId
()

Get the current object id, or get a new id from the database.

public ArrayList<Parameter>

Returns:

the parameter list
getParameters
()

Get the parameter list.

public int

Returns:

the object id or 0 if not set
getPersistedObjectId
()

Get the object id to use for the database object that is created in this statement.

public final String

Returns:

the execution plan
getPlanSQL
(int
formatting flags
sqlFlags
)

Get the SQL statement with the execution plan.

public StringBuilder

Returns:

the execution plan
getPlanSQL
(StringBuilder
string builder
builder
,
int
formatting flags
sqlFlags
)

Appends the SQL statement with the execution plan.

public final SessionLocal
public static String

Returns:

the SQL snippet
getSimpleSQL
(Expression[]
the expression list
list
)

Get the SQL snippet of the expression list.

public final String

Returns:

the SQL statement
getSQL
()

Get the SQL statement.

public final ArrayList<Token>

Returns:

the SQL tokens
getSQLTokens
()

Get the SQL tokens.

public abstract int

Returns:

the statement type
getType
()

Get the command type as defined in CommandInterface

public boolean
public boolean

Returns:

true if it is
isQuery
()

Check if this object is a query.

public boolean

Returns:

true if it is
isReadOnly
()

Check if this command is read only.

public boolean

Returns:

is this command can be repeated again on locking failure
isRetryable
()

Returns is this command can be repeated again on locking failure.

public abstract boolean

Returns:

true if it is
isTransactional
()

Check if this command is transactional.

public boolean

Returns:

are values of parameters were specified in SQL
isWithParamValues
()

Returns whether values of parameters were specified in SQL.

public boolean

Returns:

true if it must
needRecompile
()

Check if the statement needs to be re-compiled.

public void
prepare()

Prepare this statement.

public ResultInterface

Returns:

the result set
query
(long
the maximum number of rows to return
maxrows
)

Execute the query.

public abstract ResultInterface

Returns:

the result set
queryMeta
()

Get an empty result set containing the meta data.

public void
setCommand(Command
the new command
command
)

Set the command.

public void
setCurrentRowNumber(long
the row number
rowNumber
)

Set the current row number.

pack-priv void
setModificationMetaId(long
the new id
id
)

Set the meta data modification id of this statement.

public void
setParameterList(ArrayList<Parameter>
the parameter list
parameters
)

Set the parameter list of this statement.

public void
setPersistedObjectId(int
the object id
i
)

Set the persisted object id for this statement.

public void
setPrepareAlways(boolean
the new value
prepareAlways
)

Set the prepare always flag.

private void
setProgress()

Notifies query progress via the DatabaseEventListener

protected final DbException

Returns:

the exception
setRow
(DbException
the exception
e
,
long
the row number
rowId
,
String
the values of the row
values
)

Set the SQL statement of the exception to the given row.

public void
setSession(SessionLocal
the new session
currentSession
)

Set the session for this statement.

public final void
setSQL(String
the SQL statement
sql
,
ArrayList<Token>
the SQL tokens
sqlTokens
)

Set the SQL statement.

public void
setWithParamValues(boolean
are values of parameters were specified in SQL
withParamValues
)

Sets whether values of parameters were specified in SQL.

public String

Returns:

the SQL statement
toString
()

Overrides java.lang.Object.toString.

Convert the statement to a String.

pack-priv void
trace(Database
to update statistics
database
,
long
when the statement was started
startTimeNanos
,
long
the query or update row count
rowCount
)

Print information about the statement executed if info trace level is enabled.

public long

Returns:

the update count
update
()

Execute the statement.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

commandback to summary
private Command command
createback to summary
protected boolean create

Whether to create a new object (for indexes).

currentRowNumberback to summary
private long currentRowNumber
modificationMetaIdback to summary
private long modificationMetaId
parametersback to summary
protected ArrayList<Parameter> parameters

The list of parameters.

persistedObjectIdback to summary
private int persistedObjectId

Used to preserve object identities on database startup. 0 if object is not stored, -1 if object is stored and its ID is already read, >0 if object is stored and its id is not yet read.

prepareAlwaysback to summary
protected boolean prepareAlways

If the query should be prepared before each execution. This is set for queries with LIKE ?, because the query plan depends on the parameter value.

rowScanCountback to summary
private int rowScanCount
sessionback to summary
protected SessionLocal session

The session.

sqlStatementback to summary
protected String sqlStatement

The SQL string.

sqlTokensback to summary
protected ArrayList<Token> sqlTokens

The SQL tokens.

withParamValuesback to summary
private boolean withParamValues

Constructor Detail

Preparedback to summary
public Prepared(SessionLocal session)

Create a new object.

Parameters
session:SessionLocal

the session

Method Detail

checkCanceledback to summary
public void checkCanceled()

Check if this statement was canceled.

Exceptions
DbException:
if it was canceled
checkParametersback to summary
protected void checkParameters()

Check if all parameters have been set.

Exceptions
DbException:
if any parameter has not been set
collectDependenciesback to summary
public void collectDependencies(HashSet<DbObject> dependencies)

Find and collect all DbObjects, this Prepared depends on.

Parameters
dependencies:HashSet<DbObject>

collection of dependencies to populate

getCurrentRowNumberback to summary
public long getCurrentRowNumber()

Get the current row number.

Returns:long

the row number

getDatabaseback to summary
protected final Database getDatabase()
getModificationMetaIdback to summary
pack-priv long getModificationMetaId()

Get the meta data modification id of the database when this statement was compiled.

Returns:long

the meta data modification id

getObjectIdback to summary
protected int getObjectId()

Get the current object id, or get a new id from the database. The object id is used when creating new database object (CREATE statement). This method may be called only once.

Returns:int

the object id

getParametersback to summary
public ArrayList<Parameter> getParameters()

Get the parameter list.

Returns:ArrayList<Parameter>

the parameter list

getPersistedObjectIdback to summary
public int getPersistedObjectId()

Get the object id to use for the database object that is created in this statement. This id is only set when the object is already persisted. If not set, this method returns 0.

Returns:int

the object id or 0 if not set

getPlanSQLback to summary
public final String getPlanSQL(int sqlFlags)

Get the SQL statement with the execution plan.

Parameters
sqlFlags:int

formatting flags

Returns:String

the execution plan

getPlanSQLback to summary
public StringBuilder getPlanSQL(StringBuilder builder, int sqlFlags)

Appends the SQL statement with the execution plan.

Parameters
builder:StringBuilder

string builder

sqlFlags:int

formatting flags

Returns:StringBuilder

the execution plan

getSessionback to summary
public final SessionLocal getSession()
getSimpleSQLback to summary
public static String getSimpleSQL(Expression[] list)

Get the SQL snippet of the expression list.

Parameters
list:Expression[]

the expression list

Returns:String

the SQL snippet

getSQLback to summary
public final String getSQL()

Get the SQL statement.

Returns:String

the SQL statement

getSQLTokensback to summary
public final ArrayList<Token> getSQLTokens()

Get the SQL tokens.

Returns:ArrayList<Token>

the SQL tokens

getTypeback to summary
public abstract int getType()

Get the command type as defined in CommandInterface

Returns:int

the statement type

isCacheableback to summary
public boolean isCacheable()
isQueryback to summary
public boolean isQuery()

Check if this object is a query.

Returns:boolean

true if it is

isReadOnlyback to summary
public boolean isReadOnly()

Check if this command is read only.

Returns:boolean

true if it is

isRetryableback to summary
public boolean isRetryable()

Returns is this command can be repeated again on locking failure.

Returns:boolean

is this command can be repeated again on locking failure

isTransactionalback to summary
public abstract boolean isTransactional()

Check if this command is transactional. If it is not, then it forces the current transaction to commit.

Returns:boolean

true if it is

isWithParamValuesback to summary
public boolean isWithParamValues()

Returns whether values of parameters were specified in SQL.

Returns:boolean

are values of parameters were specified in SQL

needRecompileback to summary
public boolean needRecompile()

Check if the statement needs to be re-compiled.

Returns:boolean

true if it must

prepareback to summary
public void prepare()

Prepare this statement.

queryback to summary
public ResultInterface query(long maxrows)

Execute the query.

Parameters
maxrows:long

the maximum number of rows to return

Returns:ResultInterface

the result set

Annotations
@SuppressWarnings:unused
Exceptions
DbException:
if it is not a query
queryMetaback to summary
public abstract ResultInterface queryMeta()

Get an empty result set containing the meta data.

Returns:ResultInterface

the result set

setCommandback to summary
public void setCommand(Command command)

Set the command.

Parameters
command:Command

the new command

setCurrentRowNumberback to summary
public void setCurrentRowNumber(long rowNumber)

Set the current row number.

Parameters
rowNumber:long

the row number

setModificationMetaIdback to summary
pack-priv void setModificationMetaId(long id)

Set the meta data modification id of this statement.

Parameters
id:long

the new id

setParameterListback to summary
public void setParameterList(ArrayList<Parameter> parameters)

Set the parameter list of this statement.

Parameters
parameters:ArrayList<Parameter>

the parameter list

setPersistedObjectIdback to summary
public void setPersistedObjectId(int i)

Set the persisted object id for this statement.

Parameters
i:int

the object id

setPrepareAlwaysback to summary
public void setPrepareAlways(boolean prepareAlways)

Set the prepare always flag. If set, the statement is re-compiled whenever it is executed.

Parameters
prepareAlways:boolean

the new value

setProgressback to summary
private void setProgress()

Notifies query progress via the DatabaseEventListener

setRowback to summary
protected final DbException setRow(DbException e, long rowId, String values)

Set the SQL statement of the exception to the given row.

Parameters
e:DbException

the exception

rowId:long

the row number

values:String

the values of the row

Returns:DbException

the exception

setSessionback to summary
public void setSession(SessionLocal currentSession)

Set the session for this statement.

Parameters
currentSession:SessionLocal

the new session

setSQLback to summary
public final void setSQL(String sql, ArrayList<Token> sqlTokens)

Set the SQL statement.

Parameters
sql:String

the SQL statement

sqlTokens:ArrayList<Token>

the SQL tokens

setWithParamValuesback to summary
public void setWithParamValues(boolean withParamValues)

Sets whether values of parameters were specified in SQL.

Parameters
withParamValues:boolean

are values of parameters were specified in SQL

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Convert the statement to a String.

Returns:String

the SQL statement

Annotations
@Override
traceback to summary
pack-priv void trace(Database database, long startTimeNanos, long rowCount)

Print information about the statement executed if info trace level is enabled.

Parameters
database:Database

to update statistics

startTimeNanos:long

when the statement was started

rowCount:long

the query or update row count

updateback to summary
public long update()

Execute the statement.

Returns:long

the update count

Exceptions
DbException:
if it is a query