本文整理汇总了Java中org.postgresql.core.ResultHandler类的典型用法代码示例。如果您正苦于以下问题:Java ResultHandler类的具体用法?Java ResultHandler怎么用?Java ResultHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ResultHandler类属于org.postgresql.core包,在下文中一共展示了ResultHandler类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.postgresql.core.ResultHandler; //导入依赖的package包/类
public synchronized void execute(Query query,
ParameterList parameters,
ResultHandler handler,
int maxRows, int fetchSize, int flags)
throws SQLException
{
lock.lock();
try {
execute((V2Query) query, (SimpleParameterList) parameters, handler, maxRows, flags);
} finally {
lock.unlock();
}
}
示例2: execute
import org.postgresql.core.ResultHandler; //导入依赖的package包/类
@Override
public synchronized void execute(Query query, ParameterList parameters,
ResultHandler handler, int maxRows, int fetchSize, int flags)
throws SQLException {
if (simplePortal != null) {
try {
byte[] bytes = query.toString().getBytes("UTF-8");
stream.SendChar('Q');
stream.SendInteger4(bytes.length + 6);
stream.Send(bytes);
stream.SendInteger2(0);
stream.flush();
if (pendingExecute.isEmpty()) {
pendingExecute.add(new Object[] { query, new Portal((SimpleQuery)query, simplePortal) });
}
if (pendingDescribe.isEmpty()) {
pendingDescribe.add(query);
}
processResults(handler, flags);
handler.handleCompletion();
return;
} catch (Exception e) {
throw new SQLException(e);
}
}
super.execute(query, parameters, handler, maxRows, fetchSize, flags);
}
示例3: fetch
import org.postgresql.core.ResultHandler; //导入依赖的package包/类
public void fetch(ResultCursor cursor, ResultHandler handler, int rows) throws SQLException {
throw org.postgresql.Driver.notImplemented(this.getClass(), "fetch(ResultCursor,ResultHandler,int)");
}
示例4: interpretCommandStatus
import org.postgresql.core.ResultHandler; //导入依赖的package包/类
private void interpretCommandStatus(String status, ResultHandler handler) throws IOException {
int update_count = 0;
long insert_oid = 0;
if (status.equals("BEGIN"))
protoConnection.setTransactionState(ProtocolConnection.TRANSACTION_OPEN);
else if (status.equals("COMMIT") || status.equals("ROLLBACK"))
protoConnection.setTransactionState(ProtocolConnection.TRANSACTION_IDLE);
else if (status.startsWith("INSERT") || status.startsWith("UPDATE") || status.startsWith("DELETE") || status.startsWith("MOVE"))
{
try
{
long updates = Long.parseLong(status.substring(1 + status.lastIndexOf(' ')));
// deal with situations where the update modifies more than 2^32 rows
if ( updates > Integer.MAX_VALUE )
update_count = Statement.SUCCESS_NO_INFO;
else
update_count = (int)updates;
if (status.startsWith("INSERT"))
insert_oid = Long.parseLong(status.substring(1 + status.indexOf(' '),
status.lastIndexOf(' ')));
}
catch (NumberFormatException nfe)
{
handler.handleError(new PSQLException(GT.tr("Unable to interpret the update count in command completion tag: {0}.", status), PSQLState.CONNECTION_FAILURE));
return ;
}
}
handler.handleCommandStatus(status, update_count, insert_oid);
}
示例5: execute
import org.postgresql.core.ResultHandler; //导入依赖的package包/类
public void execute(Query query,
ParameterList parameters,
ResultHandler handler,
int maxRows,
int fetchSize,
int flags)
throws SQLException
{
lock.lock();
try {
waitOnLock();
if (logger.logDebug())
{
logger.debug("simple execute, handler=" + handler +
", maxRows=" + maxRows + ", fetchSize=" + fetchSize + ", flags=" + flags);
}
if (parameters == null)
parameters = SimpleQuery.NO_PARAMETERS;
boolean describeOnly = (QUERY_DESCRIBE_ONLY & flags) != 0;
((V3ParameterList)parameters).convertFunctionOutParameters();
// Check parameters are all set..
if (!describeOnly)
((V3ParameterList)parameters).checkAllParametersSet();
try
{
try
{
handler = sendQueryPreamble(handler, flags);
ErrorTrackingResultHandler trackingHandler = new ErrorTrackingResultHandler(handler);
sendQuery((V3Query)query, (V3ParameterList)parameters, maxRows, fetchSize, flags, trackingHandler);
sendSync();
processResults(handler, flags);
estimatedReceiveBufferBytes = 0;
}
catch (PGBindException se)
{
// There are three causes of this error, an
// invalid total Bind message length, a
// BinaryStream that cannot provide the amount
// of data claimed by the length arugment, and
// a BinaryStream that throws an Exception
// when reading.
//
// We simply do not send the Execute message
// so we can just continue on as if nothing
// has happened. Perhaps we need to
// introduce an error here to force the
// caller to rollback if there is a
// transaction in progress?
//
sendSync();
processResults(handler, flags);
estimatedReceiveBufferBytes = 0;
handler.handleError(new PSQLException(GT.tr("Unable to bind parameter values for statement."), PSQLState.INVALID_PARAMETER_VALUE, se.getIOException()));
}
}
catch (IOException e)
{
protoConnection.abort();
handler.handleError(new PSQLException(GT.tr("An I/O error occurred while sending to the backend."), PSQLState.CONNECTION_FAILURE, e));
}
handler.handleCompletion();
} finally {
lock.unlock();
}
}
示例6: ErrorTrackingResultHandler
import org.postgresql.core.ResultHandler; //导入依赖的package包/类
ErrorTrackingResultHandler(ResultHandler delegateHandler) {
this.delegateHandler = delegateHandler;
}
示例7: sendQueryPreamble
import org.postgresql.core.ResultHandler; //导入依赖的package包/类
private ResultHandler sendQueryPreamble(final ResultHandler delegateHandler, int flags) throws IOException {
// First, send CloseStatements for finalized SimpleQueries that had statement names assigned.
processDeadParsedQueries();
processDeadPortals();
// Send BEGIN on first statement in transaction.
if ((flags & QueryExecutor.QUERY_SUPPRESS_BEGIN) != 0 ||
protoConnection.getTransactionState() != ProtocolConnection.TRANSACTION_IDLE)
return delegateHandler;
int beginFlags = QueryExecutor.QUERY_NO_METADATA;
if ((flags & QueryExecutor.QUERY_ONESHOT) != 0) {
beginFlags |= QueryExecutor.QUERY_ONESHOT;
}
sendOneQuery(beginTransactionQuery, SimpleQuery.NO_PARAMETERS, 0, 0, beginFlags);
// Insert a handler that intercepts the BEGIN.
return new ResultHandler() {
private boolean sawBegin = false;
public void handleResultRows(Query fromQuery, Field[] fields, List tuples, ResultCursor cursor) {
if (sawBegin)
delegateHandler.handleResultRows(fromQuery, fields, tuples, cursor);
}
public void handleCommandStatus(String status, int updateCount, long insertOID) {
if (!sawBegin)
{
sawBegin = true;
if (!status.equals("BEGIN"))
handleError(new PSQLException(GT.tr("Expected command status BEGIN, got {0}.", status),
PSQLState.PROTOCOL_VIOLATION));
}
else
{
delegateHandler.handleCommandStatus(status, updateCount, insertOID);
}
}
public void handleWarning(SQLWarning warning) {
delegateHandler.handleWarning(warning);
}
public void handleError(SQLException error) {
delegateHandler.handleError(error);
}
public void handleCompletion() throws SQLException{
delegateHandler.handleCompletion();
}
};
}
示例8: doSubprotocolBegin
import org.postgresql.core.ResultHandler; //导入依赖的package包/类
public void doSubprotocolBegin() throws SQLException {
if (protoConnection.getTransactionState() == ProtocolConnection.TRANSACTION_IDLE)
{
if (logger.logDebug())
logger.debug("Issuing BEGIN before fastpath or copy call.");
ResultHandler handler = new ResultHandler() {
private boolean sawBegin = false;
private SQLException sqle = null;
public void handleResultRows(Query fromQuery, Field[] fields, List tuples, ResultCursor cursor) {
}
public void handleCommandStatus(String status, int updateCount, long insertOID) {
if (!sawBegin)
{
if (!status.equals("BEGIN"))
handleError(new PSQLException(GT.tr("Expected command status BEGIN, got {0}.", status),
PSQLState.PROTOCOL_VIOLATION));
sawBegin = true;
}
else
{
handleError(new PSQLException(GT.tr("Unexpected command status: {0}.", status),
PSQLState.PROTOCOL_VIOLATION));
}
}
public void handleWarning(SQLWarning warning) {
// we don't want to ignore warnings and it would be tricky
// to chain them back to the connection, so since we don't
// expect to get them in the first place, we just consider
// them errors.
handleError(warning);
}
public void handleError(SQLException error) {
if (sqle == null)
{
sqle = error;
}
else
{
sqle.setNextException(error);
}
}
public void handleCompletion() throws SQLException{
if (sqle != null)
throw sqle;
}
};
try
{
sendOneQuery(beginTransactionQuery, SimpleQuery.NO_PARAMETERS, 0, 0, QueryExecutor.QUERY_NO_METADATA);
sendSync();
processResults(handler, 0);
estimatedReceiveBufferBytes = 0;
}
catch (IOException ioe)
{
throw new PSQLException(GT.tr("An I/O error occurred while sending to the backend."), PSQLState.CONNECTION_FAILURE, ioe);
}
}
}
示例9: interpretCommandStatus
import org.postgresql.core.ResultHandler; //导入依赖的package包/类
private void interpretCommandStatus(String status, ResultHandler handler) {
int update_count = 0;
long insert_oid = 0;
if (status.startsWith("INSERT") || status.startsWith("UPDATE") || status.startsWith("DELETE") || status.startsWith("MOVE"))
{
try
{
long updates = Long.parseLong(status.substring(1 + status.lastIndexOf(' ')));
// deal with situations where the update modifies more than 2^32 rows
if ( updates > Integer.MAX_VALUE )
update_count = Statement.SUCCESS_NO_INFO;
else
update_count = (int)updates;
if (status.startsWith("INSERT"))
insert_oid = Long.parseLong(status.substring(1 + status.indexOf(' '),
status.lastIndexOf(' ')));
}
catch (NumberFormatException nfe)
{
handler.handleError(new PSQLException(GT.tr("Unable to interpret the update count in command completion tag: {0}.", status), PSQLState.CONNECTION_FAILURE));
return ;
}
}
handler.handleCommandStatus(status, update_count, insert_oid);
}