/** * Sets default serializer. The default serializer is common for all database instances. * * @param iDefaultSerializer new default serializer value */ public static void setDefaultSerializer(ORecordSerializer iDefaultSerializer) { ORecordSerializerFactory.instance().setDefaultRecordSerializer(iDefaultSerializer); }
/** * @return default serializer which is used to serialize documents. Default serializer is common for all database instances. */ public static ORecordSerializer getDefaultSerializer() { return ORecordSerializerFactory.instance().getDefaultRecordSerializer(); }
@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 ORecordSerializer getSerializer() { if (internal == null) { if (serializer != null) return serializer; return ORecordSerializerFactory.instance().getDefaultRecordSerializer(); } return internal.getSerializer(); }
private void printSupportedSerializerFormat() { message("\nSupported formats are:"); for (ORecordSerializer s : ORecordSerializerFactory.instance().getFormats()) { if (s instanceof ORecordSerializerStringAbstract) message("\n- " + s.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; } }
protected ODatabaseDocumentEmbedded internalCreate(OrientDBConfig config, OAbstractPaginatedStorage storage) { try { storage.create(config.getConfigurations()); } catch (IOException e) { throw OException.wrapException(new ODatabaseException("Error on database creation"), e); } ORecordSerializer serializer = ORecordSerializerFactory.instance().getDefaultRecordSerializer(); if (serializer.toString().equals("ORecordDocument2csv")) throw new ODatabaseException("Impossible to create the database with ORecordDocument2csv serializer"); storage.setRecordSerializer(serializer.toString(), serializer.getCurrentVersion()); // since 2.1 newly created databases use strict SQL validation by default storage.setProperty(OStatement.CUSTOM_STRICT_SQL, "true"); // No need to close final ODatabaseDocumentEmbedded embedded = factory.newInstance(storage); embedded.setSerializer(serializer); embedded.internalCreate(config); return embedded; }
@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); } }
return; ORecordSerializerFactory serializerFactory = ORecordSerializerFactory.instance(); String serializeName = getStorage().getConfiguration().getRecordSerializer(); if (serializeName == null)