Java Code Examples for java.util.concurrent.ConcurrentHashMap.putAll()

The following are Jave code examples for showing how to use putAll() of the java.util.concurrent.ConcurrentHashMap class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: monarch   File: RegionVersionVector.java   View Source Code Vote up 7 votes
/**
 * Retrieve a vector that can be sent to another member. This clones all of the version
 * information to protect against concurrent modification during serialization
 */
public RegionVersionVector<T> getCloneForTransmission() {
  Map<T, RegionVersionHolder<T>> liveHolders;
  liveHolders = new HashMap<T, RegionVersionHolder<T>>(this.memberToVersion);
  ConcurrentHashMap<T, RegionVersionHolder<T>> clonedHolders =
      new ConcurrentHashMap<T, RegionVersionHolder<T>>(liveHolders.size(), LOAD_FACTOR,
          CONCURRENCY_LEVEL);
  for (Map.Entry<T, RegionVersionHolder<T>> entry : liveHolders.entrySet()) {
    clonedHolders.put(entry.getKey(), entry.getValue().clone());
  }
  ConcurrentHashMap<T, Long> gcVersions = new ConcurrentHashMap<T, Long>(
      this.memberToGCVersion.size(), LOAD_FACTOR, CONCURRENCY_LEVEL);
  gcVersions.putAll(this.memberToGCVersion);
  RegionVersionHolder<T> clonedLocalHolder;
  clonedLocalHolder = this.localExceptions.clone();
  // Make sure the holder that we send to the peer does
  // have an accurate RegionVersionHolder for our local version
  return createCopy(this.myId, clonedHolders, this.localVersion.get(), gcVersions,
      this.localGCVersion.get(), false, clonedLocalHolder);
}
 
Example 2
Project: uroborosql   File: SqlLoaderImpl.java   View Source Code Vote up 7 votes
/**
 * 指定されたパッケージ以下のSQLを順次読み込みする<br>
 * 文末の"/"は削除される<br>
 *
 * @param packageName パッケージ名を格納するStringBuilder
 * @param dir 探索対象ディレクトリ
 * @return SQL識別子をキーとしたSQL文のMap
 * @throws IOException ファイルアクセスに失敗した場合
 */
private ConcurrentHashMap<String, String> load(final StringBuilder packageName, final File dir) throws IOException {
	LOG.debug("Loading SQL template.[{}]", packageName);

	ConcurrentHashMap<String, String> sqlMap = new ConcurrentHashMap<>();
	File[] files = dir.listFiles();
	for (File file : files) {
		String fileName = file.getName();
		if (file.isDirectory()) {
			sqlMap.putAll(load(makeNewPackageName(packageName, file), file));
		} else if (fileName.toLowerCase().endsWith(fileExtension)) {
			String sql = trimSlash(read(new BufferedReader(new InputStreamReader(new FileInputStream(file),
					getSqlEncoding()))));
			String sqlName = makeSqlName(packageName, fileName);
			sqlMap.put(sqlName, sql);

			LOG.trace("Loaded SQL template.[{}]", fileName);
			LOG.trace("Add SQL template.[{}],[{}]", sqlName, sql);
		}
	}
	return sqlMap;
}
 
Example 3
Project: openjdk-jdk10   File: ConcurrentHashMapTest.java   View Source Code Vote up 6 votes
/**
 * putAll adds all key-value pairs from the given map
 */
public void testPutAll() {
    ConcurrentHashMap empty = new ConcurrentHashMap();
    ConcurrentHashMap map = map5();
    empty.putAll(map);
    assertEquals(5, empty.size());
    assertTrue(empty.containsKey(one));
    assertTrue(empty.containsKey(two));
    assertTrue(empty.containsKey(three));
    assertTrue(empty.containsKey(four));
    assertTrue(empty.containsKey(five));
}
 
Example 4
Project: alfresco-repository   File: ReferenceCountingReadOnlyIndexReaderFactory.java   View Source Code Vote up 5 votes
private <T> T manageCache(ConcurrentHashMap<Integer, WithUseCount<T>> cache, Accessor<T> accessor, int n, FieldSelector fieldSelector, int limit) throws IOException
{
    Integer key = Integer.valueOf(n);
    WithUseCount<T> value = cache.get(key);
    if (value == null)
    {
        T made = accessor.get(n, fieldSelector);
        value = new WithUseCount<T>(made, n);
        cache.put(key, value);

        // resize

        if (limit >= 0)
        {
            if (cache.size() >= limit)
            {
                HashMap<Integer, WithUseCount<T>> keep = new HashMap<Integer, WithUseCount<T>>();
                WithUseCount<T>[] existing = new WithUseCount[0];
                synchronized (cache)
                {
                    existing = cache.values().toArray(existing);
                    cache.clear();
                }
                Arrays.sort(existing);

                for (WithUseCount<T> current : existing)
                {
                    keep.put(Integer.valueOf(current.doc), current);
                    if ((current.count.get() == 0) || (keep.size() > (limit / 4)))
                    {
                        break;
                    }
                }
                keep.put(key, value);
                cache.putAll(keep);
            }
        }
    }
    else
    {
        value.count.getAndIncrement();
    }
    return value.object;
}
 
Example 5
Project: headb   File: HeaSoul.java   View Source Code Vote up 5 votes
/**
 *生成删除sql
 * @param parameter
 * @return SqlParmeter
 */ 
protected SqlParmeter generateDeleteSql(HeaMap parameter) {
	initEntityInfo(this.entityType);
	String entityName = getEntityName();
	Entity entityInfo = entityMap.get(entityName);
	String tableName = entityInfo.getTableName();
	SqlParmeter sqlParmeter = new SqlParmeter();
	if (null == parameter) {
		parameter = new HeaMap();
	}
	if (parameter.size() == 0) {
		throw new RuntimeException("必须传人参数!");
	}
	List<Object> params = new ArrayList<Object>();
	ConcurrentHashMap<String, Boolean> aliasMap = new ConcurrentHashMap<String, Boolean>();
	StringBuffer whereSql = new StringBuffer();// 包含where后面的sql语局
	String link = "where";// 第一个默认连接是where
	boolean firstQueryFlag = true;// 是否是第一个需查项
	List<String> groupSqlList = new ArrayList<String>();
	for (Entry<String, ?> entry : parameter.entrySet()) {
		String key = entry.getKey();
		Object value = entry.getValue();
		key = filterKey(key);
		if (key.startsWith(HeaConstant.Instruction.ADDGROUP)) {
			groupSqlList = getOrder(groupSqlList, value);
			continue;
		}
		ColumnCondition columnCondition = new ColumnCondition();
		columnCondition = analyzeKey(columnCondition, key, value);
		if (!columnCondition.getIfQuery()) {
			continue;
		}
		if (!firstQueryFlag) {
			link = columnCondition.getAndOr();
		}
		whereSql.append(HStringUtils.format(" {0} {1}", link, columnCondition.getSqlFragment()));
		if (null != columnCondition.getCookedValue()) {
			params.addAll(columnCondition.getCookedValue());
		}
		firstQueryFlag = false;
	}
	String whereSqlStr = whereSql.toString();
	String groupSql = "";
	if (groupSqlList.size() > 0) {
		groupSql = " group by " + HStringUtils.StrList(groupSqlList, ",");
	}
	String tempStr = HStringUtils.addStr(whereSqlStr, groupSql);
	aliasMap.putAll(HOrmUtil.getAliasFromSql(tempStr));
	// 分析得到joinSql
	String joinSql = "";
	if (!aliasMap.isEmpty()) {
		HHashMap<Integer, String> joinSqlMap = new HHashMap<Integer, String>();
		analyzeAliasMap(aliasMap, joinSqlMap);
		joinSql = getJoinSql(joinSqlMap);
	}
	String tableSqlStr = HStringUtils.format("{0} t {1}", tableName, joinSql);
	Map<String, Object> viewParams = parameter.getViewParams();
	TableSql tableSql = getTableSql(tableSqlStr, viewParams);
	tableSqlStr = tableSql.getTargetTableSql();
	List<Object> tableParams = tableSql.getParams();
	// 0:tableName 1:where
	String sql = HStringUtils.format("delete t from {0}  {1}", tableSqlStr, whereSqlStr);
	sqlParmeter.setSql(sql);
	tableParams.addAll(params);
	sqlParmeter.setParameters(tableParams.toArray());
	return sqlParmeter;
}
 
Example 6
Project: headb   File: HeaSoul.java   View Source Code Vote up 5 votes
/**
 * 生成更新Sql
 * @param entity
 * @param parameter
 * @return
 */
protected SqlParmeter generateUpdateSql(T entity, HeaMap parameter) {
	initEntityInfo(this.entityType);
	String entityName = getEntityName();
	Entity entityInfo = entityMap.get(entityName);
	String tableName = entityInfo.getTableName();
	SqlParmeter sqlParmeter = new SqlParmeter();
	if (null == parameter) {
		parameter = new HeaMap();
	}
	if (parameter.size() == 0) {
		throw new RuntimeException("必须传人参数!");
	}
	List<Object> params = new ArrayList<Object>();
	ConcurrentHashMap<String, Boolean> aliasMap = new ConcurrentHashMap<String, Boolean>();
	StringBuffer whereSql = new StringBuffer();// 包含where后面的sql语局
	String link = "where";// 第一个默认连接是where
	boolean firstQueryFlag = true;// 是否是第一个需查项
	List<String> groupSqlList = new ArrayList<String>();
	for (Entry<String, ?> entry : parameter.entrySet()) {
		String key = entry.getKey();
		Object value = entry.getValue();
		key = filterKey(key);
		if (key.startsWith(HeaConstant.Instruction.ADDGROUP)) {
			groupSqlList = getOrder(groupSqlList, value);
			continue;
		}
		ColumnCondition columnCondition = new ColumnCondition();
		columnCondition = analyzeKey(columnCondition, key, value);
		if (!columnCondition.getIfQuery()) {
			continue;
		}
		if (!firstQueryFlag) {
			link = columnCondition.getAndOr();
		}
		whereSql.append(HStringUtils.format(" {0} {1}", link, columnCondition.getSqlFragment()));
		if (null != columnCondition.getCookedValue()) {
			params.addAll(columnCondition.getCookedValue());
		}
		firstQueryFlag = false;
	}
	String whereSqlStr = whereSql.toString();
	String groupSql = "";
	if (groupSqlList.size() > 0) {
		groupSql = " group by " + HStringUtils.StrList(groupSqlList, ",");
	}
	String tempStr = HStringUtils.addStr(whereSqlStr, groupSql);
	aliasMap.putAll(HOrmUtil.getAliasFromSql(tempStr));
	// 分析得到joinSql
	String joinSql = "";
	if (!aliasMap.isEmpty()) {
		HHashMap<Integer, String> joinSqlMap = new HHashMap<Integer, String>();
		analyzeAliasMap(aliasMap, joinSqlMap);
		joinSql = getJoinSql(joinSqlMap);
	}
	String tableSqlStr = HStringUtils.format("{0} t {1}", tableName, joinSql);
	Map<String, Object> viewParams = parameter.getViewParams();
	TableSql tableSql = getTableSql(tableSqlStr, viewParams);
	tableSqlStr = tableSql.getTargetTableSql();
	List<Object> tableParams = tableSql.getParams();
	// 获得setSql
	SqlFragment setSqlEntity = getUpdateSetSql(entity, entityInfo, parameter.getUpdateNullMap());
	// 0:tableSql 1:setSql 2:where
	String sql = HStringUtils.format("update {0} set {1} {2}", tableSqlStr, setSqlEntity.getSql(), whereSqlStr);
	// String sql = StringUtils.format("delete t from {0}  {1}",
	// tableSqlStr, whereSqlStr);
	sqlParmeter.setSql(sql);
	tableParams.addAll(setSqlEntity.getParams());// set
	tableParams.addAll(params);
	sqlParmeter.setParameters(tableParams.toArray());
	return sqlParmeter;
}
 
Example 7
Project: pravega-samples   File: SharedMap.java   View Source Code Vote up 5 votes
@Override
public void process(ConcurrentHashMap<K, V> impl) {
    impl.putAll(map);
}