Example usage for org.apache.commons.lang ArrayUtils toString

List of usage examples for org.apache.commons.lang ArrayUtils toString

Introduction

In this page you can find the example usage for org.apache.commons.lang ArrayUtils toString.

Prototype

public static String toString(Object array) 

Source Link

Document

Outputs an array as a String, treating null as an empty array.

Usage

From source file:org.jumpmind.symmetric.io.data.DbFill.java

private void updateRandomRecord(Table table) {
    DmlStatement updStatement = createUpdateDmlStatement(table);
    Row row = createRandomUpdateValues(updStatement, table);
    try {//from   w w w  .  j av a2 s  .c o m
        platform.getSqlTemplate().update(updStatement.getSql(), row.toArray(table.getColumnNames()));
        if (verbose) {
            log.info("Successful update in " + table.getName());
        }
    } catch (SqlException ex) {
        log.info("Failed to process {} with values of {}", updStatement.getSql(),
                ArrayUtils.toString(row.toArray(table.getColumnNames())));
        if (continueOnError) {
            if (debug) {
                log.info("", ex);
            }
        } else {
            throw ex;
        }
    }
}

From source file:org.jumpmind.symmetric.io.data.DbFill.java

/**
  * Select a random row from the table and update all columns except for primary and foreign keys.
  */*from  w w w  .j ava2s. com*/
  * @param sqlTemplate
  * @param table
  */
private void insertRandomRecord(Table table) {
    DmlStatement insertStatement = createInsertDmlStatement(table);
    Row row = createRandomInsertValues(insertStatement, table);
    try {
        platform.getSqlTemplate().update(insertStatement.getSql(), insertStatement.getValueArray(
                row.toArray(table.getColumnNames()), row.toArray(table.getPrimaryKeyColumnNames())));
        if (verbose) {
            log.info("Successful update in " + table.getName());
        }
    } catch (SqlException ex) {
        log.info("Failed to process {} with values of {}", insertStatement.getSql(),
                ArrayUtils.toString(row.toArray(table.getColumnNames())));
        if (continueOnError) {
            if (debug) {
                log.info("", ex);
            }
        } else {
            throw ex;
        }
    }
}

From source file:org.jumpmind.symmetric.io.data.DbFill.java

/**
 * Delete a random row in the given table or delete all rows matching selectColumns
 * in the given table./*from w  w  w .j  a  v  a2s  . c o  m*/
 *
 * @param table Table to delete from.
 * @param selectColumns If provided, the rows that match this criteria are deleted.
 */
private void deleteRandomRecord(Table table) {
    DmlStatement deleteStatement = createDeleteDmlStatement(table);
    Row row = selectRandomRow(table);
    try {
        platform.getSqlTemplate().update(deleteStatement.getSql(), row.toArray(table.getColumnNames()));
        if (verbose) {
            log.info("Successful update in " + table.getName());
        }
    } catch (SqlException ex) {
        log.info("Failed to process {} with values of {}", deleteStatement.getSql(),
                ArrayUtils.toString(row.toArray(table.getColumnNames())));
        if (continueOnError) {
            if (debug) {
                log.info("", ex);
            }
        } else {
            throw ex;
        }
    }
}

From source file:org.jumpmind.symmetric.io.data.reader.ProtocolDataReader.java

public Object readNext() {
    try {/*w w  w. ja  v a  2  s .  com*/
        Set<String> keys = null;
        String schemaName = null;
        String catalogName = null;
        String[] parsedOldData = null;
        long bytesRead = 0;
        Table table = null;
        while (tokens != null || csvReader.readRecord()) {
            lineNumber++;
            context.put(CTX_LINE_NUMBER, lineNumber);
            if (tokens == null) {
                tokens = csvReader.getValues();
            }
            bytesRead += logDebugAndCountBytes(tokens);
            if (batch != null) {
                statistics.get(batch).increment(DataReaderStatistics.READ_BYTE_COUNT, bytesRead);
                bytesRead = 0;
            }

            if (table != null && !(tokens[0].equals(CsvConstants.TABLE) || tokens[0].equals(CsvConstants.KEYS)
                    || tokens[0].equals(CsvConstants.COLUMNS))) {
                return table;
            }

            if (tokens[0].equals(CsvConstants.INSERT)) {
                CsvData data = new CsvData();
                data.setNoBinaryOldData(noBinaryOldData);
                data.setDataEventType(DataEventType.INSERT);
                data.putParsedData(CsvData.ROW_DATA, CollectionUtils.copyOfRange(tokens, 1, tokens.length));
                tokens = null;
                return data;
            } else if (tokens[0].equals(CsvConstants.OLD)) {
                parsedOldData = CollectionUtils.copyOfRange(tokens, 1, tokens.length);

            } else if (tokens[0].equals(CsvConstants.UPDATE)) {
                CsvData data = new CsvData();
                data.setNoBinaryOldData(noBinaryOldData);
                data.setDataEventType(DataEventType.UPDATE);
                int columnCount = context.getLastParsedTable().getColumnCount();
                if (tokens.length <= columnCount) {
                    String msg = String.format("Invalid state while parsing csv data.  "
                            + "The number of columns (%d) reported for table '%s' don't match up with the token data: %s",
                            columnCount, context.getLastParsedTable().getFullyQualifiedTableName(),
                            ArrayUtils.toString(tokens));
                    throw new IllegalStateException(msg);
                }
                data.putParsedData(CsvData.ROW_DATA, CollectionUtils.copyOfRange(tokens, 1, columnCount + 1));
                data.putParsedData(CsvData.PK_DATA,
                        CollectionUtils.copyOfRange(tokens, columnCount + 1, tokens.length));
                data.putParsedData(CsvData.OLD_DATA, parsedOldData);
                tokens = null;
                return data;
            } else if (tokens[0].equals(CsvConstants.DELETE)) {
                CsvData data = new CsvData();
                data.setNoBinaryOldData(noBinaryOldData);
                data.setDataEventType(DataEventType.DELETE);
                data.putParsedData(CsvData.PK_DATA, CollectionUtils.copyOfRange(tokens, 1, tokens.length));
                data.putParsedData(CsvData.OLD_DATA, parsedOldData);
                tokens = null;
                return data;

            } else if (tokens[0].equals(CsvConstants.BATCH)) {
                Batch batch = new Batch(batchType, Long.parseLong(tokens[1]), channelId, binaryEncoding,
                        sourceNodeId, targetNodeId, false);
                statistics.put(batch, new DataReaderStatistics());
                tokens = null;
                return batch;
            } else if (tokens[0].equals(CsvConstants.NO_BINARY_OLD_DATA)) {
                if (tokens.length > 1) {
                    noBinaryOldData = Boolean.parseBoolean(tokens[1]);
                }

            } else if (tokens[0].equals(CsvConstants.NODEID)) {
                this.sourceNodeId = tokens[1];

            } else if (tokens[0].equals(CsvConstants.BINARY)) {
                this.binaryEncoding = BinaryEncoding.valueOf(tokens[1]);

            } else if (tokens[0].equals(CsvConstants.CHANNEL)) {
                this.channelId = tokens[1];

            } else if (tokens[0].equals(CsvConstants.SCHEMA)) {
                schemaName = tokens.length == 1 || StringUtils.isBlank(tokens[1]) ? null : tokens[1];

            } else if (tokens[0].equals(CsvConstants.CATALOG)) {
                catalogName = tokens.length == 1 || StringUtils.isBlank(tokens[1]) ? null : tokens[1];

            } else if (tokens[0].equals(CsvConstants.TABLE)) {
                String tableName = tokens[1];
                table = context.getParsedTables()
                        .get(Table.getFullyQualifiedTableName(catalogName, schemaName, tableName));
                if (table != null) {
                    context.setLastParsedTable(table);
                } else {
                    table = new Table(catalogName, schemaName, tableName);
                    context.setLastParsedTable(table);
                }

            } else if (tokens[0].equals(CsvConstants.KEYS)) {
                if (keys == null) {
                    keys = new HashSet<String>(tokens.length);
                }
                for (int i = 1; i < tokens.length; i++) {
                    keys.add(tokens[i]);
                }
            } else if (tokens[0].equals(CsvConstants.COLUMNS)) {
                table.removeAllColumns();
                for (int i = 1; i < tokens.length; i++) {
                    Column column = new Column(tokens[i], keys != null && keys.contains(tokens[i]));
                    table.addColumn(column);
                }
                context.getParsedTables().put(table.getFullyQualifiedTableName(), table);
            } else if (tokens[0].equals(CsvConstants.COMMIT)) {
                if (batch != null) {
                    batch.setComplete(true);
                }
                tokens = null;
                return null;
            } else if (tokens[0].equals(CsvConstants.SQL)) {
                CsvData data = new CsvData();
                data.setNoBinaryOldData(noBinaryOldData);
                data.setDataEventType(DataEventType.SQL);
                data.putParsedData(CsvData.ROW_DATA, new String[] { tokens[1] });
                tokens = null;
                return data;
            } else if (tokens[0].equals(CsvConstants.BSH)) {
                CsvData data = new CsvData();
                data.setNoBinaryOldData(noBinaryOldData);
                data.setDataEventType(DataEventType.BSH);
                data.putParsedData(CsvData.ROW_DATA, new String[] { tokens[1] });
                tokens = null;
                return data;
            } else if (tokens[0].equals(CsvConstants.CREATE)) {
                CsvData data = new CsvData();
                data.setNoBinaryOldData(noBinaryOldData);
                data.setDataEventType(DataEventType.CREATE);
                data.putParsedData(CsvData.ROW_DATA, new String[] { tokens[1] });
                tokens = null;
                return data;
            } else if (tokens[0].equals(CsvConstants.IGNORE)) {
                if (batch != null) {
                    batch.setIgnored(true);
                }

            } else {
                log.info("Unable to handle unknown csv values: " + Arrays.toString(tokens));

            }

            tokens = null;
        }
    } catch (IOException ex) {
        throw new IoException(ex);
    }

    return null;

}

From source file:org.jumpmind.symmetric.io.data.writer.DefaultTransformWriterConflictResolver.java

@Override
protected void performFallbackToInsert(AbstractDatabaseWriter writer, CsvData data, Conflict conflict,
        boolean retransform) {
    TransformedData transformedData = data.getAttribute(TransformedData.class.getName());
    if (transformedData != null && retransform) {
        List<TransformedData> newlyTransformedDatas = transformWriter.transform(DataEventType.INSERT,
                writer.getContext(), transformedData.getTransformation(), transformedData.getSourceKeyValues(),
                transformedData.getOldSourceValues(), transformedData.getSourceValues());
        if (newlyTransformedDatas.size() > 0) {
            boolean matchedTransform = false;
            for (TransformedData newlyTransformedData : newlyTransformedDatas) {
                /*/*from  w w w  . j a v a 2s .c om*/
                 * If there is only one transform, then process it.
                 * Otherwise, we need to attempt to match the key values to
                 * choose the correct transform.
                 */
                if (newlyTransformedDatas.size() == 1
                        || newlyTransformedData.hasSameKeyValues(transformedData.getKeyValues())
                        || newlyTransformedData.isGeneratedIdentityNeeded()) {
                    matchedTransform = true;
                    Table table = newlyTransformedData.buildTargetTable();
                    CsvData newData = newlyTransformedData.buildTargetCsvData();
                    if (newlyTransformedData.isGeneratedIdentityNeeded()) {
                        if (log.isDebugEnabled()) {
                            log.debug("Enabling generation of identity for {}",
                                    newlyTransformedData.getTableName());
                        }
                        writer.allowInsertIntoAutoIncrementColumns(false, table);
                    } else if (table.hasAutoIncrementColumn()) {
                        writer.allowInsertIntoAutoIncrementColumns(true, table);
                    }

                    writer.start(table);
                    super.performFallbackToInsert(writer, newData, conflict, retransform);
                    writer.end(table);
                }

            }

            if (!matchedTransform) {
                log.warn(
                        "The attempt to retransform resulted in more than one transform.  We tried to choose one "
                                + "by matching on the ordered key values, but could not find a match.  Please check that the "
                                + "transformation is configured so that it will return keys in the same order regardless of DML type.  "
                                + "The original key values that we tried to match on were: {}"
                                + ArrayUtils.toString(transformedData.getKeyValues()));
            }
        }

    } else {
        super.performFallbackToInsert(writer, data, conflict, retransform);
    }
}

From source file:org.jumpmind.symmetric.io.data.writer.TransformWriter.java

protected List<TransformedData> transform(DataEventType eventType, DataContext context,
        TransformTable transformation, Map<String, String> sourceKeyValues, Map<String, String> oldSourceValues,
        Map<String, String> sourceValues) {
    try {//from   ww  w  .jav  a2 s .  c o m
        List<TransformedData> dataToTransform = create(context, eventType, transformation, sourceKeyValues,
                oldSourceValues, sourceValues);
        List<TransformedData> dataThatHasBeenTransformed = new ArrayList<TransformedData>(
                dataToTransform.size());
        if (log.isDebugEnabled()) {
            log.debug("{} target data was created for the {} transformation.  The target table is {}",
                    new Object[] { dataToTransform.size(), transformation.getTransformId(),
                            transformation.getFullyQualifiedTargetTableName() });
        }
        int transformNumber = 0;
        for (TransformedData targetData : dataToTransform) {
            transformNumber++;
            if (perform(context, targetData, transformation, sourceValues, oldSourceValues)) {
                if (log.isDebugEnabled()) {
                    log.debug(
                            "Data has been transformed to a {} for the #{} transform.  The mapped target columns are: {}. The mapped target values are: {}",
                            new Object[] { targetData.getTargetDmlType().toString(), transformNumber,
                                    ArrayUtils.toString(targetData.getColumnNames()),
                                    ArrayUtils.toString(targetData.getColumnValues()) });
                }
                dataThatHasBeenTransformed.add(targetData);
            } else {
                log.debug("Data has not been transformed for the #{} transform", transformNumber);
            }
        }
        return dataThatHasBeenTransformed;
    } catch (IgnoreRowException ex) {
        // ignore this row
        if (log.isDebugEnabled()) {
            log.debug("Transform indicated that the target row should be ignored with a target key of: {}",
                    "unknown.  Transformation aborted during tranformation of key");
        }
        return new ArrayList<TransformedData>(0);
    }

}

From source file:org.jumpmind.symmetric.io.data.writer.TransformWriter.java

protected boolean perform(DataContext context, TransformedData data, TransformTable transformation,
        Map<String, String> sourceValues, Map<String, String> oldSourceValues) throws IgnoreRowException {
    boolean persistData = false;
    try {//w  w w. j a  va  2  s  .com
        DataEventType eventType = data.getSourceDmlType();
        for (TransformColumn transformColumn : transformation.getTransformColumns()) {
            if (!transformColumn.isPk()) {
                IncludeOnType includeOn = transformColumn.getIncludeOn();
                if (includeOn == IncludeOnType.ALL
                        || (includeOn == IncludeOnType.INSERT && eventType == DataEventType.INSERT)
                        || (includeOn == IncludeOnType.UPDATE && eventType == DataEventType.UPDATE)
                        || (includeOn == IncludeOnType.DELETE && eventType == DataEventType.DELETE)) {
                    if (StringUtils.isBlank(transformColumn.getSourceColumnName())
                            || sourceValues.containsKey(transformColumn.getSourceColumnName())) {
                        try {
                            Object value = transformColumn(context, data, transformColumn, sourceValues,
                                    oldSourceValues);
                            if (value instanceof NewAndOldValue) {
                                data.put(transformColumn, ((NewAndOldValue) value).getNewValue(),
                                        oldSourceValues != null ? ((NewAndOldValue) value).getOldValue() : null,
                                        false);
                            } else if (value == null || value instanceof String) {
                                data.put(transformColumn, (String) value, null, false);
                            } else if (value instanceof List) {
                                throw new IllegalStateException(String.format(
                                        "Column transform failed %s.%s. Transforms that multiply rows must be marked as part of the primary key",
                                        transformColumn.getTransformId(),
                                        transformColumn.getTargetColumnName()));
                            } else {
                                throw new IllegalStateException(String.format(
                                        "Column transform failed %s.%s. It returned an unexpected type of %s",
                                        transformColumn.getTransformId(), transformColumn.getTargetColumnName(),
                                        value.getClass().getSimpleName()));
                            }
                        } catch (IgnoreColumnException e) {
                            // Do nothing. We are ignoring the column
                            if (log.isDebugEnabled()) {
                                log.debug("A transform indicated we should ignore the target column {}",
                                        transformColumn.getTargetColumnName());
                            }
                        }
                    } else {
                        if (eventType != DataEventType.DELETE) {
                            log.warn("Could not find a source column of {} for the transformation: {}",
                                    transformColumn.getSourceColumnName(), transformation.getTransformId());
                        } else {
                            log.debug(
                                    "Could not find a source column of {} for the transformation: {}.  This is probably because this was a DELETE event and no old data was captured.",
                                    transformColumn.getSourceColumnName(), transformation.getTransformId());
                        }
                    }
                }
            }
        }

        // perform a transformation if there are columns defined for
        // transformation
        if (data.getColumnNames().length > 0) {
            if (data.getTargetDmlType() != DataEventType.DELETE) {
                persistData = true;
            } else {
                // handle the delete action
                DeleteAction deleteAction = transformation.getDeleteAction();
                switch (deleteAction) {
                case DEL_ROW:
                    data.setTargetDmlType(DataEventType.DELETE);
                    persistData = true;
                    break;
                case UPDATE_COL:
                    data.setTargetDmlType(DataEventType.UPDATE);
                    persistData = true;
                    break;
                case NONE:
                default:
                    if (log.isDebugEnabled()) {
                        log.debug(
                                "The {} transformation is not configured to delete row.  Not sending the delete through.",
                                transformation.getTransformId());
                    }
                }
            }
        }
    } catch (IgnoreRowException ex) {
        // ignore this row
        if (log.isDebugEnabled()) {
            log.debug("Transform indicated that the target row should be ignored with a target key of: {}",
                    ArrayUtils.toString(data.getKeyValues()));
        }
    }
    return persistData;
}

From source file:org.jumpmind.symmetric.route.AbstractDataRouter.java

protected void testColumnNamesMatchValues(DataMetaData dataMetaData, ISymmetricDialect symmetricDialect,
        String[] columnNames, Object[] values) {
    if (columnNames.length != values.length) {
        String additionalErrorMessage = "";
        if (symmetricDialect != null
                && symmetricDialect.getPlatform().getName().equals(DatabaseNamesConstants.ORACLE)) {
            boolean isContainsBigLobs = dataMetaData.getNodeChannel().isContainsBigLob();
            additionalErrorMessage += String.format(
                    "\nOne possible cause of this issue is when channel.contains_big_lobs=0 and the captured row_data size exceeds 4k, captured data will be truncated at 4k. channel.contains_big_lobs is currently set to %s.",
                    isContainsBigLobs ? "1" : "0");
        }/*from  www. j a v a  2s . c  o m*/
        String message = String.format(
                "The number of recorded column names (%d) did not match the number of captured data values (%d).  The data_id %d failed for an %s on %s. %s\ncolumn_names:\n%s\nvalues:\n%s",
                columnNames.length, values.length, dataMetaData.getData().getDataId(),
                dataMetaData.getData().getDataEventType().name(), dataMetaData.getData().getTableName(),
                additionalErrorMessage, ArrayUtils.toString(columnNames), ArrayUtils.toString(values));
        throw new SymmetricException(message);
    }
}

From source file:org.marketcetera.util.ws.wrappers.BaseWrapper.java

@Override
public String toString() {
    return ArrayUtils.toString(getValue());
}

From source file:org.medici.bia.common.teaching.ImageConversionInvoker.java

public int fire() {
    try {/*www  .  j  a v  a2 s. co m*/
        Process process = null;

        if (SystemUtils.IS_OS_LINUX) {
            //            logger.info("IMAGE CONVERSION TASK: Linux Operating System detected...");
            //            String[] env = {"PATH=/bin:/usr/bin/"};
            //            String scriptCommand = ApplicationPropertyManager.getApplicationProperty("path.tmpdir") + 
            //                  (ApplicationPropertyManager.getApplicationProperty("path.tmpdir").endsWith("/") ? "upload_images.sh" : "/upload_images.sh");
            //            String cmd = scriptCommand + " " + fileName +  " '" + fileTitle + "' " + imageOrder + " " + storagePath;
            //            logger.info("IMAGE CONVERSION TASK: launching command [" + cmd + "]");
            //            
            //            process = rt.exec(cmd, env);
            logger.info("IMAGE CONVERSION TASK: Linux Operating System detected...");
            String[] env = { "PATH=/bin:/usr/bin/" };
            String[] commandArray = { ApplicationPropertyManager.getApplicationProperty("path.tmpdir") +
                    //(ApplicationPropertyManager.getApplicationProperty("path.tmpdir").endsWith("/") ? "upload_images.sh" : "/upload_images.sh"), fileName, "'" + fileTitle + "'", "" + imageOrder, "" + storagePath} ;
                    (ApplicationPropertyManager.getApplicationProperty("path.tmpdir").endsWith("/")
                            ? ApplicationPropertyManager.getApplicationProperty("upload.script")
                            : "/" + ApplicationPropertyManager.getApplicationProperty("upload.script")),
                    fileName, "'" + fileTitle + "'", "" + imageOrder, "" + storagePath };
            try {
                logger.info("IMAGE CONVERSION TASK: launching command : " + ArrayUtils.toString(commandArray));
                process = Runtime.getRuntime().exec(commandArray, env);
            } catch (Throwable th) {
                logger.error("errore di esecuzione", th);
            }

        } else if (SystemUtils.IS_OS_WINDOWS) {
            // XXX for development environment: we suppose the 'insert_after_upload.bat' file is
            // in the 'path.tmpdir' location
            String realCommand = "\"\"" + ApplicationPropertyManager.getApplicationProperty("path.tmpdir")
                    + "insert_after_upload.bat\"" + " \"" + fileName + "\" \"" + fileTitle + "\" \""
                    + imageOrder + "\" \"" + storagePath + "\"\"";

            logger.info("IMAGE CONVERSION TASK: Windows Operating System detected...");
            String[] command = new String[3];
            command[0] = "cmd.exe";
            command[1] = "/C";
            command[2] = realCommand;

            try {
                logger.info("IMAGE CONVERSION TASK: launching command : " + ArrayUtils.toString(command));

                process = Runtime.getRuntime().exec(command);
            } catch (Throwable th) {
                logger.error("errore di esecuzione", th);
            }
        } else {
            logger.error(
                    "IMAGE CONVERSION TASK: The detected Operating System is not supported...the task is aborted!");
            return NOT_SUPPORTED_OS;
        }

        ImageConversionProcessStreamLogger errorLoggerConsumer = new ImageConversionProcessStreamLogger(
                process.getErrorStream(), logger, ImageConversionProcessStreamLogger.LogLevel.ERROR);
        ImageConversionProcessStreamLogger infoLoggerConsumer = new ImageConversionProcessStreamLogger(
                process.getInputStream(), logger, ImageConversionProcessStreamLogger.LogLevel.INFO);

        errorLoggerConsumer.start();
        infoLoggerConsumer.start();

        return process.waitFor();
    } catch (Exception e) {
        return TASK_ERROR;
    }
}