org.apache.commons.collections.map.ListOrderedMap Java Examples

The following examples show how to use org.apache.commons.collections.map.ListOrderedMap. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JsonTools.java    From sso-oauth2 with Apache License 2.0 6 votes vote down vote up
/**
* 
* json转换map.
* <br>详细说明
* @param jsonStr json字符串
* @return
* @return Map<String,Object> 集合
* @throws
* @author slj
*/
public static Map<String, Object> parseJSON2Map(String jsonStr) {
	ListOrderedMap map = new ListOrderedMap();
	// System.out.println(jsonStr);
	// 最外层解析
	JSONObject json = JSONObject.fromObject(jsonStr);
	for (Object k : json.keySet()) {
		Object v = json.get(k);
		// 如果内层还是数组的话,继续解析
		if (v instanceof JSONArray) {
			List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
			Iterator<JSONObject> it = ((JSONArray) v).iterator();
			while (it.hasNext()) {
				JSONObject json2 = it.next();
				list.add(parseJSON2Map(json2.toString()));
			}
			map.put(k.toString(), list);
		} else {
			map.put(k.toString(), v);
		}
	}
	return map;
}
 
Example #2
Source File: CreationParameters.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the parameters for the given table.
 * 
 * @param table The table
 * @return The parameters
 */
public Map getParametersFor(Table table)
{
    ListOrderedMap result       = new ListOrderedMap();
    Map            globalParams = (Map)_parametersPerTable.get(null);
    Map            tableParams  = (Map)_parametersPerTable.get(table.getQualifiedName());

    if (globalParams != null)
    {
        result.putAll(globalParams);
    }
    if (tableParams != null)
    {
        result.putAll(tableParams);
    }
    return result;
}
 
Example #3
Source File: MyBeanUtils.java    From spring-boot with Apache License 2.0 6 votes vote down vote up
/**
 * 根据给定的条件,把 list 中的 javabean 排序。
 * 用到了 commons beanutils 和  commons.collections
 *
 * @param list           待排序的 list
 * @param listOrderedMap 排序条件。
 *                       这是一个有序的 list ,排序条件按照加入到 list 的 bean 的属性(map 的 key)的先后顺序排序。
 *                       listOrderedMap 的 key 为待排序的 bean 的属性名称,值为是否按该属性的正序排序,true 为正序,false 为逆序。
 *                       使用方法见本类的 testSortListBeans() 方法例子,使用时注意不要写错 bean 的属性名称。
 * @param <T>            list 中的 bean 类型
 */
public static <T> void sortListBeans(List<T> list, ListOrderedMap listOrderedMap) {

    int num = listOrderedMap.size();
    ArrayList sortFields = new ArrayList();

    for (int i = 0; i < num; i++) {
        //  System.out.println("key =" + listOrderedMap.get(i) + " , value=" + listOrderedMap.getValue(i));
        Comparator comp = ComparableComparator.getInstance();

        comp = ComparatorUtils.nullLowComparator(comp);  //允许null

        if ((Boolean) listOrderedMap.getValue(i) == false)
            comp = ComparatorUtils.reversedComparator(comp); //逆序

        Comparator cmp = new BeanComparator((String) listOrderedMap.get(i), comp);
        sortFields.add(cmp);
    }

    ComparatorChain multiSort = new ComparatorChain(sortFields);
    Collections.sort(list, multiSort);
}
 
Example #4
Source File: CreationParameters.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the parameters for the given table.
 * 
 * @param table The table
 * @return The parameters
 */
public Map getParametersFor(Table table)
{
    ListOrderedMap result       = new ListOrderedMap();
    Map            globalParams = (Map)_parametersPerTable.get(null);
    Map            tableParams  = (Map)_parametersPerTable.get(table.getQualifiedName());

    if (globalParams != null)
    {
        result.putAll(globalParams);
    }
    if (tableParams != null)
    {
        result.putAll(tableParams);
    }
    return result;
}
 
Example #5
Source File: JsonTools.java    From sso-oauth2 with Apache License 2.0 6 votes vote down vote up
/**
* 
* json转换map.
* <br>详细说明
* @param jsonStr json字符串
* @return
* @return Map<String,Object> 集合
* @throws
* @author slj
*/
public static Map<String, Object> parseJSON2Map(String jsonStr) {
	ListOrderedMap map = new ListOrderedMap();
	// System.out.println(jsonStr);
	// 最外层解析
	JSONObject json = JSONObject.fromObject(jsonStr);
	for (Object k : json.keySet()) {
		Object v = json.get(k);
		// 如果内层还是数组的话,继续解析
		if (v instanceof JSONArray) {
			List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
			Iterator<JSONObject> it = ((JSONArray) v).iterator();
			while (it.hasNext()) {
				JSONObject json2 = it.next();
				list.add(parseJSON2Map(json2.toString()));
			}
			map.put(k.toString(), list);
		} else {
			map.put(k.toString(), v);
		}
	}
	return map;
}
 
Example #6
Source File: AbstractMessageConverter.java    From elucidate-server with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected Map<String, Object> reorderJsonAttributes(Map<String, Object> jsonMap) {

    ListOrderedMap orderedJsonMap = new ListOrderedMap();
    orderedJsonMap.putAll(jsonMap);

    Object context = orderedJsonMap.get(JSONLDConstants.ATTRIBUTE_CONTEXT);
    if (context != null) {
        orderedJsonMap.remove(JSONLDConstants.ATTRIBUTE_CONTEXT);
        orderedJsonMap.put(0, JSONLDConstants.ATTRIBUTE_CONTEXT, context);
    }

    return orderedJsonMap;
}
 
Example #7
Source File: TableDisplayUtils.java    From beakerx with Apache License 2.0 5 votes vote down vote up
static List<Map<String, Object>> transformToIndex(Collection<Map<String, Object>> v, int columnIndex) {
  List<Map<String, Object>> result = new ArrayList<>();
  for (Map<String, Object> item : v) {
    ListOrderedMap listOrderedMap = new ListOrderedMap();
    listOrderedMap.putAll(item);
    Object key = listOrderedMap.get(columnIndex);
    Object value = listOrderedMap.getValue(columnIndex);
    listOrderedMap.remove(columnIndex);
    listOrderedMap.put(0, key, value);
    result.add(listOrderedMap);
  }
  return result;
}
 
Example #8
Source File: JdbcModelReader.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Determines the indices for the indicated table.
 * 
 * @param metaData  The database meta data
 * @param tableName The name of the table
 * @return The list of indices
 */
protected Collection readIndices(DatabaseMetaDataWrapper metaData, String tableName) throws SQLException
{
    Map       indices   = new ListOrderedMap();
    ResultSet indexData = null;

    try 
    {
        // GemStone changes BEGIN
        //indexData = metaData.getIndices(metaData.escapeForSearch(tableName), false, false);
      
        //The underlying DatabaseMetaData.getIndexInfo does not take the string pattern,
        //so do not need escape the _, see ticket 44911
        indexData = metaData.getIndices(tableName, false, false);
        // GemStone changes BEGIN
        while (indexData.next())
        {
            Map values = readColumns(indexData, getColumnsForIndex());

            readIndex(metaData, values, indices);
        }
    }
    finally
    {
        closeResultSet(indexData);
    }
    return indices.values();
}
 
Example #9
Source File: JdbcModelReader.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the foreign keys of the indicated table.
 *
 * @param metaData  The database meta data
 * @param tableName The name of the table from which to retrieve FK information
 * @return The foreign keys
 */
protected Collection readForeignKeys(DatabaseMetaDataWrapper metaData, String tableName) throws SQLException
{
    Map       fks    = new ListOrderedMap();
    ResultSet fkData = null;

    try
    {
        // GemStone changes BEGIN
        //fkData = metaData.getForeignKeys(metaData.escapeForSearch(tableName));
      
        //The underlying DatabaseMetaData.getImportedKeys does not take the string pattern,
        //so do not need escape the _, see ticket 44911
        fkData = metaData.getForeignKeys(tableName);
        // GemStone changes BEGIN
        
        while (fkData.next())
        {
            Map values = readColumns(fkData, getColumnsForFK());

            readForeignKey(metaData, values, fks);
        }
    }
    finally
    {
        closeResultSet(fkData);
    }
    return fks.values();
}
 
Example #10
Source File: FirebirdModelReader.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
protected Collection readIndices(DatabaseMetaDataWrapper metaData, String tableName) throws SQLException
{
    // Jaybird is not able to read indices when delimited identifiers are turned on,
    // so we gather the data manually using Firebird's system tables
    final String query =
        "SELECT a.RDB$INDEX_NAME INDEX_NAME, b.RDB$RELATION_NAME TABLE_NAME, b.RDB$UNIQUE_FLAG NON_UNIQUE, " +
        "a.RDB$FIELD_POSITION ORDINAL_POSITION, a.RDB$FIELD_NAME COLUMN_NAME, 3 INDEX_TYPE " +
        "FROM RDB$INDEX_SEGMENTS a, RDB$INDICES b WHERE a.RDB$INDEX_NAME=b.RDB$INDEX_NAME AND b.RDB$RELATION_NAME = ?";

    Map               indices = new ListOrderedMap();
    PreparedStatement stmt    = null;

    try
    {
        stmt = getConnection().prepareStatement(query);

        stmt.setString(1, getPlatform().isDelimitedIdentifierModeOn() ? tableName : tableName.toUpperCase());

        ResultSet indexData = stmt.executeQuery();

        while (indexData.next())
        {
            Map values = readColumns(indexData, getColumnsForIndex());

            // we have to reverse the meaning of the unique flag; also, null means false
            values.put("NON_UNIQUE", (values.get("NON_UNIQUE") == null) || Boolean.FALSE.equals(values.get("NON_UNIQUE")) ? Boolean.TRUE : Boolean.FALSE);
            // and trim the names
            values.put("INDEX_NAME",  ((String)values.get("INDEX_NAME")).trim());
            values.put("TABLE_NAME",  ((String)values.get("TABLE_NAME")).trim());
            values.put("COLUMN_NAME", ((String)values.get("COLUMN_NAME")).trim());
            readIndex(metaData, values, indices);
        }
    }
    finally
    {
        closeStatement(stmt);
    }
    return indices.values();
}
 
Example #11
Source File: FirebirdModelReader.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
protected Collection readIndices(DatabaseMetaDataWrapper metaData, String tableName) throws SQLException
{
    // Jaybird is not able to read indices when delimited identifiers are turned on,
    // so we gather the data manually using Firebird's system tables
    final String query =
        "SELECT a.RDB$INDEX_NAME INDEX_NAME, b.RDB$RELATION_NAME TABLE_NAME, b.RDB$UNIQUE_FLAG NON_UNIQUE, " +
        "a.RDB$FIELD_POSITION ORDINAL_POSITION, a.RDB$FIELD_NAME COLUMN_NAME, 3 INDEX_TYPE " +
        "FROM RDB$INDEX_SEGMENTS a, RDB$INDICES b WHERE a.RDB$INDEX_NAME=b.RDB$INDEX_NAME AND b.RDB$RELATION_NAME = ?";

    Map               indices = new ListOrderedMap();
    PreparedStatement stmt    = null;

    try
    {
        stmt = getConnection().prepareStatement(query);

        stmt.setString(1, getPlatform().isDelimitedIdentifierModeOn() ? tableName : tableName.toUpperCase());

        ResultSet indexData = stmt.executeQuery();

        while (indexData.next())
        {
            Map values = readColumns(indexData, getColumnsForIndex());

            // we have to reverse the meaning of the unique flag; also, null means false
            values.put("NON_UNIQUE", (values.get("NON_UNIQUE") == null) || Boolean.FALSE.equals(values.get("NON_UNIQUE")) ? Boolean.TRUE : Boolean.FALSE);
            // and trim the names
            values.put("INDEX_NAME",  ((String)values.get("INDEX_NAME")).trim());
            values.put("TABLE_NAME",  ((String)values.get("TABLE_NAME")).trim());
            values.put("COLUMN_NAME", ((String)values.get("COLUMN_NAME")).trim());
            readIndex(metaData, values, indices);
        }
    }
    finally
    {
        closeStatement(stmt);
    }
    return indices.values();
}
 
Example #12
Source File: MyBeanUtils.java    From spring-boot with Apache License 2.0 5 votes vote down vote up
private void testSortListBeans() {

        ListOrderedMap properties = new ListOrderedMap();
        // properties.put("name", true);
        properties.put("name", false);
        //properties.put("passwd", false);


        UserBean beanEntity1 = new UserBean();
        beanEntity1.setName("jiang");
        beanEntity1.setPasswd("jiang password");

        UserBean beanEntity2 = new UserBean();
        beanEntity2.setName("hui");
        beanEntity2.setPasswd("hui password");

        UserBean beanEntity3 = new UserBean();
        beanEntity3.setName("123");
        beanEntity3.setPasswd("123 password");

        ArrayList<UserBean> alist = new ArrayList();
        alist.add(beanEntity1);
        alist.add(beanEntity2);
        alist.add(beanEntity3);

        sortListBeans(alist, properties);

        for (UserBean bean : alist) {
            System.out.println("name =" + bean.getName() + ", passwd =" + bean.getPasswd());
        }

    }
 
Example #13
Source File: JdbcModelReader.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Determines the indices for the indicated table.
 * 
 * @param metaData  The database meta data
 * @param tableName The name of the table
 * @return The list of indices
 */
protected Collection readIndices(DatabaseMetaDataWrapper metaData, String tableName) throws SQLException
{
    Map       indices   = new ListOrderedMap();
    ResultSet indexData = null;

    try 
    {
        // GemStone changes BEGIN
        //indexData = metaData.getIndices(metaData.escapeForSearch(tableName), false, false);
      
        //The underlying DatabaseMetaData.getIndexInfo does not take the string pattern,
        //so do not need escape the _, see ticket 44911
        indexData = metaData.getIndices(tableName, false, false);
        // GemStone changes BEGIN
        while (indexData.next())
        {
            Map values = readColumns(indexData, getColumnsForIndex());

            readIndex(metaData, values, indices);
        }
    }
    finally
    {
        closeResultSet(indexData);
    }
    return indices.values();
}
 
Example #14
Source File: JdbcModelReader.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the foreign keys of the indicated table.
 *
 * @param metaData  The database meta data
 * @param tableName The name of the table from which to retrieve FK information
 * @return The foreign keys
 */
protected Collection readForeignKeys(DatabaseMetaDataWrapper metaData, String tableName) throws SQLException
{
    Map       fks    = new ListOrderedMap();
    ResultSet fkData = null;

    try
    {
        // GemStone changes BEGIN
        //fkData = metaData.getForeignKeys(metaData.escapeForSearch(tableName));
      
        //The underlying DatabaseMetaData.getImportedKeys does not take the string pattern,
        //so do not need escape the _, see ticket 44911
        fkData = metaData.getForeignKeys(tableName);
        // GemStone changes BEGIN
        
        while (fkData.next())
        {
            Map values = readColumns(fkData, getColumnsForFK());

            readForeignKey(metaData, values, fks);
        }
    }
    finally
    {
        closeResultSet(fkData);
    }
    return fks.values();
}
 
Example #15
Source File: SqlBuilder.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Writes a statement that copies the data from the source to the target table. Note
 * that this copies only those columns that are in both tables.
 * Database-specific implementations might redefine this method though it usually
 * suffices to redefine the {@link #writeCastExpression(Column, Column)} method.
 * 
 * @param sourceTable The source table
 * @param targetTable The target table
 */
protected void copyData(Table sourceTable, Table targetTable) throws IOException
{
    ListOrderedMap columns = new ListOrderedMap();

    for (int idx = 0; idx < sourceTable.getColumnCount(); idx++)
    {
        Column sourceColumn = sourceTable.getColumn(idx);
        Column targetColumn = targetTable.findColumn(sourceColumn.getName(),
                                                     getPlatform().isDelimitedIdentifierModeOn());


        if (targetColumn != null)
        {
            columns.put(sourceColumn, targetColumn);
        }
    }

    print("INSERT INTO ");
    printIdentifier(getTableName(targetTable));
    print(" (");
    for (Iterator columnIt = columns.keySet().iterator(); columnIt.hasNext();)
    {
        printIdentifier(getColumnName((Column)columnIt.next()));
        if (columnIt.hasNext())
        {
            print(",");
        }
    }
    print(") SELECT ");
    for (Iterator columnsIt = columns.entrySet().iterator(); columnsIt.hasNext();)
    {
        Map.Entry entry = (Map.Entry)columnsIt.next();

        writeCastExpression((Column)entry.getKey(),
                            (Column)entry.getValue());
        if (columnsIt.hasNext())
        {
            print(",");
        }
    }
    print(" FROM ");
    printIdentifier(getTableName(sourceTable));
    printEndOfStatement();
}
 
Example #16
Source File: MckoiModelReader.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
protected Table readTable(DatabaseMetaDataWrapper metaData, Map values) throws SQLException
{
    // Mckoi does not currently return unique indices in the metadata so we have to query
    // internal tables to get this info
    final String query =
        "SELECT uniqueColumns.column, uniqueColumns.seq_no, uniqueInfo.name" +
        " FROM SYS_INFO.sUSRUniqueColumns uniqueColumns, SYS_INFO.sUSRUniqueInfo uniqueInfo" +
        " WHERE uniqueColumns.un_id = uniqueInfo.id AND uniqueInfo.table = ?";
    final String queryWithSchema =
        query + " AND uniqueInfo.schema = ?";

    Table table = super.readTable(metaData, values);

    if (table != null)
    {
        Map               indices = new ListOrderedMap();
        PreparedStatement stmt    = null;

        try
        {
            stmt = getConnection().prepareStatement(table.getSchema() == null ? query : queryWithSchema);
            stmt.setString(1, table.getName());
            if (table.getSchema() != null)
            {
                stmt.setString(2, table.getSchema());
            }

            ResultSet  resultSet   = stmt.executeQuery();
            Map        indexValues = new HashMap();
        
            indexValues.put("NON_UNIQUE", Boolean.FALSE);
            while (resultSet.next())
            {
                indexValues.put("COLUMN_NAME",      resultSet.getString(1));
                indexValues.put("ORDINAL_POSITION", Short.valueOf(resultSet.getShort(2)));
                indexValues.put("INDEX_NAME",       resultSet.getString(3));
        
                readIndex(metaData, indexValues, indices);
            }
        }
        finally
        {
            closeStatement(stmt);
        }
    
        table.addIndices(indices.values());
    }
    
    return table;
}
 
Example #17
Source File: Oracle8ModelReader.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
    * {@inheritDoc}
    */
protected Collection readIndices(DatabaseMetaDataWrapper metaData, String tableName) throws SQLException
{
	// Oracle has a bug in the DatabaseMetaData#getIndexInfo method which fails when
	// delimited identifiers are being used
	// Therefore, we're rather accessing the user_indexes table which contains the same info
	// This also allows us to filter system-generated indices which are identified by either
       // having GENERATED='Y' in the query result, or by their index names being equal to the
       // name of the primary key of the table

	final String query =
	    "SELECT a.INDEX_NAME, a.INDEX_TYPE, a.UNIQUENESS, b.COLUMN_NAME, b.COLUMN_POSITION FROM USER_INDEXES a, USER_IND_COLUMNS b WHERE " +
	    "a.TABLE_NAME=? AND a.GENERATED=? AND a.TABLE_TYPE=? AND a.TABLE_NAME=b.TABLE_NAME AND a.INDEX_NAME=b.INDEX_NAME AND " +
	    "a.INDEX_NAME NOT IN (SELECT DISTINCT c.CONSTRAINT_NAME FROM USER_CONSTRAINTS c WHERE c.CONSTRAINT_TYPE=? AND c.TABLE_NAME=a.TABLE_NAME)";
	final String queryWithSchema =
	    query.substring(0, query.length() - 1) + " AND c.OWNER LIKE ?) AND a.TABLE_OWNER LIKE ?";

       Map               indices = new ListOrderedMap();
	PreparedStatement stmt    = null;

       try
       {
   		stmt = getConnection().prepareStatement(metaData.getSchemaPattern() == null ? query : queryWithSchema);
   		stmt.setString(1, getPlatform().isDelimitedIdentifierModeOn() ? tableName : tableName.toUpperCase());
   		stmt.setString(2, "N");
   		stmt.setString(3, "TABLE");
           stmt.setString(4, "P");
   		if (metaData.getSchemaPattern() != null)
   		{
   			stmt.setString(5, metaData.getSchemaPattern().toUpperCase());
               stmt.setString(6, metaData.getSchemaPattern().toUpperCase());
   		}

   		ResultSet rs     = stmt.executeQuery();
       	Map       values = new HashMap();

       	while (rs.next())
       	{
       		values.put("INDEX_NAME",       rs.getString(1));
       		values.put("INDEX_TYPE",       Short.valueOf(DatabaseMetaData.tableIndexOther));
       		values.put("NON_UNIQUE",       "UNIQUE".equalsIgnoreCase(rs.getString(3)) ? Boolean.FALSE : Boolean.TRUE);
       		values.put("COLUMN_NAME",      rs.getString(4));
       		values.put("ORDINAL_POSITION", Short.valueOf(rs.getShort(5)));

       		readIndex(metaData, values, indices);
       	}
       }
       finally
       {
           closeStatement(stmt);
       }
	return indices.values();
}
 
Example #18
Source File: Oracle8ModelReader.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
    * {@inheritDoc}
    */
protected Collection readIndices(DatabaseMetaDataWrapper metaData, String tableName) throws SQLException
{
	// Oracle has a bug in the DatabaseMetaData#getIndexInfo method which fails when
	// delimited identifiers are being used
	// Therefore, we're rather accessing the user_indexes table which contains the same info
	// This also allows us to filter system-generated indices which are identified by either
       // having GENERATED='Y' in the query result, or by their index names being equal to the
       // name of the primary key of the table

	final String query =
	    "SELECT a.INDEX_NAME, a.INDEX_TYPE, a.UNIQUENESS, b.COLUMN_NAME, b.COLUMN_POSITION FROM USER_INDEXES a, USER_IND_COLUMNS b WHERE " +
	    "a.TABLE_NAME=? AND a.GENERATED=? AND a.TABLE_TYPE=? AND a.TABLE_NAME=b.TABLE_NAME AND a.INDEX_NAME=b.INDEX_NAME AND " +
	    "a.INDEX_NAME NOT IN (SELECT DISTINCT c.CONSTRAINT_NAME FROM USER_CONSTRAINTS c WHERE c.CONSTRAINT_TYPE=? AND c.TABLE_NAME=a.TABLE_NAME)";
	final String queryWithSchema =
	    query.substring(0, query.length() - 1) + " AND c.OWNER LIKE ?) AND a.TABLE_OWNER LIKE ?";

       Map               indices = new ListOrderedMap();
	PreparedStatement stmt    = null;

       try
       {
   		stmt = getConnection().prepareStatement(metaData.getSchemaPattern() == null ? query : queryWithSchema);
   		stmt.setString(1, getPlatform().isDelimitedIdentifierModeOn() ? tableName : tableName.toUpperCase());
   		stmt.setString(2, "N");
   		stmt.setString(3, "TABLE");
           stmt.setString(4, "P");
   		if (metaData.getSchemaPattern() != null)
   		{
   			stmt.setString(5, metaData.getSchemaPattern().toUpperCase());
               stmt.setString(6, metaData.getSchemaPattern().toUpperCase());
   		}

   		ResultSet rs     = stmt.executeQuery();
       	Map       values = new HashMap();

       	while (rs.next())
       	{
       		values.put("INDEX_NAME",       rs.getString(1));
       		values.put("INDEX_TYPE",       Short.valueOf(DatabaseMetaData.tableIndexOther));
       		values.put("NON_UNIQUE",       "UNIQUE".equalsIgnoreCase(rs.getString(3)) ? Boolean.FALSE : Boolean.TRUE);
       		values.put("COLUMN_NAME",      rs.getString(4));
       		values.put("ORDINAL_POSITION", Short.valueOf(rs.getShort(5)));

       		readIndex(metaData, values, indices);
       	}
       }
       finally
       {
           closeStatement(stmt);
       }
	return indices.values();
}
 
Example #19
Source File: MckoiModelReader.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
protected Table readTable(DatabaseMetaDataWrapper metaData, Map values) throws SQLException
{
    // Mckoi does not currently return unique indices in the metadata so we have to query
    // internal tables to get this info
    final String query =
        "SELECT uniqueColumns.column, uniqueColumns.seq_no, uniqueInfo.name" +
        " FROM SYS_INFO.sUSRUniqueColumns uniqueColumns, SYS_INFO.sUSRUniqueInfo uniqueInfo" +
        " WHERE uniqueColumns.un_id = uniqueInfo.id AND uniqueInfo.table = ?";
    final String queryWithSchema =
        query + " AND uniqueInfo.schema = ?";

    Table table = super.readTable(metaData, values);

    if (table != null)
    {
        Map               indices = new ListOrderedMap();
        PreparedStatement stmt    = null;

        try
        {
            stmt = getConnection().prepareStatement(table.getSchema() == null ? query : queryWithSchema);
            stmt.setString(1, table.getName());
            if (table.getSchema() != null)
            {
                stmt.setString(2, table.getSchema());
            }

            ResultSet  resultSet   = stmt.executeQuery();
            Map        indexValues = new HashMap();
        
            indexValues.put("NON_UNIQUE", Boolean.FALSE);
            while (resultSet.next())
            {
                indexValues.put("COLUMN_NAME",      resultSet.getString(1));
                indexValues.put("ORDINAL_POSITION", Short.valueOf(resultSet.getShort(2)));
                indexValues.put("INDEX_NAME",       resultSet.getString(3));
        
                readIndex(metaData, indexValues, indices);
            }
        }
        finally
        {
            closeStatement(stmt);
        }
    
        table.addIndices(indices.values());
    }
    
    return table;
}
 
Example #20
Source File: SqlBuilder.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Writes a statement that copies the data from the source to the target table. Note
 * that this copies only those columns that are in both tables.
 * Database-specific implementations might redefine this method though it usually
 * suffices to redefine the {@link #writeCastExpression(Column, Column)} method.
 * 
 * @param sourceTable The source table
 * @param targetTable The target table
 */
protected void copyData(Table sourceTable, Table targetTable) throws IOException
{
    ListOrderedMap columns = new ListOrderedMap();

    for (int idx = 0; idx < sourceTable.getColumnCount(); idx++)
    {
        Column sourceColumn = sourceTable.getColumn(idx);
        Column targetColumn = targetTable.findColumn(sourceColumn.getName(),
                                                     getPlatform().isDelimitedIdentifierModeOn());


        if (targetColumn != null)
        {
            columns.put(sourceColumn, targetColumn);
        }
    }

    print("INSERT INTO ");
    printIdentifier(getTableName(targetTable));
    print(" (");
    for (Iterator columnIt = columns.keySet().iterator(); columnIt.hasNext();)
    {
        printIdentifier(getColumnName((Column)columnIt.next()));
        if (columnIt.hasNext())
        {
            print(",");
        }
    }
    print(") SELECT ");
    for (Iterator columnsIt = columns.entrySet().iterator(); columnsIt.hasNext();)
    {
        Map.Entry entry = (Map.Entry)columnsIt.next();

        writeCastExpression((Column)entry.getKey(),
                            (Column)entry.getValue());
        if (columnsIt.hasNext())
        {
            print(",");
        }
    }
    print(" FROM ");
    printIdentifier(getTableName(sourceTable));
    printEndOfStatement();
}
 
Example #21
Source File: MapUtils.java    From Penetration_Testing_POC with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a map that maintains the order of keys that are added
 * backed by the given map.
 * <p>
 * If a key is added twice, the order is determined by the first add.
 * The order is observed through the keySet, values and entrySet.
 *
 * @param map  the map to order, must not be null
 * @return an ordered map backed by the given map
 * @throws IllegalArgumentException  if the Map is null
 */
public static Map orderedMap(Map map) {
    return ListOrderedMap.decorate(map);
}