List of usage examples for java.util Set clear
void clear();
From source file:com.npower.dm.hibernate.management.ProfileAssignmentManagementBeanImpl.java
/** * Add or update the value of AttributeValue specified by the name. This is * modifier of AttributeValue in multiple-value, binary mode. * //from w w w . j av a 2 s. co m * Caution: Assign null to value is permitted. this will set the value to * null, AttributeValue will not be deleted! * * Caution: Order of AttributeValue will automaticlly increased! The * AttributeValue added lastestly will be bottom. * * @param name * Attribute's name * @param value * String[] array of multi-value * @throws DMException */ public void setAttributeValue(ProfileAssignment assignment, String name, InputStream value[]) throws DMException, IOException { // update this profile config, first. make sure the profileID will generated // by hibernate. Session hsession = this.getHibernateSession(); hsession.saveOrUpdate(assignment); Blob[] blobValues = null; try { if (value != null) { blobValues = new Blob[value.length]; for (int i = 0; value != null && i < value.length; i++) { blobValues[i] = (value[i] == null) ? null : Hibernate.createBlob(value[i]); } } } catch (IOException e) { throw e; } // Check exists? Set<ProfileAssignmentValue> vMaps = ((ProfileAssignmentEntity) assignment).getProfileAssignValues(); for (Iterator<ProfileAssignmentValue> i = vMaps.iterator(); i.hasNext();) { ProfileAssignmentValue vMap = (ProfileAssignmentValue) i.next(); ProfileAttributeValueEntity v = (ProfileAttributeValueEntity) vMap.getProfileAttribValue(); if (name.equals(v.getProfileAttribute().getName())) { // In multi-value mode, clear single value; v.setRawData(null); // Set to multi-value mode v.setIsMultiValued(true); v.setMFormat(DDFNode.DDF_FORMAT_BIN); // Clear all of old values. Set<ProfileValueItem> items = v.getProfileValueItems(); for (Iterator<ProfileValueItem> item = items.iterator(); item.hasNext();) { hsession.delete(item.next()); } // clear up the set of items. items.clear(); for (int j = 0; blobValues != null && j < blobValues.length; j++) { // Create a ProfileValueItem ProfileValueItem item = new ProfileValueItem(v); // Inherit property from AttributeValues item.setItemDataKind(v.getItemDataKind()); item.setMFormat(v.getMFormat()); item.setMType(v.getMType()); item.setUpdateId(v.getUpdateId()); // Assign the value item.setBinaryData(blobValues[j]); hsession.saveOrUpdate(item); // Save into DM inventory items.add(item); } return; } } // Create a new AttributeValue ProfileTemplate template = assignment.getProfileConfig().getProfileTemplate(); ManagementBeanFactory factory = this.getManagementBeanFactory(); ProfileAttribute attr = factory.createProfileTemplateBean().getProfileAttributeByName(template.getName(), name); if (attr == null) { throw new DMException( "Could not find attribute by name: " + name + " from the template: " + template.getName()); } // Create a ProfileAttributeValueEntity ProfileAttributeValueEntity av = new ProfileAttributeValueEntity(); av.setProfileAttribute(attr); // In Multi-value mode, clear the value of single-value mode. av.setRawData(null); // Set to multi-value mode av.setIsMultiValued(true); av.setMFormat(DDFNode.DDF_FORMAT_BIN); hsession.saveOrUpdate(av); // Create all of items from clobValues for (int j = 0; blobValues != null && j < blobValues.length; j++) { // Create a ProfileValueItem ProfileValueItem item = new ProfileValueItem(av); // Inherit the value of properties from ProfileAttributeValueEntity. item.setItemDataKind(av.getItemDataKind()); item.setMFormat(av.getMFormat()); item.setMType(av.getMType()); item.setUpdateId(av.getUpdateId()); // set the value of Clob item.setBinaryData(blobValues[j]); // Add into DMInventory. hsession.saveOrUpdate(item); // Link the Item to ProfileAttributeValueEntity av.getProfileValueItems().add(item); } // New a ProfileAssignmentValueID ProfileAssignmentValueID mapID = new ProfileAssignmentValueID(); mapID.setAttributeValueId(av.getID()); mapID.setProfileAssignmentId(assignment.getID()); // New a ProfileAssignmentValue // long index = this.getProfileValueMaps().size() + 1; ProfileAssignmentValue map = new ProfileAssignmentValue(mapID, av, assignment); // Link to ProfileAssignmentEntity Set<ProfileAssignmentValue> maps = ((ProfileAssignmentEntity) assignment).getProfileAssignValues(); maps.add(map); // Add the ProfileValueMap into DM inventory. hsession.saveOrUpdate(map); }
From source file:com.evolveum.midpoint.repo.sql.helpers.ObjectDeltaUpdater.java
private void handlePhoto(Object bean, ItemDelta delta) throws SchemaException { if (!(bean instanceof RFocus)) { throw new SystemException("Bean is not instance of " + RFocus.class + ", shouldn't happen"); }/* w ww . ja v a 2 s. c o m*/ RFocus focus = (RFocus) bean; Set<RFocusPhoto> photos = focus.getJpegPhoto(); if (delta.isDelete()) { photos.clear(); return; } MapperContext context = new MapperContext(); context.setRepositoryContext(new RepositoryContext(repositoryService, prismContext, extItemDictionary)); context.setDelta(delta); context.setOwner(bean); PrismValue value = delta.getAnyValue(); RFocusPhoto photo = prismEntityMapper.map(value.getRealValue(), RFocusPhoto.class, context); if (delta.isAdd()) { if (!photos.isEmpty()) { throw new SchemaException("Object '" + focus.getOid() + "' already contains photo"); } photo.setTransient(true); photos.add(photo); return; } if (photos.isEmpty()) { photo.setTransient(true); photos.add(photo); return; } RFocusPhoto oldPhoto = photos.iterator().next(); oldPhoto.setPhoto(photo.getPhoto()); }
From source file:hsa.awp.scire.procedureLogic.DrawProcedureLogicTest.java
/** * Generates and registers complex priority lists. The priority list combination is shown in the matrix below. * <p/>// w ww . j a v a2 s . com * <pre> * Symbols: * Priority list 1 : 1, 2, 3 * Priority list 2 : 4, 5, 6 * * | A | B | C | D | E | F * ----+---+---+---+---+---+--- * s1 | 1 | 2 | 3 | 4 | 5 | 6 * ----+---+---+---+---+---+--- * s2 | 6 | 1 | 2 | 3 | 4 | 5 * ----+---+---+---+---+---+--- * s3 | 5 | 6 | 1 | 2 | 3 | 4 * ----+---+---+---+---+---+--- * s4 | 1 | 4 | 2 | 5 | 3 | 6 * ----+---+---+---+---+---+--- * s5 | 3 | 6 | 1 | 4 | 2 | 5 * ----+---+---+---+---+---+--- * s6 | 2 | 5 | 3 | 6 | 1 | 4 * </pre> */ private void generateAndRegisterComplexPriorityLists() { Event a = events.get(0); Event b = events.get(1); Event c = events.get(2); Event d = events.get(3); Event e = events.get(4); Event f = events.get(5); SingleUser singleUser; List<Event> events = new ArrayList<Event>(); Set<PriorityList> lists = new HashSet<PriorityList>(); // student 1 events.clear(); lists.clear(); singleUser = userFacade.saveSingleUser(createUser("1")); events.add(a); events.add(b); events.add(c); lists.add(generatePriorityList(singleUser, singleUser, events)); events.clear(); events.add(d); events.add(e); events.add(f); lists.add(generatePriorityList(singleUser, singleUser, events)); // register student 1 drawProcedureLogic.register(lists); // ------------------------------------------------------------------------------------------------------------------------ // student 2 events.clear(); lists.clear(); singleUser = userFacade.saveSingleUser(createUser("2")); events.add(b); events.add(c); events.add(d); lists.add(generatePriorityList(singleUser, singleUser, events)); events.clear(); events.add(e); events.add(f); events.add(a); lists.add(generatePriorityList(singleUser, singleUser, events)); // register student 2 drawProcedureLogic.register(lists); // ------------------------------------------------------------------------------------------------------------------------ // student 3 events.clear(); lists.clear(); singleUser = userFacade.saveSingleUser(createUser("3")); events.add(c); events.add(d); events.add(e); lists.add(generatePriorityList(singleUser, singleUser, events)); events.clear(); events.add(f); events.add(a); events.add(b); lists.add(generatePriorityList(singleUser, singleUser, events)); // register student 3 drawProcedureLogic.register(lists); // ------------------------------------------------------------------------------------------------------------------------ // student 4 events.clear(); lists.clear(); singleUser = userFacade.saveSingleUser(createUser("4")); events.add(a); events.add(c); events.add(e); lists.add(generatePriorityList(singleUser, singleUser, events)); events.clear(); events.add(b); events.add(d); events.add(f); lists.add(generatePriorityList(singleUser, singleUser, events)); // register student 4 drawProcedureLogic.register(lists); // ------------------------------------------------------------------------------------------------------------------------ // student 5 events.clear(); lists.clear(); singleUser = userFacade.saveSingleUser(createUser("5")); events.add(c); events.add(e); events.add(a); lists.add(generatePriorityList(singleUser, singleUser, events)); events.clear(); events.add(d); events.add(f); events.add(b); lists.add(generatePriorityList(singleUser, singleUser, events)); // register student 5 drawProcedureLogic.register(lists); // ------------------------------------------------------------------------------------------------------------------------ // student 6 events.clear(); lists.clear(); singleUser = userFacade.saveSingleUser(createUser("6")); events.add(e); events.add(a); events.add(c); lists.add(generatePriorityList(singleUser, singleUser, events)); events.clear(); events.add(f); events.add(b); events.add(d); lists.add(generatePriorityList(singleUser, singleUser, events)); // register student 6 drawProcedureLogic.register(lists); }
From source file:com.glaf.core.db.TransformTable.java
public void transformQueryToTable(String tableName, String queryId, String sourceSystemName) { TableDefinition tableDefinition = getTableDefinitionService().getTableDefinition(tableName); QueryDefinition queryDefinition = getQueryDefinitionService().getQueryDefinition(queryId); if (queryDefinition != null && tableDefinition != null && StringUtils.isNotEmpty(tableDefinition.getAggregationKeys())) { Map<String, Object> params = SystemConfig.getContextMap(); List<ColumnDefinition> columns = DBUtils.getColumnDefinitions(tableName); Map<String, ColumnDefinition> columnMap = new java.util.HashMap<String, ColumnDefinition>(); for (ColumnDefinition column : columns) { columnMap.put(column.getColumnName(), column); columnMap.put(column.getColumnName().toLowerCase(), column); }/*from w w w .j a v a2s. c o m*/ List<String> keys = StringTools.split(tableDefinition.getAggregationKeys()); StringBuffer sb = new StringBuffer(1000); List<ColumnModel> cellModelList = new java.util.ArrayList<ColumnModel>(); Map<String, TableModel> resultMap = new java.util.HashMap<String, TableModel>(); if (queryDefinition.getSql() != null) { String sql = queryDefinition.getSql(); sql = QueryUtils.replaceSQLVars(sql); sql = QueryUtils.replaceSQLParas(sql, params); logger.debug("sql=" + sql); String systemName = Environment.getCurrentSystemName(); try { Environment.setCurrentSystemName(sourceSystemName); List<Map<String, Object>> rows = getTablePageService().getListData(sql, params); if (rows != null && !rows.isEmpty()) { logger.debug(queryDefinition.getTitle() + " " + rows.size()); logger.debug("RotatingFlag:" + queryDefinition.getRotatingFlag()); logger.debug("RotatingColumn:" + queryDefinition.getRotatingColumn()); /** * ???? */ if (StringUtils.equalsIgnoreCase(queryDefinition.getRotatingFlag(), "R2C") && StringUtils.isNotEmpty(queryDefinition.getRotatingColumn()) && rows.size() == 1) { Map<String, Object> dataMap = rows.get(0); logger.debug("?dataMap?:" + dataMap); ColumnDefinition idField = columnMap.get(keys.get(0).toLowerCase()); ColumnDefinition field = columnMap .get(queryDefinition.getRotatingColumn().toLowerCase()); if (idField != null && field != null) { String javaType = field.getJavaType(); List<TableModel> list = new ArrayList<TableModel>(); Set<Entry<String, Object>> entrySet = dataMap.entrySet(); for (Entry<String, Object> entry : entrySet) { String key = entry.getKey(); Object value = entry.getValue(); if (key == null || value == null) { continue; } TableModel tableModel = new TableModel(); tableModel.setTableName(queryDefinition.getTargetTableName()); ColumnModel cell = new ColumnModel(); cell.setColumnName(queryDefinition.getRotatingColumn()); cell.setType(javaType); // logger.debug(cell.getColumnName()+"->"+javaType); if ("String".equals(javaType)) { cell.setStringValue(ParamUtils.getString(dataMap, key)); cell.setValue(cell.getStringValue()); } else if ("Integer".equals(javaType)) { cell.setIntValue(ParamUtils.getInt(dataMap, key)); cell.setValue(cell.getIntValue()); } else if ("Long".equals(javaType)) { cell.setLongValue(ParamUtils.getLong(dataMap, key)); cell.setValue(cell.getLongValue()); } else if ("Double".equals(javaType)) { cell.setDoubleValue(ParamUtils.getDouble(dataMap, key)); cell.setValue(cell.getDoubleValue()); } else if ("Date".equals(javaType)) { cell.setDateValue(ParamUtils.getDate(dataMap, key)); cell.setValue(cell.getDateValue()); } else { cell.setValue(value); } tableModel.addColumn(cell); ColumnModel idColumn = new ColumnModel(); idColumn.setColumnName(keys.get(0)); idColumn.setJavaType(idField.getJavaType()); idColumn.setValue(key); tableModel.setIdColumn(idColumn); list.add(tableModel); } logger.debug("update datalist:" + list); Environment.setCurrentSystemName(systemName); getTableDataService().updateTableData(list); } } else { Set<String> cols = new HashSet<String>(); for (Map<String, Object> dataMap : rows) { sb.delete(0, sb.length()); cols.clear(); cellModelList.clear(); Set<Entry<String, Object>> entrySet = dataMap.entrySet(); for (Entry<String, Object> entry : entrySet) { String key = entry.getKey(); Object value = entry.getValue(); if (key == null || value == null) { continue; } /** * ???? */ if (cols.contains(key.toLowerCase())) { continue; } if (columnMap.get(key.toLowerCase()) == null) { continue; } if (keys.contains(key)) { sb.append(value).append("_"); } ColumnDefinition column = columnMap.get(key.toLowerCase()); String javaType = column.getJavaType(); ColumnModel cell = new ColumnModel(); cell.setColumnName(column.getColumnName()); cell.setType(javaType); if ("String".equals(javaType)) { cell.setStringValue(ParamUtils.getString(dataMap, key)); cell.setValue(cell.getStringValue()); } else if ("Integer".equals(javaType)) { cell.setIntValue(ParamUtils.getInt(dataMap, key)); cell.setValue(cell.getIntValue()); } else if ("Long".equals(javaType)) { cell.setLongValue(ParamUtils.getLong(dataMap, key)); cell.setValue(cell.getLongValue()); } else if ("Double".equals(javaType)) { cell.setDoubleValue(ParamUtils.getDouble(dataMap, key)); cell.setValue(cell.getDoubleValue()); } else if ("Date".equals(javaType)) { cell.setDateValue(ParamUtils.getDate(dataMap, key)); cell.setValue(cell.getDateValue()); } else { cell.setValue(value); } cellModelList.add(cell); cols.add(cell.getColumnName()); } /** * ?? */ if (sb.toString().endsWith("_")) { sb.delete(sb.length() - 1, sb.length()); String rowKey = sb.toString(); logger.debug("rowKey=" + rowKey); TableModel rowModel = resultMap.get(rowKey); if (rowModel == null) { rowModel = new TableModel(); ColumnModel cell01 = new ColumnModel(); cell01.setColumnName("ID"); cell01.setType("String"); cell01.setValueExpression(ExpressionConstants.ID_EXPRESSION); cols.add("ID"); rowModel.addColumn(cell01); rowModel.setIdColumn(cell01); ColumnModel cell04 = new ColumnModel(); cell04.setColumnName("AGGREGATIONKEY"); cell04.setType("String"); cols.add("AGGREGATIONKEY"); rowModel.addColumn(cell04); resultMap.put(rowKey, rowModel); } for (ColumnModel cell : cellModelList) { /** * ?? */ if (columnMap.get(cell.getColumnName().toLowerCase()) != null) { rowModel.addColumn(cell); } } } } } } } catch (Exception ex) { ex.printStackTrace(); throw new RuntimeException(ex); } finally { Environment.setCurrentSystemName(systemName); } } TableModel rowModel = new TableModel(); rowModel.setTableName(tableName); rowModel.setAggregationKey(tableDefinition.getAggregationKeys()); ColumnModel cell01 = new ColumnModel(); cell01.setColumnName("ID"); cell01.setType("String"); cell01.setValueExpression(ExpressionConstants.ID_EXPRESSION); rowModel.addColumn(cell01); rowModel.setIdColumn(cell01); ColumnModel cell04 = new ColumnModel(); cell04.setColumnName("AGGREGATIONKEY"); cell04.setType("String"); rowModel.addColumn(cell04); for (ColumnDefinition column : columns) { ColumnModel cell = new ColumnModel(); cell.setColumnName(column.getColumnName()); cell.setType(column.getJavaType()); rowModel.addColumn(cell); } Collection<TableModel> rows = resultMap.values(); logger.debug("fetch data list size:" + rows.size()); if (rows.size() > 0) { String seqNo = rowModel.getTableName() + "-" + DateUtils.getDateTime(new Date()); getTableDataService().saveAll(rowModel.getTableName(), seqNo, rows); } } }
From source file:org.apache.hadoop.corona.ClusterManager.java
protected boolean checkResourceRequestExcluded(List<ResourceRequest> requestList) { Set<String> excluded = new HashSet<String>(); for (ResourceRequest req : requestList) { if (req.getExcludeHosts() == null || req.getHosts() == null) { continue; }// w ww . ja va 2s. c om excluded.clear(); excluded.addAll(req.getExcludeHosts()); for (String host : req.getHosts()) { if (excluded.contains(host)) { return false; } } } return true; }
From source file:eu.europa.ec.fisheries.uvms.spatial.service.bean.impl.MapConfigServiceBean.java
private void updateReportConnectServiceAreasEntity(ReportConnectSpatialEntity entity, LayerSettingsDto layerSettingsDto) throws ServiceException { if (layerSettingsDto == null) { clearReportConectServiceAreas(entity); return;//from w w w .j a va2s . co m } Set<ReportConnectServiceAreasEntity> serviceAreas = createReportConnectServiceAreas(entity, layerSettingsDto); if (serviceAreas != null && !serviceAreas.isEmpty()) { Set<ReportConnectServiceAreasEntity> areas = entity.getReportConnectServiceAreas(); if (areas == null) { entity.setReportConnectServiceAreas(serviceAreas); } else { areas.clear(); areas.addAll(serviceAreas); entity.setReportConnectServiceAreas(areas); } } else { clearReportConectServiceAreas(entity); } }
From source file:com.datatorrent.contrib.dimensions.DimensionsStoreHDHT.java
/** * only cleanup the value. keep the entry for next time *//* w w w . j a v a 2 s . c o m*/ protected void cleanupEmbedIdentifierToEventKeys() { if (embedIdentifierToEventKeys == null) { return; } for (Set<EventKey> eventKeys : embedIdentifierToEventKeys.values()) { eventKeys.clear(); } }
From source file:ch.mobi.itc.mobiliar.rest.resources.ResourcesRest.java
/** * Alle Consumed Resources zu dieser App <br> * App Details<br>/*from w w w . jav a 2 s .co m*/ * Job name<br> * Server<br> * consumed resources (short) */ @Path("/batchjobResources/{app}") @Produces("application/json") @GET @ApiOperation(value = "Get batch job resources", notes = "Returns the consumed resources for this app") public List<BatchResourceDTO> getBatchJobResources( @ApiParam(value = "return resources for this app") @PathParam("app") String app) throws ValidationException { if (app == null || app.isEmpty()) { throw new ValidationException("App must not be empty"); } List<String> apps = new ArrayList<>(); apps.add(app); List<BatchResourceDTO> list = new ArrayList<>(); Set<String> set = new HashSet<>(); for (ResourceEntity re : resourceLocator.getBatchJobConsumedResources(apps)) { for (ConsumedResourceRelationEntity r : re.getConsumedMasterRelations()) { mapResourceDTO(list, set, r.getSlaveResource().getResourceType().getId(), r.getSlaveResource().getName(), true); } } set.clear(); for (ResourceEntity re : resourceLocator.getBatchJobProvidedResources(apps)) { for (ProvidedResourceRelationEntity r : re.getProvidedMasterRelations()) { mapResourceDTO(list, set, r.getSlaveResource().getResourceType().getId(), r.getSlaveResource().getName(), false); } } return list; }
From source file:org.jnap.core.persistence.factory.DaoFactoryBkp.java
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException { Assert.isAssignable(DefaultListableBeanFactory.class, registry.getClass(), "The DaoFactory only works within a DefaultListableBeanFactory capable" + "BeanFactory, your BeanDefinitionRegistry is " + registry.getClass()); final DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) registry; // Initialize all SessionFactory beans String[] factoryNames = beanFactory.getBeanNamesForType(EntityManagerFactory.class); Set<EntityManagerFactory> factories = new HashSet<EntityManagerFactory>(factoryNames.length); for (String factoryName : factoryNames) { factories.add(beanFactory.getBean(factoryName, EntityManagerFactory.class)); }// w w w. j a va 2 s .com for (EntityManagerFactory factory : factories) { factory.getMetamodel().getEntities(); for (EntityType<?> entityMetadata : factory.getMetamodel().getEntities()) { Class<? extends PersistentModel> entityClass = (Class<? extends PersistentModel>) entityMetadata .getJavaType(); if (entityClass != null && !isDaoDefinedForEntity(beanFactory, entityClass)) { String daoName = buildDaoName(entityClass); beanFactory.registerBeanDefinition(daoName, createDaoDefinition(entityClass, factory)); daoNameCache.put(entityClass, daoName); } } } factories.clear(); factories = null; }
From source file:org.jnap.core.persistence.factory.DaoFactory.java
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { Assert.isAssignable(DefaultListableBeanFactory.class, beanFactory.getClass(), "The DaoFactory only works within a DefaultListableBeanFactory capable " + "BeanFactory. Your BeanFactory is " + beanFactory.getClass()); this.beanFactory = beanFactory; final DefaultListableBeanFactory listableBeanFactory = (DefaultListableBeanFactory) beanFactory; String[] factoryNames = beanFactory.getBeanNamesForType(EntityManagerFactory.class); Set<EntityManagerFactory> factories = new HashSet<EntityManagerFactory>(factoryNames.length); for (String factoryName : factoryNames) { factories.add(beanFactory.getBean(factoryName, EntityManagerFactory.class)); }/* w w w.jav a 2 s. c o m*/ for (EntityManagerFactory factory : factories) { factory.getMetamodel().getEntities(); for (EntityType<?> entityMetadata : factory.getMetamodel().getEntities()) { Class<? extends PersistentModel> entityClass = (Class<? extends PersistentModel>) entityMetadata .getJavaType(); if (entityClass != null && !isDaoDefinedForEntity(beanFactory, entityClass)) { String daoName = buildDaoName(entityClass); listableBeanFactory.registerBeanDefinition(daoName, createDaoDefinition(entityClass, factory)); daoNameCache.put(entityClass, daoName); } } } factories.clear(); factories = null; }