Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
*
* Copyright 2017-2018 Nitrite author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.dizitart.no2.internals;
import org.dizitart.no2.*;
import org.dizitart.no2.event.ChangeInfo;
import org.dizitart.no2.event.ChangeListener;
import org.dizitart.no2.event.EventBus;
import org.dizitart.no2.fulltext.EnglishTextTokenizer;
import org.dizitart.no2.fulltext.TextIndexingService;
import org.dizitart.no2.fulltext.TextTokenizer;
import org.dizitart.no2.mapper.NitriteMapper;
import org.dizitart.no2.store.NitriteMap;
import java.util.Collection;
import java.util.Set;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import static org.dizitart.no2.exceptions.ErrorCodes.*;
import static org.dizitart.no2.exceptions.ErrorMessage.errorMessage;
import static org.dizitart.no2.util.ValidationUtils.notNull;
/**
* A service class for Nitrite database operations.
*
* @since 1.0
* @author Anindya Chatterjee
*/
public class NitriteService {
private NitriteContext nitriteContext;
private final NitriteMap mapStore;
private IndexingService indexingService;
private DataService dataService;
private SearchService searchService;
private IndexedSearchService indexedSearchService;
private IndexMetaService indexMetaService;
private EventBus eventBus;
private ReentrantReadWriteLock readWriteLock;
private Lock readLock;
private Lock writeLock;
/**
* Instantiates a new Nitrite service.
*
* @param mapStore the map store
* @param nitriteContext the nitrite context
*/
NitriteService(NitriteMap mapStore,
NitriteContext nitriteContext,
EventBus eventBus) {
this.mapStore = mapStore;
this.nitriteContext = nitriteContext;
this.eventBus = eventBus;
init();
}
/**
* Specifies if an indexing operation is currently running.
*
* @param field the field
* @return `true` if operation is still running; `false` otherwise.
*/
public boolean isIndexing(String field) {
notNull(field, errorMessage("field can not be null", VE_IS_INDEXING_NULL_FIELD));
return indexingService.isIndexing(field);
}
/**
* Specifies if a value is indexed.
*
* @param field the field
* @return `true` if indexed; `false` otherwise.
*/
public boolean hasIndex(String field) {
notNull(field, errorMessage("field can not be null", VE_HAS_INDEX_NULL_FIELD));
return indexMetaService.hasIndex(field);
}
/**
* Finds with equal filer using index.
*
* @param field the field
* @param value the value
* @return the result set.
*/
public Set findEqualWithIndex(String field, Object value) {
notNull(field, errorMessage("field can not be null", VE_FIND_EQUAL_INDEX_NULL_FIELD));
return indexedSearchService.findEqual(field, value);
}
/**
* Finds with greater than filer using index.
*
* @param field the field
* @param value the value
* @return the result set
*/
public Set findGreaterThanWithIndex(String field, Comparable value) {
notNull(field, errorMessage("field can not be null", VE_FIND_GT_INDEX_NULL_FIELD));
notNull(value, errorMessage("value can not be null", VE_FIND_GT_INDEX_NULL_VALUE));
return indexedSearchService.findGreaterThan(field, value);
}
/**
* Finds with greater and equal filer using index.
*
* @param field the field
* @param value the value
* @return the result set
*/
public Set findGreaterEqualWithIndex(String field, Comparable value) {
notNull(field, errorMessage("field can not be null", VE_FIND_GTE_INDEX_NULL_FIELD));
notNull(value, errorMessage("value can not be null", VE_FIND_GTE_INDEX_NULL_VALUE));
return indexedSearchService.findGreaterEqual(field, value);
}
/**
* Finds with lesser filer using index.
*
* @param field the field
* @param value the value
* @return the result set
*/
public Set findLesserThanWithIndex(String field, Comparable value) {
notNull(field, errorMessage("field can not be null", VE_FIND_LT_INDEX_NULL_FIELD));
notNull(value, errorMessage("value can not be null", VE_FIND_LT_INDEX_NULL_VALUE));
return indexedSearchService.findLesserThan(field, value);
}
/**
* Finds with lesser equal filer using index.
*
* @param field the field
* @param value the value
* @return the result set
*/
public Set findLesserEqualWithIndex(String field, Comparable value) {
notNull(field, errorMessage("field can not be null", VE_FIND_LTE_INDEX_NULL_FIELD));
notNull(value, errorMessage("value can not be null", VE_FIND_LTE_INDEX_NULL_VALUE));
return indexedSearchService.findLesserEqual(field, value);
}
/**
* Finds with in filer using index.
*
* @param field the value
* @param values the values
* @return the result set
*/
public Set findInWithIndex(String field, Collection