use of com.orientechnologies.orient.core.exception.OSerializationException in project orientdb by orientechnologies.
the class JSONTest method testInvalidJson.
public void testInvalidJson() {
ODocument doc = new ODocument();
try {
doc.fromJSON("{");
Assert.fail();
} catch (OSerializationException e) {
}
try {
doc.fromJSON("{\"foo\":{}");
Assert.fail();
} catch (OSerializationException e) {
}
try {
doc.fromJSON("{{}");
Assert.fail();
} catch (OSerializationException e) {
}
try {
doc.fromJSON("{}}");
Assert.fail();
} catch (OSerializationException e) {
}
try {
doc.fromJSON("}");
Assert.fail();
} catch (OSerializationException e) {
}
}
use of com.orientechnologies.orient.core.exception.OSerializationException in project orientdb by orientechnologies.
the class OStorageConfigurationSegment method update.
@Override
public void update() throws OSerializationException {
try {
final OFile f = segment.getFile();
if (!f.isOpen())
return;
final byte[] buffer = toStream();
final int len = buffer.length + OBinaryProtocol.SIZE_INT;
if (len > f.getFileSize())
f.allocateSpace(len - f.getFileSize());
f.writeInt(0, buffer.length);
f.write(OBinaryProtocol.SIZE_INT, buffer);
if (OGlobalConfiguration.STORAGE_CONFIGURATION_SYNC_ON_UPDATE.getValueAsBoolean())
f.synch();
} catch (Exception e) {
throw OException.wrapException(new OSerializationException("Error on update storage configuration"), e);
}
}
use of com.orientechnologies.orient.core.exception.OSerializationException in project orientdb by orientechnologies.
the class OStorageConfigurationSegment method load.
@Override
public OStorageConfiguration load(final Map<String, Object> iProperties) throws OSerializationException {
try {
initConfiguration();
bindPropertiesToContext(iProperties);
if (segment.getFile().exists())
segment.open();
else {
segment.create(START_SIZE);
// @COMPATIBILITY0.9.25
// CHECK FOR OLD VERSION OF DATABASE
final ORawBuffer rawRecord = storage.readRecord(CONFIG_RID, null, false, false, null).getResult();
if (rawRecord != null)
fromStream(rawRecord.buffer);
update();
return this;
}
final int size = segment.getFile().readInt(0);
byte[] buffer = new byte[size];
segment.getFile().read(OBinaryProtocol.SIZE_INT, buffer, size);
fromStream(buffer);
} catch (IOException e) {
throw OException.wrapException(new OSerializationException("Cannot load database configuration. The database seems corrupted"), e);
}
return this;
}
use of com.orientechnologies.orient.core.exception.OSerializationException in project orientdb by orientechnologies.
the class ODatabaseImport method importRecord.
private ORID importRecord() throws Exception {
String value = jsonReader.readString(OJSONReader.END_OBJECT, true);
// JUMP EMPTY RECORDS
while (!value.isEmpty() && value.charAt(0) != '{') {
value = value.substring(1);
}
record = null;
try {
try {
record = ORecordSerializerJSON.INSTANCE.fromString(value, record, null);
} catch (OSerializationException e) {
if (e.getCause() instanceof OSchemaException) {
// EXTRACT CLASS NAME If ANY
final int pos = value.indexOf("\"@class\":\"");
if (pos > -1) {
final int end = value.indexOf("\"", pos + "\"@class\":\"".length() + 1);
final String value1 = value.substring(0, pos + "\"@class\":\"".length());
final String clsName = value.substring(pos + "\"@class\":\"".length(), end);
final String value2 = value.substring(end);
final String newClassName = convertedClassNames.get(clsName);
value = value1 + newClassName + value2;
// OVERWRITE CLASS NAME WITH NEW NAME
record = ORecordSerializerJSON.INSTANCE.fromString(value, record, null);
}
} else
throw OException.wrapException(new ODatabaseImportException("Error on importing record"), e);
}
// Incorrect record format , skip this record
if (record == null || record.getIdentity() == null) {
OLogManager.instance().warn(this, "Broken record was detected and will be skipped");
return null;
}
if (schemaImported && record.getIdentity().equals(schemaRecordId)) {
// JUMP THE SCHEMA
return null;
}
// CHECK IF THE CLUSTER IS INCLUDED
if (includeClusters != null) {
if (!includeClusters.contains(database.getClusterNameById(record.getIdentity().getClusterId()))) {
jsonReader.readNext(OJSONReader.NEXT_IN_ARRAY);
return null;
}
} else if (excludeClusters != null) {
if (excludeClusters.contains(database.getClusterNameById(record.getIdentity().getClusterId())))
return null;
}
if (record.getIdentity().getClusterId() == 0 && record.getIdentity().getClusterPosition() == 1)
// JUMP INTERNAL RECORDS
return null;
if (exporterVersion >= 3) {
int oridsId = database.getClusterIdByName("ORIDs");
int indexId = database.getClusterIdByName(OMetadataDefault.CLUSTER_INDEX_NAME);
if (record.getIdentity().getClusterId() == indexId || record.getIdentity().getClusterId() == oridsId)
// JUMP INDEX RECORDS
return null;
}
final int manualIndexCluster = database.getClusterIdByName(OMetadataDefault.CLUSTER_MANUAL_INDEX_NAME);
final int internalCluster = database.getClusterIdByName(OMetadataDefault.CLUSTER_INTERNAL_NAME);
final int indexCluster = database.getClusterIdByName(OMetadataDefault.CLUSTER_INDEX_NAME);
if (exporterVersion >= 4) {
if (record.getIdentity().getClusterId() == manualIndexCluster)
// JUMP INDEX RECORDS
return null;
}
if (record.getIdentity().equals(indexMgrRecordId))
return null;
final ORID rid = record.getIdentity();
final int clusterId = rid.getClusterId();
if ((clusterId != manualIndexCluster && clusterId != internalCluster && clusterId != indexCluster)) {
ORecordInternal.setVersion(record, 0);
record.setDirty();
ORecordInternal.setIdentity(record, new ORecordId());
if (!preserveRids && record instanceof ODocument && ODocumentInternal.getImmutableSchemaClass(((ODocument) record)) != null)
record.save();
else
record.save(database.getClusterNameById(clusterId));
if (!rid.equals(record.getIdentity()))
// SAVE IT ONLY IF DIFFERENT
exportImportHashTable.put(rid, record.getIdentity());
}
} catch (Exception t) {
if (record != null)
OLogManager.instance().error(this, "Error importing record " + record.getIdentity() + ". Source line " + jsonReader.getLineNumber() + ", column " + jsonReader.getColumnNumber());
else
OLogManager.instance().error(this, "Error importing record. Source line " + jsonReader.getLineNumber() + ", column " + jsonReader.getColumnNumber());
throw t;
} finally {
jsonReader.readNext(OJSONReader.NEXT_IN_ARRAY);
}
return record.getIdentity();
}
use of com.orientechnologies.orient.core.exception.OSerializationException in project orientdb by orientechnologies.
the class OEmbeddedRidBag method serialize.
@Override
public int serialize(byte[] stream, int offset, UUID ownerUuid) {
OIntegerSerializer.INSTANCE.serializeLiteral(size, stream, offset);
offset += OIntegerSerializer.INT_SIZE;
ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
final int totEntries = entries.length;
for (int i = 0; i < totEntries; ++i) {
final Object entry = entries[i];
if (entry instanceof OIdentifiable) {
OIdentifiable link = (OIdentifiable) entry;
final ORID rid = link.getIdentity();
if (db != null && db.getTransaction().isActive()) {
if (!link.getIdentity().isPersistent()) {
link = db.getTransaction().getRecord(link.getIdentity());
entries[i] = link;
}
}
if (link == null)
throw new OSerializationException("Found null entry in ridbag with rid=" + rid);
OLinkSerializer.INSTANCE.serialize(link, stream, offset);
offset += OLinkSerializer.RID_SIZE;
}
}
return offset;
}
Aggregations