use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.
the class XmlQuerySender method sql.
private String sql(Connection connection, String correlationID, String query, String type) throws SenderException, JdbcException {
try {
PreparedStatement statement = getStatement(connection, correlationID, query, false);
statement.setQueryTimeout(getTimeout());
setBlobSmartGet(true);
if (StringUtils.isNotEmpty(type) && type.equalsIgnoreCase("select")) {
return executeSelectQuery(statement, null, null);
} else if (StringUtils.isNotEmpty(type) && type.equalsIgnoreCase("ddl")) {
// TODO: alles tussen -- en newline nog weggooien
StringBuffer result = new StringBuffer();
StringTokenizer stringTokenizer = new StringTokenizer(query, ";");
while (stringTokenizer.hasMoreTokens()) {
String q = stringTokenizer.nextToken();
statement = getStatement(connection, correlationID, q, false);
if (q.trim().toLowerCase().startsWith("select")) {
result.append(executeSelectQuery(statement, null, null));
} else {
result.append(executeOtherQuery(connection, correlationID, statement, q, null, null));
}
}
return result.toString();
} else {
return executeOtherQuery(connection, correlationID, statement, query, null, null);
}
} catch (SQLException e) {
throw new SenderException(getLogPrefix() + "got exception executing a SQL command", e);
}
}
use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.
the class XmlQuerySender method executeUpdate.
private String executeUpdate(Connection connection, String correlationID, String tableName, String query, Vector columns) throws SenderException {
try {
if (existLob(columns)) {
CallableStatement callableStatement = getCallWithRowIdReturned(connection, correlationID, query);
applyParameters(callableStatement, columns);
int ri = 1 + countParameters(columns);
callableStatement.registerOutParameter(ri, Types.VARCHAR);
callableStatement.setQueryTimeout(getTimeout());
int numRowsAffected = callableStatement.executeUpdate();
String rowId = callableStatement.getString(ri);
log.debug(getLogPrefix() + "returning ROWID [" + rowId + "]");
Iterator iter = columns.iterator();
while (iter.hasNext()) {
Column column = (Column) iter.next();
if (column.getType().equalsIgnoreCase(TYPE_BLOB) || column.getType().equalsIgnoreCase(TYPE_CLOB)) {
query = "SELECT " + column.getName() + " FROM " + tableName + " WHERE ROWID=?" + " FOR UPDATE";
PreparedStatement statement = getStatement(connection, correlationID, query, true);
statement.setString(1, rowId);
statement.setQueryTimeout(getTimeout());
if (column.getType().equalsIgnoreCase(TYPE_BLOB)) {
executeUpdateBlobQuery(statement, column.getValue());
} else {
executeUpdateClobQuery(statement, column.getValue());
}
}
}
return "<result><rowsupdated>" + numRowsAffected + "</rowsupdated></result>";
}
PreparedStatement statement = getStatement(connection, correlationID, query, false);
applyParameters(statement, columns);
statement.setQueryTimeout(getTimeout());
return executeOtherQuery(connection, correlationID, statement, query, null, null);
} catch (Throwable t) {
throw new SenderException(t);
}
}
use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.
the class XmlQuerySender method alterQuery.
private String alterQuery(Connection connection, String sequenceName, int startWith) throws SenderException {
try {
String callQuery = "declare" + " pragma autonomous_transaction;" + " ln_increment number;" + " ln_curr_val number;" + " ln_reset_increment number;" + " ln_reset_val number;" + "begin" + " select increment_by into ln_increment from user_sequences where sequence_name = '" + sequenceName + "';" + " select " + (startWith - 2) + " - " + sequenceName + ".nextval into ln_reset_increment from dual;" + " select " + sequenceName + ".nextval into ln_curr_val from dual;" + " EXECUTE IMMEDIATE 'alter sequence " + sequenceName + " increment by '|| ln_reset_increment ||' minvalue 0';" + " select " + sequenceName + ".nextval into ln_reset_val from dual;" + " EXECUTE IMMEDIATE 'alter sequence " + sequenceName + " increment by '|| ln_increment;" + "end;";
log.debug(getLogPrefix() + "preparing procedure for query [" + callQuery + "]");
CallableStatement callableStatement = connection.prepareCall(callQuery);
int numRowsAffected = callableStatement.executeUpdate();
return "<result><rowsupdated>" + numRowsAffected + "</rowsupdated></result>";
} catch (SQLException e) {
throw new SenderException(e);
}
}
use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.
the class ObjectServiceImpl method processProperties.
private Properties processProperties(Element cmisElement) throws SenderException {
PropertiesImpl properties = new PropertiesImpl();
Element propertiesElement = XmlUtils.getFirstChildTag(cmisElement, "properties");
Iterator<Node> propertyIterator = XmlUtils.getChildTags(propertiesElement, "property").iterator();
while (propertyIterator.hasNext()) {
Element propertyElement = (Element) propertyIterator.next();
String property = XmlUtils.getStringValue(propertyElement);
String nameAttr = propertyElement.getAttribute("name");
String typeAttr = propertyElement.getAttribute("type");
if (StringUtils.isEmpty(typeAttr) || typeAttr.equalsIgnoreCase("string")) {
if (nameAttr.startsWith("cmis:")) {
properties.addProperty(new PropertyIdImpl(nameAttr, property));
} else {
properties.addProperty(new PropertyStringImpl(nameAttr, property));
}
} else if (typeAttr.equalsIgnoreCase("integer")) {
properties.addProperty(new PropertyIntegerImpl(nameAttr, new BigInteger(property)));
} else if (typeAttr.equalsIgnoreCase("boolean")) {
properties.addProperty(new PropertyBooleanImpl(nameAttr, Boolean.parseBoolean(property)));
} else if (typeAttr.equalsIgnoreCase("datetime")) {
String formatStringAttr = propertyElement.getAttribute("formatString");
if (StringUtils.isEmpty(formatStringAttr)) {
formatStringAttr = CmisSender.FORMATSTRING_BY_DEFAULT;
}
DateFormat df = new SimpleDateFormat(formatStringAttr);
Date date;
try {
date = df.parse(property);
} catch (ParseException e) {
throw new SenderException("exception parsing date [" + property + "] using formatString [" + formatStringAttr + "]", e);
}
GregorianCalendar gregorian = new GregorianCalendar();
gregorian.setTime(date);
properties.addProperty(new PropertyDateTimeImpl(nameAttr, gregorian));
} else {
log.warn("unparsable type [" + typeAttr + "] for property [" + property + "]");
}
log.debug("set property name [" + nameAttr + "] value [" + property + "]");
}
return properties;
}
use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.
the class ZipWriterSender method sendMessage.
public String sendMessage(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
ParameterValueList pvl;
try {
pvl = prc.getValues(paramList);
} catch (ParameterException e) {
throw new SenderException("cannot determine filename and/or contents of zip entry", e);
}
IPipeLineSession session = prc.getSession();
ZipWriter sessionData = ZipWriter.getZipWriter(session, getZipWriterHandle());
if (sessionData == null) {
throw new SenderException("zipWriterHandle in session key [" + getZipWriterHandle() + "] is not open");
}
String filename = filenameParameter == null ? message : (String) pvl.getParameterValue(PARAMETER_FILENAME).getValue();
try {
if (contentsParameter == null) {
if (message != null) {
sessionData.writeEntry(filename, message, isCloseInputstreamOnExit(), getCharset());
}
} else {
Object paramValue = pvl.getParameterValue(PARAMETER_CONTENTS).getValue();
sessionData.writeEntry(filename, paramValue, isCloseInputstreamOnExit(), getCharset());
}
return message;
} catch (UnsupportedEncodingException e) {
throw new SenderException(getLogPrefix() + "cannot encode zip entry", e);
} catch (CompressionException e) {
throw new SenderException(getLogPrefix() + "cannot store zip entry", e);
} catch (IOException e) {
throw new SenderException(getLogPrefix() + "cannot store zip entry", e);
}
}
Aggregations