List of usage examples for org.springframework.dao DataAccessResourceFailureException DataAccessResourceFailureException
public DataAccessResourceFailureException(String msg, @Nullable Throwable cause)
From source file:com.jaspersoft.jasperserver.api.metadata.common.service.impl.PasswordCipherer.java
/** * <p>Decodes the specified raw password with an implementation specific algorithm if allowEncoding is TRUE.</p> * Otherwise it returns encPass.//from w w w . j av a2 s .c o m * @param encPass * @return * @throws DataAccessException */ public String decodePassword(String encPass) { synchronized (PasswordCipherer.class) { try { log.debug("Decode password: " + allowEncoding); if (!allowEncoding) return encPass; return cipherer.decode(encPass); } catch (Exception ex) { log.warn("Password decryption failed", ex); throw new DataAccessResourceFailureException(ex.getMessage(), ex.getCause()); } } }
From source file:com.jaspersoft.jasperserver.api.metadata.common.service.impl.PasswordCipherer.java
/** * <p>Encodes the specified raw password with an implementation specific algorithm if allowEncoding is TRUE.</p> * Otherwise it returns rawPass./* ww w. j a va2 s .c om*/ * @param rawPass * @return * @throws DataAccessException */ public String encodePassword(String rawPass) throws DataAccessException { synchronized (PasswordCipherer.class) { try { log.debug("Encode password: " + allowEncoding); if (!allowEncoding) return rawPass; return cipherer.encode(rawPass); } catch (Exception ex) { log.warn("Password decryption failed", ex); throw new DataAccessResourceFailureException(ex.getMessage(), ex.getCause()); } } }
From source file:net.solarnetwork.node.dao.jdbc.test.PreparedStatementCsvReaderTests.java
private void importData(final String tableName) { final Map<String, ColumnCsvMetaData> columnMetaData = new LinkedHashMap<String, ColumnCsvMetaData>(8); jdbcTemplate.execute(new ConnectionCallback<Object>() { @Override//from w ww .j ava 2 s . c o m public Object doInConnection(Connection con) throws SQLException, DataAccessException { columnMetaData.putAll(JdbcUtils.columnCsvMetaDataForDatabaseMetaData(con.getMetaData(), tableName)); String sql = JdbcUtils.insertSqlForColumnCsvMetaData(tableName, columnMetaData); PreparedStatement ps = con.prepareStatement(sql); Reader in; PreparedStatementCsvReader reader = null; try { in = new InputStreamReader(getClass().getResourceAsStream("csv-data-01.csv"), "UTF-8"); reader = new PreparedStatementCsvReader(in, CsvPreference.STANDARD_PREFERENCE); String[] header = reader.getHeader(true); Map<String, Integer> csvColumns = JdbcUtils.csvColumnIndexMapping(header); CellProcessor[] cellProcessors = JdbcUtils.parsingCellProcessorsForCsvColumns(header, columnMetaData); while (reader.read(ps, csvColumns, cellProcessors, columnMetaData)) { Savepoint sp = con.setSavepoint(); try { ps.executeUpdate(); } catch (SQLException e) { DataAccessException dae = jdbcTemplate.getExceptionTranslator().translate("Load CSV", sql, e); if (dae instanceof DataIntegrityViolationException) { con.rollback(sp); } else { throw e; } } } } catch (IOException e) { throw new DataAccessResourceFailureException("CSV encoding error", e); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { // ignore } } } return null; } }); }
From source file:org.agnitas.dao.impl.ImportRecipientsDaoImpl.java
@Override public void createTemporaryTable(int adminID, int datasource_id, String keyColumn, List<String> keyColumns, int companyId, String sessionId) { final DataSource dataSource = (DataSource) applicationContext.getBean("dataSource"); try {/*from w w w . j a v a 2 s . c o m*/ if (temporaryConnection != null) { temporaryConnection.destroy(); temporaryConnection = null; } SingleConnectionDataSource scds = null; scds = new SingleConnectionDataSource(dataSource.getConnection(), true); setTemporaryConnection(scds); } catch (SQLException e) { throw new DataAccessResourceFailureException("Unable to create single connection data source", e); } final JdbcTemplate template = getJdbcTemplateForTemporaryTable(); final String prefix = "cust_" + adminID + "_tmp_"; final String tableName = prefix + datasource_id + "_tbl"; String indexSql = ""; String duplicateSql = ""; if (keyColumns.isEmpty()) { duplicateSql += keyColumn + " as column_duplicate_check_0 "; indexSql = "column_duplicate_check_0"; } else { for (int i = 0; i < keyColumns.size(); i++) { duplicateSql += keyColumns.get(i) + " as column_duplicate_check_" + i; indexSql += "column_duplicate_check_" + i; if (i != keyColumns.size() - 1) { duplicateSql += ", "; indexSql += ", "; } } } duplicateSql += " from customer_" + companyId + "_tbl where 1=0)"; if (AgnUtils.isMySQLDB()) { String query = "CREATE TEMPORARY TABLE IF NOT EXISTS " + tableName + " as (select "; query += duplicateSql; template.execute(query); query = "ALTER TABLE " + tableName + " ADD (recipient mediumblob NOT NULL, " + "validator_result mediumblob NOT NULL, " + "temporary_id varchar(128) NOT NULL, " + "INDEX (" + indexSql + "), " + "status_type int(3) NOT NULL)"; template.execute(query); query = "alter table " + tableName + " collate utf8_unicode_ci"; template.execute(query); } else if (AgnUtils.isOracleDB()) { // @todo: we need to decide when all those tables will be removed String query = "CREATE TABLE " + tableName + " as (select "; query += duplicateSql; template.execute(query); query = "ALTER TABLE " + tableName + " ADD (recipient blob NOT NULL, " + "validator_result blob NOT NULL, " + "temporary_id varchar2(128) NOT NULL, " + "status_type number(3) NOT NULL)"; template.execute(query); String indexquery = "create index " + tableName + "_cdc on " + tableName + " (" + indexSql + ") nologging"; template.execute(indexquery); query = " INSERT INTO IMPORT_TEMPORARY_TABLES (SESSION_ID, TEMPORARY_TABLE_NAME) VALUES('" + sessionId + "', '" + tableName + "')"; template.execute(query); } }
From source file:org.apereo.portal.jdbc.DatabaseMetaDataImpl.java
/** * Run a set of tests on the database to provide better meta data. *//* w ww. j a v a2 s . co m*/ private void runDatabaseTests() { Connection conn = null; try { conn = this.dataSource.getConnection(); //The order of these tests is IMPORTANT, each may depend on the //results of the previous tests. this.getMetaData(conn); final JdbcTemplate jdbcTemplate = new JdbcTemplate(this.dataSource); this.testDatabaseInitialized(jdbcTemplate); if (this.portalTablesExist) { this.testOuterJoins(jdbcTemplate); this.testTimeStamp(jdbcTemplate); } } catch (SQLException e) { LOG.error("Error during database initialization. ", e); /* * We must throw a RuntimeException here to avoid starting the portal * with incorrect assumptions about what the database supports. */ throw new DataAccessResourceFailureException("Error during database initialization. ", e); } finally { this.releaseConnection(conn); } }
From source file:org.apereo.portal.jdbc.RDBMServices.java
/** * Returns a connection produced by a DataSource found in the * JNDI context. The DataSource should be configured and * loaded into JNDI by the J2EE container or may be the portal * default database./*from w ww. j a va2 s. com*/ * * @param dbName the database name which will be retrieved from * the JNDI context relative to "jdbc/" * @return a database Connection object or <code>null</code> if no Connection * @deprecated Where possible code should be injected with a {@link DataSource} object via the Spring application context */ @Deprecated public static Connection getConnection(String dbName) { final DataSource dataSource = getDataSource(dbName); try { final long start = System.currentTimeMillis(); final Connection c = dataSource.getConnection(); lastDatabase = databaseTimes.add(System.currentTimeMillis() - start); // metric final int current = activeConnections.incrementAndGet(); if (current > maxConnections) { maxConnections = current; } return c; } catch (SQLException e) { throw new DataAccessResourceFailureException( "RDBMServices sql error trying to get connection to " + dbName, e); } }
From source file:org.axonframework.eventhandling.scheduling.quartz.QuartzTableMaker.java
private void executeCreateSQL() { List<String> statements; try {/*from ww w . ja v a2 s . c o m*/ String script = IOUtils.toString(sqlResource.getInputStream()); statements = Arrays.asList(script.split(";")); for (String statement : statements) { while (statement.trim().startsWith("#")) { statement = statement.trim().split("\n", 2)[1]; } if (statement.trim().length() > 0) { this.entityManager.createNativeQuery(statement.trim()).executeUpdate(); } } } catch (IOException ex) { throw new DataAccessResourceFailureException("Failed to open SQL script '" + sqlResource + "'", ex); } }
From source file:org.axonframework.eventhandling.scheduling.quartz.QuartzTableMaker.java
private void executeSqlScript(String sqlResourcePath) throws DataAccessException { EncodedResource resource = new EncodedResource(applicationContext.getResource(sqlResourcePath), "UTF-8"); List<String> statements = new LinkedList<String>(); try {/* w ww. ja v a 2 s . co m*/ LineNumberReader lnr = new LineNumberReader(resource.getReader()); String script = JdbcTestUtils.readScript(lnr); char delimiter = ';'; if (!JdbcTestUtils.containsSqlScriptDelimiters(script, delimiter)) { delimiter = '\n'; } JdbcTestUtils.splitSqlScript(script, delimiter, statements); for (String statement : statements) { this.entityManager.createNativeQuery(statement).executeUpdate(); } } catch (IOException ex) { throw new DataAccessResourceFailureException("Failed to open SQL script '" + sqlResourcePath + "'", ex); } }
From source file:org.axonframework.spring.eventhandling.scheduling.quartz.QuartzTableMaker.java
private void executeSqlScript(String sqlResourcePath) throws DataAccessException { EncodedResource resource = new EncodedResource(applicationContext.getResource(sqlResourcePath), "UTF-8"); List<String> statements = new LinkedList<>(); try {// w w w. j a v a2s .c o m LineNumberReader lnr = new LineNumberReader(resource.getReader()); String script = JdbcTestUtils.readScript(lnr); char delimiter = ';'; if (!JdbcTestUtils.containsSqlScriptDelimiters(script, delimiter)) { delimiter = '\n'; } JdbcTestUtils.splitSqlScript(script, delimiter, statements); for (String statement : statements) { this.entityManager.createNativeQuery(statement).executeUpdate(); } } catch (IOException ex) { throw new DataAccessResourceFailureException("Failed to open SQL script '" + sqlResourcePath + "'", ex); } }
From source file:org.emonocot.job.io.StaxEventItemReader.java
/** * Responsible for moving the cursor before the StartElement of the fragment * root./*w w w .j a va 2 s. c om*/ * * This implementation simply looks for the next corresponding element, it * does not care about element nesting. You will need to override this * method to correctly handle composite fragments. * @param xmlEventReader Set the XML event reader * @return <code>true</code> if next fragment was found, <code>false</code> * otherwise. */ protected final boolean moveCursorToNextFragment(final XMLEventReader xmlEventReader) { try { while (true) { while (xmlEventReader.peek() != null && !xmlEventReader.peek().isStartElement()) { xmlEventReader.nextEvent(); } if (xmlEventReader.peek() == null) { return false; } QName startElementName = ((StartElement) xmlEventReader.peek()).getName(); if (startElementName.getLocalPart().equals(fragmentRootElementName)) { if (fragmentRootElementNameSpace == null || startElementName.getNamespaceURI().equals(fragmentRootElementNameSpace)) { return true; } } xmlEventReader.nextEvent(); } } catch (XMLStreamException e) { throw new DataAccessResourceFailureException("Error while reading from event reader", e); } }