Search in sources :

Example 41 with TObject

use of com.cinchapi.concourse.thrift.TObject in project concourse by cinchapi.

the class AtomicOperation method explore.

@Override
public Map<Long, Set<TObject>> explore(String key, Aliases aliases) {
    checkState();
    Operator operator = aliases.operator();
    TObject[] values = aliases.values();
    Text key0 = Text.wrapCached(key);
    RangeToken rangeToken = RangeToken.forReading(key0, operator, Transformers.transformArray(values, Value::wrap, Value.class));
    source.addVersionChangeListener(rangeToken, this);
    Iterable<Range<Value>> ranges = RangeTokens.convertToRange(rangeToken);
    for (Range<Value> range : ranges) {
        rangeReads2Lock.put(key0, range);
    }
    return super.explore(key, aliases);
}
Also used : Operator(com.cinchapi.concourse.thrift.Operator) TObject(com.cinchapi.concourse.thrift.TObject) RangeToken(com.cinchapi.concourse.server.concurrent.RangeToken) Value(com.cinchapi.concourse.server.model.Value) Text(com.cinchapi.concourse.server.model.Text) Range(com.google.common.collect.Range)

Example 42 with TObject

use of com.cinchapi.concourse.thrift.TObject in project concourse by cinchapi.

the class BufferedStore method set.

/**
 * Set {@code key} as {@code value} in {@code record}.
 * <p>
 * This method will remove all the values currently mapped from {@code key}
 * in {@code record} and add {@code value} without performing any validity
 * checks.
 * </p>
 *
 * @param key
 * @param value
 * @param record
 */
public void set(String key, TObject value, long record) {
    try {
        ensureWriteIntegrity(key, value, record);
        Set<TObject> values = select(key, record);
        for (TObject stored : values) {
            limbo.insert(Write.remove(key, stored, record));
        }
        limbo.insert(Write.add(key, value, record));
    } catch (ReferentialIntegrityException e) {
        throw new IllegalArgumentException(e.getMessage());
    }
}
Also used : TObject(com.cinchapi.concourse.thrift.TObject)

Example 43 with TObject

use of com.cinchapi.concourse.thrift.TObject in project concourse by cinchapi.

the class BufferedStore method remove.

/**
 * Remove {@code key} as {@code value} from {@code record} with the
 * directive to {@code sync} the data or not. Depending upon the
 * implementation of the {@link #limbo}, a sync may guarantee that the data
 * is durably stored.
 * <p>
 * This method deletes the mapping from {@code key} to {@code value} in
 * {@code record}, if that mapping <em>currently</em> exists (i.e.
 * {@link #verify(String, Object, long)} is {@code true}. No other mappings
 * from {@code key} in {@code record} are affected.
 * </p>
 *
 * @param write
 * @param sync
 * @param verify
 * @return {@code true} if the mapping is removed
 */
protected boolean remove(Write write, Sync sync, Verify verify) {
    try {
        String key = write.getKey().toString();
        TObject value = write.getValue().getTObject();
        long record = write.getRecord().longValue();
        ensureWriteIntegrity(key, value, record);
        // Transaction
        if (verify == Verify.NO || verifyWithReentrancy(write)) {
            // the Buffer allows group sync to happen
            return limbo.insert(write, sync == Sync.YES);
        } else {
            return false;
        }
    } catch (ReferentialIntegrityException e) {
        return false;
    }
}
Also used : TObject(com.cinchapi.concourse.thrift.TObject)

Example 44 with TObject

use of com.cinchapi.concourse.thrift.TObject in project concourse by cinchapi.

the class Value method wrap.

/**
 * Return a Value that is backed by {@code data}.
 *
 * @param data
 * @return the Value
 */
public static Value wrap(TObject data) {
    Object obj = data.getServerWrapper();
    /* (Authorized) */
    if (obj == null) {
        // We cache the Value that wraps the TObject, onto the TObject
        // itself to prevent unnecessary creation of additional wrappers
        // throughout the Engine when TObjects and Values are converted
        // back-and-forth (interface-based programming for the win, right).
        // TObject is defined in the client, which doesn't have access to
        // this Value class, so the #serverWrapper attribute of the TObject
        // is a generic object. Thats not ideal, but this approach means
        // that we only pay the penalty for a type cast (which can be JIT
        // optimized) as opposed to the penalty for object creation when
        // wrapping the same TObject to a Value more than once
        Value value = new Value(data);
        data.cacheServerWrapper(value);
        return value;
    } else if (obj instanceof Value) {
        return (Value) obj;
    } else {
        // We should never get here because this means that someone
        // deliberately cached a garbage value, which shouldn't happen once
        // the TObject is re-constructed by the server.
        data.cacheServerWrapper(null);
        return wrap(data);
    }
}
Also used : TObject(com.cinchapi.concourse.thrift.TObject)

Example 45 with TObject

use of com.cinchapi.concourse.thrift.TObject in project concourse by cinchapi.

the class Convert method javaToThrift.

/**
 * Return the Thrift Object that represents {@code object}.
 *
 * @param object
 * @return the TObject
 */
public static TObject javaToThrift(Object object) {
    if (object == null) {
        return TObject.NULL;
    } else {
        ByteBuffer bytes;
        Type type = null;
        if (object instanceof Boolean) {
            bytes = ByteBuffer.allocate(1);
            bytes.put((boolean) object ? (byte) 1 : (byte) 0);
            type = Type.BOOLEAN;
        } else if (object instanceof Double) {
            bytes = ByteBuffer.allocate(8);
            bytes.putDouble((double) object);
            type = Type.DOUBLE;
        } else if (object instanceof Float) {
            bytes = ByteBuffer.allocate(4);
            bytes.putFloat((float) object);
            type = Type.FLOAT;
        } else if (object instanceof Link) {
            bytes = ByteBuffer.allocate(8);
            bytes.putLong(((Link) object).longValue());
            type = Type.LINK;
        } else if (object instanceof Long) {
            bytes = ByteBuffer.allocate(8);
            bytes.putLong((long) object);
            type = Type.LONG;
        } else if (object instanceof Integer) {
            bytes = ByteBuffer.allocate(4);
            bytes.putInt((int) object);
            type = Type.INTEGER;
        } else if (object instanceof BigDecimal) {
            bytes = ByteBuffer.allocate(8);
            bytes.putDouble((double) ((BigDecimal) object).doubleValue());
            type = Type.DOUBLE;
        } else if (object instanceof Tag) {
            bytes = ByteBuffer.wrap(object.toString().getBytes(StandardCharsets.UTF_8));
            type = Type.TAG;
        } else if (object instanceof Timestamp) {
            try {
                bytes = ByteBuffer.allocate(8);
                bytes.putLong(((Timestamp) object).getMicros());
                type = Type.TIMESTAMP;
            } catch (IllegalStateException e) {
                throw new UnsupportedOperationException("Cannot convert string based Timestamp to a TObject");
            }
        } else if (object instanceof Function) {
            type = Type.FUNCTION;
            Function function = (Function) object;
            byte[] nameBytes = function.operation().getBytes(StandardCharsets.UTF_8);
            byte[] keyBytes = function.key().getBytes(StandardCharsets.UTF_8);
            if (function instanceof IndexFunction) {
                /*
                     * Schema:
                     * | type (1) | timestamp(8) | nameLength (4) | name
                     * (nameLength) | key |
                     */
                bytes = ByteBuffer.allocate(1 + 8 + 4 + nameBytes.length + keyBytes.length);
                bytes.put((byte) FunctionType.INDEX.ordinal());
                bytes.putLong(((TemporalFunction) function).timestamp());
                bytes.putInt(nameBytes.length);
                bytes.put(nameBytes);
                bytes.put(keyBytes);
            } else if (function instanceof KeyRecordsFunction) {
                /*
                     * Schema:
                     * | type (1) | timestamp(8) | nameLength (4) | name
                     * (nameLength) | keyLength (4) | key (keyLength) | records
                     * (8 each) |
                     */
                KeyRecordsFunction func = (KeyRecordsFunction) function;
                bytes = ByteBuffer.allocate(1 + 8 + 4 + nameBytes.length + 4 + keyBytes.length + 8 * func.source().size());
                bytes.put((byte) FunctionType.KEY_RECORDS.ordinal());
                bytes.putLong(((TemporalFunction) function).timestamp());
                bytes.putInt(nameBytes.length);
                bytes.put(nameBytes);
                bytes.putInt(keyBytes.length);
                bytes.put(keyBytes);
                for (long record : func.source()) {
                    bytes.putLong(record);
                }
            } else if (function instanceof KeyConditionFunction) {
                /*
                     * Schema:
                     * | type (1) | timestamp(8) | nameLength (4) | name
                     * (nameLength) | keyLength (4) | key (keyLength) |
                     * condition |
                     */
                KeyConditionFunction func = (KeyConditionFunction) function;
                String condition = ConcourseCompiler.get().tokenize(func.source()).stream().map(Symbol::toString).collect(Collectors.joining(" "));
                bytes = ByteBuffer.allocate(1 + 9 + 4 + nameBytes.length + 4 + keyBytes.length + condition.length());
                bytes.put((byte) FunctionType.KEY_CONDITION.ordinal());
                bytes.putLong(((TemporalFunction) function).timestamp());
                bytes.putInt(nameBytes.length);
                bytes.put(nameBytes);
                bytes.putInt(keyBytes.length);
                bytes.put(keyBytes);
                bytes.put(condition.getBytes(StandardCharsets.UTF_8));
            } else {
                throw new UnsupportedOperationException("Cannot convert the following function to a TObject: " + function);
            }
        } else {
            bytes = ByteBuffer.wrap(object.toString().getBytes(StandardCharsets.UTF_8));
            type = Type.STRING;
        }
        bytes.rewind();
        return new TObject(bytes, type).setJavaFormat(object);
    }
}
Also used : TObject(com.cinchapi.concourse.thrift.TObject) KeyRecordsFunction(com.cinchapi.ccl.type.function.KeyRecordsFunction) FunctionValueSymbol(com.cinchapi.ccl.grammar.FunctionValueSymbol) Symbol(com.cinchapi.ccl.grammar.Symbol) ByteBuffer(java.nio.ByteBuffer) Timestamp(com.cinchapi.concourse.Timestamp) BigDecimal(java.math.BigDecimal) TemporalFunction(com.cinchapi.ccl.type.function.TemporalFunction) IndexFunction(com.cinchapi.ccl.type.function.IndexFunction) TemporalFunction(com.cinchapi.ccl.type.function.TemporalFunction) KeyRecordsFunction(com.cinchapi.ccl.type.function.KeyRecordsFunction) Function(com.cinchapi.ccl.type.Function) KeyConditionFunction(com.cinchapi.ccl.type.function.KeyConditionFunction) Type(com.cinchapi.concourse.thrift.Type) IndexFunction(com.cinchapi.ccl.type.function.IndexFunction) Tag(com.cinchapi.concourse.Tag) KeyConditionFunction(com.cinchapi.ccl.type.function.KeyConditionFunction) Link(com.cinchapi.concourse.Link)

Aggregations

TObject (com.cinchapi.concourse.thrift.TObject)242 Test (org.junit.Test)100 ComplexTObject (com.cinchapi.concourse.thrift.ComplexTObject)98 Set (java.util.Set)98 AtomicSupport (com.cinchapi.concourse.server.storage.AtomicSupport)96 TranslateClientExceptions (com.cinchapi.concourse.server.aop.TranslateClientExceptions)91 VerifyAccessToken (com.cinchapi.concourse.server.aop.VerifyAccessToken)91 VerifyReadPermission (com.cinchapi.concourse.server.aop.VerifyReadPermission)88 Map (java.util.Map)76 AbstractSyntaxTree (com.cinchapi.ccl.syntax.AbstractSyntaxTree)72 SortableTable (com.cinchapi.concourse.data.sort.SortableTable)71 Store (com.cinchapi.concourse.server.storage.Store)66 Order (com.cinchapi.concourse.lang.sort.Order)63 SortableColumn (com.cinchapi.concourse.data.sort.SortableColumn)61 SortableSet (com.cinchapi.concourse.data.sort.SortableSet)60 ByteBuffer (java.nio.ByteBuffer)60 Operator (com.cinchapi.concourse.thrift.Operator)59 Entry (java.util.Map.Entry)59 Convert (com.cinchapi.concourse.util.Convert)57 Sets (com.google.common.collect.Sets)57