Java Code Examples for org.eclipse.collections.impl.tuple.Tuples#pair()

The following examples show how to use org.eclipse.collections.impl.tuple.Tuples#pair() . 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: JdbcHelper.java    From obevo with Apache License 2.0 6 votes vote down vote up
private Pair<Statement, ResultSet> queryAndLeaveStatementOpenInternal(Connection conn, int retryCount, String sql) {
    Statement statement = null;
    try {
        statement = conn.createStatement();
        if (LOG.isDebugEnabled()) {
            LOG.debug("Executing query on {}: {}", displayConnection(conn), sql);
        }
        return Tuples.pair(statement, statement.executeQuery(sql));
    } catch (SQLException e) {
        DbUtils.closeQuietly(statement);  // on an exception, close the existing statement (on success, we'd leave it open)
        DataAccessException dataAccessException = new DataAccessException(e);
        boolean retry = this.jdbcHandler.handleException(this, conn, retryCount, dataAccessException);
        if (retry) {
            return this.queryAndLeaveStatementOpenInternal(conn, retryCount + 1, sql);
        } else {
            throw dataAccessException;
        }
    }
}
 
Example 2
Source File: Main.java    From obevo with Apache License 2.0 6 votes vote down vote up
private Pair<String, Procedure<String[]>> getDeployCommand(String[] args, Runnable exitFailureMethod) {
    if (args.length == 0) {
        usage();
        exitFailureMethod.run();
    }

    Procedure<String[]> command = commandMap.get(args[0]);
    if (command == null) {
        System.out.println("No command w/ name " + args[0] + " has been defined in this distribution: " + commandMap.keysView().makeString("[", ", ", "]"));
        System.out.println("See the usage for more details");
        usage();
        exitFailureMethod.run();
    }

    return Tuples.pair(args[0], command);
}
 
Example 3
Source File: PostgreSqlFunctionChangeTypeBehavior.java    From obevo with Apache License 2.0 6 votes vote down vote up
/**
 * Functions need to be referred by their signatures for drops and grants in postgresql
 * For functions query info:
 * https://www.postgresql.org/docs/9.5/static/functions-info.html
 * https://www.postgresql.org/docs/9.5/static/catalog-pg-proc.html
 * https://www.postgresql.org/docs/9.5/static/catalog-pg-namespace.html
 */
@Override
protected Pair<Boolean, RichIterable<String>> getQualifiedObjectNames(Connection conn, PhysicalSchema physicalSchema, String objectName) {
    String schemaName = getDbPlatform().convertDbObjectName().valueOf(physicalSchema.getPhysicalName());
    String functionNameWithCase = getDbPlatform().convertDbObjectName().valueOf(objectName);

    String sql = "select format('%s.%s(%s)',n.nspname, p.proname, pg_get_function_identity_arguments(p.oid)) " +
            "as functionname\n" +
            "FROM   pg_proc p\n" +
            "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n" +
            "WHERE n.nspname = '" + schemaName + "' and p.proname = '" + functionNameWithCase + "'";

    List<Map<String, Object>> funcNameResults = getSqlExecutor().getJdbcTemplate().queryForList(conn, sql);

    MutableList<String> names = Lists.mutable.empty();
    for (Map<String, Object> funcNameResult : funcNameResults) {
        names.add((String) funcNameResult.get("functionname"));
    }

    return Tuples.<Boolean, RichIterable<String>>pair(false, names);
}
 
Example 4
Source File: Db2SqlExecutor.java    From obevo with Apache License 2.0 6 votes vote down vote up
/**
 * Finds the table name from SQL Exception. Based on the documentation as defined at
 * http://publib.boulder.ibm.com/infocenter/db2luw/v8/index.jsp?topic=/com.ibm.db2.udb.doc/ad/tjvjcerr.htm
 *
 * @param exception An instance of SQL Exception
 * TODO handle the hardcoding of these errorCodes a little bit better
 * @return The table name from SQL Exception
 */
Pair<PhysicalSchema, String> findTableNameFromException(Exception exception, int errorCode) {
    String sqlErrorMC = exception.getMessage();

    Matcher matcher;
    switch (errorCode) {
    case -20054:
        matcher = PATTERN_20054.matcher(sqlErrorMC);
        break;
    case -668:
        matcher = PATTERN_668.matcher(sqlErrorMC);
        break;
    default:
        throw new IllegalArgumentException("Unhandled error code for reorg message parsing: " + errorCode);
    }

    String schemaName;
    String tableName;
    if (matcher.find()) {
        schemaName = matcher.group(1);
        tableName = matcher.group(2);
    } else {
        throw new IllegalArgumentException("Could not parse the schema/table names for error code " + errorCode + " and message: " + sqlErrorMC);
    }
    return Tuples.pair(PhysicalSchema.parseFromString(schemaName), tableName);
}
 
Example 5
Source File: ForEachPatternUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void whenInstantiateAndChangeValues_thenCorrect() {
    Pair<Integer, String> pair1 = Tuples.pair(1, "One");
    Pair<Integer, String> pair2 = Tuples.pair(2, "Two");
    Pair<Integer, String> pair3 = Tuples.pair(3, "Three");

    UnifiedMap<Integer, String> map = UnifiedMap.newMapWith(pair1, pair2, pair3);

    for (int i = 0; i < map.size(); i++) {
        map.put(i + 1, "New Value");
    }

    for (int i = 0; i < map.size(); i++) {
        Assert.assertEquals("New Value", map.get(i + 1));
    }
}
 
Example 6
Source File: AquaRevengMain.java    From obevo with Apache License 2.0 5 votes vote down vote up
private static Pair<Integer, String> getStartIndex(String str, Pattern p) {
    Matcher m = p.matcher(str);
    while (m.find()) {
        String objectName = m.groupCount() > 0 ? m.group(1) : null;  // by convention, the second group collected has the name
        return Tuples.pair(m.start(), objectName);
    }
    return Tuples.pair(Integer.MAX_VALUE, null);
}
 
Example 7
Source File: Db2RoutineChangeTypeBehavior.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Override
public Pair<Boolean, RichIterable<String>> getQualifiedObjectNames(Connection conn, PhysicalSchema physicalSchema, final String objectName) {
    ImmutableCollection<String> specificNames = getDbMetadataManager().getRoutineInfo(physicalSchema, objectName)
            .collect(DaRoutine.TO_SPECIFIC_NAME);

    return Tuples.<Boolean, RichIterable<String>>pair(true, specificNames);
}
 
Example 8
Source File: IqOdbcDataSourceFactory.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Override
protected Pair<String, String> getUrl(DbEnvironment env, String schema, Credential credential) {
    String url = "jdbc:sqlanywhere:" +
            "ServerName=" + env.getDbServer() + "" +
            ";LINKS=TCPIP{host=" + env.getDbHost() + ":" + env.getDbPort() + "}" +
            "";
    return Tuples.pair(url, credential.getPassword());
}
 
Example 9
Source File: IqOldOdbcDataSourceFactory.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Override
protected Pair<String, String> getUrl(DbEnvironment env, String schema, Credential credential) {
    String url = "jdbc:ianywhere:" +
            "ServerName=" + env.getDbServer() + "" +
            ";LINKS=TCPIP{host=" + env.getDbHost() + ":" + env.getDbPort() + "}" +
            ";driver=" + getIanywhereDriverProperty(env.getIanywhereDriverProperty()) +
            "";
    return Tuples.pair(url, credential.getPassword());
}
 
Example 10
Source File: AbstractReveng.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Override
public Pair<String, RevengPatternOutput> valueOf(String sqlSnippet) {
    for (RevengPattern revengPattern : revengPatterns) {
        RevengPatternOutput patternMatch = revengPattern.evaluate(sqlSnippet);
        if (patternMatch != null) {
            return Tuples.pair(sqlSnippet, patternMatch);
        }
    }
    return Tuples.pair(sqlSnippet, null);
}
 
Example 11
Source File: ExercisesCrud.java    From reladomo-kata with Apache License 2.0 5 votes vote down vote up
@Test
public void testQ8()
{
    int sizeBefore = CustomerFinder.findMany(CustomerFinder.all()).size();
    Pair<String, String> customer1 = Tuples.pair("John Courage", "UK");
    Pair<String, String> customer2 = Tuples.pair("Tony Jackson", "USA");
    this.addNewCustomers(FastList.newListWith(customer1, customer2));
    int sizeAfter = CustomerFinder.findMany(CustomerFinder.all()).size();
    Assert.assertEquals(2, sizeAfter - sizeBefore);

    Assert.assertNotNull(CustomerFinder.findOne(CustomerFinder.name().eq("John Courage")));
    Assert.assertNotNull(CustomerFinder.findMany(CustomerFinder.name().eq("Tony Jackson")));
}
 
Example 12
Source File: ZipWithIndexUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Before
public void setup() {
    Pair<String, Integer> pair1 = Tuples.pair("Porsche", 0);
    Pair<String, Integer> pair2 = Tuples.pair("Volvo", 1);
    Pair<String, Integer> pair3 = Tuples.pair("Toyota", 2);
    expectedPairs = Lists.mutable.of(pair1, pair2, pair3);
}
 
Example 13
Source File: ZipUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Before
public void setup() {
    Pair<String, String> pair1 = Tuples.pair("1", "Porsche");
    Pair<String, String> pair2 = Tuples.pair("2", "Volvo");
    Pair<String, String> pair3 = Tuples.pair("3", "Toyota");
    expectedPairs = Lists.mutable.of(pair1, pair2, pair3);
}
 
Example 14
Source File: IqJconnDataSourceFactory.java    From obevo with Apache License 2.0 4 votes vote down vote up
@Override
protected Pair<String, String> getUrl(DbEnvironment env, String schema, Credential credential) {
    String url = String.format("jdbc:sybase:Tds:%1$s:%2$s", env.getDbHost(), env.getDbPort());
    return Tuples.pair(url, null);
}
 
Example 15
Source File: TextMarkupDocumentReader.java    From obevo with Apache License 2.0 4 votes vote down vote up
Pair<ImmutableMap<String, String>, ImmutableSet<String>> parseAttrsAndToggles(String line) {
    MutableMap<String, String> attrs = Maps.mutable.empty();
    MutableSet<String> toggles = Sets.mutable.empty();

    if (!legacyMode) {
        List<Token> tokens = TextMarkupParser.parseTokens(line);
        Token curToken = !tokens.isEmpty() ? tokens.get(0) : null;
        while (curToken != null && curToken.kind != TextMarkupLineSyntaxParserConstants.EOF) {
            switch (curToken.kind) {
            case TextMarkupLineSyntaxParserConstants.WHITESPACE:
                // skip whitespace if encountered
                break;
            case TextMarkupLineSyntaxParserConstants.QUOTED_LITERAL:
            case TextMarkupLineSyntaxParserConstants.STRING_LITERAL:
                // let's check if this is a toggle or an attribute
                if (curToken.next.kind == TextMarkupLineSyntaxParserConstants.ASSIGN) {
                    Token keyToken = curToken;
                    curToken = curToken.next;  // to ASSIGN
                    curToken = curToken.next;  // to the following token
                    switch (curToken.kind) {
                    case TextMarkupLineSyntaxParserConstants.QUOTED_LITERAL:
                    case TextMarkupLineSyntaxParserConstants.STRING_LITERAL:
                        // in this case, we have an attribute value
                        String value = curToken.image;
                        if (value.charAt(0) == '"' && value.charAt(value.length() - 1) == '"') {
                            value = curToken.image.substring(1, curToken.image.length() - 1);
                        }
                        value = value.replaceAll("\\\\\"", "\"");
                        attrs.put(keyToken.image, value);
                        break;
                    case TextMarkupLineSyntaxParserConstants.WHITESPACE:
                    case TextMarkupLineSyntaxParserConstants.EOF:
                        // in this case, we will assume a blank value
                        attrs.put(keyToken.image, "");
                        break;
                    case TextMarkupLineSyntaxParserConstants.ASSIGN:
                    default:
                        throw new IllegalStateException("Not allowed here");
                    }
                } else {
                    toggles.add(curToken.image);
                }
                break;
            case TextMarkupLineSyntaxParserConstants.ASSIGN:
                toggles.add(curToken.image);
                break;
            case TextMarkupLineSyntaxParserConstants.EOF:
            default:
                throw new IllegalStateException("Should not arise");
            }

            curToken = curToken.next;
        }
    } else {
        // keeping this mode for backwards-compatibility until we can guarantee all clients are fine without it
        // This way cannot handle spaces in quotes
        String[] args = StringUtils.splitByWholeSeparator(line, " ");

        for (String arg : args) {
            if (arg.contains("=")) {
                String[] attr = arg.split("=");
                if (attr.length > 2) {
                    throw new IllegalArgumentException("Cannot mark = multiple times in a parameter - " + line);
                }
                String attrVal = attr[1];
                if (attrVal.startsWith("\"") && attrVal.endsWith("\"")) {
                    attrVal = attrVal.substring(1, attrVal.length() - 1);
                }
                attrs.put(attr[0], attrVal);
            } else if (StringUtils.isNotBlank(arg)) {
                toggles.add(arg);
            }
        }
    }

    return Tuples.pair(attrs.toImmutable(), toggles.toImmutable());
}
 
Example 16
Source File: AbstractDbChangeTypeBehavior.java    From obevo with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the qualified object names (e.g. for PostgreSql where a function name corresponds to multiple
 * function overloads, each with their own specific names)
 */
protected Pair<Boolean, RichIterable<String>> getQualifiedObjectNames(Connection conn, PhysicalSchema physicalSchema, String objectName) {
    return Tuples.<Boolean, RichIterable<String>>pair(false, Lists.immutable.with(objectName));
}