use of com.orientechnologies.orient.core.serialization.serializer.record.ORecordSerializer in project orientdb by orientechnologies.
the class ODocument method readExternal.
@Override
public void readExternal(final 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;
}
}
use of com.orientechnologies.orient.core.serialization.serializer.record.ORecordSerializer in project orientdb by orientechnologies.
the class ONetworkProtocolBinary method fillRecord.
public void fillRecord(OClientConnection connection, final ORecordId rid, final byte[] buffer, final int version, final ORecord record) {
String dbSerializerName = "";
if (connection.getDatabase() != null)
dbSerializerName = connection.getDatabase().getSerializer().toString();
String name = getRecordSerializerName(connection);
if (ORecordInternal.getRecordType(record) == ODocument.RECORD_TYPE && !dbSerializerName.equals(name)) {
ORecordInternal.fill(record, rid, version, null, true);
ORecordSerializer ser = ORecordSerializerFactory.instance().getFormat(name);
ser.fromStream(buffer, record, null);
record.setDirty();
} else
ORecordInternal.fill(record, rid, version, buffer, true);
}
use of com.orientechnologies.orient.core.serialization.serializer.record.ORecordSerializer in project orientdb by orientechnologies.
the class ONetworkProtocolBinary method getRecordBytes.
public byte[] getRecordBytes(OClientConnection connection, final ORecord iRecord) {
final byte[] stream;
String dbSerializerName = null;
if (ODatabaseRecordThreadLocal.INSTANCE.getIfDefined() != null)
dbSerializerName = ((ODatabaseDocumentInternal) iRecord.getDatabase()).getSerializer().toString();
String name = getRecordSerializerName(connection);
if (ORecordInternal.getRecordType(iRecord) == ODocument.RECORD_TYPE && (dbSerializerName == null || !dbSerializerName.equals(name))) {
((ODocument) iRecord).deserializeFields();
ORecordSerializer ser = ORecordSerializerFactory.instance().getFormat(name);
stream = ser.toStream(iRecord, false);
} else
stream = iRecord.toStream();
return stream;
}
use of com.orientechnologies.orient.core.serialization.serializer.record.ORecordSerializer in project orientdb by orientechnologies.
the class OConsoleDatabaseApp method exportRecord.
@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);
}
}
use of com.orientechnologies.orient.core.serialization.serializer.record.ORecordSerializer in project orientdb by orientechnologies.
the class OCommandRequestTextAbstract method fromStream.
protected void fromStream(final OMemoryStream buffer) {
text = buffer.getAsString();
parameters = null;
ORecordSerializer serializer = ONetworkThreadLocalSerializer.getNetworkSerializer();
final boolean simpleParams = buffer.getAsBoolean();
if (simpleParams) {
final byte[] paramBuffer = buffer.getAsByteArray();
final ODocument param = new ODocument();
if (serializer != null)
serializer.fromStream(paramBuffer, param, null);
else
param.fromStream(paramBuffer);
Map<Object, Object> params = param.field("params");
parameters = new HashMap<Object, Object>();
if (params != null) {
for (Entry<Object, Object> p : params.entrySet()) {
final Object value;
if (p.getValue() instanceof String)
value = ORecordSerializerStringAbstract.getTypeValue((String) p.getValue());
else
value = p.getValue();
if (p.getKey() instanceof String && Character.isDigit(((String) p.getKey()).charAt(0)))
parameters.put(Integer.parseInt((String) p.getKey()), value);
else
parameters.put(p.getKey(), value);
}
} else {
params = param.field("parameters");
for (Entry<Object, Object> p : params.entrySet()) {
if (p.getKey() instanceof String && Character.isDigit(((String) p.getKey()).charAt(0)))
parameters.put(Integer.parseInt((String) p.getKey()), p.getValue());
else
parameters.put(p.getKey(), p.getValue());
}
}
}
final boolean compositeKeyParamsPresent = buffer.getAsBoolean();
if (compositeKeyParamsPresent) {
final byte[] paramBuffer = buffer.getAsByteArray();
final ODocument param = new ODocument();
if (serializer != null)
serializer.fromStream(paramBuffer, param, null);
else
param.fromStream(paramBuffer);
final Map<Object, Object> compositeKeyParams = param.field("compositeKeyParams");
if (parameters == null)
parameters = new HashMap<Object, Object>();
for (final Entry<Object, Object> p : compositeKeyParams.entrySet()) {
if (p.getValue() instanceof List) {
final OCompositeKey compositeKey = new OCompositeKey((List<?>) p.getValue());
if (p.getKey() instanceof String && Character.isDigit(((String) p.getKey()).charAt(0)))
parameters.put(Integer.parseInt((String) p.getKey()), compositeKey);
else
parameters.put(p.getKey(), compositeKey);
} else {
final Object value = OCompositeKeySerializer.INSTANCE.deserialize(OStringSerializerHelper.getBinaryContent(p.getValue()), 0);
if (p.getKey() instanceof String && Character.isDigit(((String) p.getKey()).charAt(0)))
parameters.put(Integer.parseInt((String) p.getKey()), value);
else
parameters.put(p.getKey(), value);
}
}
}
}
Aggregations