List of usage examples for org.apache.commons.lang3 StringUtils substringAfter
public static String substringAfter(final String str, final String separator)
Gets the substring after the first occurrence of a separator.
From source file:org.kawanfw.sql.jdbc.ResultSetHttp.java
/** * Retrieves the value of the designated column in the current row of this * <code>ResultSet</code> object as a <code>java.io.Reader</code> object. * /*from w w w . ja v a 2 s. com*/ * @return a <code>java.io.Reader</code> object that contains the column * value; if the value is SQL <code>NULL</code>, the value returned * is <code>null</code> in the Java programming language. * @param columnIndex * the first column is 1, the second is 2, ... * @exception SQLException * if the columnIndex is not valid; if a database access * error occurs or this method is called on a closed result * set * @since 1.2 */ @Override public java.io.Reader getCharacterStream(int columnIndex) throws SQLException { testIfClosed(); String value = getValueOfList(columnIndex, true); if (value == null) { // Not sure what to do throw new SQLException("Column Index is out of bound: " + columnIndex); } Reader reader = null; // Check if we must get the byte array from an input stream if (value.startsWith(TransportConverter.KAWANFW_BYTES_STREAM_FILE)) { String remoteFile = StringUtils.substringAfter(value, TransportConverter.KAWANFW_BYTES_STREAM_FILE); reader = getReaderFromRemoteFile(remoteFile); } else { String stringValue = getString(columnIndex); debug("Reader in String!"); if (stringValue == null) { return null; } else { try { // Put back clean CR_LF BufferedReader bufferedReader = new BufferedReader(new StringReader(stringValue)); StringWriter stringWriter = new StringWriter(); String line = null; while ((line = bufferedReader.readLine()) != null) { stringWriter.write(line + CR_LF); } String cleaned = stringWriter.toString(); reader = new StringReader(cleaned); } catch (Exception e) { throw new SQLException(e.getMessage(), e); } } } return reader; }
From source file:org.kawanfw.sql.jdbc.ResultSetHttp.java
/** * Retrieves the value of the designated column in the current row of this * <code>ResultSet</code> object as a stream of ASCII characters. The value * can then be read in chunks from the stream. This method is particularly * suitable for retrieving large <char>LONGVARCHAR</char> values. The JDBC * driver will do any necessary conversion from the database format into * ASCII./*w w w .j av a 2 s.c om*/ * * <P> * <B>Note:</B> All the data in the returned stream must be read prior to * getting the value of any other column. The next call to a getter method * implicitly closes the stream. Also, a stream may return <code>0</code> * when the method <code>InputStream.available</code> is called whether * there is data available or not. * * @param columnIndex * the first column is 1, the second is 2, ... * @return a Java input stream that delivers the database column value as a * stream of one-byte ASCII characters; if the value is SQL * <code>NULL</code>, the value returned is <code>null</code> * @exception SQLException * if a database access error occurs */ public java.io.InputStream getAsciiStream(int columnIndex) throws SQLException { testIfClosed(); String value = getValueOfList(columnIndex, true); if (value == null) { // Not sure what to do throw new SQLException("Column Index is out of bound: " + columnIndex); } InputStream in = null; // Check if we must get the byte array from an input stream if (value.startsWith(TransportConverter.KAWANFW_BYTES_STREAM_FILE)) { String remoteFile = StringUtils.substringAfter(value, TransportConverter.KAWANFW_BYTES_STREAM_FILE); // HACK if (!remoteFile.startsWith("/")) { remoteFile = "/" + remoteFile; } in = getAsciiInputStreamFromRemoteFile(remoteFile); } else { String stringValue = getString(columnIndex); debug("AsciiStream in String!"); try { // Put back clean CR_LF BufferedReader bufferedReader = new BufferedReader(new StringReader(stringValue)); StringWriter stringWriter = new StringWriter(); String line = null; while ((line = bufferedReader.readLine()) != null) { stringWriter.write(line + CR_LF); } String cleaned = stringWriter.toString(); byte[] bytes = cleaned.getBytes(); in = new ByteArrayInputStream(bytes); } catch (Exception e) { throw new SQLException(e.getMessage(), e); } } return in; }
From source file:org.kawanfw.sql.jdbc.StatementHttp.java
/** * Extract the getUpdatCount value store in the receiveFileFromExecute * /* ww w. jav a 2s .co m*/ * @throws SQLException */ private void extractGetUpdateCount() throws SQLException { BufferedReader bufferedReader = null; String line1 = null; try { bufferedReader = new BufferedReader(new FileReader(receiveFileFromExecute)); line1 = bufferedReader.readLine(); } catch (IOException e1) { throw new SQLException(e1); } finally { IOUtils.closeQuietly(bufferedReader); } String updateCountStr = StringUtils.substringAfter(line1, "getUpdateCount="); try { updateCount = Integer.parseInt(updateCountStr); } catch (NumberFormatException e) { throw new SQLException(Tag.PRODUCT_PRODUCT_FAIL + e.getMessage(), new IOException(e.getMessage(), e)); } }
From source file:org.kawanfw.sql.jdbc.StatementHttp.java
/** * Says if the file contains a ResultSet or if the file contains an * UpdateCount. if file contains an UpdateCount ==> first line is numeric * /* ww w .ja v a 2 s .c o m*/ * @param file * the received file from the server * @return true if the file is a result set */ protected boolean isFileResultSet(File file) throws SQLException { LineNumberReader lineNumberReader = null; try { lineNumberReader = new LineNumberReader(new FileReader(file)); String line = lineNumberReader.readLine(); line = line.trim(); if (line.startsWith("getUpdateCount=")) { String updateCountStr = StringUtils.substringAfter(line, "getUpdateCount="); try { updateCount = Integer.parseInt(updateCountStr); } catch (NumberFormatException e) { throw new SQLException(Tag.PRODUCT_PRODUCT_FAIL + e.getMessage(), new IOException(e.getMessage(), e)); } return false; } else if (line.startsWith(CallableParms.NO_RESULT_SET)) { return false; } else { return true; } } catch (IOException e) { JdbcHttpTransferUtil.wrapExceptionAsSQLException(e); } finally { IOUtils.closeQuietly(lineNumberReader); } return false; }
From source file:org.kawanfw.sql.jdbc.util.JsonLineDecryptor.java
/** * Decrypt the json line if necessary/*w w w . j ava 2s. c om*/ * * @param line * the line to decrypt * @return the decrypted line * @throws SQLException * if any Exception occurs */ public static String decrypt(String line, ConnectionHttp connectionHttp) throws SQLException { try { if (!line.startsWith(Pbe.KAWANFW_ENCRYPTED)) { return line; } SessionParameters sessionParameters = connectionHttp.getSessionParameters(); if (sessionParameters != null) { char[] password = sessionParameters.getEncryptionPassword(); if (password != null) { Pbe pbe = new Pbe(); line = StringUtils.substringAfter(line, Pbe.KAWANFW_ENCRYPTED); line = pbe.decryptFromHexa(line, password); return line; } } return line; } catch (Exception e) { throw new SQLException(e); } }
From source file:org.kawanfw.sql.servlet.executor.ServerBatchPrepStatementExecutorNew.java
/** * Execute the Sql Action// w ww . j a v a2 s . c om */ public void execute() throws IOException, SQLException, IllegalArgumentException { String username = request.getParameter(Parameter.USERNAME); String connectionId = request.getParameter(ConnectionParms.CONNECTION_ID); String conHolderParam = request.getParameter(SqlAction.CONNECTION_HOLDER); // Get the Statement Holder that contains the SQL order String statementHolderMainParam = request.getParameter(SqlAction.STATEMENT_HOLDER); List<StatementHolder> preparedStatementHolderList = StatementHolderListDecryptor .decryptFromJson(statementHolderMainParam, commonsConfigurator); StatementHolder statementHolder = preparedStatementHolderList.get(0); // First // and // only // statement // holder // Get the list of batch parameters String batchHolderParam = request.getParameter(SqlAction.BATCH_PARAMS_HOLDER); debug("SqlAction.CONNECTION_HOLDER : " + conHolderParam); debug("SqlAction.STATEMENT_HOLDER : " + statementHolderMainParam); debug("SqlAction.BATCH_PARAMS_HOLDER : " + batchHolderParam); Connection connection = null; if (connectionId.equals("0")) { try { connection = commonsConfigurator.getConnection(); ServerSqlUtil.setConnectionProperties(conHolderParam, connection); if (batchHolderParam.startsWith(TransportConverter.KAWANFW_BYTES_STREAM_FILE)) { String fileName = StringUtils.substringAfter(batchHolderParam, TransportConverter.KAWANFW_BYTES_STREAM_FILE); // Param contains only the file to read from the statements executeStatementsFromFile(username, statementHolder, fileName, connection); } else { // All statements are in single param executeStatementsFromList(username, statementHolder, batchHolderParam, connection); } if (!connection.getAutoCommit()) { connection.commit(); } } catch (IOException e) { if (!connection.getAutoCommit()) { connection.rollback(); } throw e; } catch (SQLException e) { if (!connection.getAutoCommit()) { connection.rollback(); } throw e; } finally { // Release the connection ConnectionCloser.freeConnection(connection, sqlConfigurator); } } else { ConnectionStore connectionStore = new ConnectionStore(username, connectionId); connection = connectionStore.get(); if (connection == null) { //out.println(TransferStatus.SEND_OK); //out.println(SqlReturnCode.SESSION_INVALIDATED); ServerSqlManager.writeLine(out, TransferStatus.SEND_OK); ServerSqlManager.writeLine(out, SqlReturnCode.SESSION_INVALIDATED); return; } if (batchHolderParam.startsWith(TransportConverter.KAWANFW_BYTES_STREAM_FILE)) { String fileName = StringUtils.substringAfter(batchHolderParam, TransportConverter.KAWANFW_BYTES_STREAM_FILE); // Param contains only the file to read from the statements executeStatementsFromFile(username, statementHolder, fileName, connection); } else { // All statements are in single param executeStatementsFromList(username, statementHolder, batchHolderParam, connection); } } }
From source file:org.kawanfw.sql.servlet.executor.ServerBatchStatementExecutorNew.java
/** * Execute the Sql Action// w ww . j a v a2s. c o m */ public void execute() throws IOException, SQLException, IllegalArgumentException { String username = request.getParameter(Parameter.USERNAME); String connectionId = request.getParameter(ConnectionParms.CONNECTION_ID); String conHolderParam = request.getParameter(SqlAction.CONNECTION_HOLDER); String statementHolderParam = request.getParameter(SqlAction.STATEMENT_HOLDER); debug("SqlAction.CONNECTION_HOLDER: " + conHolderParam); debug("SqlAction.STATEMENT_HOLDER : " + statementHolderParam); Connection connection = null; if (connectionId.equals("0")) { try { connection = commonsConfigurator.getConnection(); ServerSqlUtil.setConnectionProperties(conHolderParam, connection); if (statementHolderParam.startsWith(TransportConverter.KAWANFW_BYTES_STREAM_FILE)) { String fileName = StringUtils.substringAfter(statementHolderParam, TransportConverter.KAWANFW_BYTES_STREAM_FILE); // Param contains only the file to read from the statements executeStatementsFromFile(username, fileName, connection); } else { // All statements are in single param executeStatementsFromList(username, statementHolderParam, connection); } if (!connection.getAutoCommit()) { connection.commit(); } } catch (IOException e) { if (!connection.getAutoCommit()) { connection.rollback(); } throw e; } catch (SQLException e) { if (!connection.getAutoCommit()) { connection.rollback(); } throw e; } finally { // Release the connection ConnectionCloser.freeConnection(connection, sqlConfigurator); } } else { ConnectionStore connectionStore = new ConnectionStore(username, connectionId); connection = connectionStore.get(); if (connection == null) { //out.println(TransferStatus.SEND_OK); //out.println(SqlReturnCode.SESSION_INVALIDATED); ServerSqlManager.writeLine(out, TransferStatus.SEND_OK); ServerSqlManager.writeLine(out, SqlReturnCode.SESSION_INVALIDATED); return; } if (statementHolderParam.startsWith(TransportConverter.KAWANFW_BYTES_STREAM_FILE)) { String fileName = StringUtils.substringAfter(statementHolderParam, TransportConverter.KAWANFW_BYTES_STREAM_FILE); // Param contains only the file to read from the statements executeStatementsFromFile(username, fileName, connection); } else { // All statements are in single param executeStatementsFromList(username, statementHolderParam, connection); } } }
From source file:org.kawanfw.sql.servlet.executor.ServerSqlExecutorCallable.java
/** * Execute the Callable Statement//from w ww.j av a 2 s .co m * * @throws IOException * @throws SQLException * @throws IllegalArgumentException */ public void callStatement() throws IOException, SQLException, IllegalArgumentException { String username = request.getParameter(Parameter.USERNAME); String connectionId = request.getParameter(ConnectionParms.CONNECTION_ID); String conHolderParam = request.getParameter(SqlAction.CONNECTION_HOLDER); String statementHolderParam = request.getParameter(SqlAction.STATEMENT_HOLDER); debug("SqlAction.CONNECTION_HOLDER: " + conHolderParam); debug("SqlAction.STATEMENT_HOLDER : " + statementHolderParam); Connection connection = null; List<File> tempFilesForResultSet = new Vector<File>(); if (connectionId.equals("0")) { // stateless mode was set on PC try { connection = commonsConfigurator.getConnection(); ServerSqlUtil.setConnectionProperties(conHolderParam, connection); if (statementHolderParam.startsWith(TransportConverter.KAWANFW_BYTES_STREAM_FILE)) { String fileName = StringUtils.substringAfter(statementHolderParam, TransportConverter.KAWANFW_BYTES_STREAM_FILE); // Param contains only the file to read from the statements callStatementsFromFile(username, fileName, connection, tempFilesForResultSet); } else { // All statements are in single param callStatementsFromList(username, statementHolderParam, connection, tempFilesForResultSet); } if (!connection.getAutoCommit()) { connection.commit(); } } catch (IOException e) { if (!connection.getAutoCommit()) { connection.rollback(); } throw e; } catch (SQLException e) { if (!connection.getAutoCommit()) { connection.rollback(); } throw e; } finally { // Release the connection ConnectionCloser.freeConnection(connection, sqlConfigurator); } } else { ConnectionStore connectionStore = new ConnectionStore(username, connectionId); connection = connectionStore.get(); if (connection == null) { //out.println(TransferStatus.SEND_OK); //out.println(SqlReturnCode.SESSION_INVALIDATED); ServerSqlManager.writeLine(out, TransferStatus.SEND_OK); ServerSqlManager.writeLine(out, SqlReturnCode.SESSION_INVALIDATED); return; } if (statementHolderParam.startsWith(TransportConverter.KAWANFW_BYTES_STREAM_FILE)) { String fileName = StringUtils.substringAfter(statementHolderParam, TransportConverter.KAWANFW_BYTES_STREAM_FILE); // Param contains only the file to read from the statements callStatementsFromFile(username, fileName, connection, tempFilesForResultSet); } else { // All statements are in single param callStatementsFromList(username, statementHolderParam, connection, tempFilesForResultSet); } } // Of, if the list is not empty, dump it to out on servlet out stream FileDumper.dumpFile(tempFilesForResultSet, out); }
From source file:org.kawanfw.sql.servlet.executor.ServerSqlExecutorNew.java
/** * Execute the Sql Action// w w w .ja v a2 s . c o m */ private void execute() throws IOException, SQLException, IllegalArgumentException { String username = request.getParameter(Parameter.USERNAME); String connectionId = request.getParameter(ConnectionParms.CONNECTION_ID); String conHolderParam = request.getParameter(SqlAction.CONNECTION_HOLDER); String statementHolderParam = request.getParameter(SqlAction.STATEMENT_HOLDER); debug("SqlAction.CONNECTION_HOLDER: " + conHolderParam); debug("SqlAction.STATEMENT_HOLDER : " + statementHolderParam); Connection connection = null; List<File> tempFilesForResultSet = new Vector<File>(); if (connectionId.equals("0")) { try { connection = commonsConfigurator.getConnection(); ServerSqlUtil.setConnectionProperties(conHolderParam, connection); if (statementHolderParam.startsWith(TransportConverter.KAWANFW_BYTES_STREAM_FILE)) { String fileName = StringUtils.substringAfter(statementHolderParam, TransportConverter.KAWANFW_BYTES_STREAM_FILE); // Param contains only the file to read from the statements executeStatementsFromFile(username, fileName, connection, tempFilesForResultSet); } else { // All statements are in single param executeStatementsFromList(username, statementHolderParam, connection, tempFilesForResultSet); } if (!connection.getAutoCommit()) { connection.commit(); } } catch (IOException e) { if (!connection.getAutoCommit()) { connection.rollback(); } throw e; } catch (SQLException e) { if (!connection.getAutoCommit()) { connection.rollback(); } throw e; } finally { // Release the connection ConnectionCloser.freeConnection(connection, sqlConfigurator); } } else { ConnectionStore connectionStore = new ConnectionStore(username, connectionId); connection = connectionStore.get(); if (connection == null) { //out.println(TransferStatus.SEND_OK); //out.println(SqlReturnCode.SESSION_INVALIDATED); ServerSqlManager.writeLine(out, TransferStatus.SEND_OK); ServerSqlManager.writeLine(out, SqlReturnCode.SESSION_INVALIDATED); return; } if (statementHolderParam.startsWith(TransportConverter.KAWANFW_BYTES_STREAM_FILE)) { String fileName = StringUtils.substringAfter(statementHolderParam, TransportConverter.KAWANFW_BYTES_STREAM_FILE); // Param contains only the file to read from the statements executeStatementsFromFile(username, fileName, connection, tempFilesForResultSet); } else { // All statements are in single param executeStatementsFromList(username, statementHolderParam, connection, tempFilesForResultSet); } } // Of, if the list is not empty, dump it to out on servlet out stream FileDumper.dumpFile(tempFilesForResultSet, out); }
From source file:org.kawanfw.sql.tomcat.SystemPropUpdater.java
public void update() { // Do we have to set special values to the Connector? Enumeration<?> enumeration = properties.propertyNames(); if (enumeration.hasMoreElements()) { System.out.println(SqlTag.SQL_PRODUCT_START + " Setting System Properties:"); }//from w ww .ja v a 2 s . c o m while (enumeration.hasMoreElements()) { String property = (String) enumeration.nextElement(); if (property.startsWith("systemSetProperty.")) { String theValue = properties.getProperty(property); String systemProperty = StringUtils.substringAfter(property, "."); debug("property : " + property); debug("systemProperty: " + systemProperty); if (systemProperty.equals("compression")) { System.out.println(SqlTag.SQL_PRODUCT_START + " -> Tomcat " + systemProperty + " property not used in AceQL. See User Documentation for how to zip ResultSet."); } else { if (theValue != null && !theValue.isEmpty()) { theValue = theValue.trim(); System.out.println(SqlTag.SQL_PRODUCT_START + " -> " + systemProperty + " = " + theValue); System.setProperty(systemProperty, theValue); } } } if (property.equals("systemClearProperty")) { String theValue = properties.getProperty(property); if (theValue != null && !theValue.isEmpty()) { theValue = theValue.trim(); System.out.println(SqlTag.SQL_PRODUCT_START + " -> " + theValue + " clear "); System.clearProperty(theValue); } } } }