List of usage examples for org.springframework.dao DataAccessException getCause
public synchronized Throwable getCause()
From source file:com.gst.portfolio.savings.service.SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl.java
@Transactional @Override// w w w.j a v a 2 s . c o m public CommandProcessingResult modifyApplication(final Long savingsId, final JsonCommand command) { try { this.savingsAccountDataValidator.validateForUpdate(command.json()); final Map<String, Object> changes = new LinkedHashMap<>(20); final SavingsAccount account = this.savingAccountAssembler.assembleFrom(savingsId); checkClientOrGroupActive(account); account.modifyApplication(command, changes); account.validateNewApplicationState(DateUtils.getLocalDateOfTenant(), SAVINGS_ACCOUNT_RESOURCE_NAME); account.validateAccountValuesWithProduct(); if (!changes.isEmpty()) { if (changes.containsKey(SavingsApiConstants.clientIdParamName)) { final Long clientId = command.longValueOfParameterNamed(SavingsApiConstants.clientIdParamName); if (clientId != null) { final Client client = this.clientRepository.findOneWithNotFoundDetection(clientId); if (client.isNotActive()) { throw new ClientNotActiveException(clientId); } account.update(client); } else { final Client client = null; account.update(client); } } if (changes.containsKey(SavingsApiConstants.groupIdParamName)) { final Long groupId = command.longValueOfParameterNamed(SavingsApiConstants.groupIdParamName); if (groupId != null) { final Group group = this.groupRepository.findOne(groupId); if (group == null) { throw new GroupNotFoundException(groupId); } if (group.isNotActive()) { if (group.isCenter()) { throw new CenterNotActiveException(groupId); } throw new GroupNotActiveException(groupId); } account.update(group); } else { final Group group = null; account.update(group); } } if (changes.containsKey(SavingsApiConstants.productIdParamName)) { final Long productId = command .longValueOfParameterNamed(SavingsApiConstants.productIdParamName); final SavingsProduct product = this.savingsProductRepository.findOne(productId); if (product == null) { throw new SavingsProductNotFoundException(productId); } account.update(product); } if (changes.containsKey(SavingsApiConstants.fieldOfficerIdParamName)) { final Long fieldOfficerId = command .longValueOfParameterNamed(SavingsApiConstants.fieldOfficerIdParamName); Staff fieldOfficer = null; if (fieldOfficerId != null) { fieldOfficer = this.staffRepository.findOneWithNotFoundDetection(fieldOfficerId); } else { changes.put(SavingsApiConstants.fieldOfficerIdParamName, ""); } account.update(fieldOfficer); } if (changes.containsKey("charges")) { final Set<SavingsAccountCharge> charges = this.savingsAccountChargeAssembler .fromParsedJson(command.parsedJson(), account.getCurrency().getCode()); final boolean updated = account.update(charges); if (!updated) { changes.remove("charges"); } } this.savingAccountRepository.saveAndFlush(account); } return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // .withEntityId(savingsId) // .withOfficeId(account.officeId()) // .withClientId(account.clientId()) // .withGroupId(account.groupId()) // .withSavingsId(savingsId) // .with(changes) // .build(); } catch (final DataAccessException dve) { handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return new CommandProcessingResult(Long.valueOf(-1)); } catch (final PersistenceException dve) { Throwable throwable = ExceptionUtils.getRootCause(dve.getCause()); handleDataIntegrityIssues(command, throwable, dve); return CommandProcessingResult.empty(); } }
From source file:com.gst.portfolio.savings.service.DepositApplicationProcessWritePlatformServiceJpaRepositoryImpl.java
@Transactional @Override/*from www . ja v a 2 s .c o m*/ public CommandProcessingResult submitRDApplication(final JsonCommand command) { try { this.depositAccountDataValidator.validateRecurringDepositForSubmit(command.json()); final AppUser submittedBy = this.context.authenticatedUser(); final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService .isSavingsInterestPostingAtCurrentPeriodEnd(); final Integer financialYearBeginningMonth = this.configurationDomainService .retrieveFinancialYearBeginningMonth(); final RecurringDepositAccount account = (RecurringDepositAccount) this.depositAccountAssembler .assembleFrom(command, submittedBy, DepositAccountType.RECURRING_DEPOSIT); this.recurringDepositAccountRepository.save(account); if (account.isAccountNumberRequiresAutoGeneration()) { final AccountNumberFormat accountNumberFormat = this.accountNumberFormatRepository .findByAccountType(EntityAccountType.SAVINGS); account.updateAccountNo(this.accountNumberGenerator.generate(account, accountNumberFormat)); } final Long savingsId = account.getId(); final CalendarInstance calendarInstance = getCalendarInstance(command, account); this.calendarInstanceRepository.save(calendarInstance); // FIXME: Avoid save separately (Calendar instance requires account // details) final MathContext mc = MathContext.DECIMAL64; final Calendar calendar = calendarInstance.getCalendar(); final PeriodFrequencyType frequencyType = CalendarFrequencyType .from(CalendarUtils.getFrequency(calendar.getRecurrence())); Integer frequency = CalendarUtils.getInterval(calendar.getRecurrence()); frequency = frequency == -1 ? 1 : frequency; account.generateSchedule(frequencyType, frequency, calendar); final boolean isPreMatureClosure = false; account.updateMaturityDateAndAmount(mc, isPreMatureClosure, isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth); account.validateApplicableInterestRate(); this.savingAccountRepository.save(account); return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // .withEntityId(savingsId) // .withOfficeId(account.officeId()) // .withClientId(account.clientId()) // .withGroupId(account.groupId()) // .withSavingsId(savingsId) // .build(); } catch (final DataAccessException dve) { handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { Throwable throwable = ExceptionUtils.getRootCause(dve.getCause()); handleDataIntegrityIssues(command, throwable, dve); return CommandProcessingResult.empty(); } }
From source file:com.gst.portfolio.savings.service.DepositApplicationProcessWritePlatformServiceJpaRepositoryImpl.java
@Transactional @Override/* w w w. j a v a2 s . c o m*/ public CommandProcessingResult submitFDApplication(final JsonCommand command) { try { this.depositAccountDataValidator.validateFixedDepositForSubmit(command.json()); final AppUser submittedBy = this.context.authenticatedUser(); final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService .isSavingsInterestPostingAtCurrentPeriodEnd(); final Integer financialYearBeginningMonth = this.configurationDomainService .retrieveFinancialYearBeginningMonth(); final FixedDepositAccount account = (FixedDepositAccount) this.depositAccountAssembler .assembleFrom(command, submittedBy, DepositAccountType.FIXED_DEPOSIT); final MathContext mc = MathContext.DECIMAL64; final boolean isPreMatureClosure = false; account.updateMaturityDateAndAmountBeforeAccountActivation(mc, isPreMatureClosure, isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth); this.fixedDepositAccountRepository.save(account); if (account.isAccountNumberRequiresAutoGeneration()) { AccountNumberFormat accountNumberFormat = this.accountNumberFormatRepository .findByAccountType(EntityAccountType.CLIENT); account.updateAccountNo(this.accountNumberGenerator.generate(account, accountNumberFormat)); this.savingAccountRepository.save(account); } // Save linked account information final Long savingsAccountId = command .longValueOfParameterNamed(DepositsApiConstants.linkedAccountParamName); if (savingsAccountId != null) { final SavingsAccount savingsAccount = this.depositAccountAssembler.assembleFrom(savingsAccountId, DepositAccountType.SAVINGS_DEPOSIT); this.depositAccountDataValidator.validatelinkedSavingsAccount(savingsAccount, account); boolean isActive = true; final AccountAssociations accountAssociations = AccountAssociations.associateSavingsAccount(account, savingsAccount, AccountAssociationType.LINKED_ACCOUNT_ASSOCIATION.getValue(), isActive); this.accountAssociationsRepository.save(accountAssociations); } final Long savingsId = account.getId(); return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // .withEntityId(savingsId) // .withOfficeId(account.officeId()) // .withClientId(account.clientId()) // .withGroupId(account.groupId()) // .withSavingsId(savingsId) // .build(); } catch (final DataAccessException dve) { handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return CommandProcessingResult.empty(); } catch (final PersistenceException dve) { Throwable throwable = ExceptionUtils.getRootCause(dve.getCause()); handleDataIntegrityIssues(command, throwable, dve); return CommandProcessingResult.empty(); } }
From source file:com.gst.portfolio.savings.service.DepositApplicationProcessWritePlatformServiceJpaRepositoryImpl.java
@Transactional @Override/* ww w .j a v a2 s. com*/ public CommandProcessingResult modifyRDApplication(final Long accountId, final JsonCommand command) { try { this.depositAccountDataValidator.validateRecurringDepositForUpdate(command.json()); final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService .isSavingsInterestPostingAtCurrentPeriodEnd(); final Integer financialYearBeginningMonth = this.configurationDomainService .retrieveFinancialYearBeginningMonth(); final Map<String, Object> changes = new LinkedHashMap<>(20); final RecurringDepositAccount account = (RecurringDepositAccount) this.depositAccountAssembler .assembleFrom(accountId, DepositAccountType.RECURRING_DEPOSIT); checkClientOrGroupActive(account); account.modifyApplication(command, changes); account.validateNewApplicationState(DateUtils.getLocalDateOfTenant(), DepositAccountType.RECURRING_DEPOSIT.resourceName()); if (!changes.isEmpty()) { updateFDAndRDCommonChanges(changes, command, account); final MathContext mc = MathContext.DECIMAL64; final CalendarInstance calendarInstance = this.calendarInstanceRepository .findByEntityIdAndEntityTypeIdAndCalendarTypeId(accountId, CalendarEntityType.SAVINGS.getValue(), CalendarType.COLLECTION.getValue()); final Calendar calendar = calendarInstance.getCalendar(); final PeriodFrequencyType frequencyType = CalendarFrequencyType .from(CalendarUtils.getFrequency(calendar.getRecurrence())); Integer frequency = CalendarUtils.getInterval(calendar.getRecurrence()); frequency = frequency == -1 ? 1 : frequency; account.generateSchedule(frequencyType, frequency, calendar); final boolean isPreMatureClosure = false; account.updateMaturityDateAndAmount(mc, isPreMatureClosure, isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth); account.validateApplicableInterestRate(); this.savingAccountRepository.save(account); } // update calendar details if (!account.isCalendarInherited()) { final LocalDate calendarStartDate = account.depositStartDate(); final Integer frequencyType = command .integerValueSansLocaleOfParameterNamed(recurringFrequencyTypeParamName); final PeriodFrequencyType periodFrequencyType = PeriodFrequencyType.fromInt(frequencyType); final Integer frequency = command .integerValueSansLocaleOfParameterNamed(recurringFrequencyParamName); final Integer repeatsOnDay = calendarStartDate.getDayOfWeek(); CalendarInstance calendarInstance = this.calendarInstanceRepository .findByEntityIdAndEntityTypeIdAndCalendarTypeId(accountId, CalendarEntityType.SAVINGS.getValue(), CalendarType.COLLECTION.getValue()); Calendar calendar = calendarInstance.getCalendar(); calendar.updateRepeatingCalendar(calendarStartDate, CalendarFrequencyType.from(periodFrequencyType), frequency, repeatsOnDay, null); this.calendarInstanceRepository.save(calendarInstance); } return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // .withEntityId(accountId) // .withOfficeId(account.officeId()) // .withClientId(account.clientId()) // .withGroupId(account.groupId()) // .withSavingsId(accountId) // .with(changes) // .build(); } catch (final DataAccessException dve) { handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return new CommandProcessingResult(Long.valueOf(-1)); } catch (final PersistenceException dve) { Throwable throwable = ExceptionUtils.getRootCause(dve.getCause()); handleDataIntegrityIssues(command, throwable, dve); return new CommandProcessingResult(Long.valueOf(-1)); } }
From source file:com.gst.portfolio.savings.service.DepositApplicationProcessWritePlatformServiceJpaRepositoryImpl.java
@Transactional @Override//from w w w. j ava 2 s.com public CommandProcessingResult modifyFDApplication(final Long accountId, final JsonCommand command) { try { this.depositAccountDataValidator.validateFixedDepositForUpdate(command.json()); final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService .isSavingsInterestPostingAtCurrentPeriodEnd(); final Integer financialYearBeginningMonth = this.configurationDomainService .retrieveFinancialYearBeginningMonth(); final Map<String, Object> changes = new LinkedHashMap<>(20); final FixedDepositAccount account = (FixedDepositAccount) this.depositAccountAssembler .assembleFrom(accountId, DepositAccountType.FIXED_DEPOSIT); checkClientOrGroupActive(account); account.modifyApplication(command, changes); account.validateNewApplicationState(DateUtils.getLocalDateOfTenant(), DepositAccountType.FIXED_DEPOSIT.resourceName()); if (!changes.isEmpty()) { updateFDAndRDCommonChanges(changes, command, account); final MathContext mc = MathContext.DECIMAL64; final boolean isPreMatureClosure = false; account.updateMaturityDateAndAmountBeforeAccountActivation(mc, isPreMatureClosure, isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth); this.savingAccountRepository.save(account); } boolean isLinkedAccRequired = command .booleanPrimitiveValueOfParameterNamed(transferInterestToSavingsParamName); // Save linked account information final Long savingsAccountId = command .longValueOfParameterNamed(DepositsApiConstants.linkedAccountParamName); AccountAssociations accountAssociations = this.accountAssociationsRepository.findBySavingsIdAndType( accountId, AccountAssociationType.LINKED_ACCOUNT_ASSOCIATION.getValue()); if (savingsAccountId == null) { if (accountAssociations != null) { if (this.fromJsonHelper.parameterExists(DepositsApiConstants.linkedAccountParamName, command.parsedJson())) { this.accountAssociationsRepository.delete(accountAssociations); changes.put(DepositsApiConstants.linkedAccountParamName, null); if (isLinkedAccRequired) { this.depositAccountDataValidator.throwLinkedAccountRequiredError(); } } } else if (isLinkedAccRequired) { this.depositAccountDataValidator.throwLinkedAccountRequiredError(); } } else { boolean isModified = false; if (accountAssociations == null) { isModified = true; } else { final SavingsAccount savingsAccount = accountAssociations.linkedSavingsAccount(); if (savingsAccount == null || savingsAccount.getId() != savingsAccountId) { isModified = true; } } if (isModified) { final SavingsAccount savingsAccount = this.depositAccountAssembler .assembleFrom(savingsAccountId, DepositAccountType.SAVINGS_DEPOSIT); this.depositAccountDataValidator.validatelinkedSavingsAccount(savingsAccount, account); if (accountAssociations == null) { boolean isActive = true; accountAssociations = AccountAssociations.associateSavingsAccount(account, savingsAccount, AccountAssociationType.LINKED_ACCOUNT_ASSOCIATION.getValue(), isActive); } else { accountAssociations.updateLinkedSavingsAccount(savingsAccount); } changes.put(DepositsApiConstants.linkedAccountParamName, savingsAccountId); this.accountAssociationsRepository.save(accountAssociations); } } return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // .withEntityId(accountId) // .withOfficeId(account.officeId()) // .withClientId(account.clientId()) // .withGroupId(account.groupId()) // .withSavingsId(accountId) // .with(changes) // .build(); } catch (final DataAccessException dve) { handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); return new CommandProcessingResult(Long.valueOf(-1)); } catch (final PersistenceException dve) { Throwable throwable = ExceptionUtils.getRootCause(dve.getCause()); handleDataIntegrityIssues(command, throwable, dve); return new CommandProcessingResult(Long.valueOf(-1)); } }
From source file:com.gst.infrastructure.dataqueries.service.ReadWriteNonCoreDataServiceImpl.java
@Override public CommandProcessingResult createPPIEntry(final String dataTableName, final Long appTableId, final JsonCommand command) { try {//from w w w.j a v a 2 s . c o m final String appTable = queryForApplicationTableName(dataTableName); final CommandProcessingResult commandProcessingResult = checkMainResourceExistsWithinScope(appTable, appTableId); final List<ResultsetColumnHeaderData> columnHeaders = this.genericDataService .fillResultsetColumnHeaders(dataTableName); final Type typeOfMap = new TypeToken<Map<String, String>>() { }.getType(); final Map<String, String> dataParams = this.fromJsonHelper.extractDataMap(typeOfMap, command.json()); final String sql = getAddSqlWithScore(columnHeaders, dataTableName, getFKField(appTable), appTableId, dataParams); this.jdbcTemplate.update(sql); return commandProcessingResult; // } catch (final DataAccessException dve) { final Throwable cause = dve.getCause(); final Throwable realCause = dve.getMostSpecificCause(); if (realCause.getMessage().contains("Duplicate entry") || cause.getMessage().contains("Duplicate entry")) { throw new PlatformDataIntegrityException("error.msg.datatable.entry.duplicate", "An entry already exists for datatable `" + dataTableName + "` and application table with identifier `" + appTableId + "`.", "dataTableName", dataTableName, appTableId); } logAsErrorUnexpectedDataIntegrityException(dve); throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue", "Unknown data integrity issue with resource."); } catch (final PersistenceException dve) { final Throwable cause = dve.getCause(); if (cause.getMessage().contains("Duplicate entry")) { throw new PlatformDataIntegrityException("error.msg.datatable.entry.duplicate", "An entry already exists for datatable `" + dataTableName + "` and application table with identifier `" + appTableId + "`.", "dataTableName", dataTableName, appTableId); } logAsErrorUnexpectedDataIntegrityException(dve); throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue", "Unknown data integrity issue with resource."); } }
From source file:com.gst.infrastructure.dataqueries.service.ReadWriteNonCoreDataServiceImpl.java
@Transactional @Override// w w w . j a v a2 s . co m public CommandProcessingResult createNewDatatableEntry(final String dataTableName, final Long appTableId, final String json) { try { final String appTable = queryForApplicationTableName(dataTableName); final CommandProcessingResult commandProcessingResult = checkMainResourceExistsWithinScope(appTable, appTableId); final List<ResultsetColumnHeaderData> columnHeaders = this.genericDataService .fillResultsetColumnHeaders(dataTableName); final Type typeOfMap = new TypeToken<Map<String, String>>() { }.getType(); final Map<String, String> dataParams = this.fromJsonHelper.extractDataMap(typeOfMap, json); final String sql = getAddSql(columnHeaders, dataTableName, getFKField(appTable), appTableId, dataParams); this.jdbcTemplate.update(sql); return commandProcessingResult; // } catch (final DataAccessException dve) { final Throwable cause = dve.getCause(); final Throwable realCause = dve.getMostSpecificCause(); if (realCause.getMessage().contains("Duplicate entry") || cause.getMessage().contains("Duplicate entry")) { throw new PlatformDataIntegrityException("error.msg.datatable.entry.duplicate", "An entry already exists for datatable `" + dataTableName + "` and application table with identifier `" + appTableId + "`.", "dataTableName", dataTableName, appTableId); } else if (realCause.getMessage().contains("doesn't have a default value") || cause.getMessage().contains("doesn't have a default value")) { throw new PlatformDataIntegrityException( "error.msg.datatable.no.value.provided.for.required.fields", "No values provided for the datatable `" + dataTableName + "` and application table with identifier `" + appTableId + "`.", "dataTableName", dataTableName, appTableId); } logAsErrorUnexpectedDataIntegrityException(dve); throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue", "Unknown data integrity issue with resource."); } catch (final PersistenceException e) { final Throwable cause = e.getCause(); if (cause.getMessage().contains("Duplicate entry")) { throw new PlatformDataIntegrityException("error.msg.datatable.entry.duplicate", "An entry already exists for datatable `" + dataTableName + "` and application table with identifier `" + appTableId + "`.", "dataTableName", dataTableName, appTableId); } else if (cause.getMessage().contains("doesn't have a default value")) { throw new PlatformDataIntegrityException( "error.msg.datatable.no.value.provided.for.required.fields", "No values provided for the datatable `" + dataTableName + "` and application table with identifier `" + appTableId + "`.", "dataTableName", dataTableName, appTableId); } logAsErrorUnexpectedDataIntegrityException(e); throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue", "Unknown data integrity issue with resource."); } }
From source file:org.sakaiproject.genericdao.springjdbc.JdbcGenericDao.java
private void executeDDLforType(InputStream sqlDDL, Class<?> type) { // Now run the DDL commands if possible try {/*from w ww . j ava 2 s . co m*/ if (isAutoCommitDDL()) { commitTransaction(); // start the transaction } BufferedReader r = new BufferedReader(new InputStreamReader(sqlDDL)); try { // read the first line, skipping any '--' comment lines boolean firstLine = true; StringBuffer buf = new StringBuffer(); for (String line = r.readLine(); line != null; line = r.readLine()) { line = line.trim(); if (line.startsWith("--")) continue; if (line.length() == 0) continue; // add the line to the buffer buf.append(' '); buf.append(line); // process if the line ends with a ';' boolean process = line.endsWith(";"); if (!process) continue; // remove trailing ';' buf.setLength(buf.length() - 1); String ddl = buf.toString().trim(); // FIXME do replacements even if we do not know the type if (type != null) { // handle ddl replacements ddl = handleTypeReplacements(type, ddl); } // run the first line as the test - if it fails, we are done if (firstLine) { firstLine = false; try { if (showSQL) { logInfo("DDL=" + ddl); } getSpringJdbcTemplate().execute(ddl); } catch (DataAccessException e) { //log.info("Could not to execute first DDL ("+ddl+"), skipping the rest"); logInfo("Could not execute first DDL line, skipping the rest: " + e.getMessage() + ":" + e.getCause()); //e.printStackTrace(); return; } } else { // run other lines, until done - any one can fail (we will report it) try { if (showSQL) { logInfo("DDL=" + ddl); } getSpringJdbcTemplate().execute(ddl); } catch (DataAccessException e) { throw new IllegalArgumentException("Failed while executing ddl: " + e.getMessage(), e); } } if (isAutoCommitDDL()) { commitTransaction(); } // clear the buffer for next buf.setLength(0); } } catch (IOException any) { throw new RuntimeException("Failure while processing DDL", any); } finally { try { r.close(); } catch (IOException any) { //log.warn("Failure while closing DDL inputstream reader", any); } // close the connection used for this DDL if (isAutoCommitDDL()) { closeConnection(); } } } finally { try { sqlDDL.close(); } catch (IOException any) { //log.warn("Failure while closing inputstream", any); } } }
From source file:com.taobao.tddl.common.sync.RowBasedReplicationExecutor.java
/** * @param masterRow keyvalue//from w ww. ja va 2s . c om */ protected static long insertSlaveRow(RowBasedReplicationContext context, Map<String, Object> masterRow, SlaveInfo slave, boolean throwOnExist) { if (slave.isDisableInsert()) { return 0; } SqlArgs sqlInfo = buildSlaveInsertSql(masterRow, slave); if (log.isDebugEnabled()) { log.debug("sql = [" + sqlInfo.sql + "], args = " + Arrays.asList(sqlInfo.args)); } long beforeInsertSlaveDBTime = System.currentTimeMillis(); try { //context.getSlaveJdbcTemplates().get(slave.getDataSourceName()).update(sqlInfo.getSql(), sqlInfo.getArgs()); slave.getJdbcTemplate().update(sqlInfo.sql, sqlInfo.args); return System.currentTimeMillis() - beforeInsertSlaveDBTime; } catch (DataAccessException e) { if (!throwOnExist && (e instanceof DataIntegrityViolationException)) { if (e.getCause() instanceof SQLException) { SQLExceptionInfo expInfo = SyncUtils.getSqlState((SQLException) e.getCause()); if (DBType.MYSQL.equals(slave.getDbType()) && SyncConstants.ERROR_CODE_DUPLICATE_PRIMARY_KEY_MYSQL == expInfo.getErrorCode()) { return System.currentTimeMillis() - beforeInsertSlaveDBTime; } else if (DBType.ORACLE.equals(slave.getDbType()) && SyncConstants.ERROR_CODE_DUPLICATE_PRIMARY_KEY_ORACLE == expInfo.getErrorCode()) { return System.currentTimeMillis() - beforeInsertSlaveDBTime; } } } profile(e, context, timeoutThreshold, System.currentTimeMillis() - beforeInsertSlaveDBTime, slave.getIdentity()); throw e; } }
From source file:com.thinkbiganalytics.feedmgr.rest.controller.FeedRestController.java
@GET @Path("/{feedId}/profile-summary") @Produces(MediaType.APPLICATION_JSON)//from w w w . j a v a 2 s. c o m @ApiOperation("Gets a summary of the feed profiles.") @ApiResponses({ @ApiResponse(code = 200, message = "Returns the profile summaries.", response = Map.class, responseContainer = "List"), @ApiResponse(code = 500, message = "The profiles are unavailable.", response = RestResponseStatus.class) }) public Response profileSummary(@PathParam("feedId") String feedId) { FeedMetadata feedMetadata = getMetadataService().getFeedById(feedId); final String profileTable = HiveUtils.quoteIdentifier(feedMetadata.getProfileTableName()); String query = "SELECT * from " + profileTable + " where columnname = '(ALL)'"; List<Map<String, Object>> rows = new ArrayList<>(); try { QueryResult results = hiveService.query(query); rows.addAll(results.getRows()); //add in the archive date time fields if applicipable String ARCHIVE_PROCESSOR_TYPE = "com.thinkbiganalytics.nifi.GetTableData"; if (feedMetadata.getInputProcessorType().equalsIgnoreCase(ARCHIVE_PROCESSOR_TYPE)) { NifiProperty property = NifiPropertyUtil.findPropertyByProcessorType(feedMetadata.getProperties(), ARCHIVE_PROCESSOR_TYPE, "Date Field"); if (property != null && property.getValue() != null) { String field = property.getValue(); if (field.contains(".")) { field = StringUtils.substringAfterLast(field, "."); } query = "SELECT * from " + profileTable + " where metrictype IN('MIN_TIMESTAMP','MAX_TIMESTAMP') AND columnname = " + HiveUtils.quoteString(field); QueryResult dateRows = hiveService.query(query); if (dateRows != null && !dateRows.isEmpty()) { rows.addAll(dateRows.getRows()); } } } } catch (DataAccessException e) { if (e.getCause() instanceof org.apache.hive.service.cli.HiveSQLException && e.getCause().getMessage().contains("Table not found")) { //this exception is ok to swallow since it just means no profile data exists yet } else if (e.getCause().getMessage().contains("HiveAccessControlException Permission denied")) { throw new AccessControlException("You do not have permission to execute this hive query"); } else { throw e; } } return Response.ok(rows).build(); }