Ejemplo n.º 1
0
 private AkCollator collator(
     ComparisonCondition cond, TPreparedExpression left, TPreparedExpression right) {
   TInstance leftInstance = left.resultType();
   TInstance rightInstance = right.resultType();
   TClass tClass = leftInstance.typeClass();
   assert tClass.compatibleForCompare(rightInstance.typeClass())
       : tClass + " != " + rightInstance.typeClass();
   if (tClass.underlyingType() != UnderlyingType.STRING) return null;
   CharacterTypeAttributes leftAttributes = StringAttribute.characterTypeAttributes(leftInstance);
   CharacterTypeAttributes rightAttributes =
       StringAttribute.characterTypeAttributes(rightInstance);
   return TString.mergeAkCollators(leftAttributes, rightAttributes);
 }
Ejemplo n.º 2
0
 private static Value convertFromObject(Object object, TInstance type, QueryContext queryContext) {
   Value in = fromObject(object);
   TInstance inType = in.getType();
   Value out = null;
   if (!inType.equals(type)) {
     TExecutionContext context =
         new TExecutionContext(Collections.singletonList(in.getType()), type, queryContext);
     out = new Value(type);
     type.typeClass().fromObject(context, in, out);
   } else {
     out = in;
   }
   return out;
 }
 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.
     return ValueSources.valuefromObject(value, type.getType());
   }
 }
Ejemplo n.º 4
0
 public static Value valuefromObject(Object object, TInstance type, QueryContext queryContext) {
   Value value = new Value(type);
   if (object == null) {
     value.putNull();
   } else if (object instanceof String) {
     // This is the common case, so let's test for it first
     if (TInstance.underlyingType(type) == UnderlyingType.STRING)
       value.putString((String) object, null);
     else if (type == null) {
       type =
           MString.VARCHAR.instance(
               ((String) object).length(),
               StringFactory.DEFAULT_CHARSET.ordinal(),
               StringFactory.NULL_COLLATION_ID,
               false);
       value = new Value(type, (String) object);
     }
   } else if (type == null) {
     value = fromObject(object);
   } else if (object instanceof BlobRef) {
     value.putObject(object);
   } else {
     switch (TInstance.underlyingType(type)) {
       case INT_8:
       case INT_16:
       case UINT_16:
       case INT_32:
       case INT_64:
         if (object instanceof Number) valueFromLong(((Number) object).longValue(), value);
         break;
       case FLOAT:
         if (object instanceof Number) value.putFloat(((Number) object).floatValue());
         break;
       case DOUBLE:
         if (object instanceof Number) value.putDouble(((Number) object).doubleValue());
         break;
       case BYTES:
         if (object instanceof byte[]) value.putBytes((byte[]) object);
         else if (object instanceof ByteSource)
           value.putBytes(((ByteSource) object).toByteSubarray());
         else if (object instanceof JTSSpatialObject) {
           if (AkBlob.isBlob(type.typeClass())) {
             byte[] content = Spatial.serializeWKB((JTSSpatialObject) object);
             value.putObject(new BlobRef(content));
           }
         }
         break;
       case STRING:
         if ((object instanceof JTSSpatialObject)) {
           value = new Value(type, Spatial.serializeWKT((JTSSpatialObject) object));
         } else {
           throw new IllegalArgumentException("Unsafe toString(): " + object.getClass());
         }
         break;
       case BOOL:
         if (object instanceof Boolean) value.putBool((Boolean) object);
         break;
     }
   }
   if (!value.hasAnyValue()) {
     if (type == null) {
       value = fromObject(object);
     } else {
       value = convertFromObject(object, type, queryContext);
     }
   }
   return value;
 }
Ejemplo n.º 5
0
 private TClass tClass(TPreparedExpression left) {
   TInstance type = left.resultType();
   return type == null ? null : type.typeClass();
 }