protected void init(T key, Object[] hints) { if (binarySerializer == null) { final OType[] types; if (hints != null && hints.length > 0) types = (OType[]) hints; else types = OCommonConst.EMPTY_TYPES_ARRAY; if (types.length > 0) type = types[0]; else type = OType.getTypeByClass(key.getClass()); binarySerializer = OBinarySerializerFactory.getInstance().getObjectSerializer(type); } }
/** * Reads the field value forcing the return type. Use this method to force return of ORID instead of the entire document by * passing ORID.class as iFieldType. * * @param iFieldName field name * @param iFieldType Forced type. * * @return field value if defined, otherwise null */ public <RET> RET field(final String iFieldName, final Class<?> iFieldType) { RET value = this.rawField(iFieldName); if (value != null) value = ODocumentHelper.convertField(this, iFieldName, OType.getTypeByClass(iFieldType), iFieldType, value); return value; }
protected void createProperty(final OClass cls, final String f, final Object fValue) { if (fValue != null) { final OType fType = OType.getTypeByClass(fValue.getClass()); try { cls.createProperty(f, fType); } catch (OSchemaException e) { } log(Level.FINE, "created property [%s.%s] of type [%s]", cls.getName(), f, fType); } }
protected void createProperty(final OClass cls, final String f, final Object fValue) { if (fValue != null) { final OType fType = OType.getTypeByClass(fValue.getClass()); try { cls.createProperty(f, fType); } catch (OSchemaException e) { } log(OETLProcessor.LOG_LEVELS.DEBUG, "created property [%s.%s] of type [%s]", cls.getName(), f, fType); } }
type = types[i]; else type = OType.getTypeByClass(key.getClass());
fieldTypeToString(iOutput, OType.getTypeByClass(o.getValue().getClass()), o.getValue()); } else { fieldTypeToString(iOutput, iLinkedType, o.getValue());
@Override public OCompositeKey preprocess(OCompositeKey value, Object... hints) { if (value == null) { return null; } final OType[] types = getKeyTypes(hints); final List<Object> keys = value.getKeys(); final OCompositeKey compositeKey = new OCompositeKey(); final OBinarySerializerFactory factory = OBinarySerializerFactory.getInstance(); for (int i = 0; i < keys.size(); i++) { Object key = keys.get(i); if (key != null) { final OType type; if (types.length > i) type = types[i]; else { type = OType.getTypeByClass(key.getClass()); } OBinarySerializer<Object> keySerializer = factory.getObjectSerializer(type); if (key instanceof Map && !(type == OType.EMBEDDEDMAP || type == OType.LINKMAP) && ((Map) key).size() == 1 && ((Map) key) .keySet().iterator().next().getClass().isAssignableFrom(type.getDefaultJavaType())) { key = ((Map) key).keySet().iterator().next(); } compositeKey.addKey(keySerializer.preprocess(key)); } else { compositeKey.addKey(key); } } return compositeKey; }
public int getObjectSize(OCompositeKey compositeKey, Object... hints) { final OType[] types = getKeyTypes(hints); final List<Object> keys = compositeKey.getKeys(); int size = 2 * OIntegerSerializer.INT_SIZE; final OBinarySerializerFactory factory = OBinarySerializerFactory.getInstance(); for (int i = 0; i < keys.size(); i++) { final Object key = keys.get(i); if (key != null) { final OType type; if (types.length > i) type = types[i]; else type = OType.getTypeByClass(key.getClass()); size += OBinarySerializerFactory.TYPE_IDENTIFIER_SIZE + factory.getObjectSerializer(type).getObjectSize(key); } else { size += OBinarySerializerFactory.TYPE_IDENTIFIER_SIZE + ONullSerializer.INSTANCE.getObjectSize(null); } } return size; }
public void serializeNativeObject(OCompositeKey compositeKey, byte[] stream, int startPosition, Object... hints) { final OType[] types = getKeyTypes(hints); final List<Object> keys = compositeKey.getKeys(); final int keysSize = keys.size(); final int oldStartPosition = startPosition; startPosition += OIntegerSerializer.INT_SIZE; OIntegerSerializer.INSTANCE.serializeNative(keysSize, stream, startPosition); startPosition += OIntegerSerializer.INT_SIZE; final OBinarySerializerFactory factory = OBinarySerializerFactory.getInstance(); for (int i = 0; i < keys.size(); i++) { final Object key = keys.get(i); OBinarySerializer<Object> binarySerializer; if (key != null) { final OType type; if (types.length > i) type = types[i]; else type = OType.getTypeByClass(key.getClass()); binarySerializer = factory.getObjectSerializer(type); } else binarySerializer = ONullSerializer.INSTANCE; stream[startPosition] = binarySerializer.getId(); startPosition += OBinarySerializerFactory.TYPE_IDENTIFIER_SIZE; binarySerializer.serializeNativeObject(key, stream, startPosition); startPosition += binarySerializer.getObjectSize(key); } OIntegerSerializer.INSTANCE.serializeNative((startPosition - oldStartPosition), stream, oldStartPosition); }
if (!(o instanceof OIdentifiable)) { if (iLinkedType == null) linkedType = OType.getTypeByClass(o.getClass()); linkedType = OType.getTypeByClass(o.getClass()); } else if (iLinkedType == OType.CUSTOM) iOutput.append(OStringSerializerHelper.CUSTOM_TYPE);
public void serialize(OCompositeKey compositeKey, byte[] stream, int startPosition, Object... hints) { final OType[] types = getKeyTypes(hints); final List<Object> keys = compositeKey.getKeys(); final int keysSize = keys.size(); final int oldStartPosition = startPosition; startPosition += OIntegerSerializer.INT_SIZE; OIntegerSerializer.INSTANCE.serializeLiteral(keysSize, stream, startPosition); startPosition += OIntegerSerializer.INT_SIZE; final OBinarySerializerFactory factory = OBinarySerializerFactory.getInstance(); for (int i = 0; i < keys.size(); i++) { final Object key = keys.get(i); OBinarySerializer<Object> binarySerializer; if (key != null) { final OType type; if (types.length > i) type = types[i]; else type = OType.getTypeByClass(key.getClass()); binarySerializer = factory.getObjectSerializer(type); } else binarySerializer = ONullSerializer.INSTANCE; stream[startPosition] = binarySerializer.getId(); startPosition += OBinarySerializerFactory.TYPE_IDENTIFIER_SIZE; binarySerializer.serialize(key, stream, startPosition); startPosition += binarySerializer.getObjectSize(key); } OIntegerSerializer.INSTANCE.serializeLiteral((startPosition - oldStartPosition), stream, oldStartPosition); }
protected void checkForKeyType(final Object iKey) { if (delegate.getDefinition() == null) { // RECOGNIZE THE KEY TYPE AT RUN-TIME final OType type = OType.getTypeByClass(iKey.getClass()); if (type == null) return; OIndexManager indexManager = ODatabaseRecordThreadLocal.instance().get().getMetadata().getIndexManager(); getInternal().setType(type); indexManager.save(); } }
linkedType = OType.STRING; else { linkedType = OType.getTypeByClass(firstValue.getClass());
/** * {@inheritDoc} * Create a new class of OrientDB documents if necessary. Enforce specified schema over the document class. * */ @Override public void createSchema() throws GoraException { if (schemaExists()) { return; } try (ODatabaseDocumentTx schemaTx = connectionPool.acquire()) { schemaTx.activateOnCurrentThread(); OClass documentClass = schemaTx.getMetadata().getSchema().createClass(orientDBMapping.getDocumentClass()); documentClass.createProperty("_id", OType.getTypeByClass(super.getKeyClass())).createIndex(OClass.INDEX_TYPE.UNIQUE); for (String docField : orientDBMapping.getDocumentFields()) { documentClass.createProperty(docField, OType.valueOf(orientDBMapping.getDocumentFieldType(docField).name())); } schemaTx.getMetadata().getSchema().reload(); } catch (Exception e) { throw new GoraException(e); } }