public abstract class VoltProcedure
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
VoltProcedure.VoltAbortException
Thrown from a stored procedure to indicate to VoltDB
that the procedure should be aborted and rolled back.
|
Modifier and Type | Field and Description |
---|---|
static org.voltdb.Expectation |
EXPECT_EMPTY
Expect an empty result set (0 rows)
|
static org.voltdb.Expectation |
EXPECT_NON_EMPTY
Expect a result set with one or more rows
|
static org.voltdb.Expectation |
EXPECT_ONE_ROW
Expect a result set with exactly one row
|
static org.voltdb.Expectation |
EXPECT_SCALAR
Expect a result set with a single row and a single column (scalar value)
|
static org.voltdb.Expectation |
EXPECT_SCALAR_LONG
Expect a result with a single row and a single BIGINT column
|
static org.voltdb.Expectation |
EXPECT_ZERO_OR_ONE_ROW
Expect a result set with one or no rows
|
Constructor and Description |
---|
VoltProcedure()
End users should not instantiate VoltProcedure instances.
|
Modifier and Type | Method and Description |
---|---|
static org.voltdb.Expectation |
EXPECT_SCALAR_MATCH(long scalar)
Expect a result with a single row and a single BIGINT column containing
the specified value.
|
int |
getClusterId()
Get the ID of cluster that the client connects to.
|
int |
getPartitionId() |
java.util.Random |
getSeededRandomNumberGenerator()
Get a Java RNG seeded with the current transaction id.
|
java.util.Date |
getTransactionTime()
YOU MUST BE RUNNING NTP AND START NTP WITH THE -x OPTION
TO GET GOOD BEHAVIOR FROM THIS METHOD - e.g.
|
long |
getUniqueId()
Allow VoltProcedures access to a unique ID generated for each transaction.
|
void |
setAppStatusCode(byte statusCode)
Set the status code that will be returned to the client.
|
void |
setAppStatusString(java.lang.String statusString)
Set the string that will be turned to the client.
|
VoltTable[] |
voltExecuteSQL()
Execute the currently queued SQL
statements and return
the result tables. |
VoltTable[] |
voltExecuteSQL(boolean isFinalSQL)
Execute the currently queued SQL
statements and return
the result tables. |
void |
voltQueueSQL(SQLStmt stmt,
org.voltdb.Expectation expectation,
java.lang.Object... args)
Queue the SQL
statement for execution with the specified argument list,
and an Expectation describing the expected results. |
void |
voltQueueSQL(SQLStmt stmt,
java.lang.Object... args)
Queue the SQL
statement for execution with the specified argument list. |
public static final org.voltdb.Expectation EXPECT_EMPTY
public static final org.voltdb.Expectation EXPECT_ONE_ROW
public static final org.voltdb.Expectation EXPECT_ZERO_OR_ONE_ROW
public static final org.voltdb.Expectation EXPECT_NON_EMPTY
public static final org.voltdb.Expectation EXPECT_SCALAR
public static final org.voltdb.Expectation EXPECT_SCALAR_LONG
public VoltProcedure()
init
method.public static final org.voltdb.Expectation EXPECT_SCALAR_MATCH(long scalar)
scalar
- The expected value the single row/column should containpublic long getUniqueId()
Allow VoltProcedures access to a unique ID generated for each transaction.
Note that calling it repeatedly within a single transaction will return the same number.
The id consists of a time based component in the most significant bits followed by a counter, and then a partition id to allow parallel unique number generation.
Currently, if the host clock moves backwards this call may block while the clock catches up to its previous max. Running NTP with the -x option will prevent this in most cases. It may not be sufficient to 100% avoid this, especially in managed and/or virtualized environments (like AWS). The value will always be unique, but clocks moving backwards may affect system throughput.
Since this number is initially based on the wall clock time (UTC), it is not guaranteed to be unique across different clusters of VoltDB. If you snapshot, then move time back by 1HR, then load that snapshot into a new VoltDB cluster, you might see duplicate ids for up to 1HR. Since the wall clocks VoltDB uses are UTC, and it takes some amount of time to snapshot and restore, this is a pretty easy corner case to avoid. Note that failure and recovery from disk using command logs will preserve unique id continuity even if the clock shifts.
In many cases it may make sense to generate unique ids on the client-side and pass them to the server. Please reach out to VoltDB if you have questions about when using this method is appropriate.
public int getClusterId()
public java.util.Random getSeededRandomNumberGenerator()
public java.util.Date getTransactionTime()
public void voltQueueSQL(SQLStmt stmt, org.voltdb.Expectation expectation, java.lang.Object... args)
Queue the SQL statement
for execution with the specified argument list,
and an Expectation describing the expected results. If the Expectation is not met then VoltAbortException
will be thrown with a description of the expectation that was not met. This exception must not be
caught from within the procedure.
stmt
- Statement
to queue for execution.expectation
- Expectation describing the expected result of executing this SQL statement.args
- List of arguments to be bound as parameters for the statement
public void voltQueueSQL(SQLStmt stmt, java.lang.Object... args)
statement
for execution with the specified argument list.stmt
- Statement
to queue for execution.args
- List of arguments to be bound as parameters for the statement
public VoltTable[] voltExecuteSQL()
statements
and return
the result tables.tables
generated by executing the queued
query statements
public VoltTable[] voltExecuteSQL(boolean isFinalSQL)
statements
and return
the result tables. Boolean option allows caller to indicate if this is the final
batch for a procedure. If it's final, then additional optimizations can be enabled.
Any call to voltExecuteSQL() after calling this with the argument set to true
will cause the entire procedure to roll back.isFinalSQL
- Is this the final batch for a procedure?tables
generated by executing the queued
query statements
public void setAppStatusCode(byte statusCode)
statusCode
- Byte-long application-specific status code.public void setAppStatusString(java.lang.String statusString)
statusString
- Application specific status string.public int getPartitionId()