com.sleepycat.persist.SecondaryIndex Java Examples

The following examples show how to use com.sleepycat.persist.SecondaryIndex. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BerkeleyManager.java    From jstarcraft-core with Apache License 2.0 6 votes vote down vote up
/**
 * 构造方法
 * 
 * @param entityInfo
 * @param accessor
 */
public BerkeleyManager(BerkeleyMetadata metadata, EntityStore store) {
	this.metadata = metadata;
	this.store = store;

	// 通过获取主键索引准备Berkeley环境(有意义,别删除)
	primaryIndex = this.store.getPrimaryIndex(metadata.getPrimaryClass(), metadata.getStoreClass());
	for (String name : metadata.getIndexNames()) {
		Field field = metadata.getSecondaryField(name);
		Class<?> clazz = ClassUtility.primitiveToWrapper(field.getType());
		SecondaryIndex secondaryIndex;
		if (metadata.getOrmClass() == metadata.getStoreClass()) {
			secondaryIndex = store.getSecondaryIndex(primaryIndex, clazz, name);
		} else {
			secondaryIndex = store.getSubclassIndex(getPrimaryIndex(), metadata.getOrmClass(), clazz, name);
		}
		secondaryIndexes.put(name, secondaryIndex);
	}
}
 
Example #2
Source File: BerkeleyManager.java    From jstarcraft-core with Apache License 2.0 6 votes vote down vote up
public List<T> queryIntersection(BerkeleyTransactor transactor, Map<String, Object> condition, StoragePagination pagination) {
	Transaction transaction = transactor == null ? null : transactor.getTransaction();
	EntityJoin<K, T> join = new EntityJoin<K, T>(primaryIndex);
	for (Entry<String, Object> keyValue : condition.entrySet()) {
		SecondaryIndex<Object, K, T> secondaryIndex = secondaryIndexes.get(keyValue.getKey());
		join.addCondition(secondaryIndex, keyValue.getValue());
	}
	ArrayList<T> instances = new ArrayList<>();
	long ignore = pagination.getFirst();
	long size = pagination.getSize();
	try (ForwardCursor<T> cursor = join.entities(transaction, transactor.getIsolation().getCursorModel())) {
		if (ignore == 0) {
			collect(instances, cursor, size);
		}
		return instances;
	}
}
 
Example #3
Source File: BerkeleyManager.java    From jstarcraft-core with Apache License 2.0 6 votes vote down vote up
public List<T> queryUnion(BerkeleyTransactor transactor, Map<String, Object> condition, StoragePagination pagination) {
	Transaction transaction = transactor == null ? null : transactor.getTransaction();
	long ignore = pagination.getFirst();
	long size = pagination.getSize();
	ArrayList<T> instances = new ArrayList<>();
	// TODO 应该考虑实例重复计算的情况.
	for (Entry<String, Object> keyValue : condition.entrySet()) {
		SecondaryIndex<Object, K, T> secondaryIndex = secondaryIndexes.get(keyValue.getKey());
		try (ForwardCursor<T> cursor = secondaryIndex.subIndex(keyValue.getValue()).entities(transaction, transactor.getIsolation().getCursorModel())) {
			if (ignore > 0) {
				ignore -= ignore(cursor, ignore);
			}
			if (ignore == 0) {
				if (size > instances.size()) {
					collect(instances, cursor, size - instances.size());
				}
				if (size == instances.size()) {
					break;
				}
			}
		}
	}
	return instances;
}
 
Example #4
Source File: BerkeleyManager.java    From jstarcraft-core with Apache License 2.0 6 votes vote down vote up
public void iterateIntersection(StorageIterator<T> iterator, BerkeleyTransactor transactor, Map<String, Object> condition, StoragePagination pagination) {
	Transaction transaction = transactor == null ? null : transactor.getTransaction();
	EntityJoin<K, T> join = new EntityJoin<K, T>(primaryIndex);
	for (Entry<String, Object> keyValue : condition.entrySet()) {
		SecondaryIndex<Object, K, T> secondaryIndex = secondaryIndexes.get(keyValue.getKey());
		join.addCondition(secondaryIndex, keyValue.getValue());
	}
	long first = pagination.getFirst();
	long last = pagination.getLast();
	long count = 0;
	try (ForwardCursor<T> cursor = join.entities(transaction, transactor.getIsolation().getCursorModel())) {
		T element;
		while ((element = cursor.next()) != null) {
			if (count >= first && count < last) {
				iterator.iterate(element);
			}
			count++;
			if (count == last) {
				break;
			}
		}
	}
}
 
Example #5
Source File: BerkeleyManager.java    From jstarcraft-core with Apache License 2.0 6 votes vote down vote up
public void iterateUnion(StorageIterator<T> iterator, BerkeleyTransactor transactor, Map<String, Object> condition, StoragePagination pagination) {
	Transaction transaction = transactor == null ? null : transactor.getTransaction();
	long first = pagination.getFirst();
	long last = pagination.getLast();
	long count = 0;
	// TODO 应该考虑实例重复计算的情况.
	for (Entry<String, Object> keyValue : condition.entrySet()) {
		SecondaryIndex<Object, K, T> secondaryIndex = secondaryIndexes.get(keyValue.getKey());
		try (ForwardCursor<T> cursor = secondaryIndex.subIndex(keyValue.getValue()).entities(transaction, transactor.getIsolation().getCursorModel())) {
			T element;
			while ((element = cursor.next()) != null) {
				if (count >= first && count < last) {
					iterator.iterate(element);
				}
				count++;
				if (count == last) {
					break;
				}
			}
		}
		if (count == last) {
			break;
		}
	}
}
 
Example #6
Source File: BerkeleyManager.java    From jstarcraft-core with Apache License 2.0 5 votes vote down vote up
public long countIntersection(BerkeleyTransactor transactor, Map<String, Object> condition) {
	Transaction transaction = transactor == null ? null : transactor.getTransaction();
	EntityJoin<K, T> join = new EntityJoin<K, T>(primaryIndex);
	for (Entry<String, Object> keyValue : condition.entrySet()) {
		SecondaryIndex<Object, K, T> secondaryIndex = secondaryIndexes.get(keyValue.getKey());
		join.addCondition(secondaryIndex, keyValue.getValue());
	}
	try (ForwardCursor<K> cursor = join.keys(transaction, transactor.getIsolation().getCursorModel())) {
		return count(cursor);
	}
}
 
Example #7
Source File: BerkeleyManager.java    From jstarcraft-core with Apache License 2.0 5 votes vote down vote up
public long countUnion(BerkeleyTransactor transactor, Map<String, Object> condition) {
	Transaction transaction = transactor == null ? null : transactor.getTransaction();
	long count = 0;
	// TODO 应该考虑实例重复计算的情况.
	for (Entry<String, Object> keyValue : condition.entrySet()) {
		SecondaryIndex<Object, K, T> secondaryIndex = secondaryIndexes.get(keyValue.getKey());
		try (ForwardCursor<K> cursor = secondaryIndex.subIndex(keyValue.getValue()).keys(transaction, transactor.getIsolation().getCursorModel())) {
			count += count(cursor);
		}
	}
	return count;
}
 
Example #8
Source File: BerkeleyManager.java    From jstarcraft-core with Apache License 2.0 4 votes vote down vote up
SecondaryIndex getSecondaryIndex(String name) {
	return secondaryIndexes.get(name);
}