@Override public void writeExternal(ObjectOutput stream) throws IOException { ORecordSerializer serializer = ORecordSerializerFactory.instance().getFormat(ORecordSerializerNetwork.NAME); final byte[] idBuffer = _recordId.toStream(); stream.writeInt(-1); stream.writeInt(idBuffer.length); stream.write(idBuffer); stream.writeInt(_recordVersion); final byte[] content = serializer.toStream(this, false); stream.writeInt(content.length); stream.write(content); stream.writeBoolean(_dirty); stream.writeObject(serializer.toString()); }
@Override public void readExternal(ObjectInput stream) throws IOException, ClassNotFoundException { int i = stream.readInt(); int size; if (i < 0) size = stream.readInt(); else size = i; final byte[] idBuffer = new byte[size]; stream.readFully(idBuffer); _recordId.fromStream(idBuffer); _recordVersion = stream.readInt(); final int len = stream.readInt(); final byte[] content = new byte[len]; stream.readFully(content); _dirty = stream.readBoolean(); ORecordSerializer serializer = _recordFormat; if (i < 0) { final String str = (String) stream.readObject(); // TODO: WHEN TO USE THE SERIALIZER? serializer = ORecordSerializerFactory.instance().getFormat(str); } _status = ORecordElement.STATUS.UNMARSHALLING; try { serializer.fromStream(content, this, null); } finally { _status = ORecordElement.STATUS.LOADED; } }
@ConsoleCommand(description = "Export the current record in the requested format", onlineHelp = "Console-Command-Export-Record") public void exportRecord(@ConsoleParameter(name = "format", description = "Format, such as 'json'") final String iFormat, @ConsoleParameter(name = "options", description = "Options", optional = true) String iOptions) throws IOException { checkForDatabase(); checkCurrentObject(); final ORecordSerializer serializer = ORecordSerializerFactory.instance().getFormat(iFormat.toLowerCase(Locale.ENGLISH)); if (serializer == null) { message("\nERROR: Format '" + iFormat + "' was not found."); printSupportedSerializerFormat(); return; } else if (!(serializer instanceof ORecordSerializerStringAbstract)) { message("\nERROR: Format '" + iFormat + "' does not export as text."); printSupportedSerializerFormat(); return; } if (iOptions == null || iOptions.length() <= 0) { iOptions = "rid,version,class,type,keepTypes,alwaysFetchEmbedded,fetchPlan:*:0,prettyPrint"; } try { out.println(currentRecord.toJSON(iOptions)); } catch (ODatabaseExportException e) { printError(e); } }
public ORecordSerializerFactory() { register(ORecordSerializerSchemaAware2CSV.NAME, ORecordSerializerSchemaAware2CSV.INSTANCE); register(ORecordSerializerJSON.NAME, ORecordSerializerJSON.INSTANCE); register(ORecordSerializerRaw.NAME, new ORecordSerializerRaw()); register(ORecordSerializerBinary.NAME, ORecordSerializerBinary.INSTANCE); register(ORecordSerializerNetwork.NAME, ORecordSerializerNetwork.INSTANCE); register(ORecordSerializerNetworkV37.NAME,ORecordSerializerNetworkV37.INSTANCE); defaultRecordSerializer = getFormat(OGlobalConfiguration.DB_DOCUMENT_SERIALIZER.getValueAsString()); if (defaultRecordSerializer == null) throw new ODatabaseException( "Impossible to find serializer with name " + OGlobalConfiguration.DB_DOCUMENT_SERIALIZER.getValueAsString()); }
if (serializeName == null) throw new ODatabaseException("Impossible to open database from version before 2.x use export import instead"); serializer = serializerFactory.getFormat(serializeName); if (serializer == null) throw new ODatabaseException("RecordSerializer with name '" + serializeName + "' not found ");