• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java PSQLState类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.postgresql.util.PSQLState的典型用法代码示例。如果您正苦于以下问题:Java PSQLState类的具体用法?Java PSQLState怎么用?Java PSQLState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



PSQLState类属于org.postgresql.util包,在下文中一共展示了PSQLState类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
    }
}
 
开发者ID:yngui,项目名称:jephyr,代码行数:24,代码来源:QueryExecutorImpl.java


示例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();
}
 
开发者ID:yngui,项目名称:jephyr,代码行数:12,代码来源:QueryExecutorImpl.java


示例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();
    }
}
 
开发者ID:yngui,项目名称:jephyr,代码行数:30,代码来源:QueryExecutorImpl.java


示例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();
    }
}
 
开发者ID:yngui,项目名称:jephyr,代码行数:32,代码来源:QueryExecutorImpl.java


示例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();
    }
}
 
开发者ID:yngui,项目名称:jephyr,代码行数:17,代码来源:QueryExecutorImpl.java


示例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();
    }
}
 
开发者ID:yngui,项目名称:jephyr,代码行数:22,代码来源:QueryExecutorImpl.java


示例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));
}
 
开发者ID:WeAreWizards,项目名称:passopolis-server,代码行数:22,代码来源:ManagerTest.java


示例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);
    }
}
 
开发者ID:CDS-INSPIRE,项目名称:InSpider,代码行数:19,代码来源:QueryExecutorImpl.java


示例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);
    }
}
 
开发者ID:CDS-INSPIRE,项目名称:InSpider,代码行数:29,代码来源:QueryExecutorImpl.java


示例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);
    }
}
 
开发者ID:CDS-INSPIRE,项目名称:InSpider,代码行数:25,代码来源:QueryExecutorImpl.java


示例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


示例16: readDoubleValue

import org.postgresql.util.PSQLState; //导入依赖的package包/类
/**
 * Converts any numeric binary field to double value. This method
 * does no overflow checking.
 *
 * @param bytes The bytes of the numeric field.
 * @param oid The oid of the field.
 * @param targetType The target type. Used for error reporting.
 * @return The value as double.
 * @throws PSQLException If the field type is not supported numeric type.
 */
private double readDoubleValue(byte[] bytes, int oid,
                               String targetType) throws PSQLException {
    // currently implemented binary encoded fields
    switch (oid) {
    case Oid.INT2:
        return ByteConverter.int2(bytes, 0);
    case Oid.INT4:
        return ByteConverter.int4(bytes, 0);
    case Oid.INT8:
        // might not fit but there still should be no overflow checking
        return ByteConverter.int8(bytes, 0);
    case Oid.FLOAT4:
        return ByteConverter.float4(bytes, 0);
    case Oid.FLOAT8:
        return ByteConverter.float8(bytes, 0);
    }
    throw new PSQLException (GT.tr("Cannot convert the column of type {0} to requested type {1}.",
                new Object[]{Oid.toString(oid), targetType}),
                PSQLState.DATA_TYPE_MISMATCH);
}
 
开发者ID:health-and-care-developer-network,项目名称:health-and-care-developer-network,代码行数:31,代码来源:AbstractJdbc2ResultSet.java


示例17: interpretCommandStatus

import org.postgresql.util.PSQLState; //导入依赖的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
        {
            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,代码行数:23,代码来源:QueryExecutorImpl.java


示例18: setValue

import org.postgresql.util.PSQLState; //导入依赖的package包/类
/**
 * @param s Definition of the path in PostgreSQL's syntax
 * @exception SQLException on conversion failure
 */
public void setValue(String s) throws SQLException
{
    // First test to see if were open
    if (s.startsWith("[") && s.endsWith("]"))
    {
        open = true;
        s = PGtokenizer.removeBox(s);
    }
    else if (s.startsWith("(") && s.endsWith(")"))
    {
        open = false;
        s = PGtokenizer.removePara(s);
    }
    else
        throw new PSQLException(GT.tr("Cannot tell if path is open or closed: {0}.", s), PSQLState.DATA_TYPE_MISMATCH);

    PGtokenizer t = new PGtokenizer(s, ',');
    int npoints = t.getSize();
    points = new PGpoint[npoints];
    for (int p = 0;p < npoints;p++)
        points[p] = new PGpoint(t.getToken(p));
}
 
开发者ID:health-and-care-developer-network,项目名称:health-and-care-developer-network,代码行数:27,代码来源:PGpath.java


示例19: getID

import org.postgresql.util.PSQLState; //导入依赖的package包/类
/**
 * This returns the function id associated by its name.
 *
 * <p>If addFunction() or addFunctions() have not been called for this name,
 * then an SQLException is thrown.
 *
 * @param name Function name to lookup
 * @return Function ID for fastpath call
 * @exception SQLException is function is unknown.
 */
public int getID(String name) throws SQLException
{
    Integer id = (Integer)func.get(name);

    // may be we could add a lookup to the database here, and store the result
    // in our lookup table, throwing the exception if that fails.
    // We must, however, ensure that if we do, any existing ResultSet is
    // unaffected, otherwise we could break user code.
    //
    // so, until we know we can do this (needs testing, on the TODO list)
    // for now, we throw the exception and do no lookups.
    if (id == null)
        throw new PSQLException(GT.tr("The fastpath function {0} is unknown.", name), PSQLState.UNEXPECTED_ERROR);

    return id.intValue();
}
 
开发者ID:health-and-care-developer-network,项目名称:health-and-care-developer-network,代码行数:27,代码来源:Fastpath.java


示例20: setSavepoint

import org.postgresql.util.PSQLState; //导入依赖的package包/类
/**
 * Creates a savepoint with the given name in the current transaction
 * and returns the new <code>Savepoint</code> object that represents it.
 *
 * @param name a <code>String</code> containing the name of the savepoint
 * @return the new <code>Savepoint</code> object
 * @exception SQLException if a database access error occurs
 *     or this <code>Connection</code> object is currently in
 *     auto-commit mode
 * @see Savepoint
 * @since 1.4
 */
public Savepoint setSavepoint(String name) throws SQLException
{
    checkClosed();
    if (!haveMinimumServerVersion("8.0"))
        throw new PSQLException(GT.tr("Server versions prior to 8.0 do not support savepoints."), PSQLState.NOT_IMPLEMENTED);
    if (getAutoCommit())
        throw new PSQLException(GT.tr("Cannot establish a savepoint in auto-commit mode."),
                                PSQLState.NO_ACTIVE_SQL_TRANSACTION);

    PSQLSavepoint savepoint = new PSQLSavepoint(name);

    // Note we can't use execSQLUpdate because we don't want
    // to suppress BEGIN.
    Statement stmt = createStatement();
    stmt.executeUpdate("SAVEPOINT " + savepoint.getPGName());
    stmt.close();

    return savepoint;
}
 
开发者ID:health-and-care-developer-network,项目名称:health-and-care-developer-network,代码行数:32,代码来源:AbstractJdbc3Connection.java



注:本文中的org.postgresql.util.PSQLState类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ImmediateExecutor类代码示例发布时间:2022-05-23
下一篇:
Java JRPropertiesHolder类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap