use of com.cinchapi.concourse.server.model.Identifier in project concourse by cinchapi.
the class Database method explore.
@Override
public Map<Long, Set<TObject>> explore(String key, Aliases aliases, long timestamp) {
Text L = Text.wrapCached(key);
IndexRecord index = getIndexRecord(L);
Value[] Ks = Transformers.transformArray(aliases.values(), Value::wrap, Value.class);
Map<Identifier, Set<Value>> map = index.findAndGet(timestamp, aliases.operator(), Ks);
return Transformers.transformTreeMapSet(map, Identifier::longValue, Value::getTObject, Long::compare);
}
use of com.cinchapi.concourse.server.model.Identifier in project concourse by cinchapi.
the class IndexRecord method findAndGet.
/**
* Explore this record and return a mapping from PrimaryKey to the Values
* that cause the corresponding records to satisfy {@code operator} in
* relation to the specified {@code values} (and at the specified
* {@code timestamp} if {@code historical} is {@code true}).
*
* @param historical - if {@code true} query the history, otherwise query
* the current state
* @param timestamp - this value is ignored if {@code historical} is
* {@code false}, otherwise this value is the historical
* timestamp at which to query the field
* @param operator
* @param values
* @return the relevant data that causes the matching records to satisfy the
* criteria
*/
private Map<Identifier, Set<Value>> findAndGet(boolean historical, long timestamp, Operator operator, Value... values) {
/* Authorized */
// CON-667: Value ordering for Strings is such that uppercase characters
// are "smaller" than lowercase ones. Concourse uses case insensitive
// matching, so we sometimes must modify the input #values in order to
// ensure that all equal forms of a value are captured or excluded as
// necessary.
read.lock();
try {
Map<Identifier, Set<Value>> data = Maps.newHashMap();
Value value = values[0];
if (operator == Operator.EQUALS) {
for (Entry<Value, Set<Identifier>> entry : (historical ? coalesce(value, timestamp) : coalesce(value)).entrySet()) {
Value stored = entry.getKey();
for (Identifier record : entry.getValue()) {
MultimapViews.put(data, record, stored);
}
}
} else if (operator == Operator.NOT_EQUALS) {
for (Value stored : historical ? history.keySet() : present.keySet()) {
if (!value.equalsIgnoreCase(stored)) {
for (Identifier record : historical ? get(stored, timestamp) : get(stored)) {
MultimapViews.put(data, record, stored);
}
}
}
} else if (operator == Operator.GREATER_THAN) {
// CON-667
value = value.toLowerCase();
for (Value stored : historical ? history.keySet() : ((NavigableSet<Value>) present.keySet()).tailSet(value, false)) {
if (!historical || stored.compareToIgnoreCase(value) > 0) {
for (Identifier record : historical ? get(stored, timestamp) : get(stored)) {
MultimapViews.put(data, record, stored);
}
}
}
} else if (operator == Operator.GREATER_THAN_OR_EQUALS) {
// CON-667
value = value.toUpperCase();
for (Value stored : historical ? history.keySet() : ((NavigableSet<Value>) present.keySet()).tailSet(value, true)) {
if (!historical || stored.compareToIgnoreCase(value) >= 0) {
for (Identifier record : historical ? get(stored, timestamp) : get(stored)) {
MultimapViews.put(data, record, stored);
}
}
}
} else if (operator == Operator.LESS_THAN) {
// CON-667
value = value.toUpperCase();
for (Value stored : historical ? history.keySet() : ((NavigableSet<Value>) present.keySet()).headSet(value, false)) {
if (!historical || stored.compareToIgnoreCase(value) < 0) {
for (Identifier record : historical ? get(stored, timestamp) : get(stored)) {
MultimapViews.put(data, record, stored);
}
}
}
} else if (operator == Operator.LESS_THAN_OR_EQUALS) {
// CON-667
value = value.toLowerCase();
for (Value stored : historical ? history.keySet() : ((NavigableSet<Value>) present.keySet()).headSet(value, true)) {
if (!historical || stored.compareToIgnoreCase(value) <= 0) {
for (Identifier record : historical ? get(stored, timestamp) : get(stored)) {
MultimapViews.put(data, record, stored);
}
}
}
} else if (operator == Operator.BETWEEN) {
Preconditions.checkArgument(values.length > 1);
Value value2 = values[1];
// CON-667
value = value.toUpperCase();
// CON-667
value2 = value2.toUpperCase();
for (Value stored : historical ? history.keySet() : ((NavigableSet<Value>) present.keySet()).subSet(value, true, value2, false)) {
if (!historical || (stored.compareTo(value) >= 0 && stored.compareTo(value2) < 0)) {
for (Identifier record : historical ? get(stored, timestamp) : get(stored)) {
MultimapViews.put(data, record, stored);
}
}
}
} else if (operator == Operator.REGEX) {
Pattern p = Pattern.compile(value.getObject().toString());
for (Value stored : historical ? history.keySet() : present.keySet()) {
Matcher m = p.matcher(stored.getObject().toString());
if (m.matches()) {
for (Identifier record : historical ? get(stored, timestamp) : get(stored)) {
MultimapViews.put(data, record, stored);
}
}
}
} else if (operator == Operator.NOT_REGEX) {
Pattern p = Pattern.compile(value.getObject().toString());
for (Value stored : historical ? history.keySet() : present.keySet()) {
Matcher m = p.matcher(stored.getObject().toString());
if (!m.matches()) {
for (Identifier record : historical ? get(stored, timestamp) : get(stored)) {
MultimapViews.put(data, record, stored);
}
}
}
} else {
throw new UnsupportedOperationException();
}
return data;
} finally {
read.unlock();
}
}
use of com.cinchapi.concourse.server.model.Identifier in project concourse by cinchapi.
the class Database method contains.
@Override
public boolean contains(long record) {
Identifier L = Identifier.of(record);
TableRecord table = getTableRecord(L);
return !table.isEmpty();
}
use of com.cinchapi.concourse.server.model.Identifier in project concourse by cinchapi.
the class Database method verify.
@Override
public boolean verify(Write write, long timestamp) {
Identifier L = write.getRecord();
Text K = write.getKey();
Value V = write.getValue();
TableRecord table = getTableRecord(L, K);
return table.contains(K, V, timestamp);
}
use of com.cinchapi.concourse.server.model.Identifier in project concourse by cinchapi.
the class Database method gather.
@Override
public Set<TObject> gather(String key, long record, long timestamp) {
Text L = Text.wrapCached(key);
Identifier V = Identifier.of(record);
IndexRecord index = getIndexRecord(L);
Set<Value> Ks = index.gather(V, timestamp);
return Transformers.transformSet(Ks, Value::getTObject);
}
Aggregations