Example usage for org.apache.commons.lang3.tuple ImmutablePair of

List of usage examples for org.apache.commons.lang3.tuple ImmutablePair of

Introduction

In this page you can find the example usage for org.apache.commons.lang3.tuple ImmutablePair of.

Prototype

public static <L, R> ImmutablePair<L, R> of(final L left, final R right) 

Source Link

Document

Obtains an immutable pair of from two objects inferring the generic types.

This factory allows the pair to be created using inference to obtain the generic types.

Usage

From source file:org.verdictdb.coordinator.ExecutionContext.java

private Pair<BaseTable, BaseTable> getTablePairForDropScramble(String query) {
    VerdictSQLParser parser = NonValidatingSQLParser.parserOf(query);
    VerdictSQLParserBaseVisitor<Pair<BaseTable, BaseTable>> visitor = new VerdictSQLParserBaseVisitor<Pair<BaseTable, BaseTable>>() {
        @Override/*w ww.j ava  2  s  .com*/
        public Pair<BaseTable, BaseTable> visitDrop_scramble_statement(
                VerdictSQLParser.Drop_scramble_statementContext ctx) {
            RelationGen g = new RelationGen();
            BaseTable originalTable = (ctx.original_table != null) ? (BaseTable) g.visit(ctx.original_table)
                    : null;
            BaseTable scrambleTable = (BaseTable) g.visit(ctx.scrambled_table);
            return ImmutablePair.of(originalTable, scrambleTable);
        }
    };
    return visitor.visit(parser.drop_scramble_statement());
}

From source file:org.verdictdb.jdbc41.VerdictConnectionTest.java

private void setupMysql() throws SQLException {
    String mysqlConnectionString = String.format("jdbc:mysql://%s?autoReconnect=true&useSSL=false", MYSQL_HOST);
    String vcMysqlConnectionString = String.format("jdbc:verdict:mysql://%s?autoReconnect=true&useSSL=false",
            MYSQL_HOST);//  w w w  . j  a  v a2 s  . c om
    Connection conn = DriverManager.getConnection(mysqlConnectionString, MYSQL_USER, MYSQL_PASSWORD);
    Connection vc = DriverManager.getConnection(vcMysqlConnectionString, MYSQL_USER, MYSQL_PASSWORD);
    connectionPair = ImmutablePair.of(conn, vc);
}

From source file:org.verdictdb.jdbc41.VerdictConnectionTest.java

private void setupImpala() throws SQLException {
    String connectionString = String.format("jdbc:impala://%s", IMPALA_HOST);
    String impalaMetaSchema = "verdictdbmeta_impala";
    String vcConnectionString = String.format("jdbc:verdict:impala://%s;verdictdbmetaschema=%s", IMPALA_HOST,
            impalaMetaSchema);// w ww .j  a  va2 s  .c om
    Connection conn = DriverManager.getConnection(connectionString, IMPALA_USER, IMPALA_PASSWORD);
    Connection vc = DriverManager.getConnection(vcConnectionString, IMPALA_USER, IMPALA_PASSWORD);
    connectionPair = ImmutablePair.of(conn, vc);
}

From source file:org.verdictdb.jdbc41.VerdictConnectionTest.java

private void setupRedshift() throws SQLException {
    String connectionString = String.format("jdbc:redshift://%s/%s", REDSHIFT_HOST, REDSHIFT_DATABASE);
    String vcConnectionString = String.format("jdbc:verdict:redshift://%s/%s;verdictdbmetaschema=%s",
            REDSHIFT_HOST, REDSHIFT_DATABASE, SCHEMA_NAME);
    Connection conn = DriverManager.getConnection(connectionString, REDSHIFT_USER, REDSHIFT_PASSWORD);
    Connection vc = DriverManager.getConnection(vcConnectionString, REDSHIFT_USER, REDSHIFT_PASSWORD);
    connectionPair = ImmutablePair.of(conn, vc);
}

From source file:org.verdictdb.jdbc41.VerdictConnectionTest.java

private void setupPostgresql() throws SQLException {
    String connectionString = String.format("jdbc:postgresql://%s/%s", POSTGRES_HOST, POSTGRES_DATABASE);
    String vcConnectionString = String.format("jdbc:verdict:postgresql://%s/%s", POSTGRES_HOST,
            POSTGRES_DATABASE);/*from   w w w  .j a  va2  s . co  m*/
    Connection conn = DriverManager.getConnection(connectionString, POSTGRES_USER, POSTGRES_PASSWORD);
    Connection vc = DriverManager.getConnection(vcConnectionString, POSTGRES_USER, POSTGRES_PASSWORD);
    connectionPair = ImmutablePair.of(conn, vc);
}

From source file:org.verdictdb.metastore.ScrambleMetaStore.java

/**
 * Return scramble meta for an existing scramble
 *
 * @param schema schema for an existing scramble
 * @param table table name for an existing scramble
 * @return ScrambleMeta object for an existing scramble
 *///from   w  ww . j  a va2  s  .co  m
public ScrambleMeta retrieveExistingScramble(String schema, String table) {

    try {
        String storeTable = METASTORE_TABLE_NAME;

        List<String> existingSchemas = conn.getSchemas();
        if (!existingSchemas.contains(storeSchema)) {
            return null;
        }

        List<String> existingTables = conn.getTables(storeSchema);
        if (!existingTables.contains(storeTable)) {
            return null;
        }

        // now ready to retrieve
        String tableAlias = "t";
        SelectQuery query = SelectQuery.create(
                Arrays.<SelectItem>asList(new BaseColumn(tableAlias, ORIGINAL_SCHEMA_COLUMN),
                        new BaseColumn(tableAlias, ORIGINAL_TABLE_COLUMN),
                        new BaseColumn(tableAlias, SCRAMBLE_SCHEMA_COLUMN),
                        new BaseColumn(tableAlias, SCRAMBLE_TABLE_COLUMN),
                        new BaseColumn(tableAlias, ADDED_AT_COLUMN), new BaseColumn(tableAlias, DATA_COLUMN)),
                new BaseTable(storeSchema, storeTable, tableAlias));
        query.addOrderby(new OrderbyAttribute(ADDED_AT_COLUMN, "desc"));
        String sql = QueryToSql.convert(conn.getSyntax(), query);
        DbmsQueryResult result = conn.execute(sql);

        while (result.next()) {
            String scrambleSchema = result.getString(2);
            String scrambleTable = result.getString(3);
            Pair<String, String> pair = ImmutablePair.of(scrambleSchema, scrambleTable);
            String jsonString = result.getString(5);
            if (scrambleSchema.equals(schema) && scrambleTable.equals(table)) {
                return jsonString.toUpperCase().equals(DELETED) ? null
                        : ScrambleMeta.fromJsonString(jsonString);
            }
        }
    } catch (VerdictDBException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.verdictdb.metastore.ScrambleMetaStore.java

/**
 * Static version of retrieve()//from   ww w.  ja  va  2 s.  co m
 *
 * @return a set of scramble meta
 */
public static ScrambleMetaSet retrieve(DbmsConnection conn, String storeSchema) {
    ScrambleMetaSet retrieved = new ScrambleMetaSet();

    try {
        String storeTable = METASTORE_TABLE_NAME;

        List<String> existingSchemas = conn.getSchemas();
        if (existingSchemas.contains(storeSchema) == false) {
            return new ScrambleMetaSet();
        }

        List<String> existingTables = conn.getTables(storeSchema);
        if (existingTables.contains(storeTable) == false) {
            return new ScrambleMetaSet();
        }

        // now ready to retrieve
        String tableAlias = "t";
        SelectQuery query = SelectQuery.create(
                Arrays.<SelectItem>asList(new BaseColumn(tableAlias, ORIGINAL_SCHEMA_COLUMN),
                        new BaseColumn(tableAlias, ORIGINAL_TABLE_COLUMN),
                        new BaseColumn(tableAlias, SCRAMBLE_SCHEMA_COLUMN),
                        new BaseColumn(tableAlias, SCRAMBLE_TABLE_COLUMN),
                        new BaseColumn(tableAlias, ADDED_AT_COLUMN), new BaseColumn(tableAlias, DATA_COLUMN)),
                new BaseTable(storeSchema, storeTable, tableAlias));
        query.addOrderby(new OrderbyAttribute(ADDED_AT_COLUMN, "desc"));
        String sql = QueryToSql.convert(conn.getSyntax(), query);
        DbmsQueryResult result = conn.execute(sql);

        Set<Pair<String, String>> deletedSet = new HashSet<>();
        Set<Pair<String, String>> addedSet = new HashSet<>();

        while (result.next()) {
            //        String originalSchema = result.getString(0);
            //        String originalTable = result.getString(1);
            String scrambleSchema = result.getString(2);
            String scrambleTable = result.getString(3);
            //        BaseTable original = new BaseTable(originalSchema, originalTable);
            //        BaseTable scramble = new BaseTable(scrambleSchema, scrambleTable);
            Pair<String, String> pair = ImmutablePair.of(scrambleSchema, scrambleTable);
            String timestamp = result.getString(4);
            //        System.out.println("added time: " + timestamp);
            String jsonString = result.getString(5);
            if (jsonString.toUpperCase().equals(DELETED)) {
                deletedSet.add(pair);
            }
            // skip the scrambled table has been deleted
            if (deletedSet.contains(pair)) {
                continue;
            }
            if (addedSet.contains(pair)) {
                continue;
            }
            ScrambleMeta meta = ScrambleMeta.fromJsonString(jsonString);
            retrieved.addScrambleMeta(meta);

            addedSet.add(pair);
        }
    } catch (VerdictDBException e) {
        e.printStackTrace();
    }

    return retrieved;
}

From source file:org.verdictdb.sqlreader.RelationStandardizer.java

private Pair<List<String>, AbstractRelation> setupTableSource(AbstractRelation table)
        throws VerdictDBDbmsException {
    // in order to prevent informal table alias, we replace all table alias
    if (!(table instanceof JoinTable)) {
        if (table.getAliasName().isPresent()) {
            String alias = table.getAliasName().get();
            alias = alias.replace("`", "");
            alias = alias.replace("\"", "");
            oldTableAliasMap.put(alias, verdictTableAliasPrefix + itemID);
        }//w ww  .j  av a 2s .co m
        table.setAliasName(verdictTableAliasPrefix + itemID++);
    }
    // if (!table.getAliasName().isPresent() && !(table instanceof JoinTable)) {
    //  table.setAliasName(verdictTableAliasPrefix + itemID++);
    // }
    if (table instanceof BaseTable) {
        BaseTable bt = (BaseTable) table;
        List<String> colName = new ArrayList<>();
        if (bt.getSchemaName() == null) {
            bt.setSchemaName(meta.getDefaultSchema());
        }
        List<Pair<String, String>> cols = meta.getColumns(bt.getSchemaName(), bt.getTableName());
        for (Pair<String, String> c : cols) {
            colNameAndTableAlias.put(c.getKey(), bt.getAliasName().get());
            colName.add(c.getKey());
        }
        tableInfoAndAlias.put(ImmutablePair.of(bt.getSchemaName(), bt.getTableName()),
                table.getAliasName().get());
        return new ImmutablePair<>(colName, table);

    } else if (table instanceof JoinTable) {
        List<String> joinColName = new ArrayList<>();
        for (int i = 0; i < ((JoinTable) table).getJoinList().size(); i++) {
            Pair<List<String>, AbstractRelation> result = setupTableSource(
                    ((JoinTable) table).getJoinList().get(i));
            ((JoinTable) table).getJoinList().set(i, result.getValue());
            joinColName.addAll(result.getKey());
            if (i != 0) {
                ((JoinTable) table).getCondition().set(i - 1,
                        replaceFilter(((JoinTable) table).getCondition().get(i - 1)));
            }
        }
        return new ImmutablePair<>(joinColName, table);

    } else if (table instanceof SelectQuery) {
        List<String> colName = new ArrayList<>();
        RelationStandardizer g = new RelationStandardizer(meta, syntax);
        g.oldTableAliasMap.putAll(oldTableAliasMap);
        g.setTableInfoAndAlias(tableInfoAndAlias);
        g.setColNameAndTableAlias(colNameAndTableAlias);
        g.setColNameAndColAlias(colNameAndColAlias);
        String aliasName = table.getAliasName().get();
        table = g.standardize((SelectQuery) table);
        table.setAliasName(aliasName);

        // Invariant: Only Aliased Column or Asterisk Column should appear in the subquery
        for (SelectItem sel : ((SelectQuery) table).getSelectList()) {
            if (sel instanceof AliasedColumn) {
                // If the aliased name of the column is replaced by ourselves, we should remember the
                // column name
                if (((AliasedColumn) sel).getColumn() instanceof BaseColumn
                        && ((AliasedColumn) sel).getAliasName().matches("^vc[0-9]+$")) {
                    colNameAndTableAlias.put(((BaseColumn) ((AliasedColumn) sel).getColumn()).getColumnName(),
                            table.getAliasName().get());
                    colNameAndTempColAlias.put(((BaseColumn) ((AliasedColumn) sel).getColumn()).getColumnName(),
                            ((AliasedColumn) sel).getAliasName());
                } else
                    colNameAndTableAlias.put(((AliasedColumn) sel).getAliasName(), table.getAliasName().get());
                colName.add(((AliasedColumn) sel).getAliasName());

            } else if (sel instanceof AsteriskColumn) {
                // put all the columns in the fromlist of subquery to the colNameAndTableAlias
                HashMap<String, String> subqueryColumnList = g.getColNameAndTableAlias();
                for (String col : subqueryColumnList.keySet()) {
                    colNameAndTableAlias.put(col, table.getAliasName().get());
                    colName.add(col);
                }
            }
        }
        return new ImmutablePair<>(colName, table);
    }
    return null;
}

From source file:org.wso2.carbon.identity.provider.internal.dao.IdentityProviderDAO.java

/**
 * Lists the ID and name of all identity providers.
 *
 * @return/*from w  ww  . j  av a  2  s. c  om*/
 * @throws IdentityProviderException
 */
public List<Pair<Integer, String>> listAllIdentityProviders() throws IdentityProviderException {

    final String GET_ALL_IDP_SQL = "SELECT ID, NAME FROM IDP";

    List<Pair<Integer, String>> idpList = null;
    try {
        idpList = this.jdbcTemplate.executeQuery(GET_ALL_IDP_SQL,
                (resultSet, rowNumber) -> ImmutablePair.of(resultSet.getInt(1), resultSet.getString(2)));
    } catch (DataAccessException e) {
        throw new IdentityProviderException("Error occurred in listing all the Identity providers ", e);
    }

    return idpList;
}

From source file:org.wso2.carbon.identity.provider.internal.dao.IdentityProviderDAO.java

/**
 * Lists the ID and name of all identity providers.
 *
 * @return list of Pair of {ID, Name} of identity provider
 * @throws IdentityProviderException/*from  ww  w. ja  va2 s  .  co m*/
 */
public List<Pair<Integer, String>> listEnabledIdentityProviders() throws IdentityProviderException {

    final String GET_ALL_IDP_SQL = "SELECT ID, NAME FROM IDP WHERE IS_ENABLED=?";

    List<Pair<Integer, String>> idpList = null;
    try {
        idpList = this.jdbcTemplate.executeQuery(GET_ALL_IDP_SQL,
                (resultSet, rowNumber) -> ImmutablePair.of(resultSet.getInt(1), resultSet.getString(2)),
                (preparedStatement -> preparedStatement.setBoolean(1, true)));
    } catch (DataAccessException e) {
        throw new IdentityProviderException("Error occurred in listing 'Enabled' the Identity providers ", e);
    }

    return idpList;
}