本文整理汇总了Java中org.postgresql.util.PSQLState类的典型用法代码示例。如果您正苦于以下问题:Java PSQLState类的具体用法?Java PSQLState怎么用?Java PSQLState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PSQLState类属于org.postgresql.util包,在下文中一共展示了PSQLState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fastpathCall
import org.postgresql.util.PSQLState; //导入依赖的package包/类
public byte[]
fastpathCall(int fnid, ParameterList parameters, boolean suppressBegin) throws SQLException {
lock.lock();
try {
waitOnLock();
if (!suppressBegin)
{
doSubprotocolBegin();
}
try
{
sendFastpathCall(fnid, (SimpleParameterList)parameters);
return receiveFastpathResult();
}
catch (IOException ioe)
{
protoConnection.abort();
throw new PSQLException(GT.tr("An I/O error occurred while sending to the backend."), PSQLState.CONNECTION_FAILURE, ioe);
}
} finally {
lock.unlock();
}
}
示例2: toDouble
import org.postgresql.util.PSQLState; //导入依赖的package包/类
public static double toDouble(String s) throws SQLException
{
if (s != null)
{
try
{
s = s.trim();
return Double.parseDouble(s);
}
catch (NumberFormatException e)
{
throw new PSQLException(GT.tr("Bad value for type {0} : {1}", new Object[]{"double",s}),
PSQLState.NUMERIC_VALUE_OUT_OF_RANGE);
}
}
return 0; // SQL NULL
}
开发者ID:health-and-care-developer-network,项目名称:health-and-care-developer-network,代码行数:18,代码来源:AbstractJdbc2ResultSet.java
示例3: unlock
import org.postgresql.util.PSQLState; //导入依赖的package包/类
/**
* Release lock on this connection presumably held by given object.
* @param holder object that holds the lock. Normally current thread.
* @throws PSQLException when this thread does not hold the lock
*/
private void unlock(Object holder) throws PSQLException {
if(lockedFor != holder)
throw new PSQLException(GT.tr("Tried to break lock on database connection"), PSQLState.OBJECT_NOT_IN_STATE);
lockedFor = null;
condition.signal();
}
示例4: endCopy
import org.postgresql.util.PSQLState; //导入依赖的package包/类
/**
* Finishes writing to copy and unlocks connection
* @param op the copy operation presumably currently holding lock on this connection
* @return number of rows updated for server versions 8.2 or newer
* @throws SQLException on failure
*/
public long endCopy(CopyInImpl op) throws SQLException {
lock.lock();
try {
if(!hasLock(op))
throw new PSQLException(GT.tr("Tried to end inactive copy"), PSQLState.OBJECT_NOT_IN_STATE);
try {
if (logger.logDebug())
logger.debug(" FE=> CopyDone");
pgStream.SendChar('c'); // CopyDone
pgStream.SendInteger4(4);
pgStream.flush();
processCopyResults(op, true);
return op.getHandledRowCount();
} catch(IOException ioe) {
throw new PSQLException(GT.tr("Database connection failed when ending copy"), PSQLState.CONNECTION_FAILURE, ioe);
}
} finally {
lock.unlock();
}
}
示例5: writeToCopy
import org.postgresql.util.PSQLState; //导入依赖的package包/类
/**
* Sends data during a live COPY IN operation. Only unlocks the connection if server
* suddenly returns CommandComplete, which should not happen
* @param op the CopyIn operation presumably currently holding lock on this connection
* @param data bytes to send
* @param off index of first byte to send (usually 0)
* @param siz number of bytes to send (usually data.length)
* @throws SQLException on failure
*/
public void writeToCopy(CopyInImpl op, byte[] data, int off, int siz) throws SQLException {
lock.lock();
try {
if(!hasLock(op))
throw new PSQLException(GT.tr("Tried to write to an inactive copy operation"), PSQLState.OBJECT_NOT_IN_STATE);
if (logger.logDebug())
logger.debug(" FE=> CopyData(" + siz + ")");
try {
pgStream.SendChar('d');
pgStream.SendInteger4(siz + 4);
pgStream.Send(data, off, siz);
processCopyResults(op, false); // collect any pending notifications without blocking
} catch(IOException ioe) {
throw new PSQLException(GT.tr("Database connection failed when writing to copy"), PSQLState.CONNECTION_FAILURE, ioe);
}
} finally {
lock.unlock();
}
}
示例6: flushCopy
import org.postgresql.util.PSQLState; //导入依赖的package包/类
public void flushCopy(CopyInImpl op) throws SQLException {
lock.lock();
try {
if(!hasLock(op))
throw new PSQLException(GT.tr("Tried to write to an inactive copy operation"), PSQLState.OBJECT_NOT_IN_STATE);
try {
pgStream.flush();
processCopyResults(op, false); // collect any pending notifications without blocking
} catch(IOException ioe) {
throw new PSQLException(GT.tr("Database connection failed when writing to copy"), PSQLState.CONNECTION_FAILURE, ioe);
}
} finally {
lock.unlock();
}
}
示例7: readFromCopy
import org.postgresql.util.PSQLState; //导入依赖的package包/类
/**
* Blocks to wait for a row of data to be received from server on an active copy operation
* Connection gets unlocked by processCopyResults() at end of operation
* @param op the copy operation presumably currently holding lock on this connection
* @throws SQLException on any failure
*/
void readFromCopy(CopyOutImpl op) throws SQLException {
lock.lock();
try {
if(!hasLock(op))
throw new PSQLException(GT.tr("Tried to read from inactive copy"), PSQLState.OBJECT_NOT_IN_STATE);
try {
processCopyResults(op, true); // expect a call to handleCopydata() to store the data
} catch(IOException ioe) {
throw new PSQLException(GT.tr("Database connection failed when reading from copy"), PSQLState.CONNECTION_FAILURE, ioe);
}
} finally {
lock.unlock();
}
}
示例8: testExtractPSQLException
import org.postgresql.util.PSQLState; //导入依赖的package包/类
@Test
public void testExtractPSQLException() {
PSQLException psqlException = new PSQLException("fake error", PSQLState.UNEXPECTED_ERROR);
// passing in the exception itself works
assertEquals(psqlException, Manager.extractPSQLException(psqlException));
// wrapping the exception in a SQLException (as done by ORMLite) works
SQLException wrap1 = new SQLException("wrapper", psqlException);
assertEquals(psqlException, Manager.extractPSQLException(wrap1));
// ORMLite can also double wrap the exception
SQLException wrap2 = new SQLException("double", wrap1);
assertEquals(psqlException, Manager.extractPSQLException(wrap2));
// SQLException with some other kind of exception: null
SQLException other = new SQLException("other", new RuntimeException("cause"));
assertNull(Manager.extractPSQLException(other));
Throwable t = new Throwable("hello", psqlException);
assertEquals(psqlException, Manager.extractPSQLException(t));
}
示例9: fastpathCall
import org.postgresql.util.PSQLState; //导入依赖的package包/类
public synchronized byte[]
fastpathCall(int fnid, ParameterList parameters, boolean suppressBegin) throws SQLException {
waitOnLock();
if (!suppressBegin)
{
doSubprotocolBegin();
}
try
{
sendFastpathCall(fnid, (SimpleParameterList)parameters);
return receiveFastpathResult();
}
catch (IOException ioe)
{
protoConnection.close();
throw new PSQLException(GT.tr("An I/O error occured while sending to the backend."), PSQLState.CONNECTION_FAILURE, ioe);
}
}
示例10: startCopy
import org.postgresql.util.PSQLState; //导入依赖的package包/类
/**
* Sends given query to BE to start, initialize and lock connection for a CopyOperation.
* @param sql COPY FROM STDIN / COPY TO STDOUT statement
* @return CopyIn or CopyOut operation object
* @throws SQLException on failure
*/
public synchronized CopyOperation startCopy(String sql, boolean suppressBegin) throws SQLException {
waitOnLock();
if (!suppressBegin) {
doSubprotocolBegin();
}
byte buf[] = Utils.encodeUTF8(sql);
try {
if (logger.logDebug())
logger.debug(" FE=> Query(CopyStart)");
pgStream.SendChar('Q');
pgStream.SendInteger4(buf.length + 4 + 1);
pgStream.Send(buf);
pgStream.SendChar(0);
pgStream.flush();
return processCopyResults(null, true); // expect a CopyInResponse or CopyOutResponse to our query above
} catch(IOException ioe) {
throw new PSQLException(GT.tr("Database connection failed when starting copy"), PSQLState.CONNECTION_FAILURE, ioe);
}
}
示例11: endCopy
import org.postgresql.util.PSQLState; //导入依赖的package包/类
/**
* Finishes writing to copy and unlocks connection
* @param op the copy operation presumably currently holding lock on this connection
* @return number of rows updated for server versions 8.2 or newer
* @throws SQLException on failure
*/
public synchronized long endCopy(CopyInImpl op) throws SQLException {
if(!hasLock(op))
throw new PSQLException(GT.tr("Tried to end inactive copy"), PSQLState.OBJECT_NOT_IN_STATE);
try {
if (logger.logDebug())
logger.debug(" FE=> CopyDone");
pgStream.SendChar('c'); // CopyDone
pgStream.SendInteger4(4);
pgStream.flush();
processCopyResults(op, true);
return op.getHandledRowCount();
} catch(IOException ioe) {
throw new PSQLException(GT.tr("Database connection failed when ending copy"), PSQLState.CONNECTION_FAILURE, ioe);
}
}
示例12: interpretCommandStatus
import org.postgresql.util.PSQLState; //导入依赖的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
{
update_count = Integer.parseInt(status.substring(1 + status.lastIndexOf(' ')));
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);
}
开发者ID:health-and-care-developer-network,项目名称:health-and-care-developer-network,代码行数:27,代码来源:QueryExecutorImpl.java
示例13: testCopyInByRow
import org.postgresql.util.PSQLState; //导入依赖的package包/类
public void testCopyInByRow() throws SQLException {
String sql = "COPY copytest FROM STDIN";
CopyIn cp = copyAPI.copyIn(sql);
for(int i=0; i<origData.length; i++) {
byte[] buf = origData[i].getBytes();
cp.writeToCopy(buf, 0, buf.length);
}
long count1 = cp.endCopy();
long count2 = cp.getHandledRowCount();
long expectedResult = -1;
if (TestUtil.haveMinimumServerVersion(con, "8.2")) {
expectedResult = dataRows;
}
assertEquals(expectedResult, count1);
assertEquals(expectedResult, count2);
try {
cp.cancelCopy();
} catch(SQLException se) { // should fail with obsolete operation
if(! PSQLState.OBJECT_NOT_IN_STATE.getState().equals(se.getSQLState()) )
fail("should have thrown object not in state exception.");
}
int rowCount = getCount();
assertEquals(dataRows, rowCount);
}
开发者ID:health-and-care-developer-network,项目名称:health-and-care-developer-network,代码行数:27,代码来源:CopyTest.java
示例14: testTooManyParameters
import org.postgresql.util.PSQLState; //导入依赖的package包/类
public void testTooManyParameters() throws Throwable
{
CallableStatement cs = con.prepareCall("{call myif(?,?)}");
try
{
cs.setInt(1,1);
cs.setInt(2,2);
cs.registerOutParameter(1,Types.INTEGER);
cs.registerOutParameter(2,Types.INTEGER);
cs.execute();
fail("should throw an exception");
}
catch( SQLException ex )
{
assertTrue(ex.getSQLState().equalsIgnoreCase(PSQLState.SYNTAX_ERROR.getState()));
}
}
开发者ID:health-and-care-developer-network,项目名称:health-and-care-developer-network,代码行数:20,代码来源:Jdbc3CallableStatementTest.java
示例15: bind
import org.postgresql.util.PSQLState; //导入依赖的package包/类
private void bind(int index, Object value, int oid, int binary) throws SQLException {
if (index < 1 || index > paramValues.length)
throw new PSQLException(GT.tr("The column index is out of range: {0}, number of columns: {1}.", new Object[]{new Integer(index), new Integer(paramValues.length)}), PSQLState.INVALID_PARAMETER_VALUE);
--index;
encoded[index] = null;
paramValues[index] = value ;
flags[index] = direction(index) | IN | binary;
// If we are setting something to an UNSPECIFIED NULL, don't overwrite
// our existing type for it. We don't need the correct type info to
// send this value, and we don't want to overwrite and require a
// reparse.
if (oid == Oid.UNSPECIFIED && paramTypes[index] != Oid.UNSPECIFIED && value == NULL_OBJECT)
return;
paramTypes[index] = oid;
}
开发者ID:health-and-care-developer-network,项目名称:health-and-care-developer-network,代码行数:20,代码来源:SimpleParameterList.java