private CustomAttribute(String name, OType type, Class<?> javaClass, Object defaultValue, boolean encode, boolean hiearchical) { this.name = name; this.type = type; this.javaClass = javaClass!=null?javaClass:type.getDefaultJavaType(); this.defaultValue = defaultValue; this.encode = encode; this.hiearchical = hiearchical; CACHE.put(name, this); }
/** * {@inheritDoc} */ public Object createValue(final Object... params) { return OType.convert(params[0], keyType.getDefaultJavaType()); }
@Override public Object createSingleValue(Object... param) { return OType.convert(param[0], keyType.getDefaultJavaType()); }
public Object createValue(final List<?> params) { return OType.convert(params.get(0), keyType.getDefaultJavaType()); }
private Object convert(Object o, OType oType) { return OType.convert(o, oType.getDefaultJavaType()); }
protected Object convertValue(final OIndex<?> idx, Object iValue) { if (iValue != null) { final OType[] types = idx.getKeyTypes(); if (types.length == 0) iValue = iValue.toString(); else iValue = OType.convert(iValue, types[0].getDefaultJavaType()); } return iValue; }
protected Object convertKey(final OIndex<?> idx, Object iValue) { if (iValue != null) { final OType[] types = idx.getKeyTypes(); if (types.length == 0) iValue = iValue.toString(); else iValue = OType.convert(iValue, types[0].getDefaultJavaType()); } return iValue; }
public static boolean equals(final Object iLeft, final Object iRight, OType type) { if (type == null) { return equals(iLeft, iRight); } Object left = OType.convert(iLeft, type.getDefaultJavaType()); Object right = OType.convert(iRight, type.getDefaultJavaType()); return equals(left, right); }
@Override public Object apply(ODocument input) { return OType.convert(input.field("value"), linkedType.getDefaultJavaType()); } });
protected Object[] convertKeys(final OIndex<?> idx, Object[] iValue) { if (iValue != null) { final OType[] types = idx.getKeyTypes(); if (types.length == iValue.length) { Object[] newValue = new Object[types.length]; for (int i = 0; i < types.length; i++) { newValue[i] = OType.convert(iValue[i], types[i].getDefaultJavaType()); } iValue = newValue; } } return iValue; }
public static Object convertValue(final String iValue, final OType iExpectedType) { final Object v = getTypeValue((String) iValue); return OType.convert(v, iExpectedType.getDefaultJavaType()); }
private static String resolveSortExpression(OProperty property) { if(property==null || property.getType()==null) return null; Class<?> defType = property.getType().getDefaultJavaType(); return defType!=null && Comparable.class.isAssignableFrom(defType)?property.getName():null; }
public Object createValue(final Object... params) { if (params == null || params.length == 0) return null; if (keyTypes.length == 1) return OType.convert(params[0], keyTypes[0].getDefaultJavaType()); final OCompositeKey compositeKey = new OCompositeKey(); for (int i = 0; i < params.length; ++i) { final Comparable<?> paramValue = (Comparable<?>) OType.convert(params[i], keyTypes[i].getDefaultJavaType()); if (paramValue == null) return null; compositeKey.addKey(paramValue); } return compositeKey; }
public Object createSingleValue(final Object... param) { try { return OType.convert(param[0], keyType.getDefaultJavaType()); } catch (Exception e) { OException ex = OException .wrapException(new OIndexException("Invalid key for index: " + param[0] + " cannot be converted to " + keyType), e); throw ex; } }
private Object processKnownType(ODocument doc, int i, String fieldName, String fieldStringValue, OType fieldType) { Object fieldValue; fieldValue = getCellContent(fieldStringValue); try { fieldValue = OType.convert(fieldValue, fieldType.getDefaultJavaType()); doc.field(fieldName, fieldValue); } catch (Exception e) { processor.getStats().incrementErrors(); log(OETLProcessor.LOG_LEVELS.ERROR, "Error on converting row %d field '%s' (%d), value '%s' (class:%s) to type: %s", processor.getExtractor().getProgress(), fieldName, i, fieldValue, fieldValue.getClass().getName(), fieldType); } return fieldValue; }
protected void validateType(final IValidatable<T> validatable, final OProperty p, final Object value) { if (value != null) if (OType.convert(value, p.getLinkedType().getDefaultJavaType()) == null) validatable.error(newValidationError("wrongtype", "expectedType", p.getLinkedType().toString())); }
protected static void validateType(final OProperty p, final Object value) { if (value != null) if (OType.convert(value, p.getLinkedType().getDefaultJavaType()) == null) throw new OValidationException( "The field '" + p.getFullName() + "' has been declared as " + p.getType() + " of type '" + p.getLinkedType() + "' but the value is " + value); }
protected void validateType(final IValidatable<T> validatable, final OProperty p, final Object value) { if (value != null) if (OType.convert(value, p.getLinkedType().getDefaultJavaType()) == null) validatable.error(newValidationError("wrongtype", "expectedType", p.getLinkedType().toString())); }
@Override public void setValue(Object object, Object value, PropertyResolverConverter converter) { ODocument doc = toODocument(object); if(value!=null && ! OType.isSimpleType(value)) { //Try to convert if type is not simple OClass schemaClass = doc.getSchemaClass(); OProperty property = schemaClass.getProperty(exp); if(property!=null) { value = converter.convert(value, property.getType().getDefaultJavaType()); } } doc.field(exp, value); }
@Override public void setValue(Object object, Object value, PropertyResolverConverter converter) { ODocument doc = toODocument(object); if(value!=null && ! OType.isSimpleType(value)) { //Try to convert if type is not simple OClass schemaClass = doc.getSchemaClass(); OProperty property = schemaClass.getProperty(exp); if(property!=null) { value = converter.convert(value, property.getType().getDefaultJavaType()); } } doc.field(exp, value); }