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


Java ServerErrorMessage.getDetail方法代码示例

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


在下文中一共展示了ServerErrorMessage.getDetail方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
 
开发者ID:manniwood,项目名称:cl4pg,代码行数:23,代码来源:Cl4pgPgSqlException.java

示例2: wrapIfNeededOrReturnNull

import org.postgresql.util.ServerErrorMessage; //导入方法依赖的package包/类
@Override
public DBException wrapIfNeededOrReturnNull(final Throwable t)
{
	final Boolean referencingTableHasDLMLevel;

	if (DBException.isSQLState(t, PG_SQLSTATE_Referencing_Record_Has_Wrong_DLM_Level))
	{
		referencingTableHasDLMLevel = true;
	}
	else if (DBException.isSQLState(t, PG_SQLSTATE_Referencing_Table_Has_No_DLM_LEvel))
	{
		referencingTableHasDLMLevel = false;
	}
	else
	{
		return null;
	}

	//
	// parse the exception detail and extract the infos
	final SQLException sqlException = DBException.extractSQLExceptionOrNull(t);
	Check.errorUnless(sqlException instanceof PSQLException, "exception={} needs to be a PSQLExcetion", sqlException);

	final PSQLException psqlException = (PSQLException)sqlException;
	final ServerErrorMessage serverErrorMessage = psqlException.getServerErrorMessage();
	Check.errorIf(serverErrorMessage == null, "ServerErrorMessage of PSQLException={} may not be null", psqlException);

	final String detail = serverErrorMessage.getDetail();
	Check.errorIf(Check.isEmpty(detail, true), "DETAIL ServerErrorMessage={} from of PSQLException={} may not be null", serverErrorMessage, psqlException);

	final String[] infos = extractInfos(detail);

	//
	// the the "real" tables and column from the extracted lowercase infos
	final IADTableDAO adTableDAO = Services.get(IADTableDAO.class);

	final I_AD_Table referencedTable = adTableDAO.retrieveTable(infos[0]);
	Check.errorIf(referencedTable == null, "Unable to retrieve an AD_Table for referencedTable name={}", infos[0]);

	final I_AD_Table referencingTable = adTableDAO.retrieveTable(infos[2]);
	Check.errorIf(referencingTable == null, "Unable to retrieve an AD_Table for referencingTable name={}", infos[2]);

	final I_AD_Column referencingColumn = adTableDAO.retrieveColumn(referencingTable.getTableName(), infos[3]);
	Check.errorIf(referencingTable == null, "Unable to retrieve an AD_Column for referencingTable name={} and referencingColumn name={}", infos[2], infos[3]);

	final DLMReferenceException ex = new DLMReferenceException(t,
			TableRecordIdDescriptor.of(
					referencingTable.getTableName(),
					referencingColumn.getColumnName(),
					referencedTable.getTableName()),
			referencingTableHasDLMLevel);
	ex.setParameter("referencedRecordId", Integer.parseInt(infos[1]));
	ex.appendParametersToMessage();
	return ex;
}
 
开发者ID:metasfresh,项目名称:metasfresh,代码行数:56,代码来源:DLMReferenceExceptionWrapper.java

示例3: translateDependentObjectsStillExist

import org.postgresql.util.ServerErrorMessage; //导入方法依赖的package包/类
/**
 * Package private for testability
 *
 * @param pSqlException PostgreSQL exception
 * @return translated validation exception
 */
MolgenisValidationException translateDependentObjectsStillExist(PSQLException pSqlException)
{
	ServerErrorMessage serverErrorMessage = pSqlException.getServerErrorMessage();
	String detail = serverErrorMessage.getDetail();
	Matcher matcher = Pattern.compile("constraint (.+) on table \"?([^\"]+)\"? depends on table \"?([^\"]+)\"?\n?")
							 .matcher(detail);

	Map<String, Set<String>> entityTypeDependencyMap = new LinkedHashMap<>();
	while (matcher.find())
	{
		String tableName = matcher.group(2);
		String dependentTableName = matcher.group(3);

		String entityTypeName = getEntityTypeName(tableName);
		String dependentEntityTypeName = getEntityTypeName(dependentTableName);
		Set<String> dependentTableNames = entityTypeDependencyMap.computeIfAbsent(dependentEntityTypeName,
				k -> new LinkedHashSet<>());
		dependentTableNames.add(entityTypeName);
	}

	if (entityTypeDependencyMap.isEmpty()) // no matches
	{
		LOG.error("Error translating postgres exception: ", pSqlException);
		throw new RuntimeException("Error translating exception", pSqlException);
	}

	Set<ConstraintViolation> constraintViolations = entityTypeDependencyMap.entrySet().stream().map(entry ->
	{
		String message;
		if (entry.getValue().size() == 1)
		{
			message = format("Cannot delete entity '%s' because entity '%s' depends on it.", entry.getKey(),
					entry.getValue().iterator().next());
		}
		else
		{
			message = format("Cannot delete entity '%s' because entities '%s' depend on it.", entry.getKey(),
					entry.getValue().stream().collect(joining(", ")));
		}
		return new ConstraintViolation(message, null);
	}).collect(toCollection(LinkedHashSet::new));

	return new MolgenisValidationException(constraintViolations);
}
 
开发者ID:molgenis,项目名称:molgenis,代码行数:51,代码来源:PostgreSqlExceptionTranslator.java

示例4: translateForeignKeyViolation

import org.postgresql.util.ServerErrorMessage; //导入方法依赖的package包/类
/**
 * Package private for testability
 *
 * @param pSqlException PostgreSQL exception
 * @return translated validation exception
 */
MolgenisValidationException translateForeignKeyViolation(PSQLException pSqlException)
{
	ServerErrorMessage serverErrorMessage = pSqlException.getServerErrorMessage();
	String tableName = serverErrorMessage.getTable();
	String detailMessage = serverErrorMessage.getDetail();
	Matcher m = Pattern.compile("\\((.*?)\\)").matcher(detailMessage);
	if (!m.find())
	{
		LOG.error("Error translating postgres exception: ", pSqlException);
		throw new RuntimeException("Error translating exception", pSqlException);
	}
	String colName = m.group(1);
	if (!m.find())
	{
		LOG.error("Error translating postgres exception: ", pSqlException);
		throw new RuntimeException("Error translating exception", pSqlException);
	}
	String value = m.group(1);

	String constraintViolationMessageTemplate;
	String attrName;
	if (detailMessage.contains("still referenced from"))
	{
		// ERROR: update or delete on table "x" violates foreign key constraint "y" on table "z"
		// Detail: Key (k)=(v) is still referenced from table "x".
		constraintViolationMessageTemplate = "Value '%s' for attribute '%s' is referenced by entity '%s'.";
		String refTableName = getRefTableFromForeignKeyPsqlException(pSqlException);
		attrName = getAttributeName(refTableName, colName);
	}
	else
	{
		// ERROR: insert or update on table "x" violates foreign key constraint "y"
		// Detail: Key (k)=(v) is not present in table "z".
		constraintViolationMessageTemplate = "Unknown xref value '%s' for attribute '%s' of entity '%s'.";
		attrName = getAttributeName(tableName, colName);
	}
	ConstraintViolation constraintViolation = new ConstraintViolation(
			format(constraintViolationMessageTemplate, value, attrName, getEntityTypeName(tableName)), null);
	return new MolgenisValidationException(singleton(constraintViolation));
}
 
开发者ID:molgenis,项目名称:molgenis,代码行数:47,代码来源:PostgreSqlExceptionTranslator.java


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