当前位置: 首页>>代码示例>>Java>>正文


Java PSQLException类代码示例

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


PSQLException类属于org.postgresql.util包,在下文中一共展示了PSQLException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createTempTable

import org.postgresql.util.PSQLException; //导入依赖的package包/类
private void createTempTable(final String relation, final String definition)
		throws SQLException {
	Statement stmnt = conn.createStatement();
	try {
		String sqlStmnt = "CREATE TEMP TABLE IF NOT EXISTS %s (%s) "
				+ "ON COMMIT DELETE ROWS;";
		String query = String.format(sqlStmnt, relation, definition);
		stmnt.execute(query);
		MyLogger.logSQL(query);
	} catch (PSQLException e) {
		System.err.println("Can not create this temp table: " + relation);
		throw e;
	} finally {
		stmnt.close();
	}

}
 
开发者ID:prup,项目名称:data-lawyer,代码行数:18,代码来源:Postgres.java

示例2: fastpathCall

import org.postgresql.util.PSQLException; //导入依赖的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

示例3: toDouble

import org.postgresql.util.PSQLException; //导入依赖的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

示例4: unableToExecuteStatement

import org.postgresql.util.PSQLException; //导入依赖的package包/类
@ExceptionHandler(value = UnableToExecuteStatementException.class)
public ResponseEntity<Object> unableToExecuteStatement(UnableToExecuteStatementException exception) {
    logger.error(exception.getMessage(), exception);

    Optional<Throwable> cause = Optional.ofNullable(Throwables.getRootCause(exception))
        .filter(c -> c != exception);

    Optional<String> exceptionName = cause.map(c -> c.getClass().getName());
    Optional<String> message = cause.map(Throwable::getMessage);

    if (exceptionName.isPresent() && exceptionName.get().contains(PSQLException.class.getName())
        && message.isPresent() && message.get().contains(UNIQUE_CONSTRAINT_MESSAGE)) {
        return new ResponseEntity<>(message.get(), HttpStatus.CONFLICT);
    }

    return new ResponseEntity<>("Internal server error", new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR);
}
 
开发者ID:hmcts,项目名称:cmc-claim-store,代码行数:18,代码来源:ResourceExceptionHandler.java

示例5: saveClaimShouldReturnConflictForDuplicateClaimFailures

import org.postgresql.util.PSQLException; //导入依赖的package包/类
@Test
public void saveClaimShouldReturnConflictForDuplicateClaimFailures() throws Exception {
    String claimantId = "1";

    Exception duplicateKeyError = new UnableToExecuteStatementException(new PSQLException(
        "ERROR: duplicate key value violates unique constraint \"external_id_unique\"", null), null);

    given(userService.getUserDetails(anyString())).willReturn(SampleUserDetails.builder()
        .withUserId(claimantId)
        .withMail("[email protected]")
        .build());

    given(claimRepository.saveRepresented(anyString(), anyString(), any(LocalDate.class),
        any(LocalDate.class), anyString(), anyString()))
        .willThrow(duplicateKeyError);

    webClient
        .perform(post("/claims/" + claimantId)
            .header(HttpHeaders.CONTENT_TYPE, "application/json")
            .header(HttpHeaders.AUTHORIZATION, "token")
            .content(jsonMapper.toJson(SampleClaimData.validDefaults()))
        )
        .andExpect(status().isConflict());
}
 
开发者ID:hmcts,项目名称:cmc-claim-store,代码行数:25,代码来源:EndpointErrorsTest.java

示例6: getEvents

import org.postgresql.util.PSQLException; //导入依赖的package包/类
@Override
public List<Event> getEvents()
{
    try
    {
        return executeSelect("select * from events order by date", null, Event.class.getConstructor(ResultSet.class));
    }
    catch (Exception ioe)
    {
        List<Event> blank = new ArrayList<Event>();
        if (ioe instanceof PSQLException) {
            if (((PSQLException)ioe).getSQLState().equals("42P01")) {
                return blank;
            }
        }
        logError("getEvents", ioe);
        return new ArrayList<Event>();
    }
}
 
开发者ID:drytoastman,项目名称:scorekeeperfrontend,代码行数:20,代码来源:SQLDataInterface.java

示例7: unlock

import org.postgresql.util.PSQLException; //导入依赖的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

示例8: endCopy

import org.postgresql.util.PSQLException; //导入依赖的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

示例9: writeToCopy

import org.postgresql.util.PSQLException; //导入依赖的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

示例10: flushCopy

import org.postgresql.util.PSQLException; //导入依赖的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

示例11: readFromCopy

import org.postgresql.util.PSQLException; //导入依赖的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

示例12: testExtractPSQLException

import org.postgresql.util.PSQLException; //导入依赖的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

示例13: testConnPropertiesNegative

import org.postgresql.util.PSQLException; //导入依赖的package包/类
@Test
public void testConnPropertiesNegative() throws Exception {
  Map<String, String> connProperties = new HashMap<>();
  connProperties.put("user", "postgresX");
  connProperties.put("password", "");

  String uri = PgSQLTestServer.getInstance().getJdbcUrl().split("\\?")[0];
  Tablespace space = new PgSQLTablespace("t1", URI.create(uri), getJsonTablespace(connProperties));
  try {
    space.init(new TajoConf());
    fail("Must be failed");
  } catch (IOException ioe) {
    assertTrue(ioe.getCause() instanceof PSQLException);
  } finally {
    space.close();
  }
}
 
开发者ID:apache,项目名称:tajo,代码行数:18,代码来源:TestPgSQLJdbcTableSpace.java

示例14: fastpathCall

import org.postgresql.util.PSQLException; //导入依赖的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

示例15: startCopy

import org.postgresql.util.PSQLException; //导入依赖的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


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