org.eclipse.collections.api.list.ImmutableList Java Examples

The following examples show how to use org.eclipse.collections.api.list.ImmutableList. 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: AseToH2TranslationDialect.java    From obevo with Apache License 2.0 6 votes vote down vote up
@Override
public ImmutableList<PrepareDbChange> getAdditionalTranslators() {
    SqlTranslatorConfigHelper configHelper = SqlTranslatorConfigHelper.createInMemoryDefault();
    configHelper.setNameMapper(new AseSqlTranslatorNameMapper());
    configHelper.getPostColumnSqlTranslators()
            .with(new AseToH2SqlTranslator());
    configHelper.getPostParsedSqlTranslators()
            .with(new AseToInMemorySqlTranslator())
            .with(new DateFormatterPostParsedSqlTranslator(AseToInMemorySqlTranslator.ACCEPTED_DATE_FORMATS))
            .with(new AseToH2SqlTranslator());
    configHelper.getUnparsedSqlTranslators()
            .with(new AseToInMemorySqlTranslator())
            .with(new AseToH2DomainSqlTranslator())
            .with(new AseRenameTranslator())
    ;

    return Lists.immutable.<PrepareDbChange>with(new InMemoryTranslator(configHelper));
}
 
Example #2
Source File: SchemaGenerator.java    From obevo with Apache License 2.0 6 votes vote down vote up
private ImmutableList<MyInput> getTables() {
    return IntInterval.fromTo(0, numTables - 1).collect(new IntToObjectFunction<MyInput>() {
        @Override
        public MyInput valueOf(int i) {
            MutableSetMultimap<String, String> params = Multimaps.mutable.set.empty();

            int tableNumTypes = tableToTypesRatio.getValue();
            for (int depIndex = 0; depIndex < tableNumTypes; depIndex++) {
                int depNum = rand.nextInt(numTypes);
                params.put("usertype", "usertype" + depNum);
            }

            return new MyInput("table" + i, "table", params, CONVERT_NAME_FUNCTION);
        }
    });
}
 
Example #3
Source File: JdbcDataSourceFactory.java    From obevo with Apache License 2.0 6 votes vote down vote up
private static DataSource createFromJdbcUrl(Class<? extends Driver> driverClass, String url,
        Credential credential, int numThreads, ImmutableList<String> initSqls, Properties extraConnectionProperties) {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(driverClass.getName());
    // TODO validate non-null host name, notably for postgresl jdbc url
    dataSource.setUrl(url);
    dataSource.setUsername(credential.getUsername());
    dataSource.setPassword(credential.getPassword());

    // connection pool settings
    dataSource.setInitialSize(numThreads);
    dataSource.setMaxActive(numThreads);
    // keep the connections open if possible; only close them via the removeAbandonedTimeout feature
    dataSource.setMaxIdle(numThreads);
    dataSource.setMinIdle(0);
    dataSource.setRemoveAbandonedTimeout(300);

    dataSource.setConnectionInitSqls(initSqls.castToList());
    if (extraConnectionProperties != null) {
        for (String key : extraConnectionProperties.stringPropertyNames()) {
            dataSource.addConnectionProperty(key, extraConnectionProperties.getProperty(key));
        }
    }

    return dataSource;
}
 
Example #4
Source File: DbDeployer.java    From obevo with Apache License 2.0 6 votes vote down vote up
@Override
public void validatePriorToDeployment(DbEnvironment env, DeployStrategy deployStrategy, ImmutableList<Change> sourceChanges, ImmutableCollection<Change> deployedChanges, Changeset artifactsToProcess) {

    if (env.isChecksumDetectionEnabled() && dbChecksumManager.isInitialized()) {
        Predicate<? super ChecksumEntry> platformInclusionPredicate = getPlatformInclusionPredicate(env);
        ImmutableCollection<ChecksumBreak> checksumBreaks = this.dbChecksumManager.determineChecksumDifferences(platformInclusionPredicate)
                .reject(ChecksumBreak.IS_EXPECTED_BREAK);

        if (checksumBreaks.notEmpty()) {
            LOG.info("*******************************************");
            LOG.info("WARNING: The following objects were modified or managed outside of {}.", PlatformConfiguration.getInstance().getToolName());
            LOG.info("Please revert these changes or incorporate into your {} codebase", PlatformConfiguration.getInstance().getToolName());

            for (ChecksumBreak checksumBreak : checksumBreaks) {
                LOG.info("\t" + checksumBreak.toDisplayString());
            }

            LOG.info("*******************************************");
            LOG.info("");
        }
    }
}
 
Example #5
Source File: AseDdlgenReveng.java    From obevo with Apache License 2.0 6 votes vote down vote up
private static ImmutableList<RevengPattern> getRevengPatterns() {
    String nameSubPattern = getCatalogSchemaObjectPattern("", "");
    NamePatternType namePatternType = RevengPattern.NamePatternType.THREE;
    return Lists.immutable.with(
            new RevengPattern(ChangeType.SEQUENCE_STR, namePatternType, "(?i)create\\s+seq(?:uence)?\\s+" + nameSubPattern),
            new RevengPattern(ChangeType.TABLE_STR, namePatternType, "(?i)create\\s+table\\s+" + nameSubPattern),
            new RevengPattern(ChangeType.TABLE_STR, namePatternType, "(?i)alter\\s+table\\s+" + nameSubPattern + "\\s+add\\s+constraint\\s+" + nameSubPattern + "\\s+foreign\\s+key", 1, 2, "FK"),
            new RevengPattern(ChangeType.TABLE_STR, namePatternType, "(?i)alter\\s+table\\s+" + nameSubPattern + "\\s+add\\s+constraint\\s+" + nameSubPattern, 1, 2, null),
            new RevengPattern(ChangeType.TABLE_STR, namePatternType, "(?i)alter\\s+table\\s+" + nameSubPattern),
            new RevengPattern(ChangeType.TABLE_STR, namePatternType, "(?i)create\\s+(?:unique\\s+)?(?:\\w+\\s+)?index\\s+" + nameSubPattern + "\\s+on\\s+" + nameSubPattern, 2, 1, "INDEX"),
            new RevengPattern(ChangeType.FUNCTION_STR, namePatternType, "(?i)create\\s+func(?:tion)?\\s+" + nameSubPattern),
            new RevengPattern(ChangeType.VIEW_STR, namePatternType, "(?i)create\\s+view\\s+" + nameSubPattern),
            new RevengPattern(ChangeType.SP_STR, namePatternType, "(?i)create\\s+proc(?:edure)?\\s+" + nameSubPattern),
            new RevengPattern(ChangeType.TRIGGER_STR, namePatternType, "(?i)create\\s+trigger\\s+" + nameSubPattern),
            new RevengPattern(ChangeType.DEFAULT_STR, namePatternType, "(?i)create\\s+default\\s+" + nameSubPattern),
            new RevengPattern(ChangeType.RULE_STR, namePatternType, "(?i)create\\s+rule\\s+" + nameSubPattern),
            new RevengPattern(ChangeType.USERTYPE_STR, namePatternType, "(?i)^(?:exec\\s+)?sp_addtype\\s+'" + nameSubPattern + "'")
    );
}
 
Example #6
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 #7
Source File: AseToHsqlTranslationDialect.java    From obevo with Apache License 2.0 6 votes vote down vote up
@Override
public ImmutableList<PrepareDbChange> getAdditionalTranslators() {
    SqlTranslatorConfigHelper configHelper = SqlTranslatorConfigHelper.createInMemoryDefault();
    configHelper.setNameMapper(new AseSqlTranslatorNameMapper());
    configHelper.getColumnSqlTranslators()
            .with(new AseToHsqlSqlTranslator());
    configHelper.getPostColumnSqlTranslators()
            .with(new AseToHsqlSqlTranslator());
    configHelper.getPostParsedSqlTranslators()
            .with(new AseToInMemorySqlTranslator())
            .with(new DateFormatterPostParsedSqlTranslator(AseToInMemorySqlTranslator.ACCEPTED_DATE_FORMATS));
    configHelper.getUnparsedSqlTranslators()
            .with(new AseToInMemorySqlTranslator())
            .with(new AseToHsqlDomainSqlTranslator())
            .with(new AseRenameTranslator())
    ;

    return Lists.immutable.<PrepareDbChange>with(new InMemoryTranslator(configHelper));
}
 
Example #8
Source File: PostgresqlMetadataDialect.java    From obevo with Apache License 2.0 6 votes vote down vote up
@Override
public ImmutableCollection<DaUserType> searchUserTypes(final DaSchema schema, Connection conn) {
    String sql = "SELECT t.typname \n" +
            "FROM        pg_type t \n" +
            "LEFT JOIN   pg_catalog.pg_namespace n ON n.oid = t.typnamespace \n" +
            "WHERE       (t.typrelid = 0 OR (SELECT c.relkind = 'c' FROM pg_catalog.pg_class c WHERE c.oid = t.typrelid)) \n" +
            "AND     NOT EXISTS(SELECT 1 FROM pg_catalog.pg_type el WHERE el.oid = t.typelem AND el.typarray = t.oid)\n" +
            "AND     n.nspname IN ('" + schema.getName() + "')";
    ImmutableList<Map<String, Object>> maps = ListAdapter.adapt(jdbc.query(conn, sql, new MapListHandler())).toImmutable();

    return maps.collect(new Function<Map<String, Object>, DaUserType>() {
        @Override
        public DaUserType valueOf(Map<String, Object> map) {
            return new DaUserTypeImpl((String) map.get("typname"), schema);
        }
    });
}
 
Example #9
Source File: MsSqlToH2TranslationDialect.java    From obevo with Apache License 2.0 6 votes vote down vote up
@Override
public ImmutableList<PrepareDbChange> getAdditionalTranslators() {
    SqlTranslatorConfigHelper configHelper = SqlTranslatorConfigHelper.createInMemoryDefault();
    configHelper.setNameMapper(new MsSqlSqlTranslatorNameMapper());
    configHelper.getPostColumnSqlTranslators()
            .with(new MsSqlToH2SqlTranslator());
    configHelper.getPostParsedSqlTranslators()
            .with(new MsSqlToInMemorySqlTranslator())
            .with(new DateFormatterPostParsedSqlTranslator(MsSqlToInMemorySqlTranslator.ACCEPTED_DATE_FORMATS))
            .with(new MsSqlToH2SqlTranslator());

    configHelper.getUnparsedSqlTranslators()
            .with(new MsSqlToInMemorySqlTranslator())
            .with(new MsSqlToH2DomainSqlTranslator());

    return Lists.immutable.<PrepareDbChange>with(new InMemoryTranslator(configHelper));
}
 
Example #10
Source File: Db2lookReveng.java    From obevo with Apache License 2.0 6 votes vote down vote up
static ImmutableList<RevengPattern> getRevengPatterns() {
    String schemaNameSubPattern = getSchemaObjectPattern("\"", "\"");
    NamePatternType namePatternType = RevengPattern.NamePatternType.TWO;
    return Lists.immutable.with(
            new RevengPattern(ChangeType.SEQUENCE_STR, namePatternType, "(?i)create\\s+or\\s+replace\\s+sequence\\s+" + schemaNameSubPattern).withPostProcessSql(REPLACE_TABLESPACE).withPostProcessSql(REMOVE_QUOTES),
            new RevengPattern(ChangeType.TABLE_STR, namePatternType, "(?i)create\\s+table\\s+" + schemaNameSubPattern).withPostProcessSql(REPLACE_TABLESPACE).withPostProcessSql(REMOVE_QUOTES),
            new RevengPattern(ChangeType.TABLE_STR, namePatternType, "(?i)alter\\s+table\\s+" + schemaNameSubPattern + "\\s+add\\s+constraint\\s+" + schemaNameSubPattern + "\\s+foreign\\s+key", 1, 2, "FK").withPostProcessSql(REMOVE_QUOTES),
            new RevengPattern(ChangeType.TABLE_STR, namePatternType, "(?i)alter\\s+table\\s+" + schemaNameSubPattern + "\\s+add\\s+constraint\\s+" + schemaNameSubPattern, 1, 2, null).withPostProcessSql(REMOVE_QUOTES),
            new RevengPattern(ChangeType.TABLE_STR, namePatternType, "(?i)alter\\s+table\\s+" + schemaNameSubPattern).withPostProcessSql(REMOVE_QUOTES),
            new RevengPattern(ChangeType.TABLE_STR, namePatternType, "(?i)create\\s+index\\s+" + schemaNameSubPattern + "\\s+on\\s+" + schemaNameSubPattern, 2, 1, "INDEX").withPostProcessSql(REPLACE_TABLESPACE).withPostProcessSql(REMOVE_QUOTES),
            new RevengPattern(ChangeType.FUNCTION_STR, namePatternType, "(?i)create\\s+or\\s+replace\\s+function\\s+" + schemaNameSubPattern),
            new RevengPattern(ChangeType.VIEW_STR, namePatternType, "(?i)create\\s+or\\s+replace\\s+view\\s+" + schemaNameSubPattern),
            new RevengPattern(ChangeType.SP_STR, namePatternType, "(?i)create\\s+or\\s+replace\\s+procedure\\s+" + schemaNameSubPattern),
            new RevengPattern(ChangeType.TRIGGER_STR, namePatternType, "(?i)create\\s+or\\s+replace\\s+trigger\\s+" + schemaNameSubPattern)
    );
}
 
Example #11
Source File: HsqlMetadataDialect.java    From obevo with Apache License 2.0 6 votes vote down vote up
@Override
public ImmutableCollection<DaUserType> searchUserTypes(final DaSchema schema, Connection conn) throws SQLException {
    ImmutableList<Map<String, Object>> maps = ListAdapter.adapt(jdbc.query(conn,
            "select dom.DOMAIN_NAME AS USER_TYPE_NAME\n" +
                    "from INFORMATION_SCHEMA.DOMAINS dom\n" +
                    "WHERE dom.DOMAIN_SCHEMA = ucase('" + schema.getName() + "')\n",
            new MapListHandler()
    )).toImmutable();

    return maps.collect(new Function<Map<String, Object>, DaUserType>() {
        @Override
        public DaUserType valueOf(Map<String, Object> map) {
            return new DaUserTypeImpl((String) map.get("USER_TYPE_NAME"), schema);
        }
    });
}
 
Example #12
Source File: MySqlDumpReveng.java    From obevo with Apache License 2.0 6 votes vote down vote up
private static ImmutableList<RevengPattern> getRevengPatterns() {
    String schemaNameSubPattern = getSchemaObjectPattern("\"", "\"");
    String objectNameSubPattern = getObjectPattern("\"", "\"");

    NamePatternType namePatternType = NamePatternType.TWO;
    return Lists.immutable.with(
            new RevengPattern(ChangeType.SEQUENCE_STR, namePatternType, "(?i)create\\s+(?:or\\s+replace\\s+)?sequence\\s+" + schemaNameSubPattern).withPostProcessSql(REPLACE_TABLESPACE).withPostProcessSql(REMOVE_QUOTES),
            new RevengPattern(ChangeType.TABLE_STR, namePatternType, "(?i)create\\s+table\\s+" + schemaNameSubPattern).withPostProcessSql(REPLACE_TABLESPACE).withPostProcessSql(REMOVE_QUOTES),
            new RevengPattern(ChangeType.TABLE_STR, namePatternType, "(?i)alter\\s+table\\s+(?:only\\s+)" + schemaNameSubPattern).withPostProcessSql(REMOVE_QUOTES),
            new RevengPattern(ChangeType.TABLE_STR, namePatternType, "(?i)alter\\s+sequence\\s+" + schemaNameSubPattern + "\\s+owned\\s+by\\s+" + schemaNameSubPattern, 2, 1, null).withPostProcessSql(REMOVE_QUOTES),
            new RevengPattern(ChangeType.TABLE_STR, namePatternType, "(?i)create\\s+(?:unique\\s+)index\\s+" + schemaNameSubPattern + "\\s+on\\s+" + schemaNameSubPattern, 2, 1, "INDEX").withPostProcessSql(REPLACE_TABLESPACE).withPostProcessSql(REMOVE_QUOTES),
            new RevengPattern(ChangeType.FUNCTION_STR, namePatternType, "(?i)create\\s+(?:or\\s+replace\\s+)?(?:force\\s+)?(?:editionable\\s+)?function\\s+" + schemaNameSubPattern),
            new RevengPattern(ChangeType.SP_STR, namePatternType, "(?i)create\\s+(?:or\\s+replace\\s+)?(?:force\\s+)?(?:editionable\\s+)?procedure\\s+" + schemaNameSubPattern),
            new RevengPattern(ChangeType.VIEW_STR, namePatternType, "(?i)/*!\\d+\\s+create\\s+(?:or\\s+replace\\s+)?(?:force\\s+)?(?:editionable\\s+)?view\\s+" + schemaNameSubPattern).withKeepLastOnly(true),
            new RevengPattern(ChangeType.SP_STR, namePatternType, "(?i)create\\s+(?:or\\s+replace\\s+)(?:editionable\\s+)procedure\\s+" + schemaNameSubPattern),
            new RevengPattern(ChangeType.PACKAGE_STR, namePatternType, "(?i)create\\s+(?:or\\s+replace\\s+)(?:editionable\\s+)package\\s+" + schemaNameSubPattern),
            new RevengPattern(ChangeType.TRIGGER_STR, namePatternType, "(?i)create\\s+or\\s+replace\\s+trigger\\s+" + schemaNameSubPattern),
            new RevengPattern(ChangeType.USERTYPE_STR, namePatternType, "(?i)create\\s+(?:or\\s+replace\\s+)?type\\s+" + schemaNameSubPattern)
    );
}
 
Example #13
Source File: AseToHsqlTranslationDialect.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Override
public ImmutableList<String> getInitSqls() {
    return Lists.immutable.with(
            "SET DATABASE SQL SYNTAX MSS TRUE"
            //, "SET DATABASE SQL NAMES FALSE"  // Sybase allows keywords as identifier names; we will be flexible as well
    );
}
 
Example #14
Source File: BaselineTableChangeParserTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void testValue() throws Exception {
    ChangeType tableChangeType = mock(ChangeType.class);
    ChangeType fkChangeType = mock(ChangeType.class);
    ChangeType triggerChangeType = mock(ChangeType.class);
    BaselineTableChangeParser parser = new BaselineTableChangeParser(fkChangeType, triggerChangeType);

    ImmutableList<ChangeInput> changes = parser.value(
            tableChangeType, null, "CREATE TABLE TABLE_A (\n" +
                    "\tA_ID    INT\tNOT NULL,\n" +
                    "\tCOL2 INT NULL,\n" +
                    "\tCOL3 INT NULL\n" +
                    ")\n" +
                    "GO\n" +
                    "ALTER TABLE TABLE_A ADD PRIMARY KEY (A_ID)\n" +
                    "GO\n" +
                    "ALTER TABLE TABLE_A ADD FOREIGN KEY FK_B (B_ID) REFERENCES TABLE_B(B_ID)\n" +
                    "GO\n" +
                    "CREATE INDEX TABLE_A_IND ON TABLE_A(COL2, COL3)\n" +
                    "GO\n" +
                    "ALTER TABLE TABLE_A ADD COLUMN COL10 INT NULL\n" +
                    "GO\n", "TABLE_A", "schema", null);
    assertEquals(5, changes.size());

    // ensure that the foreign key is detected and placed at the end, regardless of where it was in the original
    // file
    // the rest of the changes should appear here in order
    assertThat(changes.get(0).getContent(), containsString("CREATE TABLE"));
    assertThat(changes.get(1).getContent(), containsString("PRIMARY KEY"));
    assertThat(changes.get(2).getContent(), containsString("CREATE INDEX"));
    assertThat(changes.get(3).getContent(), containsString("ADD COLUMN"));
    assertThat(changes.get(4).getContent(), containsString("FOREIGN KEY"));
}
 
Example #15
Source File: DbTableChangeParserTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
private ChangeInput create3(ChangeType changeType, String schema, String objectName, String changeName,
        int orderWithinObject, String hash, String content, String rollbackIfAlreadyDeployedContent, boolean active, ImmutableList<ArtifactRestrictions> restrictions) {
    ChangeInput changeInput = new ChangeInput(false);
    changeInput.setChangeKey(new ChangeKey(schema, changeType, objectName, changeName));
    changeInput.setOrderWithinObject(orderWithinObject);
    changeInput.setContentHash(hash);
    changeInput.setContent(content);
    changeInput.setRollbackIfAlreadyDeployedContent(rollbackIfAlreadyDeployedContent);
    changeInput.setActive(active);
    changeInput.setRestrictions(restrictions);
    return changeInput;
}
 
Example #16
Source File: TextMarkupDocumentReaderOld.java    From obevo with Apache License 2.0 5 votes vote down vote up
public TextMarkupDocument parseString(String text, final TextMarkupDocumentSection otherSection) {
    ImmutableList<TextMarkupDocumentSection> textMarkupDocumentSections = this.parseString(text, this.firstLevelElements, true, "////");
    if (otherSection != null) {
        TextMarkupDocumentSection thisSection = textMarkupDocumentSections.detect(it -> Objects.equals(it.getName(), otherSection.getName()));
        if (thisSection != null) {
            thisSection.mergeAttributes(otherSection);
        } else {
            textMarkupDocumentSections = textMarkupDocumentSections.newWith(otherSection);
        }
    }

    return new TextMarkupDocument(textMarkupDocumentSections);
}
 
Example #17
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 #18
Source File: DaTableImpl.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Override
public ImmutableList<DaColumn> getColumns() {
    return ListAdapter.adapt(table.getColumns()).collect(new Function<Column, DaColumn>() {
        @Override
        public DaColumn valueOf(Column object) {
            return (DaColumn) new DaColumnImpl(object, schemaStrategy);
        }
    }).toImmutable();
}
 
Example #19
Source File: AbstractEnvironmentEnricher.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Override
public ImmutableCollection<E> readSystem(final HierarchicalConfiguration sysCfg, final FileObject sourcePath) {
    final Platform systemDbPlatform = dbPlatformConfiguration.valueOf(sysCfg.getString("type"));

    // Check for dbEnvironments first for backwards-compatibility
    ImmutableList<HierarchicalConfiguration> envConfigs = iterConfigMutable(sysCfg, "environments.dbEnvironment");
    if (envConfigs.isEmpty()) {
        envConfigs = iterConfigMutable(sysCfg, "environments.environment");
    }

    ImmutableList<E> envList = envConfigs.collect(new Function<HierarchicalConfiguration, E>() {
        @Override
        public E valueOf(HierarchicalConfiguration envCfg) {
            E dbEnv = AbstractEnvironmentEnricher.this.createNewEnv();

            // combining the sys and env configurations before passing to downstream methods so that we can support only having env configs passed in
            CombinedConfiguration combinedConfiguration = new CombinedConfiguration(new OverrideCombiner());
            combinedConfiguration.addConfiguration(envCfg);
            combinedConfiguration.addConfiguration(sysCfg);
            combinedConfiguration.setExpressionEngine(sysCfg.getExpressionEngine());

            AbstractEnvironmentEnricher.this.enrich(dbEnv, combinedConfiguration, sourcePath, systemDbPlatform);
            AbstractEnvironmentEnricher.this.createEnv(dbEnv, combinedConfiguration, systemDbPlatform);
            return dbEnv;
        }
    });

    CollectionUtil.verifyNoDuplicates(envList, new Function<E, Object>() {
        @Override
        public Object valueOf(E e) {
            return e.getName();
        }
    }, "Invalid configuration from " + sourcePath + "; not expecting duplicate env names");
    return envList;
}
 
Example #20
Source File: IssuesModelTest.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
@Test
void shouldShowOnlyColumnsWithMeaningfulContent() {
    ImmutableList<Issue> issues = Lists.immutable.of(createIssue(1));
    Report report = mock(Report.class);
    when(report.iterator()).thenReturn(issues.iterator());

    DetailsTableModel model = createModel(report);
    assertThat(getLabels(model))
            .containsExactly("Details", "File", "Severity", "Age");
    assertThat(getWidths(model))
            .containsExactly(1, 1, 1, 1);
    assertThat(model.getRows()).hasSize(1);

    when(report.hasPackages()).thenReturn(true);
    assertThat(getLabels(model))
            .containsExactly("Details", "File", "Package", "Severity", "Age");
    assertThat(getWidths(model))
            .containsExactly(1, 1, 2, 1, 1);

    when(report.hasCategories()).thenReturn(true);
    assertThat(getLabels(model))
            .containsExactly("Details", "File", "Package", "Category", "Severity", "Age");
    assertThat(getWidths(model))
            .containsExactly(1, 1, 2, 1, 1, 1);

    when(report.hasTypes()).thenReturn(true);
    assertThat(getLabels(model))
            .containsExactly("Details", "File", "Package", "Category", "Type", "Severity", "Age");
    assertThat(getWidths(model))
            .containsExactly(1, 1, 2, 1, 1, 1, 1);
}
 
Example #21
Source File: Db2MetadataDialect.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Override
public ImmutableCollection<DaRoutine> searchExtraRoutines(final DaSchema schema, String procedureName, Connection conn) throws SQLException {
    String procedureClause = procedureName == null ? "" : " AND R.ROUTINENAME = '" + procedureName + "'";
    final String sql = "SELECT ROUTINENAME, SPECIFICNAME, TEXT FROM SYSCAT.ROUTINES R WHERE R.ROUTINETYPE = 'F'\n" +
            "AND R.ROUTINESCHEMA = '" + schema.getName() + "'\n" + procedureClause;
    LOG.debug("Executing function metadata query SQL: {}", sql);

    ImmutableList<Map<String, Object>> maps = ListAdapter.adapt(jdbc.query(conn,
            sql,
            new MapListHandler()
    )).toImmutable();

    if (LOG.isDebugEnabled()) {
        LOG.debug("Results:");
        for (Map<String, Object> map : maps) {
            LOG.debug("ROW: {}", map.toString());
        }
    }

    return maps.collect(map -> new DaRoutinePojoImpl(
            (String) map.get("ROUTINENAME"),
            schema,
            DaRoutineType.function,
            (String) map.get("SPECIFICNAME"),
            clobToString((Clob) map.get("TEXT"))
    ));
}
 
Example #22
Source File: DeserializerTest.java    From jackson-datatypes-collections with Apache License 2.0 5 votes vote down vote up
@Test
public void immutableList() throws IOException {
    testCollection(Lists.immutable.of("1", "2", "3"),
                   "[\"1\", \"2\", \"3\"]",
                   new TypeReference<ImmutableList<String>>() {});
    testCollection(BooleanLists.immutable.of(true, false, true), "[true, false, true]", ImmutableBooleanList.class);
    testCollection(ByteLists.immutable.of((byte) 1, (byte) 2, (byte) 3), "[1, 2, 3]", ImmutableByteList.class);
    testCollection(ShortLists.immutable.of((short) 1, (short) 2, (short) 3), "[1, 2, 3]", ImmutableShortList.class);
    testCollection(CharLists.immutable.of('a', 'b', 'c'), "\"abc\"", ImmutableCharList.class);
    testCollection(IntLists.immutable.of(1, 2, 3), "[1, 2, 3]", ImmutableIntList.class);
    testCollection(FloatLists.immutable.of(1.1F, 2.3F, 3.5F), "[1.1, 2.3, 3.5]", ImmutableFloatList.class);
    testCollection(LongLists.immutable.of(1, 2, 3), "[1, 2, 3]", ImmutableLongList.class);
    testCollection(DoubleLists.immutable.of(1.1, 2.3, 3.5), "[1.1, 2.3, 3.5]", ImmutableDoubleList.class);
}
 
Example #23
Source File: DbEnvironmentXmlEnricherTest1DbPlatform.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Override
public ImmutableList<ChangeType> getChangeTypes() {
    return Lists.immutable.with(
            newChangeType(ChangeType.TABLE_STR),
            newChangeType(ChangeType.VIEW_STR),
            newChangeType(ChangeType.SP_STR)
    );
}
 
Example #24
Source File: AbstractEnvironmentEnricher.java    From obevo with Apache License 2.0 5 votes vote down vote up
private Schema convertCfgToSchema(ImmutableHierarchicalConfiguration object, final Platform systemDbPlatform, final int schemaNameValidation) {
    String schemaName = object.getString("name");
    if (schemaNameValidation >= 2) {
        validateSchemaName(schemaName);
    }
    boolean readOnly = object.getBoolean("readOnly", false);

    MutableSetMultimap<String, String> excludedNameMap = Multimaps.mutable.set.empty();

    ImmutableList<ImmutableHierarchicalConfiguration> excludes = iterConfig(object, "excludes");
    if (!excludes.isEmpty()) {
        if (excludes.size() > 1) {
            throw new IllegalArgumentException("Only expecting 1 excludes element under <schema>");
        }
        ImmutableHierarchicalConfiguration excludesConfig = excludes.get(0);
        if (excludesConfig != null) {
            for (ChangeType changeType : systemDbPlatform.getChangeTypes()) {
                ImmutableList<String> excludedNames = iterListString(excludesConfig, changeType.getName().toLowerCase());
                if (excludedNames.notEmpty()) {
                    excludedNameMap.putAll(changeType.getName(), excludedNames);
                }

                ImmutableList<String> excludedPatterns = iterListString(excludesConfig, changeType.getName().toLowerCase() + "Pattern");
                if (excludedPatterns.notEmpty()) {
                    throw new IllegalArgumentException("The <objectType>Pattern element is deprecated. Use just the <objectType> element w/ wildcards (% or *)");
                }
            }

            if (iterListString(excludesConfig, "procedure").notEmpty() || iterListString(excludesConfig, "procedurePattern").notEmpty()) {
                throw new IllegalArgumentException("The procedure and procedurePattern elements are no longer supported. Use <sp> only, with wildcards (% or *) if  needed");
            }
        }
    }

    return new Schema(schemaName, systemDbPlatform.getObjectExclusionPredicateBuilder().add(excludedNameMap.toImmutable()), readOnly);
}
 
Example #25
Source File: ObjectTypeAndNamePredicateBuilder.java    From obevo with Apache License 2.0 5 votes vote down vote up
public static ObjectTypeAndNamePredicateBuilder parse(String input, FilterType filterType) {
    ImmutableList<String> fullPredicateParts = ArrayAdapter.adapt(input.split(PREDICATE_SPLITTER)).toImmutable();

    MutableListMultimap<String, String> objectNamesByType = Multimaps.mutable.list.empty();
    for (String fullPredicatePart : fullPredicateParts) {
        ImmutableList<String> predicatePart = ArrayAdapter.adapt(fullPredicatePart.split(SINGLE_PREDICATE_SPLITTER)).toImmutable();
        Validate.isTrue(predicatePart.size() == 2, "Must only have 1 delimiter " + SINGLE_PREDICATE_SPLITTER + " in this clause " + fullPredicatePart + " to find 2 parts, but found " + predicatePart.size() + " parts");
        for (String objectName : predicatePart.get(1).split(PART_SPLITTER)) {
            objectNamesByType.put(predicatePart.get(0), objectName);
        }
    }

    return new ObjectTypeAndNamePredicateBuilder(objectNamesByType.toImmutable(), filterType);
}
 
Example #26
Source File: DefaultRollbackDetector.java    From obevo with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
boolean determineRollbackForSchema(final String deployVersion, ImmutableCollection<DeployExecution> deployExecutions) {
    logDeployExecutions(deployExecutions, "deploy executions");

    ImmutableList<DeployExecution> activeDeployments = getActiveDeployments(deployExecutions);

    logDeployExecutions(activeDeployments, "filtered active deploy executions");

    if (activeDeployments == null || activeDeployments.isEmpty()) {
        return false;
    }

    if (getDeployVersion(activeDeployments.getLast()).equals(deployVersion)) {
        return false;
    }

    ImmutableList<DeployExecution> deploymentsExcludingTheLast = activeDeployments.subList(0, activeDeployments.size() - 1);

    ImmutableList<DeployExecution> rollbackIndicativeDeployments = deploymentsExcludingTheLast.select(new Predicate<DeployExecution>() {
        @Override
        public boolean accept(DeployExecution pastDeployment) {
            return getDeployVersion(pastDeployment).equals(deployVersion);
        }
    });
    logDeployExecutions(rollbackIndicativeDeployments, "deploy executions that indicate a rollback");
    return rollbackIndicativeDeployments.notEmpty();
}
 
Example #27
Source File: ChangeRestrictionsReaderTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void testExcludePlatforms() {
    ImmutableList<ArtifactRestrictions> restrictions = this.restrictionsReader.valueOf(
            this.doc(TextMarkupDocumentReader.TAG_METADATA, null,
                    Maps.immutable.with("excludePlatforms", "HSQL,HIVE"))
    );
    assertEquals(1, restrictions.size());
    assertEquals(UnifiedSet.newSetWith("HSQL", "HIVE"), restrictions.getFirst().getExcludes());
    assertTrue(restrictions.getFirst().getIncludes().isEmpty());
}
 
Example #28
Source File: DbDeployer.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Override
public void doPostDeployAction(DbEnvironment env, final ImmutableList<Change> sourceChanges) {
    if (env.isChecksumDetectionEnabled()) {
        if (!dbChecksumManager.isInitialized()) {
            // need this check done here to account for existing clients
            dbChecksumManager.initialize();
        }

        dbChecksumManager.applyChecksumDiffs(Predicates.and(getPlatformInclusionPredicate(env), getSourceChangesInclusionPredicate(env, sourceChanges)));
    }
}
 
Example #29
Source File: RerunnableChangeParserTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void readSimpleFile() throws Exception {
    RerunnableChangeParser parser = new RerunnableChangeParser();
    String fileContent = "\n" +
            "mycontent" +
            "";

    ImmutableList<ChangeInput> changes = parser.value(mock(ChangeType.class), null, fileContent, objectName, "schema", null);
    Verify.assertSize(1, changes);
    ChangeInput change = changes.get(0);

    assertEquals(objectName, change.getObjectName());
    assertEquals("\nmycontent", change.getContent());
    assertEquals(null, change.getDropContent());
}
 
Example #30
Source File: ChangeRestrictionsReaderTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void testIncludePlatforms() {
    ImmutableList<ArtifactRestrictions> restrictions = this.restrictionsReader.valueOf(
            this.doc(TextMarkupDocumentReader.TAG_METADATA, null,
                    Maps.immutable.with("includePlatforms", "DB2,SYBASE_ASE"))
    );
    assertEquals(1, restrictions.size());
    assertThat(restrictions.getFirst(), instanceOf(ArtifactPlatformRestrictions.class));
    assertEquals(UnifiedSet.newSetWith("DB2", "SYBASE_ASE"), restrictions.getFirst().getIncludes());
    assertTrue(restrictions.getFirst().getExcludes().isEmpty());
}