List of usage examples for java.util LinkedHashSet size
int size();
From source file:org.apache.tajo.engine.planner.rewrite.ProjectionPushDownRule.java
public LogicalNode visitScan(Context context, LogicalPlan plan, LogicalPlan.QueryBlock block, ScanNode node, Stack<LogicalNode> stack) throws PlanningException { Context newContext = new Context(context); Target[] targets;/*w w w . j av a2 s.c om*/ if (node.hasTargets()) { targets = node.getTargets(); } else { targets = PlannerUtil.schemaToTargets(node.getTableSchema()); } LinkedHashSet<Target> projectedTargets = Sets.newLinkedHashSet(); for (Iterator<Target> it = getFilteredTarget(targets, newContext.requiredSet); it.hasNext();) { Target target = it.next(); newContext.addExpr(target); } for (Iterator<Target> it = context.targetListMgr.getFilteredTargets(newContext.requiredSet); it .hasNext();) { Target target = it.next(); if (LogicalPlanner.checkIfBeEvaluatedAtRelation(block, target.getEvalTree(), node)) { projectedTargets.add(target); newContext.targetListMgr.markAsEvaluated(target); } } node.setTargets(projectedTargets.toArray(new Target[projectedTargets.size()])); LogicalPlanner.verifyProjectedFields(block, node); return node; }
From source file:org.apache.tajo.engine.planner.rewrite.ProjectionPushDownRule.java
@Override public LogicalNode visitPartitionedTableScan(Context context, LogicalPlan plan, LogicalPlan.QueryBlock block, PartitionedTableScanNode node, Stack<LogicalNode> stack) throws PlanningException { Context newContext = new Context(context); Target[] targets;// ww w. j a v a 2 s. c o m if (node.hasTargets()) { targets = node.getTargets(); } else { targets = PlannerUtil.schemaToTargets(node.getOutSchema()); } LinkedHashSet<Target> projectedTargets = Sets.newLinkedHashSet(); for (Iterator<Target> it = getFilteredTarget(targets, newContext.requiredSet); it.hasNext();) { Target target = it.next(); newContext.addExpr(target); } for (Iterator<Target> it = context.targetListMgr.getFilteredTargets(newContext.requiredSet); it .hasNext();) { Target target = it.next(); if (LogicalPlanner.checkIfBeEvaluatedAtRelation(block, target.getEvalTree(), node)) { projectedTargets.add(target); newContext.targetListMgr.markAsEvaluated(target); } } node.setTargets(projectedTargets.toArray(new Target[projectedTargets.size()])); LogicalPlanner.verifyProjectedFields(block, node); return node; }
From source file:org.apache.tajo.engine.planner.rewrite.ProjectionPushDownRule.java
@Override public LogicalNode visitTableSubQuery(Context upperContext, LogicalPlan plan, LogicalPlan.QueryBlock block, TableSubQueryNode node, Stack<LogicalNode> stack) throws PlanningException { Context childContext = new Context(plan, upperContext.requiredSet); stack.push(node);/*from w ww. j ava 2s . co m*/ LogicalNode child = super.visitTableSubQuery(childContext, plan, block, node, stack); node.setSubQuery(child); stack.pop(); Target[] targets; if (node.hasTargets()) { targets = node.getTargets(); } else { targets = PlannerUtil.schemaToTargets(node.getOutSchema()); } LinkedHashSet<Target> projectedTargets = Sets.newLinkedHashSet(); for (Iterator<Target> it = getFilteredTarget(targets, upperContext.requiredSet); it.hasNext();) { Target target = it.next(); upperContext.addExpr(target); } for (Iterator<Target> it = upperContext.targetListMgr.getFilteredTargets(upperContext.requiredSet); it .hasNext();) { Target target = it.next(); if (LogicalPlanner.checkIfBeEvaluatedAtRelation(block, target.getEvalTree(), node)) { projectedTargets.add(target); upperContext.targetListMgr.markAsEvaluated(target); } } node.setTargets(projectedTargets.toArray(new Target[projectedTargets.size()])); LogicalPlanner.verifyProjectedFields(block, node); return node; }
From source file:org.jahia.taglibs.template.include.ModuleTag.java
protected List<String> contributeTypes(RenderContext renderContext, JCRNodeWrapper node) { if (!"contributemode".equals(renderContext.getEditModeConfigName())) { return null; }/*from www. ja v a2s . c om*/ JCRNodeWrapper contributeNode = null; if (renderContext.getRequest().getAttribute("areaListResource") != null) { contributeNode = (JCRNodeWrapper) renderContext.getRequest().getAttribute("areaListResource"); } try { if (node.hasProperty(Constants.JAHIA_CONTRIBUTE_TYPES)) { contributeNode = node; } if (contributeNode != null && contributeNode.hasProperty(Constants.JAHIA_CONTRIBUTE_TYPES)) { LinkedHashSet<String> l = new LinkedHashSet<String>(); Value[] v = contributeNode.getProperty(Constants.JAHIA_CONTRIBUTE_TYPES).getValues(); if (v.length == 0) { l.add("jmix:editorialContent"); } else { for (Value value : v) { l.add(value.getString()); } } LinkedHashSet<String> subtypes = new LinkedHashSet<String>(); final Set<String> installedModulesWithAllDependencies = renderContext.getSite() .getInstalledModulesWithAllDependencies(); for (String s : l) { ExtendedNodeType nt = NodeTypeRegistry.getInstance().getNodeType(s); if (nt != null) { if (!nt.isAbstract() && !nt.isMixin() && (nt.getTemplatePackage() == null || installedModulesWithAllDependencies.contains(nt.getTemplatePackage().getId()))) { subtypes.add(nt.getName()); } for (ExtendedNodeType subtype : nt.getSubtypesAsList()) { if (!subtype.isAbstract() && !subtype.isMixin() && (subtype.getTemplatePackage() == null || installedModulesWithAllDependencies .contains(subtype.getTemplatePackage().getId()))) { subtypes.add(subtype.getName()); } } } } if (subtypes.size() < 10) { return new ArrayList<String>(subtypes); } return new ArrayList<String>(l); } } catch (RepositoryException e) { logger.error(e.getMessage(), e); } return null; }
From source file:ca.sqlpower.object.SPVariableHelper.java
public Collection<Object> resolveCollection(String key, Object defaultValue) { LinkedHashSet<Object> results = new LinkedHashSet<Object>(); String namespace = getNamespace(key); try {/* www.j ava 2s . c o m*/ if (namespace != null) { List<SPVariableResolver> resolvers = SPResolverRegistry.getResolvers(this.contextSource, namespace); for (SPVariableResolver resolver : resolvers) { if (resolver.resolves(key)) { results.addAll(resolver.resolveCollection(key)); if (!globalCollectionResolve) { break; } } } } else { SPObject node = this.contextSource; while (true) { if (node instanceof SPVariableResolverProvider) { SPVariableResolver resolver = ((SPVariableResolverProvider) node).getVariableResolver(); if (resolver.resolves(key)) { results.addAll(resolver.resolveCollection(key)); if (!globalCollectionResolve) { break; } } } node = node.getParent(); if (node == null) break; } } if (results.size() == 0) { if (defaultValue == null) { return Collections.emptySet(); } else { return Collections.singleton(defaultValue); } } else { return results; } } catch (StackOverflowError soe) { throw new RecursiveVariableException(); } }
From source file:org.springframework.cloud.dataflow.app.launcher.ModuleLauncher.java
public void launchAggregatedModules(List<ModuleLaunchRequest> moduleLaunchRequests, Map<String, String> aggregateArgs) { try {/*from w w w . j av a 2s . c o m*/ List<String> mainClassNames = new ArrayList<>(); LinkedHashSet<URL> jarURLs = new LinkedHashSet<>(); List<String> seenArchives = new ArrayList<>(); final List<String[]> arguments = new ArrayList<>(); final ClassLoader classLoader; if (!(aggregateArgs.containsKey(EXCLUDE_DEPENDENCIES_ARG) || aggregateArgs.containsKey(INCLUDE_DEPENDENCIES_ARG))) { for (ModuleLaunchRequest moduleLaunchRequest : moduleLaunchRequests) { Resource resource = resolveModule(moduleLaunchRequest.getModule()); JarFileArchive jarFileArchive = new JarFileArchive(resource.getFile()); jarURLs.add(jarFileArchive.getUrl()); for (Archive archive : jarFileArchive.getNestedArchives(ArchiveMatchingEntryFilter.FILTER)) { // avoid duplication based on unique JAR names String urlAsString = archive.getUrl().toString(); String jarNameWithExtension = urlAsString.substring(0, urlAsString.lastIndexOf("!/")); String jarNameWithoutExtension = jarNameWithExtension .substring(jarNameWithExtension.lastIndexOf("/") + 1); if (!seenArchives.contains(jarNameWithoutExtension)) { seenArchives.add(jarNameWithoutExtension); jarURLs.add(archive.getUrl()); } } mainClassNames.add(jarFileArchive.getMainClass()); arguments.add(toArgArray(moduleLaunchRequest.getArguments())); } classLoader = ClassloaderUtils.createModuleClassloader(jarURLs.toArray(new URL[jarURLs.size()])); } else { // First, resolve modules and extract main classes - while slightly less efficient than just // doing the same processing after resolution, this ensures that module artifacts are processed // correctly for extracting their main class names. It is not possible in the general case to // identify, after resolution, whether a resource represents a module artifact which was part of the // original request or not. We will include the first module as root and the next as direct dependencies Coordinates root = null; ArrayList<Coordinates> includeCoordinates = new ArrayList<>(); for (ModuleLaunchRequest moduleLaunchRequest : moduleLaunchRequests) { Coordinates moduleCoordinates = toCoordinates(moduleLaunchRequest.getModule()); if (root == null) { root = moduleCoordinates; } else { includeCoordinates.add(toCoordinates(moduleLaunchRequest.getModule())); } Resource moduleResource = resolveModule(moduleLaunchRequest.getModule()); JarFileArchive moduleArchive = new JarFileArchive(moduleResource.getFile()); mainClassNames.add(moduleArchive.getMainClass()); arguments.add(toArgArray(moduleLaunchRequest.getArguments())); } for (String include : StringUtils .commaDelimitedListToStringArray(aggregateArgs.get(INCLUDE_DEPENDENCIES_ARG))) { includeCoordinates.add(toCoordinates(include)); } // Resolve all artifacts - since modules have been specified as direct dependencies, they will take // precedence in the resolution order, ensuring that the already resolved artifacts will be returned as // part of the response. Resource[] libraries = moduleResolver.resolve(root, includeCoordinates.toArray(new Coordinates[includeCoordinates.size()]), StringUtils.commaDelimitedListToStringArray(aggregateArgs.get(EXCLUDE_DEPENDENCIES_ARG))); for (Resource library : libraries) { jarURLs.add(library.getURL()); } classLoader = new URLClassLoader(jarURLs.toArray(new URL[jarURLs.size()])); } final List<Class<?>> mainClasses = new ArrayList<>(); for (String mainClass : mainClassNames) { mainClasses.add(ClassUtils.forName(mainClass, classLoader)); } Runnable moduleAggregatorRunner = new ModuleAggregatorRunner(classLoader, mainClasses, toArgArray(aggregateArgs), arguments); Thread moduleAggregatorRunnerThread = new Thread(moduleAggregatorRunner); moduleAggregatorRunnerThread.setContextClassLoader(classLoader); moduleAggregatorRunnerThread.setName(MODULE_AGGREGATOR_RUNNER_THREAD_NAME); moduleAggregatorRunnerThread.start(); } catch (Exception e) { throw new RuntimeException("failed to start aggregated modules: " + StringUtils.collectionToCommaDelimitedString(moduleLaunchRequests), e); } }
From source file:org.pentaho.reporting.engine.classic.extensions.datasources.mondrian.AbstractMDXDataFactory.java
public String[] getReferencedFields(final String queryName, final DataRow parameters) throws ReportDataFactoryException { final boolean isNewConnection = connection == null; try {//from ww w. j ava 2 s . c o m if (connection == null) { connection = mondrianConnectionProvider.createConnection(computeProperties(parameters), dataSourceProvider.getDataSource()); } } catch (SQLException e) { logger.error(e); throw new ReportDataFactoryException("Failed to create DataSource (SQL Exception - error code: " + e.getErrorCode() + "):" + e.toString(), e); } catch (MondrianException e) { logger.error(e); throw new ReportDataFactoryException("Failed to create DataSource (Mondrian Exception):" + e.toString(), e); } try { if (connection == null) { throw new ReportDataFactoryException("Factory is closed."); } final LinkedHashSet<String> parameter = new LinkedHashSet<String>(); final MDXCompiler compiler = new MDXCompiler(parameters, getLocale()); final String computedQuery = computedQuery(queryName, parameters); final String mdxQuery = compiler.translateAndLookup(computedQuery, parameters); parameter.addAll(compiler.getCollectedParameter()); // Alternatively, JNDI is possible. Maybe even more .. final Query query = connection.parseQuery(mdxQuery); final Parameter[] queryParameters = query.getParameters(); for (int i = 0; i < queryParameters.length; i++) { final Parameter queryParameter = queryParameters[i]; parameter.add(queryParameter.getName()); } if (jdbcUserField != null) { parameter.add(jdbcUserField); } if (roleField != null) { parameter.add(roleField); } parameter.add(DataFactory.QUERY_LIMIT); return parameter.toArray(new String[parameter.size()]); } catch (MondrianException e) { throw new ReportDataFactoryException("Failed to create datasource:" + e.getLocalizedMessage(), e); } finally { if (isNewConnection) { close(); } } }
From source file:org.apache.ws.scout.registry.BusinessLifeCycleManagerImpl.java
public BulkResponse saveServiceBindings(Collection bindings) throws JAXRException { BulkResponseImpl bulk = new BulkResponseImpl(); BindingTemplate[] sbarr = new BindingTemplate[bindings.size()]; LinkedHashSet<Key> coll = new LinkedHashSet<Key>(); Collection<Exception> exceptions = new ArrayList<Exception>(); Iterator iter = bindings.iterator(); int currLoc = 0; while (iter.hasNext()) { try {/*w ww. j a v a 2 s. c o m*/ BindingTemplate bs = ScoutJaxrUddiHelper.getBindingTemplateFromJAXRSB((ServiceBinding) iter.next()); sbarr[currLoc] = bs; currLoc++; } catch (ClassCastException ce) { throw new UnexpectedObjectException(); } } // Save ServiceBinding BindingDetail bd = null; try { bd = (BindingDetail) executeOperation(sbarr, "SAVE_SERVICE_BINDING"); } catch (RegistryException e) { exceptions.add(new SaveException(e.getLocalizedMessage())); bulk.setStatus(JAXRResponse.STATUS_FAILURE); return bulk; } List<BindingTemplate> bindingTemplateList = bd.getBindingTemplate(); sbarr = new BindingTemplate[bindingTemplateList.size()]; bindingTemplateList.toArray(sbarr); for (int i = 0; sbarr != null && i < sbarr.length; i++) { BindingTemplate bt = (BindingTemplate) sbarr[i]; coll.add(new KeyImpl(bt.getBindingKey())); } if (coll.size() > 0) { bulk.setCollection(coll); } bulk.setExceptions(exceptions); return bulk; }
From source file:org.apache.ws.scout.registry.BusinessLifeCycleManagerV3Impl.java
public BulkResponse saveServiceBindings(Collection bindings) throws JAXRException { BulkResponseImpl bulk = new BulkResponseImpl(); BindingTemplate[] sbarr = new BindingTemplate[bindings.size()]; LinkedHashSet<Key> coll = new LinkedHashSet<Key>(); Collection<Exception> exceptions = new ArrayList<Exception>(); Iterator iter = bindings.iterator(); int currLoc = 0; while (iter.hasNext()) { try {//from w w w. j ava 2 s . co m BindingTemplate bs = ScoutJaxrUddiV3Helper .getBindingTemplateFromJAXRSB((ServiceBinding) iter.next()); sbarr[currLoc] = bs; currLoc++; } catch (ClassCastException ce) { throw new UnexpectedObjectException(); } } // Save ServiceBinding BindingDetail bd = null; try { bd = (BindingDetail) executeOperation(sbarr, "SAVE_SERVICE_BINDING"); } catch (RegistryV3Exception e) { exceptions.add(new SaveException(e.getLocalizedMessage())); bulk.setStatus(JAXRResponse.STATUS_FAILURE); return bulk; } List<BindingTemplate> bindingTemplateList = bd.getBindingTemplate(); sbarr = new BindingTemplate[bindingTemplateList.size()]; bindingTemplateList.toArray(sbarr); for (int i = 0; sbarr != null && i < sbarr.length; i++) { BindingTemplate bt = (BindingTemplate) sbarr[i]; coll.add(new KeyImpl(bt.getBindingKey())); } if (coll.size() > 0) { bulk.setCollection(coll); } bulk.setExceptions(exceptions); return bulk; }
From source file:org.apache.tajo.engine.planner.rewrite.ProjectionPushDownRule.java
public LogicalNode visitJoin(Context context, LogicalPlan plan, LogicalPlan.QueryBlock block, JoinNode node, Stack<LogicalNode> stack) throws PlanningException { Context newContext = new Context(context); String joinQualReference = null; if (node.hasJoinQual()) { for (EvalNode eachQual : AlgebraicUtil.toConjunctiveNormalFormArray(node.getJoinQual())) { if (eachQual instanceof BinaryEval) { BinaryEval binaryQual = (BinaryEval) eachQual; for (int i = 0; i < 2; i++) { EvalNode term = binaryQual.getChild(i); pushDownIfComplexTermInJoinCondition(newContext, eachQual, term); }/*from w w w . ja v a 2 s.com*/ } } joinQualReference = newContext.addExpr(node.getJoinQual()); newContext.addNecessaryReferences(node.getJoinQual()); } String[] referenceNames = null; if (node.hasTargets()) { referenceNames = new String[node.getTargets().length]; int i = 0; for (Iterator<Target> it = getFilteredTarget(node.getTargets(), context.requiredSet); it.hasNext();) { Target target = it.next(); referenceNames[i++] = newContext.addExpr(target); } } stack.push(node); LogicalNode left = visit(newContext, plan, block, node.getLeftChild(), stack); LogicalNode right = visit(newContext, plan, block, node.getRightChild(), stack); stack.pop(); Schema merged = SchemaUtil.merge(left.getOutSchema(), right.getOutSchema()); node.setInSchema(merged); if (node.hasJoinQual()) { Target target = context.targetListMgr.getTarget(joinQualReference); if (newContext.targetListMgr.isEvaluated(joinQualReference)) { throw new PlanningException( "Join condition must be evaluated in the proper Join Node: " + joinQualReference); } else { node.setJoinQual(target.getEvalTree()); newContext.targetListMgr.markAsEvaluated(target); } } LinkedHashSet<Target> projectedTargets = Sets.newLinkedHashSet(); for (Iterator<String> it = getFilteredReferences(context.targetListMgr.getNames(), context.requiredSet); it .hasNext();) { String referenceName = it.next(); Target target = context.targetListMgr.getTarget(referenceName); if (context.targetListMgr.isEvaluated(referenceName)) { Target fieldReference = new Target(new FieldEval(target.getNamedColumn())); if (LogicalPlanner.checkIfBeEvaluatedAtJoin(block, fieldReference.getEvalTree(), node, stack.peek().getType() != NodeType.JOIN)) { projectedTargets.add(fieldReference); } } else if (LogicalPlanner.checkIfBeEvaluatedAtJoin(block, target.getEvalTree(), node, stack.peek().getType() != NodeType.JOIN)) { projectedTargets.add(target); context.targetListMgr.markAsEvaluated(target); } } node.setTargets(projectedTargets.toArray(new Target[projectedTargets.size()])); LogicalPlanner.verifyProjectedFields(block, node); return node; }