Search in sources :

Example 96 with SenderException

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);
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) SenderException(nl.nn.adapterframework.core.SenderException)

Example 97 with SenderException

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);
    }
}
Also used : CallableStatement(java.sql.CallableStatement) Iterator(java.util.Iterator) PreparedStatement(java.sql.PreparedStatement) SenderException(nl.nn.adapterframework.core.SenderException)

Example 98 with SenderException

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);
    }
}
Also used : SQLException(java.sql.SQLException) CallableStatement(java.sql.CallableStatement) SenderException(nl.nn.adapterframework.core.SenderException)

Example 99 with SenderException

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;
}
Also used : PropertiesImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl) PropertyDateTimeImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDateTimeImpl) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) GregorianCalendar(java.util.GregorianCalendar) PropertyBooleanImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyBooleanImpl) Date(java.util.Date) PropertyIdImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIdImpl) PropertyIntegerImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIntegerImpl) PropertyStringImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringImpl) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) BigInteger(java.math.BigInteger) ParseException(java.text.ParseException) SenderException(nl.nn.adapterframework.core.SenderException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 100 with SenderException

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);
    }
}
Also used : ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ParameterException(nl.nn.adapterframework.core.ParameterException) IOException(java.io.IOException) SenderException(nl.nn.adapterframework.core.SenderException) IPipeLineSession(nl.nn.adapterframework.core.IPipeLineSession)

Aggregations

SenderException (nl.nn.adapterframework.core.SenderException)130 TimeOutException (nl.nn.adapterframework.core.TimeOutException)41 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)37 IOException (java.io.IOException)36 SQLException (java.sql.SQLException)25 HashMap (java.util.HashMap)21 ParameterException (nl.nn.adapterframework.core.ParameterException)21 PreparedStatement (java.sql.PreparedStatement)20 Map (java.util.Map)20 DomBuilderException (nl.nn.adapterframework.util.DomBuilderException)18 Iterator (java.util.Iterator)17 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)16 InputStream (java.io.InputStream)15 ResultSet (java.sql.ResultSet)13 Element (org.w3c.dom.Element)13 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)12 Date (java.util.Date)10 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)10 XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)10 UnsupportedEncodingException (java.io.UnsupportedEncodingException)9