本文整理汇总了Java中org.postgresql.util.ServerErrorMessage类的典型用法代码示例。如果您正苦于以下问题:Java ServerErrorMessage类的具体用法?Java ServerErrorMessage怎么用?Java ServerErrorMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ServerErrorMessage类属于org.postgresql.util包,在下文中一共展示了ServerErrorMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initFromServerErrorMessage
import org.postgresql.util.ServerErrorMessage; //导入依赖的package包/类
private void initFromServerErrorMessage(ServerErrorMessage sem) {
if (sem == null) {
return;
}
sqlState = sem.getSQLState();
serverMessage = sem.getMessage();
severity = sem.getSeverity();
detail = sem.getDetail();
hint = sem.getHint();
position = sem.getPosition();
where = sem.getWhere();
schema = sem.getSchema();
table = sem.getTable();
column = sem.getColumn();
dataType = sem.getDatatype();
constraint = sem.getConstraint();
file = sem.getFile();
line = sem.getLine();
routine = sem.getRoutine();
internalQuery = sem.getInternalQuery();
internalPosition = sem.getInternalPosition();
}
示例2: receiveNoticeResponse
import org.postgresql.util.ServerErrorMessage; //导入依赖的package包/类
private SQLWarning receiveNoticeResponse() throws IOException {
int nlen = pgStream.ReceiveInteger4();
ServerErrorMessage warnMsg = new ServerErrorMessage(pgStream.ReceiveString(nlen - 4), logger.getLogLevel());
if (logger.logDebug())
logger.debug(" <=BE NoticeResponse(" + warnMsg.toString() + ")");
return new PSQLWarning(warnMsg);
}
示例3: receiveErrorResponse
import org.postgresql.util.ServerErrorMessage; //导入依赖的package包/类
private SQLException receiveErrorResponse() throws IOException {
// it's possible to get more than one error message for a query
// see libpq comments wrt backend closing a connection
// so, append messages to a string buffer and keep processing
// check at the bottom to see if we need to throw an exception
int elen = pgStream.ReceiveInteger4();
String totalMessage = pgStream.ReceiveString(elen - 4);
ServerErrorMessage errorMsg = new ServerErrorMessage(totalMessage, logger.getLogLevel());
if (logger.logDebug())
logger.debug(" <=BE ErrorMessage(" + errorMsg.toString() + ")");
return new PSQLException(errorMsg);
}
示例4: getRefTableFromForeignKeyPsqlException
import org.postgresql.util.ServerErrorMessage; //导入依赖的package包/类
private String getRefTableFromForeignKeyPsqlException(PSQLException pSqlException)
{
ServerErrorMessage serverErrorMessage = pSqlException.getServerErrorMessage();
Matcher messageMatcher = Pattern.compile(
"update or delete on table \"(.*)\" violates foreign key constraint \"(.*)\" on table \"(.*)\"")
.matcher(serverErrorMessage.getMessage());
if (!messageMatcher.matches())
{
LOG.error("Error translating postgres exception: ", pSqlException);
throw new RuntimeException("Error translating exception", pSqlException);
}
return messageMatcher.group(1);
}
示例5: translateCheckConstraintViolation
import org.postgresql.util.ServerErrorMessage; //导入依赖的package包/类
/**
* Package private for testability
*
* @param pSqlException PostgreSQL exception
* @return translated validation exception
*/
MolgenisValidationException translateCheckConstraintViolation(PSQLException pSqlException)
{
ServerErrorMessage serverErrorMessage = pSqlException.getServerErrorMessage();
String tableName = serverErrorMessage.getTable();
String constraintName = serverErrorMessage.getConstraint();
// constraint name: <tableName>_<columnName>_chk
String columnName = constraintName.substring(tableName.length() + 1, constraintName.length() - 4);
ConstraintViolation constraintViolation = new ConstraintViolation(
format("Unknown enum value for attribute '%s' of entity '%s'.", getAttributeName(tableName, columnName),
getEntityTypeName(tableName)), null);
return new MolgenisValidationException(singleton(constraintViolation));
}
示例6: translateUndefinedColumnException
import org.postgresql.util.ServerErrorMessage; //导入依赖的package包/类
/**
* Package private for testability
*
* @param pSqlException PostgreSQL exception
* @return translated validation exception
*/
static MolgenisValidationException translateUndefinedColumnException(PSQLException pSqlException)
{
ServerErrorMessage serverErrorMessage = pSqlException.getServerErrorMessage();
String message = serverErrorMessage.getMessage(); // FIXME exposes internal message
ConstraintViolation constraintViolation = new ConstraintViolation(message);
return new MolgenisValidationException(singleton(constraintViolation));
}
示例7: translateReadonlyViolation
import org.postgresql.util.ServerErrorMessage; //导入依赖的package包/类
@Test
public void translateReadonlyViolation()
{
ServerErrorMessage serverErrorMessage = mock(ServerErrorMessage.class);
when(serverErrorMessage.getMessage()).thenReturn(
"Updating read-only column \"myColumn\" of table \"myTable\" with id [abc] is not allowed");
//noinspection ThrowableResultOfMethodCallIgnored
MolgenisValidationException e = postgreSqlExceptionTranslator.translateReadonlyViolation(
new PSQLException(serverErrorMessage));
assertEquals(e.getMessage(),
"Updating read-only attribute 'myAttr' of entity 'myEntity' with id 'abc' is not allowed.");
}
示例8: translateReadonlyViolationNoDoubleQuotes
import org.postgresql.util.ServerErrorMessage; //导入依赖的package包/类
@Test
public void translateReadonlyViolationNoDoubleQuotes()
{
ServerErrorMessage serverErrorMessage = mock(ServerErrorMessage.class);
when(serverErrorMessage.getMessage()).thenReturn(
"Updating read-only column myColumn of table myTable with id [abc] is not allowed");
//noinspection ThrowableResultOfMethodCallIgnored
MolgenisValidationException e = postgreSqlExceptionTranslator.translateReadonlyViolation(
new PSQLException(serverErrorMessage));
assertEquals(e.getMessage(),
"Updating read-only attribute 'myAttr' of entity 'myEntity' with id 'abc' is not allowed.");
}
示例9: translateDependentObjectsStillExistOneDependentTableSingleDependency
import org.postgresql.util.ServerErrorMessage; //导入依赖的package包/类
@Test
public void translateDependentObjectsStillExistOneDependentTableSingleDependency()
{
ServerErrorMessage serverErrorMessage = mock(ServerErrorMessage.class);
when(serverErrorMessage.getSQLState()).thenReturn("2BP01");
when(serverErrorMessage.getDetail()).thenReturn(
"constraint my_foreign_key_constraint on table \"myTable\" depends on table \"myDependentTable\"");
//noinspection ThrowableResultOfMethodCallIgnored
MolgenisValidationException e = postgreSqlExceptionTranslator.translateDependentObjectsStillExist(
new PSQLException(serverErrorMessage));
assertEquals(e.getMessage(), "Cannot delete entity 'myRefEntity' because entity 'myEntity' depends on it.");
}
示例10: translateDependentObjectsStillExistOneDependentTableMultipleDependencies
import org.postgresql.util.ServerErrorMessage; //导入依赖的package包/类
@Test
public void translateDependentObjectsStillExistOneDependentTableMultipleDependencies()
{
ServerErrorMessage serverErrorMessage = mock(ServerErrorMessage.class);
when(serverErrorMessage.getSQLState()).thenReturn("2BP01");
when(serverErrorMessage.getDetail()).thenReturn(
"constraint my_foreign_key_constraint on table \"myTable\" depends on table \"myDependentTable\"\nconstraint myOther_foreign_key_constraint on table \"myTable\" depends on table \"myDependentTable\"");
//noinspection ThrowableResultOfMethodCallIgnored
MolgenisValidationException e = postgreSqlExceptionTranslator.translateDependentObjectsStillExist(
new PSQLException(serverErrorMessage));
assertEquals(e.getMessage(), "Cannot delete entity 'myRefEntity' because entity 'myEntity' depends on it.");
}
示例11: translateDependentObjectsStillExistMultipleDependentTables
import org.postgresql.util.ServerErrorMessage; //导入依赖的package包/类
@Test
public void translateDependentObjectsStillExistMultipleDependentTables()
{
ServerErrorMessage serverErrorMessage = mock(ServerErrorMessage.class);
when(serverErrorMessage.getSQLState()).thenReturn("2BP01");
when(serverErrorMessage.getDetail()).thenReturn(
"constraint my_foreign_key_constraint on table \"myTable\" depends on table \"myDependentTable\"\nconstraint myOther_foreign_key_constraint on table \"myTable\" depends on table \"myOtherDependentTable\"");
//noinspection ThrowableResultOfMethodCallIgnored
MolgenisValidationException e = postgreSqlExceptionTranslator.translateDependentObjectsStillExist(
new PSQLException(serverErrorMessage));
assertEquals(e.getMessage(),
"Cannot delete entity 'myRefEntity' because entity 'myEntity' depends on it..Cannot delete entity 'myOtherRefEntity' because entity 'myEntity' depends on it.");
}
示例12: translateDependentObjectsStillExistNoDoubleQuotes
import org.postgresql.util.ServerErrorMessage; //导入依赖的package包/类
@Test
public void translateDependentObjectsStillExistNoDoubleQuotes()
{
ServerErrorMessage serverErrorMessage = mock(ServerErrorMessage.class);
when(serverErrorMessage.getSQLState()).thenReturn("2BP01");
when(serverErrorMessage.getDetail()).thenReturn(
"constraint my_foreign_key_constraint on table myTable depends on table myDependentTable");
//noinspection ThrowableResultOfMethodCallIgnored
MolgenisValidationException e = postgreSqlExceptionTranslator.translateDependentObjectsStillExist(
new PSQLException(serverErrorMessage));
assertEquals(e.getMessage(), "Cannot delete entity 'myRefEntity' because entity 'myEntity' depends on it.");
}
示例13: translateNotNullViolation
import org.postgresql.util.ServerErrorMessage; //导入依赖的package包/类
@Test
public void translateNotNullViolation()
{
ServerErrorMessage serverErrorMessage = mock(ServerErrorMessage.class);
when(serverErrorMessage.getSQLState()).thenReturn("23502");
when(serverErrorMessage.getTable()).thenReturn("myTable");
when(serverErrorMessage.getMessage()).thenReturn(
"null value in column \"myColumn\" violates not-null constraint");
//noinspection ThrowableResultOfMethodCallIgnored
MolgenisValidationException e = postgreSqlExceptionTranslator.translateNotNullViolation(
new PSQLException(serverErrorMessage));
assertEquals(e.getMessage(), "The attribute 'myAttr' of entity 'myEntity' can not be null.");
}
示例14: translateNotNullViolationBadMessage
import org.postgresql.util.ServerErrorMessage; //导入依赖的package包/类
@Test(expectedExceptions = RuntimeException.class)
public void translateNotNullViolationBadMessage()
{
ServerErrorMessage serverErrorMessage = mock(ServerErrorMessage.class);
when(serverErrorMessage.getSQLState()).thenReturn("23502");
when(serverErrorMessage.getTable()).thenReturn("mytable");
when(serverErrorMessage.getMessage()).thenReturn("xxxyyyzzzz");
//noinspection ThrowableResultOfMethodCallIgnored
postgreSqlExceptionTranslator.translateNotNullViolation(new PSQLException(serverErrorMessage));
}
示例15: translateNotNullViolationNoDoubleQuotes
import org.postgresql.util.ServerErrorMessage; //导入依赖的package包/类
@Test
public void translateNotNullViolationNoDoubleQuotes()
{
ServerErrorMessage serverErrorMessage = mock(ServerErrorMessage.class);
when(serverErrorMessage.getSQLState()).thenReturn("23502");
when(serverErrorMessage.getTable()).thenReturn("myTable");
when(serverErrorMessage.getMessage()).thenReturn("null value in column myColumn violates not-null constraint");
//noinspection ThrowableResultOfMethodCallIgnored
MolgenisValidationException e = postgreSqlExceptionTranslator.translateNotNullViolation(
new PSQLException(serverErrorMessage));
assertEquals(e.getMessage(), "The attribute 'myAttr' of entity 'myEntity' can not be null.");
}