Java Code Examples for org.eclipse.collections.api.tuple.Pair#getTwo()

The following examples show how to use org.eclipse.collections.api.tuple.Pair#getTwo() . 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: AbstractIqDataSourceFactory.java    From obevo with Apache License 2.0 6 votes vote down vote up
@Override
public final DataSource createDataSource(DbEnvironment env, Credential credential, String schema, int numThreads) {
    String url;
    String password;
    if (env.getJdbcUrl() != null) {
        url = env.getJdbcUrl();
        password = credential.getPassword();
    } else {
        Pair<String, String> urlPasswordPair = this.getUrl(env, schema, credential);
        url = urlPasswordPair.getOne();
        password = urlPasswordPair.getTwo() != null ? urlPasswordPair.getTwo() : credential.getPassword();
    }

    LOG.info("Connecting using URL: {}", url);
    Credential schemaCredential = new Credential(schema, password);
    return JdbcDataSourceFactory.createFromJdbcUrl(env.getDriverClass(), url, schemaCredential, numThreads);
}
 
Example 2
Source File: DeepCompareUtil.java    From obevo with Apache License 2.0 4 votes vote down vote up
private void compareObjectsInternal(Object key, Object left, Object right, MutableCollection<CompareBreak> breaks) {
    Class objectClass = left.getClass();

    MutableCollection<ClassCompareInfo> classCompareInfos = this.getClassCompareInfos(objectClass);

    if (classCompareInfos.isEmpty()) {
        if (!ObjectUtils.equals(left, right)) {
            breaks.add(new FieldCompareBreak(objectClass, key, left, right, "this", left, right));
        }
    } else {
        for (ClassCompareInfo<Object> classCompareInfo : classCompareInfos) {
            for (Pair<String, Function<Object, ?>> functionPair : classCompareInfo.getCompareFunctions()) {
                Function<Object, ?> function = functionPair.getTwo();
                Object leftFuncVal = function.valueOf(left);
                Object rightFuncVal = function.valueOf(right);

                if (leftFuncVal == null && rightFuncVal == null) {
                    continue;  // no break - continue
                } else if (leftFuncVal == null ^ rightFuncVal == null) {  // XOR - if one of these is null, but not
                    // the other
                    breaks.add(new FieldCompareBreak(objectClass, key, left, right, functionPair.getOne(),
                            leftFuncVal, rightFuncVal));
                } else {
                    MutableCollection<ClassCompareInfo> funcClassCompareInfos = this.getClassCompareInfos(leftFuncVal
                            .getClass());

                    if (funcClassCompareInfos.isEmpty()) {
                        if (!ObjectUtils.equals(leftFuncVal, rightFuncVal)) {
                            breaks.add(new FieldCompareBreak(objectClass, key, left, right, functionPair.getOne(),
                                    leftFuncVal, rightFuncVal));
                        }
                    } else {
                        this.compareObjectsInternal(key, leftFuncVal, rightFuncVal, breaks);
                    }
                }
            }

            for (CollectionFieldCompareInfo collectionCompareInfo : classCompareInfo.getCollectionComparisonInfos()) {
                this.compareCollectionsInternal(collectionCompareInfo.getElementClass()
                        , (Collection) collectionCompareInfo.getCollectionFieldFunction().valueOf(left)
                        , (Collection) collectionCompareInfo.getCollectionFieldFunction().valueOf(right)
                        , breaks);
            }
        }
    }
}
 
Example 3
Source File: SameSchemaDeployExecutionDao.java    From obevo with Apache License 2.0 4 votes vote down vote up
private void backfillDbSchemaColumn(Connection conn, PhysicalSchema physicalSchema) {
    // first, get a mapping of all the IDs to DB schemas from the artifactdeployment table. Note that technically
    // we may have lost information as rows can get updated in place, but we'll make do here
    final MutableSetMultimap<Long, String> execIdToSchemaMap = Multimaps.mutable.set.empty();
    for (Map<String, Object> tempExecIdToSchemaMap : jdbc.queryForList(conn, "SELECT DISTINCT INSERTDEPLOYID, UPDATEDEPLOYID, DBSCHEMA FROM " + platform.getSubschemaPrefix(physicalSchema) + platform.convertDbObjectName().valueOf(ChangeAuditDao.CHANGE_AUDIT_TABLE_NAME))) {
        Long insertDeployId = platform.getLongValue(tempExecIdToSchemaMap.get("INSERTDEPLOYID"));
        Long updateDeployId = platform.getLongValue(tempExecIdToSchemaMap.get("UPDATEDEPLOYID"));
        String dbSchema = (String) tempExecIdToSchemaMap.get("DBSCHEMA");
        if (insertDeployId != null) {
            execIdToSchemaMap.put(insertDeployId, dbSchema);
        }
        if (updateDeployId != null) {
            execIdToSchemaMap.put(updateDeployId, dbSchema);
        }
    }

    // find the list of distinct schemas from that list
    MutableSet<String> dbSchemas = execIdToSchemaMap.valuesView().toSet();

    if (dbSchemas.size() == 1) {
        // If we only found 1 schema in ARTIFACTDEPLOYMENT, then we can assume that all the IDs in ARTIFACTEXECUTION
        // also belonged to that schema. So we go w/ the simple update
        jdbc.execute(conn, "UPDATE " + platform.getSubschemaPrefix(physicalSchema) + deployExecutionTableName + " " +
                "SET " + dbSchemaColName + " = '" + dbSchemas.getFirst() + "' ");
    } else if (dbSchemas.size() > 1) {
        // If not, then we need to look a bit deeper to try to match the ID to a schema

        // First compare based on the version name (hoping that all the deployments of a version are traced back to only
        MutableListMultimap<String, Long> versionToIdsMap = Multimaps.mutable.list.empty();
        for (Map<String, Object> idToVersionMap : jdbc.queryForList(conn, "SELECT " + idColName + ", " + productVersionColName + " FROM " + platform.getSubschemaPrefix(physicalSchema) + deployExecutionTableName)) {
            versionToIdsMap.put((String) idToVersionMap.get(productVersionColName), platform.getLongValue(idToVersionMap.get(idColName)).longValue());
        }

        for (Pair<String, RichIterable<Long>> versionIdsPair : versionToIdsMap.keyMultiValuePairsView()) {
            RichIterable<Long> ids = versionIdsPair.getTwo();

            // Find all the schemas matched to the version
            MutableSet<String> versionSchemas = ids.flatCollect(new Function<Long, Iterable<String>>() {
                @Override
                public Iterable<String> valueOf(Long aLong) {
                    return execIdToSchemaMap.get(aLong);
                }
            }, Sets.mutable.<String>empty());

            for (Long id : ids) {
                // iterate for each ID of the version

                if (versionSchemas.size() == 1) {
                    // If we just had 1 schema for all the versions, then do the simple update
                    jdbc.execute(conn, "UPDATE " + platform.getSubschemaPrefix(physicalSchema) + deployExecutionTableName + " " +
                            "SET " + dbSchemaColName + " = '" + versionSchemas.getFirst() + "' " +
                            "WHERE " + idColName + " = " + id
                    );
                } else {
                    // Otherwise, fall back to the schema list per id
                    String schemaToSet;
                    MutableSet<String> idSchemas = execIdToSchemaMap.get(id);
                    if (idSchemas.size() == 1) {
                        schemaToSet = idSchemas.getFirst();
                    } else if (idSchemas.size() >= 1) {
                        LOG.warn("Not expecting multiple schemas on ID {} to be defined: {} ", id, idSchemas);
                        schemaToSet = "MULTISCHEMA";
                    } else {
                        LOG.warn("No schemas found for ID {}", id, idSchemas);
                        schemaToSet = "NOSCHEMA";
                    }

                    jdbc.execute(conn, "UPDATE " + platform.getSubschemaPrefix(physicalSchema) + deployExecutionTableName + " " +
                            "SET " + dbSchemaColName + " = '" + schemaToSet + "' " +
                            "WHERE " + idColName + " = " + id
                    );
                }
            }
        }
    }
}
 
Example 4
Source File: TextMarkupDocumentReader.java    From obevo with Apache License 2.0 4 votes vote down vote up
@Override
public Iterable<TextMarkupDocumentSection> valueOf(Pair<String, String> outerSection) {
    String currentSectionName = outerSection.getOne();
    if (currentSectionName == null) {
        return Lists.mutable.with(new TextMarkupDocumentSection(null, outerSection.getTwo()));
    } else {
        String[] contents = outerSection.getTwo().split("\\r?\\n", 2);
        String firstLine = contents[0];
        firstLine = firstLine.replaceFirst(elementPrefix + " " + currentSectionName, "");

        Pair<ImmutableMap<String, String>, ImmutableSet<String>> attrsTogglesPair = parseAttrsAndToggles(firstLine);
        ImmutableMap<String, String> attrs = attrsTogglesPair.getOne();
        ImmutableSet<String> toggles = attrsTogglesPair.getTwo();

        String sectionContent = contents.length > 1 ? contents[1] : null;
        if (singleLineElements.contains(currentSectionName)) {
            TextMarkupDocumentSection metadataSection = new TextMarkupDocumentSection(currentSectionName, null, attrs.toImmutable());
            metadataSection.setToggles(toggles.toImmutable());
            return Lists.mutable.with(metadataSection, new TextMarkupDocumentSection(null, sectionContent));
        } else {
            ImmutableList<TextMarkupDocumentSection> finalsubsections = Lists.immutable.empty();
            String finalContent;
            if (!recurse) {
                finalContent = sectionContent;
            } else if (sectionContent != null) {
                ImmutableList<TextMarkupDocumentSection> subsections = parseString(sectionContent, secondLevelElements, false, "//");
                if (subsections.size() == 1) {
                    finalContent = sectionContent;
                } else {
                    finalContent = subsections.get(0).getContent();
                    finalsubsections = subsections.subList(1, subsections.size());
                }
            } else {
                finalContent = null;
            }

            TextMarkupDocumentSection section = new TextMarkupDocumentSection(currentSectionName, finalContent, attrs.toImmutable());
            section.setToggles(toggles.toImmutable());
            section.setSubsections(finalsubsections);
            return Lists.mutable.with(section);
        }
    }
}
 
Example 5
Source File: AbstractReveng.java    From obevo with Apache License 2.0 4 votes vote down vote up
private MutableList<ChangeEntry> revengFile(SchemaObjectReplacer schemaObjectReplacer, List<Pair<String, RevengPatternOutput>> snippetPatternMatchPairs, String inputSchema, boolean debugLogEnabled) {
    final MutableList<ChangeEntry> changeEntries = Lists.mutable.empty();

    MutableMap<String, AtomicInteger> countByObject = Maps.mutable.empty();

    int selfOrder = 0;
    String candidateObject = "UNKNOWN";
    ChangeType candidateObjectType = UnclassifiedChangeType.INSTANCE;
    for (Pair<String, RevengPatternOutput> snippetPatternMatchPair : snippetPatternMatchPairs) {
        String sqlSnippet = snippetPatternMatchPair.getOne();
        try {
            sqlSnippet = removeQuotesFromProcxmode(sqlSnippet);  // sybase ASE

            MutableMap<String, Object> debugComments = Maps.mutable.empty();

            RevengPattern chosenRevengPattern = null;
            String secondaryName = null;
            final RevengPatternOutput patternMatch = snippetPatternMatchPair.getTwo();

            debugComments.put("newPatternMatch", patternMatch != null);

            if (patternMatch != null) {
                chosenRevengPattern = patternMatch.getRevengPattern();

                if (chosenRevengPattern.isShouldBeIgnored()) {
                    continue;
                }

                debugComments.put("objectType", patternMatch.getRevengPattern().getChangeType());
                // we add this here to allow post-processing to occur on RevengPatterns but still not define the object to write to
                if (patternMatch.getRevengPattern().getChangeType() != null) {
                    candidateObject = patternMatch.getPrimaryName();
                    debugComments.put("originalObjectName", candidateObject);
                    candidateObject = chosenRevengPattern.remapObjectName(candidateObject);

                    debugComments.put("secondaryName", patternMatch.getSecondaryName());
                    if (patternMatch.getSecondaryName() != null) {
                        secondaryName = patternMatch.getSecondaryName();
                    }
                    if (patternMatch.getRevengPattern().getChangeType().equalsIgnoreCase(UnclassifiedChangeType.INSTANCE.getName())) {
                        candidateObjectType = UnclassifiedChangeType.INSTANCE;
                    } else {
                        candidateObjectType = platform.getChangeType(patternMatch.getRevengPattern().getChangeType());
                    }
                }
            }

            // Ignore other schemas that may have been found in your parsing (came up during HSQLDB use case)

            sqlSnippet = schemaObjectReplacer.replaceSnippet(sqlSnippet);

            AtomicInteger objectOrder2 = countByObject.getIfAbsentPut(candidateObject, new Function0<AtomicInteger>() {
                @Override
                public AtomicInteger value() {
                    return new AtomicInteger(0);
                }
            });

            if (secondaryName == null) {
                secondaryName = "change" + objectOrder2.getAndIncrement();
            }

            RevEngDestination destination = new RevEngDestination(inputSchema, candidateObjectType, candidateObject, false, Optional.ofNullable(chosenRevengPattern).map(RevengPattern::isKeepLastOnly).orElse(false));

            String annotation = chosenRevengPattern != null ? chosenRevengPattern.getAnnotation() : null;
            MutableList<Function<String, LineParseOutput>> postProcessSqls = chosenRevengPattern != null ? chosenRevengPattern.getPostProcessSqls() : Lists.mutable.<Function<String, LineParseOutput>>empty();

            for (Function<String, LineParseOutput> postProcessSql : postProcessSqls) {
                LineParseOutput lineParseOutput = postProcessSql.valueOf(sqlSnippet);
                sqlSnippet = lineParseOutput.getLineOutput();
            }

            Integer suggestedOrder = patternMatch != null ? patternMatch.getRevengPattern().getSuggestedOrder() : null;

            if (debugLogEnabled && debugComments.notEmpty()) {
                String debugCommentsStr = debugComments.keyValuesView().collect(new Function<Pair<String, Object>, String>() {
                    @Override
                    public String valueOf(Pair<String, Object> object) {
                        return object.getOne() + "=" + object.getTwo();
                    }
                }).makeString("; ");
                sqlSnippet = "-- DEBUG COMMENT: " + debugCommentsStr + "\n" + sqlSnippet;
            }
            ChangeEntry change = new ChangeEntry(destination, sqlSnippet + "\nGO", secondaryName, annotation, ObjectUtils.firstNonNull(suggestedOrder, selfOrder++));

            postProcessChange.value(change, sqlSnippet);

            changeEntries.add(change);
        } catch (RuntimeException e) {
            throw new RuntimeException("Failed parsing on statement " + sqlSnippet, e);
        }
    }

    return changeEntries;
}