use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.
the class JdbcQuerySenderBase method fillParamArray.
protected String fillParamArray(Object[] paramArray, String message) throws SenderException {
int lengthMessage = message.length();
int startHaakje = message.indexOf('(');
int eindHaakje = message.indexOf(')');
int beginOutput = message.indexOf('?');
if (startHaakje < 1)
return message;
if (beginOutput < 0)
beginOutput = eindHaakje;
// Watch out, this cannot handle nested parentheses
// String packageCall = message.substring(startHaakje, eindHaakje + 1);
String packageInput = message.substring(startHaakje + 1, beginOutput);
int idx = 0;
if (message.indexOf(',') == -1) {
if (message.indexOf('?') == -1) {
idx = 1;
} else {
idx = 0;
}
}
int ix = 1;
String element = null;
try {
if (packageInput.lastIndexOf(',') > 0) {
while ((packageInput.charAt(packageInput.length() - ix) != ',') && (ix < packageInput.length())) {
ix++;
}
int eindInputs = beginOutput - ix;
/*
Copyright 2013 Nationale-Nederlanden
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
packageInput = message.substring(startHaakje + 1, eindInputs);
StringTokenizer st2 = new StringTokenizer(packageInput, ",");
if (idx != 1) {
while (st2.hasMoreTokens()) {
element = st2.nextToken().trim();
if (element.startsWith("'")) {
int x = element.indexOf('\'');
int y = element.lastIndexOf('\'');
paramArray[idx] = element.substring(x + 1, y);
} else {
if (element.indexOf('-') >= 0) {
if (element.length() > 10) {
String pattern = "yyyy-MM-dd HH:mm:ss";
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
java.util.Date nDate = (java.util.Date) sdf.parseObject(element.toString());
java.sql.Timestamp sqlTimestamp = new java.sql.Timestamp(nDate.getTime());
paramArray[idx] = sqlTimestamp;
} else {
String pattern = "yyyy-MM-dd";
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
java.util.Date nDate;
nDate = sdf.parse(element.toString());
java.sql.Date sDate = new java.sql.Date(nDate.getTime());
paramArray[idx] = sDate;
}
} else {
if (element.indexOf('.') >= 0) {
paramArray[idx] = new Float(element);
} else {
paramArray[idx] = new Integer(element);
}
}
}
idx++;
}
}
}
StringBuffer newMessage = new StringBuffer(message.substring(0, startHaakje + 1));
if (idx > 0) {
newMessage.append("?");
}
for (int i = 0; i < idx; i++) {
if (i < idx - 1) {
newMessage.append(",?");
}
}
if (idx >= 0) {
// check if output parameter exists is expected in original message and append an ending ?(out-parameter)
if (message.indexOf('?') > 0) {
if (idx == 0) {
newMessage.append("?");
} else {
newMessage.append(",?");
}
newMessage.append(message.substring(eindHaakje, lengthMessage));
} else {
newMessage.append(message.substring(eindHaakje, lengthMessage));
}
}
return newMessage.toString();
} catch (ParseException e) {
throw new SenderException(getLogPrefix() + "got exception parsing a date string from element [" + element + "]", e);
}
}
use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.
the class JdbcQuerySenderBase method executeUpdateBlobQuery.
protected String executeUpdateBlobQuery(PreparedStatement statement, Object message) throws SenderException {
ResultSet rs = null;
try {
log.debug(getLogPrefix() + "executing an updating BLOB command");
rs = statement.executeQuery();
XmlBuilder result = new XmlBuilder("result");
JdbcUtil.warningsToXml(statement.getWarnings(), result);
rs.next();
if (message instanceof Reader) {
Object blobHandle = getDbmsSupport().getBlobUpdateHandle(rs, blobColumn);
Reader inReader = (Reader) message;
Writer writer = JdbcUtil.getBlobWriter(getDbmsSupport(), blobHandle, rs, blobColumn, getBlobCharset(), isBlobsCompressed());
Misc.readerToWriter(inReader, writer, isCloseInputstreamOnExit());
writer.close();
getDbmsSupport().updateBlob(rs, blobColumn, blobHandle);
} else if (message instanceof InputStream) {
Object blobHandle = getDbmsSupport().getBlobUpdateHandle(rs, blobColumn);
InputStream inStream = (InputStream) message;
if (StringUtils.isNotEmpty(getStreamCharset())) {
Writer writer = JdbcUtil.getBlobWriter(getDbmsSupport(), blobHandle, rs, blobColumn, getBlobCharset(), isBlobsCompressed());
Reader reader = new InputStreamReader(inStream, getStreamCharset());
Misc.readerToWriter(reader, writer, isCloseInputstreamOnExit());
writer.close();
} else {
OutputStream outStream = JdbcUtil.getBlobOutputStream(getDbmsSupport(), blobHandle, rs, blobColumn, isBlobsCompressed());
Misc.streamToStream(inStream, outStream, isCloseInputstreamOnExit());
outStream.close();
}
getDbmsSupport().updateBlob(rs, blobColumn, blobHandle);
} else if (message instanceof byte[]) {
JdbcUtil.putByteArrayAsBlob(getDbmsSupport(), rs, blobColumn, (byte[]) message, isBlobsCompressed());
} else {
JdbcUtil.putStringAsBlob(getDbmsSupport(), rs, blobColumn, (String) message, getBlobCharset(), isBlobsCompressed());
}
rs.updateRow();
JdbcUtil.warningsToXml(rs.getWarnings(), result);
return result.toXML();
} catch (SQLException sqle) {
throw new SenderException(getLogPrefix() + "got exception executing an updating BLOB command", sqle);
} catch (JdbcException e) {
throw new SenderException(getLogPrefix() + "got exception executing an updating BLOB command", e);
} catch (IOException e) {
throw new SenderException(getLogPrefix() + "got exception executing an updating BLOB command", e);
} finally {
try {
if (rs != null) {
rs.close();
}
} catch (SQLException e) {
log.warn(new SenderException(getLogPrefix() + "got exception closing resultset", e));
}
}
}
use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.
the class JdbcQuerySenderBase method executeSelectQuery.
protected String executeSelectQuery(PreparedStatement statement, Object blobSessionVar, Object clobSessionVar, HttpServletResponse response, String contentType, String contentDisposition) throws SenderException {
ResultSet resultset = null;
try {
if (getMaxRows() > 0) {
statement.setMaxRows(getMaxRows() + (getStartRow() > 1 ? getStartRow() - 1 : 0));
}
log.debug(getLogPrefix() + "executing a SELECT SQL command");
resultset = statement.executeQuery();
if (getStartRow() > 1) {
resultset.absolute(getStartRow() - 1);
log.debug(getLogPrefix() + "Index set at position: " + resultset.getRow());
}
return getResult(resultset, blobSessionVar, clobSessionVar, response, contentType, contentDisposition);
} catch (SQLException sqle) {
throw new SenderException(getLogPrefix() + "got exception executing a SELECT SQL command", sqle);
} catch (JdbcException e) {
throw new SenderException(getLogPrefix() + "got exception executing a SELECT SQL command", e);
} catch (IOException e) {
throw new SenderException(getLogPrefix() + "got exception executing a SELECT SQL command", e);
} catch (JMSException e) {
throw new SenderException(getLogPrefix() + "got exception executing a SELECT SQL command", e);
} finally {
try {
if (resultset != null) {
resultset.close();
}
} catch (SQLException e) {
log.warn(new SenderException(getLogPrefix() + "got exception closing resultset", e));
}
}
}
use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.
the class JdbcQuerySenderBase method executeUpdateClobQuery.
protected String executeUpdateClobQuery(PreparedStatement statement, Object message) throws SenderException {
ResultSet rs = null;
try {
log.debug(getLogPrefix() + "executing an updating CLOB command");
rs = statement.executeQuery();
XmlBuilder result = new XmlBuilder("result");
JdbcUtil.warningsToXml(statement.getWarnings(), result);
rs.next();
if (message instanceof Reader) {
Object clobHandle = getDbmsSupport().getClobUpdateHandle(rs, clobColumn);
Reader inReader = (Reader) message;
Writer writer = getDbmsSupport().getClobWriter(rs, clobColumn, clobHandle);
Misc.readerToWriter(inReader, writer, isCloseInputstreamOnExit());
writer.close();
getDbmsSupport().updateClob(rs, clobColumn, clobHandle);
} else if (message instanceof InputStream) {
Object clobHandle = getDbmsSupport().getClobUpdateHandle(rs, clobColumn);
InputStream inStream = (InputStream) message;
Reader reader;
if (StringUtils.isNotEmpty(getStreamCharset())) {
reader = new InputStreamReader(inStream, getStreamCharset());
} else {
reader = new InputStreamReader(inStream);
}
Writer writer = getDbmsSupport().getClobWriter(rs, clobColumn, clobHandle);
Misc.readerToWriter(reader, writer, isCloseInputstreamOnExit());
writer.close();
getDbmsSupport().updateClob(rs, clobColumn, clobHandle);
} else {
JdbcUtil.putStringAsClob(getDbmsSupport(), rs, clobColumn, (String) message);
}
rs.updateRow();
JdbcUtil.warningsToXml(rs.getWarnings(), result);
return result.toXML();
} catch (SQLException sqle) {
throw new SenderException(getLogPrefix() + "got exception executing an updating CLOB command", sqle);
} catch (JdbcException e) {
throw new SenderException(getLogPrefix() + "got exception executing an updating CLOB command", e);
} catch (IOException e) {
throw new SenderException(getLogPrefix() + "got exception executing an updating CLOB command", e);
} finally {
try {
if (rs != null) {
rs.close();
}
} catch (SQLException e) {
log.warn(new SenderException(getLogPrefix() + "got exception closing resultset", e));
}
}
}
use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.
the class JdbcSenderBase method sendMessage.
@Override
public String sendMessage(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
if (isConnectionsArePooled()) {
Connection c = null;
try {
c = getConnectionWithTimeout(getTimeout());
String result = sendMessage(c, correlationID, message, prc);
return result;
} catch (JdbcException e) {
throw new SenderException(e);
} finally {
if (c != null) {
try {
c.close();
} catch (SQLException e) {
log.warn(new SenderException(getLogPrefix() + "caught exception closing sender after sending message, ID=[" + correlationID + "]", e));
}
}
}
}
synchronized (connection) {
return sendMessage(connection, correlationID, message, prc);
}
}
Aggregations