Package com.foundationdb.server.types.value

Examples of com.foundationdb.server.types.value.Value


        getTypesTranslator().setTimestampMillisValue(value, x.getTime(), 0);
        setValue(index, value);
    }

    public void setTimestamp(int index, Timestamp x) {
        Value value = new Value(jdbcInstance(Types.TIMESTAMP));
        getTypesTranslator().setTimestampMillisValue(value, x.getTime(), x.getNanos());
        setValue(index, value);
    }
View Full Code Here


    // For use by this class

    private Row intRow(RowType rowType, int x)
    {
        List<TPreparedExpression> pExpressions = Arrays.<TPreparedExpression>asList(new TPreparedLiteral(MNumeric.INT.instance(false), new Value(MNumeric.INT.instance(false), x)));
        return new ExpressionRow(rowType, queryContext, queryBindings, pExpressions);
    }
View Full Code Here

            if (tcast == null)
                throw new NoSuchCastException(sourceInstance, targetInstance);
            tcontext = new TExecutionContext(Collections.singletonList(sourceInstance),
                                             targetInstance,
                                             context);
            target = new Value(targetInstance);
        }
View Full Code Here

        if (targetType == null && encoded != null) {
            throw new UnknownDataTypeException(null);
        }
        ValueSource source;
        if (encoded == null) {
            Value value = new Value(targetType);
            value.putNull();
            bindings.setValue(index, value);
            return;
        }
        else if (!binary) {
            try {
                source = new Value(MString.varchar(), new String(encoded, encoding));
            }
            catch (UnsupportedEncodingException ex) {
                throw new UnsupportedCharsetException(encoding);
            }
        }
        else {
            try {
                switch (type.getBinaryEncoding()) {
                case BINARY_OCTAL_TEXT:
                    source = new Value(MBinary.VARBINARY.instance(false), encoded);
                    break;
                case INT_8:
                case INT_16:
                case INT_32:
                case INT_64: // Types.BIGINT
                    // Go by the length sent rather than the implied type.
                    source = decodeIntegerType(encoded);
                    break;
                case FLOAT_32:

                    source = new Value(MApproximateNumber.FLOAT.instance(false), getDataStream(encoded).readFloat());
                    break;
                case FLOAT_64:
                    source = new Value(MApproximateNumber.DOUBLE.instance(false), getDataStream(encoded).readDouble());
                    break;
                case BOOLEAN_C:
                    source = new Value(AkBool.INSTANCE.instance(false), encoded[0] != 0);
                    break;
                case TIMESTAMP_INT64_MICROS_2000_NOTZ: // Types.TIMESTAMP
                    source = decodeTimestampInt64Micros2000NoTZ(encoded);
                    break;
                case UUID:
                    Value value = new Value(AkGUID.INSTANCE.instance(false));
                    value.putObject(AkGUID.bytesToUUID(encoded, 0));
                    source = value;
                    break;
                // Note: these types had previous implementations, but I couldn't exercise them in tests to verify
                // either with jdbc or pg8000. If you run into them, try looking at the log for this file, it most
                // likely has a correct starting point
                case STRING_BYTES:
                case TIMESTAMP_FLOAT64_SECS_2000_NOTZ: // Types.TIMESTAMP
                case DAYS_2000: // DATE
                case TIME_FLOAT64_SECS_NOTZ: // TIME
                case TIME_INT64_MICROS_NOTZ: // TIME
                case DECIMAL_PG_NUMERIC_VAR:
                default:
                    throw new UnknownDataTypeException(type.toString());
                }
            }
            catch (UnsupportedEncodingException ex) {
                throw new UnsupportedCharsetException(encoding);
            }
            catch (IOException ex) {
                throw new AkibanInternalException("IO error reading from byte array", ex);
            }
        }
        TCast cast = typesRegistryService.getCastsResolver().cast(source.getType(), targetType);
        TExecutionContext context =
                new TExecutionContext(Collections.singletonList(source.getType()),
                        targetType,
                        queryContext);
        Value target = new Value(targetType);
        cast.evaluate(context, source, target);
        bindings.setValue(index, target);
    }
View Full Code Here

    private ValueSource decodeTimestampInt64Micros2000NoTZ(byte[] encoded) throws IOException {
        long micros = getDataStream(encoded).readLong();
        long secs = micros / 1000000;
        long milliseconds = seconds2000NoTZ(secs);
        int nanos = (int) (micros - secs * 1000000) * 1000;
        Value source = new Value(MDateAndTime.TIMESTAMP.instance(false));
        typesTranslator.setTimestampMillisValue(source, milliseconds, nanos);
        return source;
    }
View Full Code Here

    }

    public ValueSource decodeIntegerType(byte[] encoded) throws IOException {
        switch (encoded.length) {
        case 1:
            return new Value(MNumeric.TINYINT.instance(false), getDataStream(encoded).read());
        case 2:
            return new Value(MNumeric.SMALLINT.instance(false), getDataStream(encoded).readShort());
        case 4:
            return new Value(MNumeric.INT.instance(false), getDataStream(encoded).readInt());
        case 8:
            return new Value(MNumeric.BIGINT.instance(false), getDataStream(encoded).readLong());
        default:
            throw new AkibanInternalException("Not an integer size: " + encoded);
        }
    }
View Full Code Here

    }

    public ValueSource valuefromObject(Object value, ServerType type) {
        if (value instanceof Date) {
            TInstance dateType = javaDateTInstance(value);
            Value dateValue = new Value(dateType);
            typesTranslator.setTimestampMillisValue(dateValue, ((Date)value).getTime(),
                                                    (value instanceof java.sql.Timestamp) ?
                                                    ((java.sql.Timestamp)value).getNanos() : 0);
            TInstance targetType = type.getType();
            if (dateType.equals(targetType))
                return dateValue;
            TExecutionContext context =
                new TExecutionContext(Collections.singletonList(dateType),
                                      targetType, null);
            Value result = new Value(targetType);
            targetType.typeClass().fromObject(context, dateValue, result);
            return result;
        }
        else {
            // TODO this is inefficient, but I want to get it working.
View Full Code Here

    static abstract class ValueRoutineInvocation extends ServerRoutineInvocation {
        protected Value returnValue;

        protected ValueRoutineInvocation(Routine routine) {
            super(routine);
            returnValue = new Value(routine.getReturnValue().getType());
        }
View Full Code Here

            else {
                source = bindings.getValue(parameterArgs[index]);
            }
            // Constants passed or parameters bound may not be of the
            // type specified in the signature.
            Value value = new Value(type);
            TExecutionContext executionContext =
                new TExecutionContext(null, null, type,
                                      context, null, null, null);
            tclass.fromObject(executionContext, source, value);
            return value;
View Full Code Here

                pvalue = ValueSources.fromObject(value, (TInstance) null);
            TExecutionContext context = new TExecutionContext(null,
                                                              Collections.singletonList(pvalue.type()),
                    type,
                                                              null, null, null, null);
            Value pvalue2 = new Value(type);
            type.typeClass().fromObject(context, pvalue.value(), pvalue2);
            type.writeCollating(pvalue2, keyTarget);
        }
        return key;
    }
View Full Code Here

TOP

Related Classes of com.foundationdb.server.types.value.Value

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.