org.eclipse.collections.api.block.function.Function Java Examples
The following examples show how to use
org.eclipse.collections.api.block.function.Function.
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: ArgsParser.java From obevo with Apache License 2.0 | 6 votes |
public <T> T parse(String[] args, T inputArgs, Function<? super T, String> validationFunction) { try { List<String> extraArgs = Args.parse(inputArgs, args); if (extraArgs.size() > 0) { printUsageAndExit(inputArgs, "Passed in unnecessary args: " + StringUtils.join(extraArgs, "; ")); } String validationMessage = validationFunction.valueOf(inputArgs); if (validationMessage != null) { printUsageAndExit(inputArgs, validationMessage); } } catch (IllegalArgumentException exc) { printUsageAndExit(inputArgs, ExceptionUtils.getStackTrace(exc)); } LOG.info("Arguments parsed: " + inputArgs.toString()); return inputArgs; }
Example #2
Source File: DbEnvironment.java From obevo with Apache License 2.0 | 6 votes |
@Override public String getDisplayString() { String connectionInfo; if (this.getJdbcUrl() != null) { connectionInfo = this.getJdbcUrl(); } else if (this.getDbDataSourceName() != null) { connectionInfo = this.getDbDataSourceName(); } else if (this.getDbServer() != null) { connectionInfo = this.getDbHost() + ":" + this.getDbPort() + "/" + this.getDbServer(); } else { connectionInfo = this.getDbHost() + ":" + this.getDbPort(); } return super.getDisplayString() + ": Connecting to [" + connectionInfo + "] against schemas [" + this.getPhysicalSchemas().collect(new Function<PhysicalSchema, String>() { @Override public String valueOf(PhysicalSchema physicalSchema) { return physicalSchema.getPhysicalName(); } }).makeString(",") + "]"; }
Example #3
Source File: LookupPredicateBuilder.java From obevo with Apache License 2.0 | 6 votes |
public static Predicates<? super String> convert(ImmutableCollection<String> patterns) { if (patterns == null) { return Predicates.alwaysTrue(); } PartitionIterable<String> wildcardPartition = patterns.partition(Predicates.or(StringPredicates.contains("*"), StringPredicates.contains("%"))); RichIterable<String> wildcardPatterns = wildcardPartition.getSelected(); RichIterable<WildcardPatternIndex> wildcardPatternIndexes = wildcardPatterns.collect(new Function<String, WildcardPatternIndex>() { @Override public WildcardPatternIndex valueOf(String patternString) { return new WildcardPatternIndex(patternString); } }); RichIterable<String> lookupPatterns = wildcardPartition.getRejected(); LookupIndex lookupIndex = lookupPatterns.notEmpty() ? new LookupIndex(lookupPatterns.toSet().toImmutable()) : null; MutableList<Index> indexes = Lists.mutable.empty(); if (lookupIndex != null) { indexes.add(lookupIndex); } indexes.withAll(wildcardPatternIndexes); return Predicates.or(indexes); }
Example #4
Source File: DaTableImpl.java From obevo with Apache License 2.0 | 6 votes |
@Override public ImmutableCollection<DaIndex> getIndices() { return CollectionAdapter.adapt(table.getIndexes()) .collect(new Function<Index, DaIndex>() { @Override public DaIndex valueOf(Index object) { return new DaIndexImpl(object, schemaStrategy, extraIndexInfoMap.get(object.getName())); } }) .reject(new Predicate<DaIndex>() { @Override public boolean accept(DaIndex index) { ExtraIndexInfo extraIndexInfo = extraIndexInfoMap.get(index.getName()); return extraIndexInfo != null && extraIndexInfo.isConstraint(); } }) .toImmutable(); }
Example #5
Source File: DefaultRollbackDetector.java From obevo with Apache License 2.0 | 6 votes |
/** * Returns true/false if all the schemas in the environment either need rollback (true) or don't (false). * * If some do and some don't, an exception is thrown. */ @Override public boolean determineRollback(final String productVersion, final ImmutableSet<String> schemas, final DeployExecutionDao deployExecutionDao) { MutableMap<String, Boolean> rollbackFlags = schemas.toMap( Functions.<String>getPassThru(), new Function<String, Boolean>() { @Override public Boolean valueOf(String schema) { LOG.info("Checking rollback status on Product Version {} and Schema {}", productVersion, schema); return DefaultRollbackDetector.this.determineRollbackForSchema(productVersion, deployExecutionDao.getDeployExecutions(schema)); } } ); MutableSet<Boolean> values = rollbackFlags.valuesView().toSet(); if (values.size() > 1) { MutableSetMultimap<Boolean, String> schemasByRollbackFlag = rollbackFlags.flip(); MutableSet<String> rollbackSchemas = schemasByRollbackFlag.get(Boolean.TRUE); MutableSet<String> nonrollbackSchemas = schemasByRollbackFlag.get(Boolean.FALSE); throw new IllegalArgumentException("The following schemas were calculated for rollback [" + rollbackSchemas + "], though the rest were not [" + nonrollbackSchemas + "]; cannot proceed in this mixed mode"); } return values.iterator().next().booleanValue(); }
Example #6
Source File: DeepCompareUtil.java From obevo with Apache License 2.0 | 6 votes |
private MutableCollection<ClassCompareInfo> getClassCompareInfos(final Class clazz) { if (!this.classCompareInfoMap.containsKey(clazz)) { // We may have defined the comparison on a generalization (interface or superclass), so we check if there // are any compatible classes to check RichIterable<Class> realizedClasses = this.classCompareInfoMap.keysView().select(new Predicate<Class>() { @Override public boolean accept(Class each) { return each.isAssignableFrom(clazz); } }); RichIterable<ClassCompareInfo> realizedClassCompareInfos = realizedClasses .flatCollect(new Function<Class, MutableCollection<ClassCompareInfo>>() { @Override public MutableCollection<ClassCompareInfo> valueOf(Class realizedClass) { return DeepCompareUtil.this.classCompareInfoMap.get(realizedClass); } }); this.classCompareInfoMap.putAll(clazz, realizedClassCompareInfos.toList()); } return this.classCompareInfoMap.get(clazz); }
Example #7
Source File: DaCatalogImpl.java From obevo with Apache License 2.0 | 6 votes |
public DaCatalogImpl(Catalog delegate, SchemaStrategy schemaStrategy, ImmutableCollection<DaUserType> userTypes, ImmutableCollection<DaRule> rules, ImmutableCollection<RuleBinding> ruleBindings, ImmutableCollection<DaRoutine> extraRoutines, Multimap<String, ExtraIndexInfo> extraIndexes, ImmutableCollection<ExtraRerunnableInfo> extraViewInfo, DaRoutineType routineOverrideValue, ImmutableCollection<DaPackage> packages) { this.delegate = Validate.notNull(delegate); this.userTypes = userTypes; this.rules = rules; this.ruleBindings = ruleBindings; this.extraRoutines = extraRoutines; this.extraIndexes = extraIndexes; this.extraViewInfoMap = extraViewInfo.groupByUniqueKey(new Function<ExtraRerunnableInfo, String>() { @Override public String valueOf(ExtraRerunnableInfo extraRerunnableInfo) { return extraRerunnableInfo.getName(); } }); this.routineOverrideValue = routineOverrideValue; this.schemaStrategy = schemaStrategy; this.packages = packages; }
Example #8
Source File: SybaseAseMetadataDialect.java From obevo with Apache License 2.0 | 6 votes |
@Override public ImmutableCollection<DaUserType> searchUserTypes(final DaSchema schema, Connection conn) throws SQLException { ImmutableList<Map<String, Object>> maps = ListAdapter.adapt(jdbc.query(conn, "SELECT s1.name as USER_TYPE_NAME\n" + "FROM " + schema.getName() + "..systypes s1\n" + " , " + schema.getName() + "..sysusers sch\n" + "WHERE s1.usertype>100 " + "AND s1.uid = sch.uid and sch.name = '" + schema.getSubschemaName() + "' " , 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 #9
Source File: DefaultRollbackDetectorTest.java From obevo with Apache License 2.0 | 6 votes |
@Test public void testGetActiveDeploymentsOnNormalCase() throws Exception { assertEquals(Lists.immutable.with(1L), rollbackDetector.getActiveDeployments(Sets.immutable.with( newExecution(1, "a") )).collect(new Function<DeployExecution, Long>() { @Override public Long valueOf(DeployExecution deployExecution1) { return deployExecution1.getId(); } })); assertEquals(Lists.immutable.with(1L, 2L, 3L), rollbackDetector.getActiveDeployments(Sets.immutable.with( newExecution(1, "a") , newExecution(2, "b") , newExecution(3, "c") )).collect(new Function<DeployExecution, Long>() { @Override public Long valueOf(DeployExecution deployExecution) { return deployExecution.getId(); } })); }
Example #10
Source File: Environment.java From obevo with Apache License 2.0 | 6 votes |
public RichIterable<FileObject> getSourceDirs() { if (this.sourceDirs == null) { // only keep the distinct list of files here LinkedHashSet<FileObject> fileObjects = new LinkedHashSet<FileObject>(); if (coreSourcePath != null) { fileObjects.add(coreSourcePath); } if (additionalSourceDirs != null) { fileObjects.addAll(additionalSourceDirs.flatCollect(new Function<String, Iterable<FileObject>>() { @Override public Iterable<FileObject> valueOf(String path) { MutableList<FileObject> resolvedFileObjects = Lists.mutable.empty(); for (FileResolverStrategy fileResolverStrategy : fileResolverStrategies) { resolvedFileObjects.addAllIterable(fileResolverStrategy.resolveFileObjects(path)); } if (resolvedFileObjects.isEmpty()) { throw new IllegalArgumentException("Unable to find the given path [" + path + "] via any of the fileResolverStrategies:" + fileResolverStrategies.makeString(", ")); } return resolvedFileObjects; } }).toList()); } this.sourceDirs = Lists.mutable.withAll(fileObjects); } return this.sourceDirs; }
Example #11
Source File: HsqlMetadataDialect.java From obevo with Apache License 2.0 | 6 votes |
@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: DbEnvironmentCleaner.java From obevo with Apache License 2.0 | 6 votes |
private ImmutableCollection<DbCleanCommand> getTableDrops(DaCatalog database, final PhysicalSchema physicalSchema) { final ChangeType viewType = this.env.getPlatform().getChangeType(ChangeType.VIEW_STR); final ChangeType fkType = this.env.getPlatform().getChangeType(ChangeType.FOREIGN_KEY_STR); final ChangeType tableType = this.env.getPlatform().getChangeType(ChangeType.TABLE_STR); return database.getTables().flatCollect(new Function<DaTable, Iterable<DbCleanCommand>>() { @Override public Iterable<DbCleanCommand> valueOf(DaTable table) { if (table.isView()) { return Lists.immutable.with(new DbCleanCommand(physicalSchema, viewType, table.getName())); } else { MutableList<DbCleanCommand> cleanCommands = Lists.mutable.empty(); for (DaForeignKey foreignKey : table.getImportedForeignKeys()) { cleanCommands.add(new DbCleanCommand(physicalSchema, fkType, table.getName(), "ALTER TABLE " + table.getName() + " DROP CONSTRAINT " + foreignKey.getName())); } cleanCommands.add(new DbCleanCommand(physicalSchema, tableType, table.getName())); return cleanCommands; } } }); }
Example #13
Source File: TestTupleTempTableCreationFailure.java From reladomo with Apache License 2.0 | 6 votes |
private void runListQueryAcrossTwoSources() { IntHashSet intHashSet = new IntHashSet(); for (int i=1;i>-1007;i--) { intHashSet.add(i); } Operation op = AccountTransactionFinder.transactionId().notIn(intHashSet).and(AccountTransactionFinder.deskId().in(UnifiedSet.newSetWith("A", "B"))); AccountTransactionList list = new AccountTransactionList(op); // Assert not only that the SQL execution does not fail but also that the in-clause is resolved correctly (upon retry) to retrieve the correct results assertEquals(4, list.size()); Collection<String> tranIds = Iterate.collect(list, new Function<AccountTransaction, String>() { @Override public String valueOf(AccountTransaction tran) { return tran.getDeskId() + ":" + tran.getTransactionId(); } }); assertEquals(4, tranIds.size()); assertTrue(tranIds.contains("A:100")); assertTrue(tranIds.contains("A:1000")); assertTrue(tranIds.contains("B:10000")); assertTrue(tranIds.contains("B:100000")); }
Example #14
Source File: DefaultRollbackDetector.java From obevo with Apache License 2.0 | 6 votes |
private void logDeployExecutions(ImmutableCollection<DeployExecution> deployExecutions, String message) { if (LOG.isInfoEnabled()) { LOG.info("Found {} {} for this schema", deployExecutions.size(), message); if (LOG.isDebugEnabled()) { for (DeployExecution deployExecution : deployExecutions.toSortedListBy(new Function<DeployExecution, Long>() { @Override public Long valueOf(DeployExecution deployExecution1) { return deployExecution1.getId(); } })) { LOG.debug("Execution ID={}, Version Name={}, Deploy Time={}, Rollback={}", deployExecution.getId(), getDeployVersion(deployExecution), deployExecution.getDeployTime(), deployExecution.isRollback()); } } } }
Example #15
Source File: DbDeployer.java From obevo with Apache License 2.0 | 6 votes |
private ChecksumEntryInclusionPredicate createLookupIndexForObjectType(DbEnvironment env, ImmutableList<Change> sourceChanges, final String changeTypeName) { LookupIndex objectTypeIndex = new LookupIndex(Sets.immutable.with(changeTypeName)); ImmutableList<Change> objectTypeChanges = sourceChanges.select(new Predicate<Change>() { @Override public boolean accept(Change it) { return it.getChangeTypeName().equals(changeTypeName); } }); MutableSet<String> objectNames = objectTypeChanges.collect(new Function<Change, String>() { @Override public String valueOf(Change change) { return change.getObjectName(); } }).collect(env.getPlatform().convertDbObjectName()).toSet(); LookupIndex objectNameIndex = new LookupIndex(objectNames.toImmutable()); return new ChecksumEntryInclusionPredicate( Lists.immutable.with(objectTypeIndex), Lists.immutable.with(objectNameIndex) ); }
Example #16
Source File: DbDeployer.java From obevo with Apache License 2.0 | 6 votes |
private Predicate<? super ChecksumEntry> getPlatformInclusionPredicate(DbEnvironment env) { // 1) exclude those tables that are excluded by default from source code, e.g. explain tables or others that users configure ImmutableSet<Predicate<? super ChecksumEntry>> schemaObjectNamePredicates = env.getSchemas().collect(new Function<Schema, Predicate<? super ChecksumEntry>>() { @Override public Predicate<? super ChecksumEntry> valueOf(Schema schema) { return schema.getObjectExclusionPredicateBuilder().build(ChecksumEntry.TO_OBJECT_TYPE, ChecksumEntry.TO_NAME1); } }); // 2) exclude the audit tables MutableMultimap<String, String> tablesToExclude = Multimaps.mutable.set.empty(); tablesToExclude.putAll(ChangeType.TABLE_STR, Sets.immutable.with( env.getPlatform().convertDbObjectName().valueOf(getArtifactDeployerDao().getAuditContainerName()), env.getPlatform().convertDbObjectName().valueOf(dbChecksumManager.getChecksumContainerName()), env.getPlatform().convertDbObjectName().valueOf(getDeployExecutionDao().getExecutionContainerName()), env.getPlatform().convertDbObjectName().valueOf(getDeployExecutionDao().getExecutionAttributeContainerName()) )); ObjectTypeAndNamePredicateBuilder auditTablePredicateBuilder = new ObjectTypeAndNamePredicateBuilder(tablesToExclude.toImmutable(), ObjectTypeAndNamePredicateBuilder.FilterType.EXCLUDE); Predicates<? super ChecksumEntry> auditTablePredicate = auditTablePredicateBuilder.build(ChecksumEntry.TO_OBJECT_TYPE, ChecksumEntry.TO_NAME1); return auditTablePredicate.and(schemaObjectNamePredicates); }
Example #17
Source File: DefaultRollbackDetectorTest.java From obevo with Apache License 2.0 | 6 votes |
/** * This is for some legacy edge cases where the product version column was not consistently updated. */ @Test public void testWithNullVersionNames() throws Exception { assertEquals(Lists.immutable.with(0L, 3L, 7L, 8L), rollbackDetector.getActiveDeployments(Sets.immutable.with( newExecution(0, null) , newExecution(1, "a") , newExecution(2, null) , newExecution(3, "a", true) // we go back to a; hence, erasing the impact of execution #2 , newExecution(4, "c") , newExecution(5, "d") , newExecution(6, null) , newExecution(7, "c", true) , newExecution(8, null) )).collect(new Function<DeployExecution, Long>() { @Override public Long valueOf(DeployExecution deployExecution) { return deployExecution.getId(); } })); }
Example #18
Source File: PostgresqlMetadataDialect.java From obevo with Apache License 2.0 | 6 votes |
@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 #19
Source File: DefaultRollbackDetectorTest.java From obevo with Apache License 2.0 | 6 votes |
@Test public void testGetActiveDeploymentsWithRollback() throws Exception { assertEquals(Lists.immutable.with(3L), rollbackDetector.getActiveDeployments(Sets.immutable.with( newExecution(1, "a") , newExecution(2, "b") , newExecution(3, "a", true) // we go back to a; hence, erasing the impact of b )).collect(new Function<DeployExecution, Long>() { @Override public Long valueOf(DeployExecution deployExecution1) { return deployExecution1.getId(); } })); assertEquals(Lists.immutable.with(3L, 4L, 5L), rollbackDetector.getActiveDeployments(Sets.immutable.with( newExecution(1, "a") , newExecution(2, "b") , newExecution(3, "a", true) // we go back to a; hence, erasing the impact of b , newExecution(4, "b") , newExecution(5, "c") )).collect(new Function<DeployExecution, Long>() { @Override public Long valueOf(DeployExecution deployExecution) { return deployExecution.getId(); } })); }
Example #20
Source File: TableSyncher.java From obevo with Apache License 2.0 | 6 votes |
public void execute(DbFileMergerArgs args) { Configuration config; try { config = new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class) .configure(new Parameters().properties() .setFile(args.getDbMergeConfigFile()) .setListDelimiterHandler(new LegacyListDelimiterHandler(',')) ).getConfiguration(); } catch (ConfigurationException e) { throw new RuntimeException(e); } RichIterable<DbMergeInfo> dbMergeInfos = DbMergeInfo.parseFromProperties(config); RichIterable<TableSyncSide> tableSyncSides = dbMergeInfos.collect(new Function<DbMergeInfo, TableSyncSide>() { @Override public TableSyncSide valueOf(DbMergeInfo dbMergeInfo) { DataSource ds = ds(dbMergeInfo.getDriverClassName(), dbMergeInfo.getUrl(), dbMergeInfo.getUsername(), dbMergeInfo.getPassword()); return new TableSyncSide(ds, PhysicalSchema.parseFromString(dbMergeInfo.getPhysicalSchema())); } }); this.syncSchemaTables(DbPlatformConfiguration.getInstance().valueOf(config.getString("dbType")), tableSyncSides, args.getOutputDir()); }
Example #21
Source File: DefaultRollbackDetector.java From obevo with Apache License 2.0 | 5 votes |
/** * Returns the active deployments from the given list, i.e. removing the impact of those deployments rolled back. * * Logic: * -Play through the history of the DeployExecutions sorting by the ID field * -If a regular deploy is found, push it to the stack * -If a rollback is found, pop items from the stack until we find the corresponding version to be rolled back, and * then add the (new) rollback version to the stack. We assume the prior version must exist; if not, an exception is * thrown. */ @VisibleForTesting ImmutableList<DeployExecution> getActiveDeployments(ImmutableCollection<DeployExecution> deployExecutions) { if (deployExecutions == null) { return Lists.immutable.empty(); } MutableList<DeployExecution> idSortedExecutions = deployExecutions.toSortedListBy(new Function<DeployExecution, Long>() { @Override public Long valueOf(DeployExecution deployExecution) { return deployExecution.getId(); } }); MutableStack<DeployExecution> executionStack = Stacks.mutable.empty(); for (DeployExecution currentExecution : idSortedExecutions) { if (!currentExecution.isRollback()) { executionStack.push(currentExecution); } else { while (true) { if (executionStack.isEmpty()) { throw new IllegalStateException("Found a rollback deployment without the corresponding version: " + getDeployVersion(currentExecution) + ", " + currentExecution); } else { DeployExecution previousExecution = executionStack.pop(); if (getDeployVersion(previousExecution).equals(getDeployVersion(currentExecution))) { executionStack.push(currentExecution); break; } } } } } return executionStack.toList().reverseThis().toImmutable(); }
Example #22
Source File: FieldToColumnMapping.java From obevo with Apache License 2.0 | 5 votes |
public static Function<FieldToColumnMapping, Object> defaultValue() { return new Function<FieldToColumnMapping, Object>() { @Override public Object valueOf(FieldToColumnMapping arg0) { return arg0.getDefaultValue(); } }; }
Example #23
Source File: PlatformConfigReader.java From obevo with Apache License 2.0 | 5 votes |
private MutableList<PropertyInput> readConfigPackages(RichIterable<String> configPackages) { MutableSet<PropertyInput> prioritizedProperties = HashingStrategySets.mutable.of(HashingStrategies.fromFunction(new Function<PropertyInput, URL>() { @Override public URL valueOf(PropertyInput propertyInput) { return propertyInput.getPropertyFilePath(); } })); for (String configPackage : configPackages) { ListIterable<FileObject> fileObjects = FileRetrievalMode.CLASSPATH.resolveFileObjects(configPackage) .flatCollect(new Function<FileObject, Iterable<FileObject>>() { @Override public Iterable<FileObject> valueOf(FileObject object) { return ArrayAdapter.adapt(object.getChildren()); } }); ListIterable<FileObject> propertyFiles = fileObjects .select(new Predicate<FileObject>() { @Override public boolean accept(FileObject it) { return it.getName().getExtension().equals("yaml"); } }); for (FileObject propertyFile : propertyFiles) { HierarchicalConfiguration<ImmutableNode> fileProps = loadPropertiesFromUrl(propertyFile); String configPriorityProp = fileProps.getString(PROP_CONFIG_PRIORITY); if (configPriorityProp != null) { int priority = Integer.parseInt(configPriorityProp); prioritizedProperties.add(new PropertyInput(propertyFile.getName().getBaseName(), propertyFile.getURLDa(), priority, fileProps)); } else { LOG.warn("Property file {} was ignored as it did not contain {} property", propertyFile, PROP_CONFIG_PRIORITY); } } } return prioritizedProperties.toList(); }
Example #24
Source File: AbstractEnvironmentEnricher.java From obevo with Apache License 2.0 | 5 votes |
@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 #25
Source File: DirectoryAssert.java From obevo with Apache License 2.0 | 5 votes |
private static Function<File, String> toRelativePath(final File baseFile) { return new Function<File, String>() { @Override public String valueOf(File object) { return getRelativePath(object, baseFile); } }; }
Example #26
Source File: ObjectTypeAndNamePredicateBuilderTest.java From obevo with Apache License 2.0 | 5 votes |
@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 #27
Source File: TableSyncher.java From obevo with Apache License 2.0 | 5 votes |
private RichIterable<DaIndex> createIdealIndices(RichIterable<DaTable> tables) { Multimap<String, DaIndex> indexMap = tables.flatCollect(DaTable.TO_INDICES).groupBy( new Function<DaIndex, String>() { @Override public String valueOf(DaIndex index) { return index.getName() + ":" + index.getParent().getName(); } } ); return indexMap.multiValuesView().collect(new Function<RichIterable<DaIndex>, DaIndex>() { @Override public DaIndex valueOf(RichIterable<DaIndex> indices) { if (indices.size() == 1) { return indices.getFirst(); } DaIndex candidate = indices.detect(DaIndex::isUnique); if (candidate != null) { return candidate; } candidate = indices.detect(Predicates.attributeEqual(DaIndex::getIndexType, DaIndexType.CLUSTERED)); if (candidate != null) { return candidate; } return indices.getFirst(); } }); }
Example #28
Source File: DaIndexImpl.java From obevo with Apache License 2.0 | 5 votes |
private DaIndexImpl(DependantObject<Table> index, List<? extends Column> columns, SchemaStrategy schemaStrategy, boolean unique, DaIndexType indexType) { this.index = Validate.notNull(index); Validate.notNull(schemaStrategy); this.columns = ListAdapter.adapt(columns) .collect((Function<Column, DaColumn>) object -> new DaColumnImpl(object, schemaStrategy)) .toImmutable(); this.schemaStrategy = Validate.notNull(schemaStrategy); this.unique = unique; this.indexType = indexType; }
Example #29
Source File: FileObject.java From obevo with Apache License 2.0 | 5 votes |
@Override public FileObject[] findFiles(FileSelector selector) { try { return Lists.mutable.with(this.fileObject.findFiles(selector)).collect(new Function<org.apache.commons.vfs2.FileObject, FileObject>() { @Override public FileObject valueOf(org.apache.commons.vfs2.FileObject fileObject1) { return toDaFileObject(fileObject1); } }) .toArray(new FileObject[0]); } catch (FileSystemException e) { throw new VFSFileSystemException(e); } }
Example #30
Source File: DaTableImpl.java From obevo with Apache License 2.0 | 5 votes |
@Override public ImmutableCollection<DaForeignKey> getImportedForeignKeys() { return CollectionAdapter.adapt(table.getImportedForeignKeys()) .collect(new Function<ForeignKey, DaForeignKey>() { @Override public DaForeignKey valueOf(ForeignKey object) { return new DaForeignKeyImpl(object, schemaStrategy); } }).toImmutable(); }