List of usage examples for java.util Map clear
void clear();
From source file:com.evolveum.polygon.connector.hcm.DocumentProcessing.java
private Map<String, Object> modifySchemaAttributeMap(Map<String, Object> schemaAttributeMap) { schemaAttributeMap.clear(); for (String attribute : attrsToGet) { schemaAttributeMap.put(attribute, ""); }/*from www . ja v a2 s . co m*/ return schemaAttributeMap; }
From source file:com.redhat.persistence.oql.Query.java
public Code generate(Root root, boolean oracle) { Generator gen = (Generator) s_generators.get(); gen.init(root);/*from ww w .j a v a2 s .c o m*/ m_query.hash(gen); for (int i = 0; i < m_names.size(); i++) { String name = (String) m_names.get(i); gen.hash(name); Expression e = get(name); e.hash(gen); } Code cached; synchronized (s_cache) { cached = (Code) s_cache.get(gen.getLookupKey()); } if (cached != null) { Code c = cached.resolve(gen.getBindings(), root); return c; } m_query.frame(gen); QFrame qframe = gen.getFrame(m_query); gen.push(qframe); try { for (int i = 0; i < m_names.size(); i++) { Expression e = get((String) m_names.get(i)); e.frame(gen); } } finally { gen.pop(); } if (s_log.isDebugEnabled()) { s_log.debug("unoptimized frame:\n" + qframe); } List frames = gen.getFrames(); boolean modified; do { modified = false; for (int i = 0; i < frames.size(); i++) { QFrame qf = (QFrame) frames.get(i); modified |= qf.hoist(); } } while (modified); if (s_log.isDebugEnabled()) { s_log.debug("hoisted frame:\n" + qframe); } for (int i = 0; i < frames.size(); i++) { QFrame qf = (QFrame) frames.get(i); qf.mergeOuter(); } if (s_log.isDebugEnabled()) { s_log.debug("outers merged:\n" + qframe); } for (int i = 0; i < frames.size(); i++) { QFrame qf = (QFrame) frames.get(i); if (qf.getParent() == null) { qf.equifill(); } } if (s_log.isDebugEnabled()) { s_log.debug("eq/nn filled:\n" + qframe); } Set collapse = new HashSet(); Map canon = new HashMap(); do { collapse.clear(); canon.clear(); modified = false; for (int i = 0; i < frames.size(); i++) { QFrame qf = (QFrame) frames.get(i); long st = System.currentTimeMillis(); modified |= qf.innerize(collapse, canon); } if (modified) { for (Iterator it = collapse.iterator(); it.hasNext();) { EquiSet eq = (EquiSet) it.next(); eq.collapse(); } } } while (modified); if (s_log.isDebugEnabled()) { s_log.debug("innerized frame:\n" + qframe); } for (Iterator it = gen.getFrames().iterator(); it.hasNext();) { QFrame qf = (QFrame) it.next(); qf.shrink(); } if (s_log.isDebugEnabled()) { s_log.debug("shrunk frame:\n" + qframe); } Code sql = new Code("select "); for (Iterator it = m_names.iterator(); it.hasNext();) { String name = (String) it.next(); Expression e = get(name); // XXX: should eliminate duplicate fetches here when // we return something smarter than a string from this // method. sql = sql.add(e.emit(gen)).add(" as \"").add(name).add("\""); if (it.hasNext()) { sql = sql.add(",\n "); } } if (m_names.isEmpty()) { sql = sql.add("1 as dummy"); } sql = sql.add("\nfrom ").add(qframe.emit(false, !oracle)); Expression offset = qframe.getOffset(); Expression limit = qframe.getLimit(); if (oracle && (offset != null || limit != null)) { // We need one level of nesting here to make sure that the // order by happens before the rownum assignments. The // second level of nesting is required because filtering // on rownum directly doesn't work. sql = new Code("select * from (select r__.*, rownum as ").add(ROWNUM).add(" from (").add(sql) .add(") r__) where "); if (offset != null) { sql = sql.add(ROWNUM).add(" > ").add(offset.emit(gen)); } if (limit != null) { if (offset != null) { sql = sql.add(" and "); } sql = sql.add(ROWNUM); if (offset != null) { sql = sql.add(" - ").add(offset.emit(gen)); } sql = sql.add(" <= ").add(limit.emit(gen)); } } // XXX: need better way to do size if (m_query instanceof Size) { sql = new Code("select count(*) as \"size\" from (").add(sql).add(") count__"); } synchronized (s_cache) { if (s_log.isInfoEnabled()) { s_log.info("Query cache MISS. Cache size " + s_cache.size()); if (s_log.isDebugEnabled()) { StringBuffer buf = new StringBuffer(); buf.append("Cache Key: ").append(gen.getStoreKey().toString()); buf.append("\nValue: ").append(sql); buf.append("\nQuery: ").append(toString()); s_log.debug(buf.toString()); } } s_cache.put(gen.getStoreKey(), sql); } sql = sql.resolve(gen.getBindings(), root); return sql; }
From source file:org.gbif.registry.metasync.protocols.digir.DigirMetadataSynchroniserTest.java
/** * Make sure the determination of DiGIR endpoint type is catching DIGIR_MANIS. *//*from w ww . j ava 2 s. c o m*/ @Test public void testDetermineEndpointType() { // populate map with namespace (conceptualSchema) / schemaLocation key value pair Map<String, URI> schemas = Maps.newHashMap(); schemas.put("http://digir.net/schema/conceptual/darwin/2003/1.0", URI.create("http://bnhm.berkeley.museum/manis/DwC/darwin2jrw030315.xsd")); assertThat(synchroniser.determineEndpointType(schemas)).isEqualTo(EndpointType.DIGIR_MANIS); // reset, try another schemas.clear(); schemas.put("http://digir.net/schema/conceptual/darwin/2003/1.0", URI.create("http://bnhm.berkeley.edu/DwC/bnhm_dc2_schema.xsd")); assertThat(synchroniser.determineEndpointType(schemas)).isEqualTo(EndpointType.DIGIR_MANIS); }
From source file:eagle.log.entity.meta.IndexDefinition.java
/** * Check if the query is suitable to go through index. If true, then return the value of index fields in order. Otherwise return null. * TODO: currently index fields should be string type. * //from w w w . j a va 2 s . c om * @param query query expression after re-write * @param rowkeys if the query can go through the index, all rowkeys will be added into rowkeys. * @return true if the query can go through the index, otherwise return false */ public IndexType canGoThroughIndex(ORExpression query, List<byte[]> rowkeys) { if (query == null || query.getANDExprList() == null || query.getANDExprList().isEmpty()) return IndexType.NON_CLUSTER_INDEX; if (rowkeys != null) { rowkeys.clear(); } final Map<String, String> indexfieldMap = new HashMap<String, String>(); for (ANDExpression andExpr : query.getANDExprList()) { indexfieldMap.clear(); for (AtomicExpression ae : andExpr.getAtomicExprList()) { // TODO temporarily ignore those fields which are not for attributes final String fieldName = parseEntityAttribute(ae.getKey()); if (fieldName != null && ComparisonOperator.EQUAL.equals(ae.getOp())) { indexfieldMap.put(fieldName, ae.getValue()); } } final String[] partitions = entityDef.getPartitions(); int[] partitionValueHashs = null; if (partitions != null) { partitionValueHashs = new int[partitions.length]; for (int i = 0; i < partitions.length; ++i) { final String value = indexfieldMap.get(partitions[i]); if (value == null) { throw new IllegalArgumentException( "Partition " + partitions[i] + " is not defined in the query: " + query.toString()); } partitionValueHashs[i] = value.hashCode(); } } final byte[][] indexFieldValues = new byte[columns.length][]; for (int i = 0; i < columns.length; ++i) { final IndexColumn col = columns[i]; if (!indexfieldMap.containsKey(col.getColumnName())) { // If we have to use scan anyway, there's no need to go through index return IndexType.NON_INDEX; } final String value = indexfieldMap.get(col.getColumnName()); indexFieldValues[i] = value.getBytes(); } final byte[] rowkey = generateUniqueIndexRowkey(indexFieldValues, partitionValueHashs, null); if (rowkeys != null) { rowkeys.add(rowkey); } } if (index.unique()) { return IndexType.UNIQUE_INDEX; } return IndexType.NON_CLUSTER_INDEX; }
From source file:com.netsteadfast.greenstep.sys.GreenStepBaseAuthorizingLdapRealm.java
private SimpleAuthorizationInfo getSimpleAuthorizationInfo(String username) throws Exception { Map<String, Object> params = new HashMap<String, Object>(); params.put("account", username); List<TbUserRole> roleList = userRoleService.findListByParams(params); if (roleList == null) { return null; }/*from ww w .j a va 2 s. c o m*/ SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(); for (TbUserRole userRole : roleList) { info.addRole(userRole.getRole()); params.clear(); params.put("role", userRole.getRole()); List<TbRolePermission> rolePermissionList = rolePermissionService.findListByParams(params); if (rolePermissionList == null) { continue; } for (TbRolePermission rolePermission : rolePermissionList) { info.addStringPermission(rolePermission.getPermission()); } } return info; }
From source file:com.microsoft.projectoxford.vision.VisionServiceRestClient.java
@Override public OCR recognizeText(String url, String languageCode, boolean detectOrientation) throws VisionServiceException { Map<String, Object> params = new HashMap<>(); params.put("language", languageCode); params.put("detectOrientation", detectOrientation); String path = apiRoot + "/ocr"; String uri = WebServiceRequest.getUrl(path, params); params.clear(); params.put("url", url); String json = (String) this.restCall.request(uri, "POST", params, null, false); OCR ocr = this.gson.fromJson(json, OCR.class); return ocr;// w ww.j av a 2 s .c om }
From source file:com.impetus.kundera.metadata.processor.TableProcessor.java
/** * Populate metadata.// ww w . j a v a2s . c o m * * @param metadata * the metadata * @param clazz * the clazz */ private void populateMetadata(EntityMetadata metadata, Class<?> clazz) { Table table = clazz.getAnnotation(Table.class); boolean isEmbeddable = false; // Set Name of persistence object metadata.setTableName(table.name()); // Add named/native query related application metadata. addNamedNativeQueryMetadata(clazz); // set schema name and persistence unit name (if provided) String schemaStr = table.schema(); Index idx = clazz.getAnnotation(Index.class); List<String> colToBeIndexed = null; if (idx != null) { if (idx.columns() != null && idx.columns().length != 0) { colToBeIndexed = Arrays.asList(idx.columns()); } } if (schemaStr == null) { LOG.error("It is mandatory to specify Schema alongwith Table name:" + table.name() + ". This entity won't be persisted"); throw new InvalidEntityDefinitionException("It is mandatory to specify Schema alongwith Table name:" + table.name() + ". This entity won't be persisted"); } MetadataUtils.setSchemaAndPersistenceUnit(metadata, schemaStr); metadata.setType(com.impetus.kundera.metadata.model.EntityMetadata.Type.COLUMN_FAMILY); // scan for fields for (Field f : clazz.getDeclaredFields()) { /* Scan @Id field */ if (f.isAnnotationPresent(Id.class)) { LOG.debug(f.getName() + " => Id"); populateIdAccessorMethods(metadata, clazz, f); populateIdColumn(metadata, clazz, f); } else if (f.isAnnotationPresent(Embedded.class)) { /* Scan @Embedded fields */ metadata.setType(com.impetus.kundera.metadata.model.EntityMetadata.Type.SUPER_COLUMN_FAMILY); Class embeddedFieldClass = f.getType(); isEmbeddable = true; if (Collection.class.isAssignableFrom(embeddedFieldClass)) { LOG.warn(f.getName() + " was annotated with @Embedded, and shouldn't have been a java Collection field, it won't be persisted"); } else { // An @Embedded attribute will be a DTO (@Embeddable) populateEmbeddedFieldIntoMetadata(metadata, f, embeddedFieldClass); /* TODO: Bad code, see how to remove this */ metadata.addToEmbedCollection(embeddedFieldClass); } } else if (f.isAnnotationPresent(ElementCollection.class)) { /* Scan @ElementCollection fields */ metadata.setType(com.impetus.kundera.metadata.model.EntityMetadata.Type.SUPER_COLUMN_FAMILY); Class elementCollectionFieldClass = f.getType(); isEmbeddable = true; // An @ElementCollection must be a java collection, a generic // class must be declared (@Embeddable) if (Collection.class.isAssignableFrom(elementCollectionFieldClass)) { Class elementCollectionGenericClass = PropertyAccessorHelper.getGenericClass(f); populateElementCollectionIntoMetadata(metadata, f, elementCollectionGenericClass); /* TODO: Bad code, see how to remove this */ metadata.addToEmbedCollection(elementCollectionGenericClass); } else { LOG.warn(f.getName() + " was annotated with @ElementCollection but wasn't a java Collection field, it won't be persisted"); } } else { /* if any valid JPA annotation? */ String name = getValidJPAColumnName(clazz, f); if (null != name) { // additional check for not to load Unnecessary column // objects in JVM. if (!isEmbeddable) { metadata.addColumn(name, new com.impetus.kundera.metadata.model.Column(name, f, colToBeIndexed != null ? colToBeIndexed.contains(name) : false)); } EmbeddedColumn embeddedColumn = new EmbeddedColumn(name, f); metadata.addEmbeddedColumn(name, embeddedColumn); embeddedColumn.addColumn(name, f); } } /* Scan for Relationship field */ addRelationIntoMetadata(clazz, f, metadata); } // TODO: Below if/else block is possibly not required, should be removed if (isEmbeddable) { Map<String, com.impetus.kundera.metadata.model.Column> cols = metadata.getColumnsMap(); cols.clear(); cols = null; metadata.setType(Type.SUPER_COLUMN_FAMILY); } else { Map<String, EmbeddedColumn> embeddedColumns = metadata.getEmbeddedColumnsMap(); embeddedColumns.clear(); embeddedColumns = null; metadata.setType(Type.COLUMN_FAMILY); } }
From source file:com.microsoft.projectoxford.vision.VisionServiceRestClient.java
@Override public AnalysisResult analyzeImage(InputStream stream, String[] visualFeatures, String[] details) throws VisionServiceException, IOException { Map<String, Object> params = new HashMap<>(); AppendParams(params, "visualFeatures", visualFeatures); AppendParams(params, "details", details); String path = apiRoot + "/analyze"; String uri = WebServiceRequest.getUrl(path, params); params.clear(); byte[] data = IOUtils.toByteArray(stream); params.put("data", data); String json = (String) this.restCall.request(uri, "POST", params, "application/octet-stream", false); AnalysisResult visualFeature = this.gson.fromJson(json, AnalysisResult.class); return visualFeature; }
From source file:com.microsoft.projectoxford.vision.VisionServiceRestClient.java
@Override public AnalysisResult analyzeImage(String url, String[] visualFeatures, String[] details) throws VisionServiceException { Map<String, Object> params = new HashMap<>(); AppendParams(params, "visualFeatures", visualFeatures); AppendParams(params, "details", details); String path = apiRoot + "/analyze"; String uri = WebServiceRequest.getUrl(path, params); params.clear(); params.put("url", url); String json = (String) this.restCall.request(uri, "POST", params, null, false); AnalysisResult visualFeature = this.gson.fromJson(json, AnalysisResult.class); return visualFeature; }
From source file:com.haulmont.cuba.core.sys.AbstractScripting.java
@Override public void clearCache() { getGroovyClassLoader().clearCache(); javaClassLoader.clearCache();//from ww w .jav a 2 s . com getPool().clear(); GroovyScriptEngine gse = getGroovyScriptEngine(); try { Field scriptCacheField = gse.getClass().getDeclaredField("scriptCache"); scriptCacheField.setAccessible(true); Map scriptCacheMap = (Map) scriptCacheField.get(gse); scriptCacheMap.clear(); } catch (NoSuchFieldException | IllegalAccessException e) { //ignore the exception } }