Example usage for org.apache.commons.collections.keyvalue MultiKey MultiKey

List of usage examples for org.apache.commons.collections.keyvalue MultiKey MultiKey

Introduction

In this page you can find the example usage for org.apache.commons.collections.keyvalue MultiKey MultiKey.

Prototype

public MultiKey(Object[] keys, boolean makeClone) 

Source Link

Document

Constructor taking an array of keys, optionally choosing whether to clone.

Usage

From source file:com.bstek.dorado.data.resource.DefaultModelResourceBundleManager.java

public ResourceBundle getBundle(Resource resource, Locale locale) throws Exception {
    if (resource == null) {
        return null;
    }/* www  .j a  v a 2  s .  co m*/
    String path = resource.getPath();
    if (StringUtils.isEmpty(path)) {
        return null;
    }

    Object cacheKey = new MultiKey(path, locale);
    synchronized (cache) {
        Element element = cache.get(cacheKey);
        if (element == null) {
            ResourceBundle bundle = doGetBundle(resource, locale);
            element = new Element(cacheKey, bundle);
            cache.put(element);
        }
        return (ResourceBundle) element.getObjectValue();
    }
}

From source file:com.bstek.dorado.view.resource.DefaultViewResourceBundleManager.java

public ResourceBundle getBundle(ViewConfigDefinition viewConfigDefinition, Locale locale) throws Exception {
    Resource resource = viewConfigDefinition.getResource();
    if (resource == null) {
        return null;
    }//from   ww  w  .jav a2s  .c o m
    String path = resource.getPath();
    if (StringUtils.isEmpty(path)) {
        return null;
    }

    Object cacheKey = new MultiKey(path, locale);
    synchronized (cache) {
        Element element = cache.get(cacheKey);
        if (element == null) {
            ResourceBundle bundle = doGetBundle(viewConfigDefinition, locale);
            element = new Element(cacheKey, bundle);
            cache.put(element);
        }
        return (ResourceBundle) element.getObjectValue();
    }
}

From source file:com.nextep.designer.sqlgen.mssql.impl.MSSQLCapturer.java

@Override
public Collection<IBasicTable> getTables(ICaptureContext context, IProgressMonitor monitor) {
    // DRH 2/17/2011 good enough
    Collection<IBasicTable> tables = jdbcCapturer.getTables(context, monitor);

    // We retrieve from the capture context the list of database objects captured with their
    // associated schema.
    Map<IDatabaseObject<?>, String> dbObjSchemas = context.getAttributeValues(ATTR_SCHEMA);

    // We create a map of the captured tables hashed by their name and schema so we can easily
    // retrieve them later to set their description.
    Map<MultiKey, IBasicTable> capturedTables = new HashMap<MultiKey, IBasicTable>();
    for (IBasicTable table : tables) {
        capturedTables.put(new MultiKey(dbObjSchemas.get(table), table.getName()), table);
    }/*w  w w . j  a  v a  2  s .  co  m*/

    // update table descriptions from MS_DESCRIPTION extended properties
    updateTablesDescriptions(context, monitor, capturedTables);

    // Update columns properties (IDENTITY, FILESTREAM, ROWGUIDCOL, etc.)
    updateColumnsProperties(context, monitor, capturedTables);

    return tables;
}

From source file:com.nextep.designer.sqlgen.mssql.impl.MSSQLCapturer.java

/**
 * @param context a {@link ICaptureContext} representing the current capture context
 * @param monitor the {@link IProgressMonitor} to notify while capturing objects
 * @param capturedTables a <code>Map</code> of all tables previously captured hashed by a
 *        <code>MultiKey</code> containing their schema name and their object name
 *//*from  w  ww  . j av a 2 s  . c om*/
private void updateTablesDescriptions(ICaptureContext context, IProgressMonitor monitor,
        Map<MultiKey, IBasicTable> capturedTables) {
    monitor.subTask("Retrieving tables and columns descriptions...");

    // We define the list of distinct schema names for all tables previously captured
    Set<String> schemaNames = new HashSet<String>();
    for (MultiKey key : capturedTables.keySet()) {
        schemaNames.add((String) key.getKey(0));
    }

    // For each unique schema, we fetch the extended properties of all tables
    for (String schemaName : schemaNames) {
        final Map<String, String> tablesDescriptions = getSchemaTablesDescriptions(context, monitor,
                schemaName);

        for (String tableName : tablesDescriptions.keySet()) {
            final IBasicTable table = capturedTables.get(new MultiKey(schemaName, tableName));
            if (table != null) {
                table.setDescription(tablesDescriptions.get(tableName));
            } else {
                LOGGER.warn("Table [" + schemaName + "." + tableName
                        + "] description has been ignored during import because the referenced "
                        + "table could not be found in the current workspace");
            }
        }
    }

    // For each captured table, we fetch the extended properties of all columns
    for (MultiKey key : capturedTables.keySet()) {
        final String schemaName = (String) key.getKey(0);
        final String tableName = (String) key.getKey(1);
        final IBasicTable table = capturedTables.get(key);
        final Map<String, String> columnsDescriptions = getTableColumnsDescriptions(context, monitor,
                schemaName, tableName);

        if (!columnsDescriptions.isEmpty()) {
            // We create a map of the table's columns hashed by their name so we can easily
            // retrieve them to set their description.
            Map<String, IBasicColumn> tableColumns = new HashMap<String, IBasicColumn>();
            for (IBasicColumn column : table.getColumns()) {
                tableColumns.put(column.getName(), column);
            }

            // We browse the list of retrieved column descriptions to set each column
            // description.
            for (String columnName : columnsDescriptions.keySet()) {
                final IBasicColumn column = tableColumns.get(columnName);
                if (column != null) {
                    column.setDescription(columnsDescriptions.get(columnName));
                } else {
                    LOGGER.warn("Column [" + schemaName + "." + tableName + "." + columnName
                            + "] description has been ignored during import because the "
                            + "referenced column could not be found in the current workspace");
                }
            }
        }
    }
}

From source file:com.nextep.designer.sqlgen.db2.impl.DB2Capturer.java

@Override
public Collection<IIndex> getIndexes(ICaptureContext context, IProgressMonitor monitor) {
    Map<MultiKey, IIndex> indexes = new HashMap<MultiKey, IIndex>();
    final Connection conn = (Connection) context.getConnectionObject();
    IFormatter formatter = context.getConnection().getDBVendor().getNameFormatter();

    Statement stmt = null;/*from   w  w  w . j  ava  2  s  . c o  m*/
    ResultSet rset = null;
    try {
        stmt = conn.createStatement();

        rset = stmt.executeQuery("SELECT i.tabname, i.indname, i.indextype, i.uniquerule, i.remarks, " //$NON-NLS-1$
                + "c.colname, c.colseq, c.colorder " //$NON-NLS-1$
                + "FROM syscat.indexes i, syscat.indexcoluse c " //$NON-NLS-1$
                + "WHERE i.indschema = '" + context.getSchema() + "' AND i.tabschema = i.indschema " //$NON-NLS-1$ //$NON-NLS-2$
                + "AND i.uniquerule <> 'P' AND i.indextype = 'REG' " //$NON-NLS-1$
                + "AND c.indname = i.indname AND c.indschema = i.indschema " //$NON-NLS-1$
                + "ORDER BY i.tabname, i.indname, c.colseq"); //$NON-NLS-1$
        CaptureHelper.updateMonitor(monitor, getCounter(), 1, 1);

        IIndex currIndex = null;
        String currIndexName = null;
        boolean indexIsValid = false;

        while (rset.next()) {
            final String tableName = rset.getString("tabname"); //$NON-NLS-1$
            final String indexName = rset.getString("indname"); //$NON-NLS-1$
            final String indexType = rset.getString("indextype"); //$NON-NLS-1$
            final String uniqueRule = rset.getString("uniquerule"); //$NON-NLS-1$
            final String indexDesc = rset.getString("remarks"); //$NON-NLS-1$
            final String indexColumnName = rset.getString("colname"); //$NON-NLS-1$
            final int indexColumnSeq = rset.getInt("colseq"); //$NON-NLS-1$
            final String ascOrDesc = rset.getString("colorder"); //$NON-NLS-1$

            if (indexName != null && !"".equals(indexName.trim())) { //$NON-NLS-1$
                if (LOGGER.isDebugEnabled()) {
                    String logPrefix = "[" + indexName + "]"; //$NON-NLS-1$ //$NON-NLS-2$
                    LOGGER.debug("= " + logPrefix + " Index Metadata ="); //$NON-NLS-1$ //$NON-NLS-2$
                    LOGGER.debug(logPrefix + "[SYSCAT.INDEXES.TABNAME] " + tableName); //$NON-NLS-1$
                    LOGGER.debug(logPrefix + "[SYSCAT.INDEXES.INDEXTYPE] " + indexType); //$NON-NLS-1$
                    LOGGER.debug(logPrefix + "[SYSCAT.INDEXES.UNIQUERULE] " + uniqueRule); //$NON-NLS-1$
                    LOGGER.debug(logPrefix + "[SYSCAT.INDEXES.REMARKS] " + indexDesc); //$NON-NLS-1$
                    LOGGER.debug(logPrefix + "[SYSCAT.INDEXCOLUSE.COLNAME] " + indexColumnName); //$NON-NLS-1$
                    LOGGER.debug(logPrefix + "[SYSCAT.INDEXCOLUSE.COLSEQ] " + indexColumnSeq); //$NON-NLS-1$
                    LOGGER.debug(logPrefix + "[SYSCAT.INDEXCOLUSE.COLORDER] " + ascOrDesc); //$NON-NLS-1$
                }

                if (null == currIndexName || !currIndexName.equals(indexName) || indexIsValid) {
                    currIndexName = indexName;
                    final String formatTableName = formatter.format(tableName);
                    final String formatIndexName = formatter.format(indexName);
                    final String formatIndexColumnName = formatter.format(indexColumnName);

                    if (null == currIndex || !formatIndexName.equals(currIndex.getIndexName())) {
                        IVersionable<IIndex> v = VersionableFactory.createVersionable(IIndex.class);
                        currIndex = v.getVersionnedObject().getModel();
                        currIndex.setName(formatIndexName);
                        currIndex.setDescription(indexDesc);
                        currIndex.setIndexType("U".equals(uniqueRule) ? IndexType.UNIQUE //$NON-NLS-1$
                                : IndexType.NON_UNIQUE);
                        indexes.put(new MultiKey(formatTableName, formatIndexName), currIndex);
                        indexIsValid = true;
                        CaptureHelper.updateMonitor(monitor, getCounter(), 5, 1);
                    }

                    final IBasicColumn column = (IBasicColumn) context.getCapturedObject(
                            IElementType.getInstance(IBasicColumn.TYPE_ID),
                            CaptureHelper.getUniqueObjectName(formatTableName, formatIndexColumnName));
                    if (column != null) {
                        /*
                         * Columns are ordered by SYSCAT.INDEXCOLUSE.COLSEQ in the returned
                         * Resultset, so we don't have to specify the position of the index
                         * column when adding it to the index.
                         */
                        currIndex.addColumnRef(column.getReference());
                    } else {
                        LOGGER.warn("Index [" + formatIndexName
                                + "] has been ignored during import because the referencing column ["
                                + formatTableName + "[" + formatIndexColumnName //$NON-NLS-1$
                                + "]] could not be found in the current workspace");
                        indexIsValid = false;

                        /*
                         * Now the index is invalid, we remove it from the indexes list that
                         * will be returned to the caller of this method.
                         */
                        indexes.remove(new MultiKey(formatTableName, formatIndexName));
                    }
                }
            }
        }

        /*
         * Once the list of valid indexes has been set, we can link the indexes with their
         * corresponding table.
         */
        for (MultiKey key : indexes.keySet()) {
            String tableName = (String) key.getKey(0);
            IIndex index = indexes.get(key);
            final IBasicTable table = context.getTable(tableName);
            index.setIndexedTableRef(table.getReference());
            table.addIndex(index);
        }
    } catch (SQLException sqle) {
        LOGGER.error("Unable to fetch indexes from DB2 server: " + sqle.getMessage(), sqle);
    } finally {
        CaptureHelper.safeClose(rset, stmt);
    }

    return indexes.values();
}

From source file:com.nextep.datadesigner.vcs.impl.MergeStrategyDatabase.java

/**
 * Hashes a collection of <code>IReferenceable</code> objects by their reference
 * /*from   www .ja  va 2  s.c o m*/
 * @param <V> type of the collection which must be a subclass of <code>IReferenceable</code>
 * @param refList a collection of <code>IReferenceable</code>
 * @return a Map of the <code>IReferenceable</code> hashed by reference
 */
@SuppressWarnings("unchecked")
protected <V extends IReferenceable> Map<MultiKey, IReferenceable> hashByNameAndType(Collection<V> refList) {
    int size = refList.size();
    Map<MultiKey, IReferenceable> m = MultiKeyMap.decorate(new HashedMap((0 == size ? 1 : size)));

    for (V r : refList) {
        INamedObject o = getNamedObject(r);
        if (isCaseSensitive()) {
            m.put(new MultiKey(o.getName(), getElementType(r)), r);
        } else {
            m.put(new MultiKey(o.getName().toUpperCase(), getElementType(r)), r);
        }
    }
    return m;
}

From source file:com.nextep.datadesigner.vcs.impl.MergeStrategyDatabase.java

private MultiKey getReferenceableKey(IReferenceable ref) {
    return new MultiKey(getNamedObjectName(ref), getElementType(ref));
}

From source file:at.tuwien.ifs.somtoolbox.visualization.PMatrix.java

public DoubleMatrix2D createPMatrix(GrowingSOM gsom) throws MetricException, LayerAccessException {
    // we store a cache of the PMatrix, as it is computationally expensive, and is be used for both P-Matrix and
    // U*-Matrix//from   w ww  .ja v a 2s.  co m
    if (!pMatrixCache.containsKey(new MultiKey(gsom, radius))) {

        GrowingLayer layer = gsom.getLayer();
        InputData data = gsom.getSharedInputObjects().getInputData();
        DistanceMetric metric = layer.getMetric();

        int pmatW = layer.getXSize();
        int pmatH = layer.getYSize();
        DoubleMatrix2D pmatrix = new DenseDoubleMatrix2D(pmatH, pmatW);

        // now check // for each unit in the SOM how many of the input data items lie within the Pareto radius
        // around the unit's weight vector
        int index = 0;
        for (int x = 0; x < layer.getXSize(); x++) {
            for (int y = 0; y < layer.getYSize(); y++) {
                int withinRadius = 0;
                for (int i = 0; i < data.numVectors(); i++) { // check whether the distance to each input is within
                    // the pareto radius
                    if (metric.distance(layer.getUnit(x, y).getWeightVector(),
                            data.getInputVector(i)) < radius) {
                        withinRadius++;
                    }
                    pmatrix.set(y, x, withinRadius);
                }
                index++;
            }
        }
        pMatrixCache.put(new MultiKey(gsom, radius), pmatrix);
    }

    return pMatrixCache.get(new MultiKey(gsom, radius));
}

From source file:com.nextep.designer.sqlgen.mssql.impl.MSSQLCapturer.java

/**
 * @param context a {@link ICaptureContext} representing the current capture context
 * @param monitor the {@link IProgressMonitor} to notify while capturing objects
 * @return a <code>Map</code> of all identity columns in the current database hashed by a
 *         <code>MultiKey</code> containing the schema and table names of the parent tables.
 *         Each identity column is represented by a <code>MultiKey</code> containing the name of
 *         the column, followed by the seed and increment attributes
 *//*  w ww. j  a v  a  2 s .  c  o m*/
private Map<MultiKey, MultiKey> getIdentityColumnsAttributes(ICaptureContext context,
        IProgressMonitor monitor) {
    monitor.subTask("Retrieving identity columns attributes...");
    final Map<MultiKey, MultiKey> attributes = new HashMap<MultiKey, MultiKey>();
    final String schema = context.getSchema();

    Connection conn = (Connection) context.getConnectionObject();
    PreparedStatement prepStmt = null;
    ResultSet rset = null;
    try {
        String query = "SELECT s.name AS schema_name, t.name AS table_name, c.name AS column_name, " //$NON-NLS-1$
                + "  c.seed_value, c.increment_value, IDENT_CURRENT(s.name + '.' + t.name) AS last_value " //$NON-NLS-1$
                + "FROM sys.schemas AS s " //$NON-NLS-1$
                + "  JOIN sys.tables AS t ON t.schema_id = s.schema_id " //$NON-NLS-1$
                + "  JOIN sys.identity_columns AS c ON c.object_id = t.object_id"; //$NON-NLS-1$
        if (schema != null) {
            query += " WHERE s.name = ?"; //$NON-NLS-1$
        }

        prepStmt = conn.prepareStatement(query);
        if (schema != null) {
            prepStmt.setString(1, schema);
        }

        rset = prepStmt.executeQuery();
        while (rset.next()) {
            monitor.worked(1);
            final String schemaName = rset.getString("schema_name"); //$NON-NLS-1$
            final String tableName = rset.getString("table_name"); //$NON-NLS-1$
            final String columnName = rset.getString("column_name"); //$NON-NLS-1$
            final int seed = rset.getInt("seed_value"); //$NON-NLS-1$
            final int increment = rset.getInt("increment_value"); //$NON-NLS-1$
            final BigDecimal lastValue = rset.getBigDecimal("last_value"); //$NON-NLS-1$

            // We check that the schema name is not null, and that the table and column names
            // are not null and not empty.
            if (schemaName != null && tableName != null && !"".equals(tableName.trim()) //$NON-NLS-1$
                    && columnName != null && !"".equals(columnName.trim())) { //$NON-NLS-1$
                if (LOGGER.isDebugEnabled()) {
                    String logPrefix = "[" + schemaName + "." + tableName + "." + columnName //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                            + "] "; //$NON-NLS-1$
                    LOGGER.debug("= " + logPrefix + "Identity Property Metadata ="); //$NON-NLS-1$ //$NON-NLS-2$
                    LOGGER.debug(logPrefix + "[SEED] " + seed); //$NON-NLS-1$
                    LOGGER.debug(logPrefix + "[INCREMENT] " + increment); //$NON-NLS-1$
                    LOGGER.debug(logPrefix + "[LAST_VALUE] " + lastValue); //$NON-NLS-1$
                }

                attributes.put(new MultiKey(schemaName, tableName), new MultiKey(columnName, seed, increment));
            }
        }
    } catch (SQLException sqle) {
        LOGGER.error("Unable to fetch identity columns attributes from SQL Server server: " + sqle.getMessage(),
                sqle);
    } finally {
        CaptureHelper.safeClose(rset, prepStmt);
    }

    return attributes;
}

From source file:com.nextep.designer.sqlgen.mssql.impl.MSSQLCapturer.java

@Override
public Collection<IView> getViews(ICaptureContext context, IProgressMonitor m) {
    final IProgressMonitor monitor = new CustomProgressMonitor(m, 100);
    monitor.subTask(MSSQLMessages.getString("capturer.mssql.retrievingViews")); //$NON-NLS-1$

    final Map<MultiKey, IView> views = new HashMap<MultiKey, IView>();
    final IFormatter formatter = context.getConnection().getDBVendor().getNameFormatter();
    final Connection conn = (Connection) context.getConnectionObject();
    final String schema = context.getSchema();

    ResultSet rset = null;/* w  ww  . j a  va2s.co  m*/
    PreparedStatement prepStmt = null;
    try {
        /*
         * [BGA] Migrating to the Catalog Views approach, since information_schema.views will
         * show only the first 4000 characters of the SQL definition. This query works with SQL
         * Server 2005/2008 but not with SQL Server 2000. Compatibility views might be used as a
         * fallback strategy if we plan to support SQL Server 2000.
         */
        String query = "SELECT s.name AS schema_name, v.name AS view_name, m.definition AS view_definition " //$NON-NLS-1$
                + "FROM sys.schemas AS s " //$NON-NLS-1$
                + "  JOIN sys.views AS v ON v.schema_id = s.schema_id " //$NON-NLS-1$
                + "  JOIN sys.sql_modules AS m ON m.object_id = v.object_id"; //$NON-NLS-1$
        if (schema != null) {
            query += " WHERE s.name = ?"; //$NON-NLS-1$
        }

        // alternative approach for older versions
        // [BGA] Warning with this query, views with a SQL definition longer than 4000
        // characters might be returned with multiple records
        // SELECT u.name AS schema_name, o.name AS view_name, c.text AS view_definition
        // FROM sysobjects AS o
        // JOIN syscomments AS c ON o.id = c.id
        // JOIN sysusers AS u ON o.uid = u.uid
        // WHERE o.xtype = 'V';

        prepStmt = conn.prepareStatement(query);
        if (schema != null) {
            prepStmt.setString(1, schema);
        }

        rset = prepStmt.executeQuery();
        while (rset.next()) {
            monitor.worked(1);
            final String schemaName = rset.getString("schema_name"); //$NON-NLS-1$
            final String viewName = rset.getString("view_name"); //$NON-NLS-1$
            final String sql = rset.getString("view_definition"); //$NON-NLS-1$

            String viewQuery = CaptureHelper.getQueryFromCreateAsStatement(sql);

            if (viewQuery != null && !"".equals(viewQuery.trim())) { //$NON-NLS-1$
                IVersionable<IView> v = VersionableFactory.createVersionable(IView.class);
                IView view = v.getVersionnedObject().getModel();
                view.setName(formatter.format(viewName));
                view.setSQLDefinition(viewQuery);

                views.put(new MultiKey(schemaName, viewName), view);
            } else {
                LOGGER.warn("View [" + viewName + "] has been ignored during import because the SQL definition "
                        + "could not be extracted from dictionary tables. " + "View definition [" + sql + "]"); //$NON-NLS-3$
            }
        }
    } catch (SQLException e) {
        LOGGER.warn(
                MessageFormat.format(MSSQLMessages.getString("capturer.mssql.fetchViewsError"), e.getMessage()), //$NON-NLS-1$
                e);
    } finally {
        CaptureHelper.safeClose(rset, prepStmt);
    }

    // TODO [BGA] Implement the views descriptions retrieval as what has been done for the
    // tables descriptions.
    // Update views descriptions from MS_Description extended properties
    // updateViewsDescriptions(context, monitor, views);

    return views.values();
}