Java Code Examples for org.eclipse.collections.api.list.MutableList#toImmutable()

The following examples show how to use org.eclipse.collections.api.list.MutableList#toImmutable() . 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: PostgreSqlDbPlatform.java    From obevo with Apache License 2.0 6 votes vote down vote up
@Override
protected ImmutableList<ChangeType> initializeChangeTypes() {
    MutableList<ChangeType> changeTypes = super.initializeChangeTypes().toList();

    DbChangeType sequenceType = getChangeType(changeTypes, ChangeType.SEQUENCE_STR);
    sequenceType = DbChangeTypeImpl.newDbChangeType(sequenceType).setGrantObjectQualifier("SEQUENCE").build();
    replaceChangeType(changeTypes, sequenceType);

    DbChangeType functionType = getChangeType(changeTypes, ChangeType.FUNCTION_STR);
    functionType = DbChangeTypeImpl.newDbChangeType(functionType).setGrantObjectQualifier("FUNCTION").build();
    replaceChangeType(changeTypes, functionType);

    DbChangeType typeType = DbChangeTypeImpl.newDbChangeType(ChangeType.USERTYPE_STR, true, 1, "TYPE").build();
    changeTypes.add(typeType);

    return changeTypes.toImmutable();
}
 
Example 2
Source File: Db2DbPlatform.java    From obevo with Apache License 2.0 6 votes vote down vote up
@Override
protected ImmutableList<ChangeType> initializeChangeTypes() {
    MutableList<ChangeType> changeTypes = super.initializeChangeTypes().toList();

    DbChangeType sequenceType = getChangeType(changeTypes, ChangeType.SEQUENCE_STR);
    sequenceType = DbChangeTypeImpl.newDbChangeType(sequenceType).setGrantObjectQualifier("SEQUENCE").build();
    replaceChangeType(changeTypes, sequenceType);

    DbChangeType functionType = getChangeType(changeTypes, ChangeType.FUNCTION_STR);
    functionType = DbChangeTypeImpl.newDbChangeType(functionType).setGrantObjectQualifier("FUNCTION").build();
    replaceChangeType(changeTypes, functionType);

    DbChangeType spType = getChangeType(changeTypes, ChangeType.SP_STR);
    spType = DbChangeTypeImpl.newDbChangeType(spType).setGrantObjectQualifier("PROCEDURE").build();
    replaceChangeType(changeTypes, spType);

    return changeTypes.toImmutable();
}
 
Example 3
Source File: DbChangeRestrictionsReader.java    From obevo with Apache License 2.0 6 votes vote down vote up
public ImmutableList<ArtifactRestrictions> valueOf(TextMarkupDocumentSection section) {
    if (section == null) {
        return Lists.immutable.of();
    }

    MutableList<ArtifactRestrictions> restrictions = Lists.mutable.empty();

    Twin<MutableSet<String>> envRestrictions = readRestrictions(section, TextMarkupDocumentReader.INCLUDE_ENVS, TextMarkupDocumentReader.EXCLUDE_ENVS);
    if (envRestrictions != null) {
        restrictions.add(new ArtifactEnvironmentRestrictions(envRestrictions.getOne(), envRestrictions.getTwo()));
    }

    Twin<MutableSet<String>> platformRestrictions = readRestrictions(section, TextMarkupDocumentReader.INCLUDE_PLATFORMS, TextMarkupDocumentReader.EXCLUDE_PLATFORMS);
    if (platformRestrictions != null) {
        restrictions.add(new ArtifactPlatformRestrictions(platformRestrictions.getOne(), platformRestrictions.getTwo()));
    }

    return restrictions.toImmutable();
}
 
Example 4
Source File: BaselineTableChangeParser.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Override
public ImmutableList<ChangeInput> value(final ChangeType defaultChangeType, final FileObject file, String fileContent, final String objectName, final String schema, TextMarkupDocumentSection packageMetadata) {
    MutableList<String> sqls = MultiLineStringSplitter.createSplitterOnSpaceAndLine("GO").valueOf(fileContent);
    sqls = sqls.reject(Predicates.attributePredicate(StringFunctions.trim(), StringPredicates.empty()));

    MutableList<String> sortedSqls = this.sortSqls(sqls);

    MutableList<ChangeInput> changes = sortedSqls.zipWithIndex().collect(
            new Function<Pair<String, Integer>, ChangeInput>() {
                @Override
                public ChangeInput valueOf(Pair<String, Integer> object) {
                    String content = object.getOne();
                    int index = object.getTwo();

                    ChangeType changeType = getChangeType(content, defaultChangeType);

                    String changeName = "baseline-change-" + index;
                    boolean active = true;
                    String rollbackIfAlreadyDeployedCommand = null;
                    String rollbackContent = null;

                    ChangeInput change = new ChangeInput(false);
                    change.setChangeKey(new ChangeKey(schema, changeType, objectName, changeName));
                    change.setOrder(index);
                    change.setContentHash(contentHashStrategy.hashContent(content));
                    change.setContent(content);
                    change.setRollbackIfAlreadyDeployedContent(rollbackIfAlreadyDeployedCommand);
                    change.setActive(active);
                    change.setRollbackContent(rollbackContent);
                    change.setFileLocation(file);
                    return change;
                }
            });

    return changes.toImmutable();
}
 
Example 5
Source File: GrantChangeParser.java    From obevo with Apache License 2.0 5 votes vote down vote up
ImmutableList<String> generateGrantChanges(RichIterable<Permission> permsToApply, final DbChangeType changeType, final PhysicalSchema physicalSchema, final String mainObjectName, RichIterable<String> objectNames, final boolean specific) {
    final MutableList<String> changes = Lists.mutable.empty();

    for (Permission perm : permsToApply) {
        for (final Grant grant : perm.getGrants()) {
            grant.validate();

            for (final String objectName : objectNames) {
                grant.getGrantTargets().forEachKeyValue(new Procedure2<GrantTargetType, String>() {
                    @Override
                    public void value(GrantTargetType grantTargetType, String grantTarget) {
                        for (String privilege : grant.getPrivileges()) {
                            changes.add(GrantChangeParser.this.createGrant(env, privilege, changeType, physicalSchema, objectName, grantTargetType, grantTarget, specific));
                        }
                    }
                });
            }
        }
    }

    if (LOG.isInfoEnabled()) {
        LOG.info(String.format("Applying grants on [%s] with [%d] permission entries on these qualified object names: [%s]",
                mainObjectName, permsToApply.size(), objectNames.makeString("; ")));
    }

    return changes.toImmutable();
}
 
Example 6
Source File: DbChecksumCalculator.java    From obevo with Apache License 2.0 5 votes vote down vote up
private ImmutableCollection<ChecksumEntry> getTableChecksums(DaTable table) {
    MutableList<ChecksumEntry> checksums = Lists.mutable.empty();

    String pkContent = table.getPrimaryKey() != null ? table.getPrimaryKey().toString() : "";
    ChecksumEntry tableChecksum = ChecksumEntry.createFromText(table.getSchema().toPhysicalSchema(), ChangeType.TABLE_STR, table.getName(), "primaryKey", pkContent);
    checksums.add(tableChecksum);

    for (DaColumn column : table.getColumns()) {
        checksums.add(getColumnChecksum(table, column));
    }

    return checksums.toImmutable();
}
 
Example 7
Source File: DbChecksumCalculator.java    From obevo with Apache License 2.0 5 votes vote down vote up
private ImmutableCollection<ChecksumEntry> getViewChecksums(DaView view) {
    MutableList<ChecksumEntry> checksums = Lists.mutable.empty();

    String tableContent = view.getDefinition();
    ChecksumEntry tableChecksum = ChecksumEntry.createFromText(view.getSchema().toPhysicalSchema(), ChangeType.VIEW_STR, view.getName(), null, tableContent);
    checksums.add(tableChecksum);
    return checksums.toImmutable();
}
 
Example 8
Source File: MsSqlMetadataDialect.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Override
public ImmutableCollection<RuleBinding> getRuleBindings(DaSchema schema, Connection conn) {
    String schemaName = schema.getName();
    // return the bindings to columns and bindings to domains
    String sql = "select tab.name 'object', rul.name 'rule', " +
            "'sp_bindrule ' + rul.name + ', ''' + tab.name + '.' + col.name + '''' 'sql'\n" +
            "from " + schemaName + "..syscolumns col, " + schemaName + "..sysobjects rul, " + schemaName + "..sysobjects tab\n" +
            "    , sys.schemas sch\n" +
            "where col.domain = rul.id and col.id = tab.id and tab.type='U' and col.domain <> 0\n" +
            "    and tab.uid = sch.schema_id and sch.name = '" + schema.getSubschemaName() + "'\n" +
            "union\n" +
            "select obj.name 'object', rul.name 'rule', " +
            "'sp_bindrule ' + rul.name + ', ' + obj.name 'sql'\n" +
            "from " + schemaName + "..systypes obj, " + schemaName + "..sysobjects rul\n" +
            "    , sys.schemas sch\n" +
            "where obj.domain = rul.id and obj.domain <> 0\n" +
            "    and obj.uid = sch.schema_id and sch.name = '" + schema.getSubschemaName() + "'\n";
    PreparedStatement ps = null;
    ResultSet rs = null;
    try {
        ps = conn.prepareStatement(sql);
        rs = ps.executeQuery();

        MutableList<RuleBinding> ruleBindings = Lists.mutable.empty();
        while (rs.next()) {
            RuleBindingImpl ruleBinding = new RuleBindingImpl();
            ruleBinding.setObject(rs.getString("object"));
            ruleBinding.setRule(rs.getString("rule"));
            ruleBinding.setSql(rs.getString("sql"));
            ruleBindings.add(ruleBinding);
        }
        return ruleBindings.toImmutable();
    } catch (SQLException e) {
        throw new RuntimeException(e);
    } finally {
        DbUtils.closeQuietly(rs);
        DbUtils.closeQuietly(ps);
    }
}
 
Example 9
Source File: SybaseAseMetadataDialect.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Override
public ImmutableCollection<RuleBinding> getRuleBindings(DaSchema schema, Connection conn) {
    String schemaName = schema.getName();
    // return the bindings to columns and bindings to domains
    String sql = "select tab.name 'object', rul.name 'rule', " +
            "'sp_bindrule ' || rul.name || ', ''' || tab.name || '.' || col.name || '''' 'sql'\n" +
            "from " + schemaName + "..syscolumns col, " + schemaName + "..sysobjects rul, " + schemaName + "..sysobjects tab\n" +
            "    , " + schemaName + "..sysusers sch\n" +
            "where col.domain = rul.id and col.id = tab.id and tab.type='U' and col.domain <> 0\n" +
            "    and tab.uid = sch.uid and sch.name = '" + schema.getSubschemaName() + "'\n" +
            "union\n" +
            "select obj.name 'object', rul.name 'rule', " +
            "'sp_bindrule ' || rul.name || ', ' || obj.name 'sql'\n" +
            "from " + schemaName + "..systypes obj, " + schemaName + "..sysobjects rul\n" +
            "    , " + schemaName + "..sysusers sch\n" +
            "where obj.domain = rul.id and obj.domain <> 0\n" +
            "    and obj.uid = sch.uid and sch.name = '" + schema.getSubschemaName() + "'\n";
    PreparedStatement ps = null;
    ResultSet rs = null;
    try {
        ps = conn.prepareStatement(sql);
        rs = ps.executeQuery();

        MutableList<RuleBinding> ruleBindings = Lists.mutable.empty();
        while (rs.next()) {
            RuleBindingImpl ruleBinding = new RuleBindingImpl();
            ruleBinding.setObject(rs.getString("object"));
            ruleBinding.setRule(rs.getString("rule"));
            ruleBinding.setSql(rs.getString("sql"));
            ruleBindings.add(ruleBinding);
        }
        return ruleBindings.toImmutable();
    } catch (SQLException e) {
        throw new RuntimeException(e);
    } finally {
        DbUtils.closeQuietly(rs);
        DbUtils.closeQuietly(ps);
    }
}
 
Example 10
Source File: EnvironmentFactory.java    From obevo with Apache License 2.0 5 votes vote down vote up
public <E extends Environment> ImmutableCollection<E> readFromSourcePath(String sourcePath, String... envNames) {
    EnvironmentLocator dbEnvironmentLocator = new EnvironmentLocator();
    ImmutableCollection<E> environments = dbEnvironmentLocator.readSystem(sourcePath);

    MutableList<E> requestedEnvs = Lists.mutable.empty();

    for (E env : environments) {
        if (envNames == null || envNames.length == 0) {
            requestedEnvs.add(env);
        } else {
            for (String envPattern : envNames) {
                if (Pattern.compile(RegexUtil.convertWildcardPatternToRegex(envPattern))
                        .matcher(env.getName())
                        .matches()) {
                    requestedEnvs.add(env);
                }
            }
        }
    }

    if (requestedEnvs.isEmpty()) {
        throw new IllegalArgumentException("No environment with name/s "
                + Lists.mutable.with(envNames).makeString("(", ",", ")") + " found");
    }

    return requestedEnvs.toImmutable();
}
 
Example 11
Source File: CollectionUtil.java    From obevo with Apache License 2.0 5 votes vote down vote up
public static <T> ImmutableList<T> iteratorToList(Iterator<T> iterator) {
    MutableList<T> list = Lists.mutable.empty();
    while (iterator.hasNext()) {
        list.add(iterator.next());
    }
    return list.toImmutable();
}
 
Example 12
Source File: RerunnableChangeTypeCommandCalculator.java    From obevo with Apache License 2.0 5 votes vote down vote up
/**
 * TODO for rerunnable to support a better change group:
 * -add dependent changes where applicable (e.g. views, sps, functions, but not static data)
 * -group the related changes as needed
 * -create the change for each group
 */
private ImmutableList<ChangeCommand> processRerunnableChanges(ChangeType changeType,
        RerunnableObjectInfo rerunnableObjectInfo,
        RichIterable<Change> fromSourceList) {
    final MutableList<ChangeCommand> commands = Lists.mutable.empty();

    commands.addAll(rerunnableObjectInfo.getDroppedObjects().collect(new Function<Change, ExecuteChangeCommand>() {
        @Override
        public ExecuteChangeCommand valueOf(Change droppedObject) {
            return changeCommandFactory.createRemove(droppedObject).withDrop(true);
        }
    }));

    if (changeType.isDependentObjectRecalculationRequired()) {
        commands.addAll(getObjectChangesRequiringRecompilation(changeType, fromSourceList, rerunnableObjectInfo.getChangedObjects()
                .reject(new Predicate<Change>() {
                    @Override
                    public boolean accept(Change change1) {
                        return change1.isCreateOrReplace();
                    }
                }))
                .collect(new Function<Change, ExecuteChangeCommand>() {
                    @Override
                    public ExecuteChangeCommand valueOf(Change change) {
                        return changeCommandFactory.createDeployCommand(change, "Re-deploying this object due to change in dependent object [" + change.getObjectName() + "]");
                    }
                }));
    }

    commands.addAll(rerunnableObjectInfo.getChangedObjects().collect(new Function<Change, ExecuteChangeCommand>() {
        @Override
        public ExecuteChangeCommand valueOf(Change source) {
            return changeCommandFactory.createDeployCommand(source);
        }
    }));

    return commands.toImmutable();
}
 
Example 13
Source File: TextMarkupDocumentReaderOld.java    From obevo with Apache License 2.0 4 votes vote down vote up
private ImmutableList<TextMarkupDocumentSection> parseString(String text, MutableList<String> elementsToCheck, boolean recurse,
        String elementPrefix) {
    MutableList<TextMarkupDocumentSection> sections = Lists.mutable.empty();
    while (true) {
        int earliestIndex = Integer.MAX_VALUE;

        for (String firstLevelElement : elementsToCheck) {
            int index = text.indexOf(elementPrefix + " " + firstLevelElement, 1);
            if (index != -1 && index < earliestIndex) {
                earliestIndex = index;
            }
        }

        if (earliestIndex == Integer.MAX_VALUE) {
            sections.add(new TextMarkupDocumentSection(null, text));
            break;
        } else {
            sections.add(new TextMarkupDocumentSection(null, text.substring(0, earliestIndex)));
            text = text.substring(earliestIndex);
        }
    }
    for (TextMarkupDocumentSection section : sections) {
        MutableMap<String, String> attrs = Maps.mutable.empty();
        MutableSet<String> toggles = Sets.mutable.empty();
        String content = StringUtils.chomp(section.getContent());

        String[] contents = content.split("\\r?\\n", 2);
        String firstLine = contents[0];

        for (String elementToCheck : elementsToCheck) {
            if (firstLine.startsWith(elementPrefix + " " + elementToCheck)) {
                section.setName(elementToCheck);
                String[] args = StringUtils.splitByWholeSeparator(firstLine, " ");
                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 - "
                                    + firstLine);
                        }
                        String attrVal = attr[1];
                        if (attrVal.startsWith("\"") && attrVal.endsWith("\"")) {
                            attrVal = attrVal.substring(1, attrVal.length() - 1);
                        }
                        attrs.put(attr[0], attrVal);
                    } else {
                        toggles.add(arg);
                    }
                }
                if (contents.length > 1) {
                    content = contents[1];
                } else {
                    content = null;
                }
            }
        }
        section.setAttrs(attrs.toImmutable());
        section.setToggles(toggles.toImmutable());

        if (!recurse) {
            section.setContent(content);
        } else if (content != null) {
            ImmutableList<TextMarkupDocumentSection> subsections = this.parseString(content, this.secondLevelElements, false, "//");
            if (subsections.size() == 1) {
                section.setContent(content);
            } else {
                section.setContent(subsections.get(0).getContent());
                section.setSubsections(subsections.subList(1, subsections.size()));
            }
        } else {
            section.setContent(null);
        }
    }

    return sections.toImmutable();
}
 
Example 14
Source File: ImmutableListDeserializer.java    From jackson-datatypes-collections with Apache License 2.0 4 votes vote down vote up
@Override
protected ImmutableList<?> finish(MutableList<Object> objects) {
    return objects.toImmutable();
}