List of usage examples for com.google.common.collect ImmutableSet.Builder addAll
boolean addAll(Collection<? extends E> c);
From source file:org.openspotlight.storage.mongodb.MongoStorageSessionImpl.java
@Override public Iterable<StorageNode> search(final NodeCriteria criteria) throws Exception, IllegalStateException { checkNotNull("criteria", criteria); final DBObject criteriaAsObj = new BasicDBObject(); for (final NodeCriteriaItem c : criteria.getCriteriaItems()) { if (c instanceof PropertyCriteriaItem) { final PropertyCriteriaItem p = (PropertyCriteriaItem) c; criteriaAsObj.put(INDEXED + "." + p.getPropertyName(), p.getValue() == null ? NULL_VALUE : p.getValue()); }/*from w ww .j av a 2 s .c o m*/ if (c instanceof PropertyContainsString) { final PropertyContainsString p = (PropertyContainsString) c; criteriaAsObj.put(INDEXED + "." + p.getPropertyName(), Pattern.compile("(.*)" + beforeRegex(p.getValue()) + "(.*)")); } if (c instanceof PropertyStartsWithString) { final PropertyStartsWithString p = (PropertyStartsWithString) c; criteriaAsObj.put(INDEXED + "." + p.getPropertyName(), Pattern.compile("^" + beforeRegex(p.getValue()) + "(.*)")); } if (c instanceof PropertyEndsWithString) { final PropertyEndsWithString p = (PropertyEndsWithString) c; criteriaAsObj.put(INDEXED + "." + p.getPropertyName(), Pattern.compile("(.*)" + beforeRegex(p.getValue()) + "$")); } if (c instanceof NodeKeyCriteriaItem) { final NodeKeyCriteriaItem uniqueCriteria = (NodeKeyCriteriaItem) c; criteriaAsObj.put(ID, uniqueCriteria.getValue().getKeyAsString()); } if (c instanceof NodeKeyAsStringCriteriaItem) { final NodeKeyAsStringCriteriaItem uniqueCriteria = (NodeKeyAsStringCriteriaItem) c; criteriaAsObj.put(ID, uniqueCriteria.getKeyAsString()); } if (c instanceof CompositeKeyCriteriaItem) { final CompositeKeyCriteriaItem uniqueCriteria = (CompositeKeyCriteriaItem) c; final String localHash = uniqueCriteria.getValue().getKeyAsString(); criteriaAsObj.put(LOCAL_ID, localHash); } } final ImmutableSet.Builder<String> nodeNamesBuilder = ImmutableSet.builder(); if (criteria.getNodeType() != null) { nodeNamesBuilder.add(criteria.getNodeType()); } else { nodeNamesBuilder.addAll(getCachedDbForPartition(criteria.getPartition()).getCollectionNames()); } final List<Iterable<DBObject>> dbCursors = newLinkedList(); for (final String s : nodeNamesBuilder.build()) { final DBCursor resultAsDbObject = getCachedCollection(criteria.getPartition(), s).find(criteriaAsObj); dbCursors.add(resultAsDbObject); } final IteratorBuilder.SimpleIteratorBuilder<StorageNode, DBObject> b = IteratorBuilder .createIteratorBuilder(); b.withConverter(new IteratorBuilder.Converter<StorageNode, DBObject>() { @Override public StorageNode convert(final DBObject nodeEntry) throws Exception { return convertToNode(criteria.getPartition(), nodeEntry); } }); return b.withItems(SLCollections.<DBObject>iterableOfAll(dbCursors)).andBuild(); }
From source file:com.facebook.presto.hive.metastore.CachingHiveMetastore.java
@Override public Set<HivePrivilege> getDatabasePrivileges(String user, String databaseName) { ImmutableSet.Builder<HivePrivilege> privileges = ImmutableSet.builder(); if (isDatabaseOwner(user, databaseName)) { privileges.add(OWNERSHIP);// w ww. ja va 2 s . c o m } privileges.addAll( getPrivileges(user, new HiveObjectRef(HiveObjectType.DATABASE, databaseName, null, null, null))); return privileges.build(); }
From source file:com.facebook.presto.hive.metastore.CachingHiveMetastore.java
private Set<HivePrivilege> loadTablePrivileges(String user, String databaseName, String tableName) { ImmutableSet.Builder<HivePrivilege> privileges = ImmutableSet.builder(); if (isTableOwner(user, databaseName, tableName)) { privileges.add(OWNERSHIP);//from w w w. java2 s .co m } privileges.addAll( getPrivileges(user, new HiveObjectRef(HiveObjectType.TABLE, databaseName, tableName, null, null))); return privileges.build(); }
From source file:com.facebook.buck.rules.TargetNodeFactory.java
@SuppressWarnings("unchecked") public <T, U extends Description<T>> TargetNode<T, U> create(HashCode rawInputsHashCode, U description, T constructorArg, ProjectFilesystem filesystem, BuildTarget buildTarget, ImmutableSet<BuildTarget> declaredDeps, ImmutableSet<VisibilityPattern> visibilityPatterns, CellPathResolver cellRoots) throws NoSuchBuildTargetException { ImmutableSortedSet.Builder<BuildTarget> extraDepsBuilder = ImmutableSortedSet.naturalOrder(); ImmutableSet.Builder<Path> pathsBuilder = ImmutableSet.builder(); // Scan the input to find possible BuildTargets, necessary for loading dependent rules. T arg = description.createUnpopulatedConstructorArg(); for (Field field : arg.getClass().getFields()) { ParamInfo info = new ParamInfo(typeCoercerFactory, arg.getClass(), field); if (info.isDep() && info.isInput() && info.hasElementTypes(BuildTarget.class, SourcePath.class, Path.class)) { detectBuildTargetsAndPathsForConstructorArg(extraDepsBuilder, pathsBuilder, info, constructorArg); }//from w ww. ja va2s. com } if (description instanceof ImplicitDepsInferringDescription) { extraDepsBuilder.addAll(((ImplicitDepsInferringDescription<T>) description) .findDepsForTargetFromConstructorArgs(buildTarget, cellRoots, constructorArg)); } if (description instanceof ImplicitInputsInferringDescription) { pathsBuilder.addAll(((ImplicitInputsInferringDescription<T>) description) .inferInputsFromConstructorArgs(buildTarget.getUnflavoredBuildTarget(), constructorArg)); } return new TargetNode<>(this, rawInputsHashCode, description, constructorArg, filesystem, buildTarget, declaredDeps, ImmutableSortedSet.copyOf(Sets.difference(extraDepsBuilder.build(), declaredDeps)), visibilityPatterns, pathsBuilder.build(), cellRoots, Optional.empty()); }
From source file:com.facebook.presto.hive.metastore.ThriftHiveMetastore.java
private Set<HivePrivilegeInfo> getRolePrivileges(HivePrincipal hivePrincipal, HiveObjectRef hiveObjectRef) { checkArgument(hivePrincipal.getPrincipalType() == ROLE, "Expected ROLE PrincipalType but found USER"); try {// ww w . j a v a 2s .co m return retry().stopOnIllegalExceptions().run("getListPrivileges", stats.getListPrivileges().wrap(() -> { try (HiveMetastoreClient client = clientProvider.createMetastoreClient()) { ImmutableSet.Builder<HivePrivilegeInfo> privileges = ImmutableSet.builder(); List<HiveObjectPrivilege> hiveObjectPrivilegeList = client.listPrivileges( hivePrincipal.getPrincipalName(), hivePrincipal.getPrincipalType(), hiveObjectRef); for (HiveObjectPrivilege hiveObjectPrivilege : hiveObjectPrivilegeList) { privileges.addAll(parsePrivilege(hiveObjectPrivilege.getGrantInfo())); } return privileges.build(); } })); } catch (TException e) { throw new PrestoException(HIVE_METASTORE_ERROR, e); } catch (Exception e) { throw propagate(e); } }
From source file:org.fcrepo.kernel.utils.impl.InfinispanCacheStoreEntry.java
@Override public Collection<FixityResult> checkFixity(final URI checksum, final long size) throws RepositoryException { final BinaryKey key = binaryKey(); final ImmutableSet.Builder<FixityResult> fixityResults = new ImmutableSet.Builder<>(); if (store().hasBinary(key)) { final String dataKey = dataKeyFor(key); final DistributedFixityCheck task = new DistributedFixityCheck(dataKey); final List<Future<Collection<FixityResult>>> futures = clusterExecutor().submitEverywhere(task, dataKey + "-0"); while (!futures.isEmpty()) { final Iterator<Future<Collection<FixityResult>>> iterator = futures.iterator(); while (iterator.hasNext()) { final Future<Collection<FixityResult>> future = iterator.next(); try { final Collection<FixityResult> result = future.get(100, MILLISECONDS); iterator.remove();/* w ww .j av a 2s .c o m*/ for (final FixityResult fixityResult : result) { setFixityStatus(fixityResult, size, checksum); } fixityResults.addAll(result); } catch (final TimeoutException e) { LOGGER.trace("Going to retry cluster transform after timeout", e); } catch (InterruptedException | ExecutionException e) { throw propagate(e); } } } } return fixityResults.build(); }
From source file:io.prestosql.plugin.raptor.legacy.RaptorMetadata.java
@Override public void finishDelete(ConnectorSession session, ConnectorTableHandle tableHandle, Collection<Slice> fragments) { RaptorTableHandle table = (RaptorTableHandle) tableHandle; long transactionId = table.getTransactionId().getAsLong(); long tableId = table.getTableId(); List<ColumnInfo> columns = getColumnHandles(session, tableHandle).values().stream() .map(RaptorColumnHandle.class::cast).map(ColumnInfo::fromHandle).collect(toList()); ImmutableSet.Builder<UUID> oldShardUuidsBuilder = ImmutableSet.builder(); ImmutableList.Builder<ShardInfo> newShardsBuilder = ImmutableList.builder(); fragments.stream().map(fragment -> SHARD_DELTA_CODEC.fromJson(fragment.getBytes())).forEach(delta -> { oldShardUuidsBuilder.addAll(delta.getOldShardUuids()); newShardsBuilder.addAll(delta.getNewShards()); });/*w w w . j ava2 s . c o m*/ Set<UUID> oldShardUuids = oldShardUuidsBuilder.build(); List<ShardInfo> newShards = newShardsBuilder.build(); OptionalLong updateTime = OptionalLong.of(session.getStartTime()); log.info("Finishing delete for tableId %s (removed: %s, rewritten: %s)", tableId, oldShardUuids.size() - newShards.size(), newShards.size()); shardManager.replaceShardUuids(transactionId, tableId, columns, oldShardUuids, newShards, updateTime); clearRollback(); }
From source file:com.facebook.buck.android.AndroidBinary.java
/** * @return the resulting set of ProGuarded classpath entries to dex. *//*from w ww .j a va2 s.co m*/ @VisibleForTesting ImmutableSet<Path> addProguardCommands(Set<Path> classpathEntriesToDex, Set<Path> depsProguardConfigs, ImmutableList.Builder<Step> steps, Set<Path> resDirectories, BuildableContext buildableContext) { final ImmutableSetMultimap<JavaLibrary, Path> classpathEntriesMap = getTransitiveClasspathEntries(); ImmutableSet.Builder<Path> additionalLibraryJarsForProguardBuilder = ImmutableSet.builder(); for (JavaLibrary buildRule : rulesToExcludeFromDex) { additionalLibraryJarsForProguardBuilder.addAll(classpathEntriesMap.get(buildRule)); } // Clean out the directory for generated ProGuard files. Path proguardDirectory = getPathForProGuardDirectory(); steps.add(new MakeCleanDirectoryStep(proguardDirectory)); // Generate a file of ProGuard config options using aapt. Path generatedProGuardConfig = proguardDirectory.resolve("proguard.txt"); GenProGuardConfigStep genProGuardConfig = new GenProGuardConfigStep( aaptPackageResources.getAndroidManifestXml(), resDirectories, generatedProGuardConfig); steps.add(genProGuardConfig); // Create list of proguard Configs for the app project and its dependencies ImmutableSet.Builder<Path> proguardConfigsBuilder = ImmutableSet.builder(); proguardConfigsBuilder.addAll(depsProguardConfigs); if (proguardConfig.isPresent()) { proguardConfigsBuilder.add(proguardConfig.get().resolve()); } // Transform our input classpath to a set of output locations for each input classpath. // TODO(devjasta): the output path we choose is the result of a slicing function against // input classpath. This is fragile and should be replaced with knowledge of the BuildTarget. final ImmutableMap<Path, Path> inputOutputEntries = FluentIterable.from(classpathEntriesToDex) .toMap(new Function<Path, Path>() { @Override public Path apply(Path classpathEntry) { return getProguardOutputFromInputClasspath(classpathEntry); } }); // Run ProGuard on the classpath entries. // TODO(user): ProGuardObfuscateStep's final argument should be a Path Step obfuscateCommand = ProGuardObfuscateStep.create(proguardJarOverride, generatedProGuardConfig, proguardConfigsBuilder.build(), useAndroidProguardConfigWithOptimizations, optimizationPasses, inputOutputEntries, additionalLibraryJarsForProguardBuilder.build(), proguardDirectory, buildableContext); steps.add(obfuscateCommand); // Apply the transformed inputs to the classpath (this will modify deps.classpathEntriesToDex // so that we're now dexing the proguarded artifacts). return ImmutableSet.copyOf(inputOutputEntries.values()); }
From source file:org.obm.provisioning.dao.GroupDaoJdbcImpl.java
private Set<Integer> getAllUserIdsOfGroup(Connection con, Group.Id groupId) throws SQLException { PreparedStatement ps = null;//from w w w . j a v a2 s . co m ResultSet rs = null; ImmutableSet.Builder<Integer> users = ImmutableSet.builder(); try { ps = con.prepareStatement("SELECT groupgroup_child_id FROM GroupGroup WHERE groupgroup_parent_id = ?"); ps.setInt(1, groupId.getId()); rs = ps.executeQuery(); while (rs.next()) { users.addAll(getAllUserIdsOfGroup(con, Group.Id.valueOf(rs.getInt("groupgroup_child_id")))); } ps.close(); ps = con.prepareStatement("SELECT userobmgroup_userobm_id FROM UserObmGroup " + "LEFT JOIN UserObm ON userobm_id = userobmgroup_userobm_id " + "WHERE userobmgroup_group_id = ? AND userobm_archive = 0"); ps.setInt(1, groupId.getId()); rs = ps.executeQuery(); while (rs.next()) { users.add(rs.getInt("userobmgroup_userobm_id")); } } finally { JDBCUtils.cleanup(null, ps, rs); } return users.build(); }
From source file:org.fcrepo.kernel.impl.utils.impl.InfinispanCacheStoreEntry.java
@Override public Collection<FixityResult> checkFixity(final String algorithm) { final BinaryKey key = binaryKey(); final ImmutableSet.Builder<FixityResult> fixityResults = new ImmutableSet.Builder<>(); if (store().hasBinary(key)) { final String dataKey = InfinispanUtils.dataKeyFrom((InfinispanBinaryStore) store(), key); final ChunkBinaryMetadata metadata = InfinispanUtils.getMetadata((InfinispanBinaryStore) store(), key); final DistributedFixityCheck task = new DistributedFixityCheck(dataKey, algorithm, metadata.getChunkSize(), metadata.getLength()); final List<Future<Collection<FixityResult>>> futures = clusterExecutor().submitEverywhere(task, dataKey + "-0"); while (!futures.isEmpty()) { final Iterator<Future<Collection<FixityResult>>> iterator = futures.iterator(); while (iterator.hasNext()) { final Future<Collection<FixityResult>> future = iterator.next(); try { final Collection<FixityResult> result = future.get(100, MILLISECONDS); iterator.remove();/*from w ww . ja v a 2 s .co m*/ fixityResults.addAll(result); } catch (final TimeoutException e) { LOGGER.trace("Going to retry cluster transform after timeout", e); } catch (InterruptedException | ExecutionException e) { throw propagate(e); } } } } return fixityResults.build(); }