org.eclipse.collections.impl.tuple.Tuples Java Examples

The following examples show how to use org.eclipse.collections.impl.tuple.Tuples. 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: 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 #2
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 #3
Source File: ExercisesAdvancedFinder.java    From reladomo-kata with Apache License 2.0 6 votes vote down vote up
@Test
public void testQ18()
{
    AllTypes allTypes = new AllTypes();

    // Test no changes
    this.applyChanges(allTypes, UnifiedMap.<Integer, Object>newMap());

    Assert.assertEquals(0, allTypes.getIntValue());
    Assert.assertNull(allTypes.getStringValue());
    Assert.assertFalse(allTypes.isBooleanValue());
    Assert.assertEquals(0.0, allTypes.getDoubleValue(), 0.0);

    MutableMap<Integer, Object> changes = UnifiedMap.newMapWith(
            Tuples.<Integer, Object>pair(124, 65536),  // int
            Tuples.<Integer, Object>pair(237, "Charlie Croker"), // String
            Tuples.<Integer, Object>pair(874, true),  // boolean
            Tuples.<Integer, Object>pair(765, 1.2358));  // double
    this.applyChanges(allTypes, changes);

    Assert.assertEquals(65536, allTypes.getIntValue());
    Assert.assertEquals("Charlie Croker", allTypes.getStringValue());
    Assert.assertTrue(allTypes.isBooleanValue());
    Assert.assertEquals(1.2358, allTypes.getDoubleValue(), 0.0);
}
 
Example #4
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 #5
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 #6
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 #7
Source File: ExercisesRelationships.java    From reladomo-kata with Apache License 2.0 6 votes vote down vote up
@Test
public void testQ4()
{
    CustomerAccountList accountsBefore = CustomerAccountFinder.findMany(CustomerAccountFinder.all());
    CustomerList customersBefore = CustomerFinder.findMany(CustomerFinder.all());
    accountsBefore.forceResolve(); //to get this list resolved before we add the new customer.
    customersBefore.forceResolve();

    MutableList<Pair<String, String>> accountDescriptionAndTypePairs = FastList.newListWith(
            Tuples.pair("Tom's saving Account", "Savings"),
            Tuples.pair("Tom's running Account", "Running")
    );

    this.addCustomerAccounts("Tom Jones", "UK", accountDescriptionAndTypePairs);

    CustomerAccountList accountsAfter = CustomerAccountFinder.findMany(CustomerAccountFinder.all());
    CustomerList customersAfter = CustomerFinder.findMany(CustomerFinder.all());

    Assert.assertEquals(1, customersAfter.size() - customersBefore.size());
    Assert.assertEquals(2, accountsAfter.size() - accountsBefore.size());

    Customer tom = CustomerFinder.findOne(CustomerFinder.name().eq("Tom Jones"));
    CustomerAccountList tomsAccounts = new CustomerAccountList(CustomerAccountFinder.customerId().eq(tom.getCustomerId()));
    Verify.assertSize(2, tomsAccounts);
}
 
Example #8
Source File: ExercisesAdvancedFinder.java    From reladomo-kata with Apache License 2.0 6 votes vote down vote up
@Test
public void testQ14()
{
    Person person10 = PersonFinder.findOne(PersonFinder.personId().eq(10));
    this.applyValues(person10,
            FastList.newListWith(
                    Tuples.<Attribute, Object>pair(PersonFinder.country(), "FR"),
                    Tuples.<Attribute, Object>pair(PersonFinder.name(), "Billy Bob"),
                    Tuples.<Attribute, Object>pair(PersonFinder.age(), 62),
                    Tuples.<Attribute, Object>pair(PersonFinder.country(), "UK")));
    Assert.assertEquals(10, person10.getPersonId());
    Assert.assertEquals("Billy Bob", person10.getName());
    Assert.assertEquals("UK", person10.getCountry());
    Assert.assertEquals(62, person10.getAge());

    CustomerAccount virtual = new CustomerAccount();
    this.applyValues(virtual,
            FastList.newListWith(
                    Tuples.<Attribute, Object>pair(CustomerAccountFinder.customerId(), 42),
                    Tuples.<Attribute, Object>pair(CustomerAccountFinder.accountType(), "Virtual"),
                    Tuples.<Attribute, Object>pair(CustomerAccountFinder.accountName(), "Rainy Day")));
    Assert.assertEquals(0, virtual.getAccountId());
    Assert.assertEquals(42, virtual.getCustomerId());
    Assert.assertEquals("Rainy Day", virtual.getAccountName());
    Assert.assertEquals("Virtual", virtual.getAccountType());
}
 
Example #9
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 #10
Source File: TextMarkupDocumentReader.java    From obevo with Apache License 2.0 5 votes vote down vote up
private MutableList<Pair<String, String>> splitIntoMainSections(String text, ImmutableList<String> elementsToCheck, String elementPrefix) {
    MutableList<Pair<String, String>> outerSections = Lists.mutable.empty();
    String nextSectionName = null;
    boolean startOfSearch = true;

    // here, we go in a loop searching for the next referenc of "[elementPrefix] [sectionName]", e.g. //// CHANGE
    // By each of those points, we split those into separate text sections and return back to the client.
    // We aim to preserve the line breaks found when parsing the sections
    while (text != null) {
        String currentSectionName = nextSectionName;
        String currentSectionText;

        int earliestIndex = Integer.MAX_VALUE;

        for (String firstLevelElement : elementsToCheck) {
            // on the first search, the text may start w/ the section; hence, we set the search fromIndex param to 0.
            // Subsequently, the index picks up at the beginning of the next section; hence, we must start
            // the search at the next character, so the fromIndex param is 1
            int index = text.indexOf(elementPrefix + " " + firstLevelElement, startOfSearch ? 0 : 1);

            if (index != -1 && index < earliestIndex) {
                earliestIndex = index;
                nextSectionName = firstLevelElement;
            }
        }

        startOfSearch = false;

        if (earliestIndex == Integer.MAX_VALUE) {
            currentSectionText = StringUtils.chomp(text);
            text = null;
        } else {
            currentSectionText = StringUtils.chomp(text.substring(0, earliestIndex));
            text = text.substring(earliestIndex);
        }

        outerSections.add(Tuples.pair(currentSectionName, currentSectionText));
    }
    return outerSections;
}
 
Example #11
Source File: ObjectTypeAndNamePredicateBuilderTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void testStringParsing() {
    ObjectTypeAndNamePredicateBuilder parse = ObjectTypeAndNamePredicateBuilder.parse("TABLE~tab1,tab2;-VIEW~view1", null);
    Predicates<? super Pair<String, String>> predicate = parse.build(Functions.<String>firstOfPair(), (Function<Pair<String, String>, String>) (Function) Functions.<String>secondOfPair());

    assertTrue(predicate.accept(Tuples.pair("OTHER", "otherInclude")));
    assertTrue(predicate.accept(Tuples.pair("TABLE", "tab1")));
    assertTrue(predicate.accept(Tuples.pair("TABLE", "tab2")));
    assertFalse(predicate.accept(Tuples.pair("TABLE", "tabNo")));
    assertFalse(predicate.accept(Tuples.pair("VIEW", "view1")));
    assertTrue(predicate.accept(Tuples.pair("VIEW", "viewInclude")));
}
 
Example #12
Source File: ObjectTypeAndNamePredicateBuilderTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void testStringParsingWithExclusionDefault() {
    ObjectTypeAndNamePredicateBuilder parse = ObjectTypeAndNamePredicateBuilder.parse("TABLE~tab1,tab2;VIEW~view1", ObjectTypeAndNamePredicateBuilder.FilterType.EXCLUDE);
    Predicates<? super Pair<String, String>> predicate = parse.build(Functions.<String>firstOfPair(), (Function<Pair<String, String>, String>) (Function) Functions.<String>secondOfPair());

    assertTrue(predicate.accept(Tuples.pair("OTHER", "otherInclude")));
    assertFalse(predicate.accept(Tuples.pair("TABLE", "tab1")));
    assertFalse(predicate.accept(Tuples.pair("TABLE", "tab2")));
    assertTrue(predicate.accept(Tuples.pair("TABLE", "tabNo")));
    assertFalse(predicate.accept(Tuples.pair("VIEW", "view1")));
    assertTrue(predicate.accept(Tuples.pair("VIEW", "viewInclude")));
}
 
Example #13
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 #14
Source File: ExercisesAdvancedFinder.java    From reladomo-kata with Apache License 2.0 5 votes vote down vote up
@Test
public void testQ2()
{
    MutableList accountNameAndTypes = FastList.newListWith(
            Tuples.twin("John's Saving Account 2", "Savings"),
            Tuples.twin("My Account", "Running"),
            Tuples.twin("No customer Account", "Virtual")
    );

    CustomerAccountList accounts = this.getAccountsBasedOnTuples(accountNameAndTypes);

    Verify.assertListsEqual(FastList.newListWith(300, 500, 600),
            accounts.asEcList().collect(CustomerAccountFinder.accountId()));
}
 
Example #15
Source File: ExercisesAdvancedFinder.java    From reladomo-kata with Apache License 2.0 5 votes vote down vote up
@Test
public void testQ7()
{
    MutableMap<String, Integer> peopleByCountry = this.getCountOfPeopleByCountry();

    MutableMap<String, Integer> expectedResult = UnifiedMap.newMapWith(
            Tuples.pair("USA", 4),
            Tuples.pair("AU", 3),
            Tuples.pair("DE", 2),
            Tuples.pair("UK", 2),
            Tuples.pair("JPN", 4),
            Tuples.pair("MA", 1)
    );
    Verify.assertMapsEqual(expectedResult, peopleByCountry);
}
 
Example #16
Source File: ExercisesAdvancedFinder.java    From reladomo-kata with Apache License 2.0 5 votes vote down vote up
@Test
public void testQ11()
{
    Verify.assertMapsEqual(
            UnifiedMap.newMapWith(Tuples.pair("name", 64), Tuples.pair("country", 48)),
            this.getStringToMaxLength(CustomerFinder.getFinderInstance()));
}
 
Example #17
Source File: ExercisesAdvancedFinder.java    From reladomo-kata with Apache License 2.0 5 votes vote down vote up
@Test
public void testQ17()
{
    MutableMap<Integer, Attribute> actualMap = this.getMyIdToAttributeMap();

    MutableMap<Integer, Attribute> expectedMap = UnifiedMap.newMapWith(
            Tuples.<Integer, Attribute>pair(Integer.valueOf(124), AllTypesFinder.intValue()),
            Tuples.<Integer, Attribute>pair(Integer.valueOf(237), AllTypesFinder.stringValue()),
            Tuples.<Integer, Attribute>pair(Integer.valueOf(874), AllTypesFinder.booleanValue()),
            Tuples.<Integer, Attribute>pair(Integer.valueOf(765), AllTypesFinder.doubleValue()));

    Verify.assertMapsEqual(expectedMap, actualMap);
}
 
Example #18
Source File: Exercise4Test.java    From reladomo-kata with Apache License 2.0 5 votes vote down vote up
/**
 * Similar to {@link Exercise3Test#getTotalAgeOfAllSmithPets()} only get the number of {@code Pet}s per {@code Person}.
 * <p>
 * Use Reladomo's aggregation methods.
 * </p>
 */
@Test
public void getNumberOfPetsPerPerson()
{
    AggregateList aggregateList = null;

    MutableMap<Integer, Integer> personIdToPetCountMap = Iterate.toMap(
            aggregateList,
            aggregateData -> aggregateData.getAttributeAsInteger("personId"),
            aggregateData -> aggregateData.getAttributeAsInteger("petCount"));

    Verify.assertMapsEqual(Maps.mutable.with(Tuples.pair(1, 1), Tuples.pair(2, 2), Tuples.pair(3, 1), Tuples.pair(5, 1), Tuples.pair(6, 1), Tuples.pair(7, 2)),
            personIdToPetCountMap);
}
 
Example #19
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 #20
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 #21
Source File: DbChangeRestrictionsReader.java    From obevo with Apache License 2.0 5 votes vote down vote up
private Twin<MutableSet<String>> readRestrictions(TextMarkupDocumentSection section, String includeKey, String excludeKey) {
    MutableSet<String> include = readList(section, includeKey);
    MutableSet<String> exclude = readList(section, excludeKey);
    if (include != null && exclude != null) {
        throw new IllegalArgumentException(
                String.format("Cannot define the %s param with both %s and %s; must be one or the other", TextMarkupDocumentReader.TAG_METADATA, includeKey, excludeKey)
        );
    } else if (include == null && exclude == null) {
        return null;
    } else {
        return Tuples.twin(include, exclude);
    }
}
 
Example #22
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 #23
Source File: DbDataComparisonConfigFactory.java    From obevo with Apache License 2.0 5 votes vote down vote up
private static DbDataComparisonConfig createFromProperties(final Configuration config) {
    Properties propsView = ConfigurationConverter.getProperties(config);  // config.getString() automatically parses
    // for commas...would like to avoid this
    DbDataComparisonConfig compConfig = new DbDataComparisonConfig();
    compConfig.setInputTables(Lists.mutable.with(propsView.getProperty("tables.include").split(",")));
    compConfig.setExcludedTables(Lists.mutable.with(propsView.getProperty("tables.exclude").split(",")).toSet());
    String comparisonsStr = propsView.getProperty("comparisons");

    MutableList<Pair<String, String>> compCmdPairs = Lists.mutable.empty();
    MutableSet<String> dsNames = UnifiedSet.newSet();
    for (String compPairStr : comparisonsStr.split(";")) {
        String[] pairParts = compPairStr.split(",");
        compCmdPairs.add(Tuples.pair(pairParts[0], pairParts[1]));

        // note - if I knew where the Pair.TO_ONE TO_TWO selectors were, I'd use those
        dsNames.add(pairParts[0]);
        dsNames.add(pairParts[1]);
    }

    compConfig.setComparisonCommandNamePairs(compCmdPairs);

    MutableList<DbDataSource> dbDataSources = dsNames.toList().collect(new Function<String, DbDataSource>() {
        @Override
        public DbDataSource valueOf(String dsName) {
            Configuration dsConfig = config.subset(dsName);

            DbDataSource dbDataSource = new DbDataSource();
            dbDataSource.setName(dsName);
            dbDataSource.setUrl(dsConfig.getString("url"));
            dbDataSource.setSchema(dsConfig.getString("schema"));
            dbDataSource.setUsername(dsConfig.getString("username"));
            dbDataSource.setPassword(dsConfig.getString("password"));
            dbDataSource.setDriverClassName(dsConfig.getString("driverClass"));

            return dbDataSource;
        }
    });
    compConfig.setDbDataSources(dbDataSources);
    return compConfig;
}
 
Example #24
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 #25
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 #26
Source File: Db2SqlExecutorTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void testFindTableNameFromSQLException668() {
    SQLException diagnosable = mock(SQLException.class);
    // Note: We will be using SqlErrmc code alone inside the findTableFromSQLException method. Hence we are mocking
    // only the getSqlErrmc method
    when(diagnosable.getMessage()).thenReturn("random prefix - DB2 SQL Error: SQLCODE=-668, SQLSTATE=57016, SQLERRMC=7;MY_SCHEMA.MYTAB3, DRIVER=3.59.81");
    assertEquals(Tuples.pair(new PhysicalSchema("MY_SCHEMA"), "MYTAB3"),
            this.executor.findTableNameFromException(diagnosable, -668));

    verify(diagnosable, times(1)).getMessage();
}
 
Example #27
Source File: DbDataComparisonExample.java    From obevo with Apache License 2.0 5 votes vote down vote up
public static void option2() throws Exception {
    Class.forName("com.sybase.jdbc3.jdbc.SybDriver");

    DbDataComparisonConfig reconConfig = new DbDataComparisonConfig();
    MutableList<DbDataSource> dbDataSources = Lists.mutable.with(
            new DbDataSource.Builder().setName("dev1").setUrl("jdbc:sybase:Tds:myhost1.me.com:1234")
                    .setSchema("schemaA").setUsername("user1").setPassword("NOT_A_PASSWORD")
                    .createDbDataSource()
            ,
            new DbDataSource.Builder().setName("uat").setUrl("jdbc:sybase:Tds:myhost2.me.com:1234")
                    .setSchema("schemaB").setUsername("user2").setPassword("NOT_A_PASSWORD")
                    .createDbDataSource()
            ,
            new DbDataSource.Builder().setName("prod1")
                    .setUrl("jdbc:sybase:Tds:myhost3.me.com:1234")
                    .setSchema("schemaC").setUsername("user3").setPassword("NOT_A_PASSWORD")
                    .createDbDataSource()
            ,
            new DbDataSource.Builder().setName("prod2")
                    .setUrl("jdbc:sybase:Tds:myhost4.me.com:1234")
                    .setSchema("schemaD").setUsername("user4").setPassword("NOT_A_PASSWORD")
                    .createDbDataSource()
    );
    reconConfig.setDbDataSources(dbDataSources);
    reconConfig.setComparisonCommandNamePairs(Lists.mutable.with(
            Tuples.pair("dev1", "uat")
            , Tuples.pair("uat", "prod1")
            , Tuples.pair("dev1", "prod2")
    ));
    reconConfig.setInputTables(Lists.mutable.of("TableA", "TableB", "TableC", "TableD"));
    reconConfig.setExcludedTables(Sets.mutable.of("ExcludedTableA", "ExcludedTableB"));
    new DbDataComparisonUtil().execute(reconConfig, new File("./comps"));
}
 
Example #28
Source File: Db2SqlExecutorTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void testFindTableNameFromSQLException668WithSpace() {
    SQLException diagnosable = mock(SQLException.class);
    // Note: We will be using SqlErrmc code alone inside the findTableFromSQLException method. Hence we are mocking
    // only the getSqlErrmc method
    when(diagnosable.getMessage()).thenReturn("DB2 SQL error: SQLCODE: -668, SQLSTATE: 57016, SQLERRMC: 7;7MY_SCHEMA.MYTAB2_");
    assertEquals(Tuples.pair(new PhysicalSchema("7MY_SCHEMA"), "MYTAB2_"),
            this.executor.findTableNameFromException(diagnosable, -668));

    verify(diagnosable, times(1)).getMessage();
}
 
Example #29
Source File: Db2SqlExecutorTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void testFindTableNameFromSQLException20054() {
    SQLException diagnosable = mock(SQLException.class);
    when(diagnosable.getMessage()).thenReturn("DB2 SQL error: SQLCODE: -20054, SQLSTATE: 55019, SQLERRMC=MY_SCHEMA.MYTAB1_;23");
    assertEquals(Tuples.pair(new PhysicalSchema("MY_SCHEMA"), "MYTAB1_"),
            this.executor.findTableNameFromException(diagnosable, -20054));
    verify(diagnosable, times(1)).getMessage();
}
 
Example #30
Source File: Db2SqlExecutorTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void testFindTableNameFromSQLException20054WithSpace() {
    SQLException diagnosable = mock(SQLException.class);
    when(diagnosable.getMessage()).thenReturn("DB2 SQL error: SQLCODE: -20054, SQLSTATE: 55019, SQLERRMC: _MY_SCHEMA.MYTAB1_;23");
    assertEquals(Tuples.pair(new PhysicalSchema("_MY_SCHEMA"), "MYTAB1_"),
            this.executor.findTableNameFromException(diagnosable, -20054));
    verify(diagnosable, times(1)).getMessage();
}