public void fromStream() { name = document.field("name"); if (document.field("type") != null) type = OType.getById(((Long) document.field("type")).byteValue()); offset = ((Long) document.field("offset")).intValue(); mandatory = (Boolean) document.field("mandatory"); notNull = (Boolean) document.field("notNull"); min = document.field("min"); max = document.field("max"); linkedClassName = (String) document.field("linkedClass"); if (document.field("linkedType") != null) linkedType = OType.getById(((Long) document.field("linkedType")).byteValue()); if (document.field("index") != null) { setIndex( INDEX_TYPE.valueOf((String) document.field("index-type")), ((ODocument) document.field("index")).getIdentity()); try { index.load(); } catch (IOException e) { OLogManager.instance() .error( this, "Can't load index for property %s", e, ODatabaseException.class, toString()); } } }
public String getColumnTypeName(int column) throws SQLException { ODocument currentRecord = this.resultSet.unwrap(ODocument.class); if (currentRecord == null) return null; else { OType columnType = currentRecord.fieldType(currentRecord.fieldNames()[column - 1]); if (columnType == null) return null; return columnType.toString(); } }
protected OGlobalProperty findOrCreateGlobalProperty(final String name, final OType type) { OGlobalProperty global = propertiesByNameType.get(name + "|" + type.name()); if (global == null) { int id = properties.size(); global = new OGlobalPropertyImpl(name, type, id); properties.add(id, global); propertiesByNameType.put(global.getName() + "|" + global.getType().name(), global); } return global; }
@Override @SuppressWarnings("unchecked") protected boolean evaluateExpression( final OIdentifiable iRecord, final OSQLFilterCondition iCondition, final Object iLeft, final Object iRight, OCommandContext iContext) { final Object right = OType.convert(iRight, iLeft.getClass()); if (right == null) return false; return ((Comparable<Object>) iLeft).compareTo(right) >= 0; }
public static boolean equals(final Object iLeft, final Object iRight) { if (iLeft == null || iRight == null) return false; // RECORD & ORID if (iLeft instanceof ORecord<?>) return comparesValues(iRight, (ORecord<?>) iLeft, true); else if (iRight instanceof ORecord<?>) return comparesValues(iLeft, (ORecord<?>) iRight, true); // ALL OTHER CASES final Object right = OType.convert(iRight, iLeft.getClass()); if (right == null) return false; return iLeft.equals(right); }
@SuppressWarnings({"unchecked", "rawtypes"}) public Object execute( Object iThis, final OIdentifiable iCurrentRecord, Object iCurrentResult, final Object[] iParams, OCommandContext iContext) { // calculate min value for current record // consider both collection of parameters and collection in each parameter Object min = null; for (Object item : iParams) { if (item instanceof Collection<?>) { for (Object subitem : ((Collection<?>) item)) { if (min == null || subitem != null && ((Comparable) subitem).compareTo(min) < 0) min = subitem; } } else { if (min == null || item != null && ((Comparable) item).compareTo(min) < 0) min = item; } } // what to do with the result, for current record, depends on how this function has been invoked // for an unique result aggregated from all output records if (aggregateResults() && min != null) { if (context == null) // FIRST TIME context = (Comparable) min; else { if (context instanceof Number && min instanceof Number) { final Number[] casted = OType.castComparableNumber((Number) context, (Number) min); context = casted[0]; min = casted[1]; } if (((Comparable<Object>) context).compareTo((Comparable) min) > 0) // MINOR context = (Comparable) min; } return null; } // for non aggregated results (a result per output record) return min; }
public static Object convertValue(final String iValue, final OType iExpectedType) { final Object v = getTypeValue((String) iValue); return OType.convert(v, iExpectedType.getDefaultJavaType()); }