Example usage for java.lang Exception initCause

List of usage examples for java.lang Exception initCause

Introduction

In this page you can find the example usage for java.lang Exception initCause.

Prototype

public synchronized Throwable initCause(Throwable cause) 

Source Link

Document

Initializes the cause of this throwable to the specified value.

Usage

From source file:com.eucalyptus.objectstorage.pipeline.binding.ObjectStorageRESTBinding.java

private LifecycleConfiguration getLifecycle(MappingHttpRequest httpRequest) throws S3Exception {
    LifecycleConfiguration lifecycleConfigurationType = new LifecycleConfiguration();
    lifecycleConfigurationType.setRules(new ArrayList<LifecycleRule>());
    String message = getMessageString(httpRequest);
    if (message.length() > 0) {
        try {/*from  w ww.  j av a2 s. c  o m*/
            XMLParser xmlParser = new XMLParser(message);
            DTMNodeList rules = xmlParser.getNodes("//LifecycleConfiguration/Rule");
            if (rules == null) {
                throw new MalformedXMLException("/LifecycleConfiguration/Rule");
            }
            for (int idx = 0; idx < rules.getLength(); idx++) {
                lifecycleConfigurationType.getRules().add(extractLifecycleRule(xmlParser, rules.item(idx)));
            }
        } catch (S3Exception e) {
            throw e;
        } catch (Exception ex) {
            MalformedXMLException e = new MalformedXMLException("/LifecycleConfiguration");
            ex.initCause(ex);
            throw e;
        }
    }
    return lifecycleConfigurationType;
}

From source file:org.nuxeo.ecm.core.storage.sql.jdbc.JDBCRowMapper.java

/**
 * Inserts multiple rows, all for the same table.
 *//*  ww w .  j av a2  s.  c o m*/
protected void insertSimpleRows(String tableName, List<Row> rows) throws StorageException {
    if (rows.isEmpty()) {
        return;
    }
    String sql = sqlInfo.getInsertSql(tableName);
    if (sql == null) {
        throw new StorageException("Unknown table: " + tableName);
    }
    String loggedSql = supportsBatchUpdates && rows.size() > 1 ? sql + " -- BATCHED" : sql;
    List<Column> columns = sqlInfo.getInsertColumns(tableName);
    try {
        PreparedStatement ps = connection.prepareStatement(sql);
        try {
            int batch = 0;
            for (Row row : rows) {
                batch++;
                if (logger.isLogEnabled()) {
                    logger.logSQL(loggedSql, columns, row);
                }
                int i = 1;
                for (Column column : columns) {
                    column.setToPreparedStatement(ps, i++, row.get(column.getKey()));
                }
                if (supportsBatchUpdates) {
                    ps.addBatch();
                    if (batch % UPDATE_BATCH_SIZE == 0) {
                        ps.executeBatch();
                        countExecute();
                    }
                } else {
                    ps.execute();
                    countExecute();
                }
            }
            if (supportsBatchUpdates) {
                ps.executeBatch();
                countExecute();
            }
        } finally {
            closeStatement(ps);
        }
    } catch (Exception e) {
        checkConnectionReset(e);
        if (e instanceof BatchUpdateException) {
            BatchUpdateException bue = (BatchUpdateException) e;
            if (e.getCause() == null && bue.getNextException() != null) {
                // provide a readable cause in the stack trace
                e.initCause(bue.getNextException());
            }
        }
        checkConcurrentUpdate(e);
        throw new StorageException("Could not insert: " + sql, e);
    }
}