Search in sources :

Example 16 with OSerializationException

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) {
    }
}
Also used : OSerializationException(com.orientechnologies.orient.core.exception.OSerializationException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 17 with OSerializationException

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);
    }
}
Also used : OFile(com.orientechnologies.orient.core.storage.fs.OFile) OSerializationException(com.orientechnologies.orient.core.exception.OSerializationException) OException(com.orientechnologies.common.exception.OException) IOException(java.io.IOException) OSerializationException(com.orientechnologies.orient.core.exception.OSerializationException)

Example 18 with OSerializationException

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;
}
Also used : ORawBuffer(com.orientechnologies.orient.core.storage.ORawBuffer) OSerializationException(com.orientechnologies.orient.core.exception.OSerializationException) IOException(java.io.IOException)

Example 19 with OSerializationException

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();
}
Also used : OSerializationException(com.orientechnologies.orient.core.exception.OSerializationException) ORID(com.orientechnologies.orient.core.id.ORID) OSchemaException(com.orientechnologies.orient.core.exception.OSchemaException) ORecordId(com.orientechnologies.orient.core.id.ORecordId) OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) OException(com.orientechnologies.common.exception.OException) OSchemaException(com.orientechnologies.orient.core.exception.OSchemaException) ParseException(java.text.ParseException) InvocationTargetException(java.lang.reflect.InvocationTargetException) OSerializationException(com.orientechnologies.orient.core.exception.OSerializationException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 20 with OSerializationException

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;
}
Also used : OSerializationException(com.orientechnologies.orient.core.exception.OSerializationException) ORID(com.orientechnologies.orient.core.id.ORID) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Aggregations

OSerializationException (com.orientechnologies.orient.core.exception.OSerializationException)34 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)11 OException (com.orientechnologies.common.exception.OException)10 IOException (java.io.IOException)9 OType (com.orientechnologies.orient.core.metadata.schema.OType)7 ODatabaseObject (com.orientechnologies.orient.core.db.object.ODatabaseObject)6 ORecord (com.orientechnologies.orient.core.record.ORecord)6 ORID (com.orientechnologies.orient.core.id.ORID)5 ORecordId (com.orientechnologies.orient.core.id.ORecordId)5 OSerializableStream (com.orientechnologies.orient.core.serialization.OSerializableStream)5 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 Map (java.util.Map)4 Entry (java.util.Map.Entry)4 ORecordLazyMap (com.orientechnologies.orient.core.db.record.ORecordLazyMap)3 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)3 OProperty (com.orientechnologies.orient.core.metadata.schema.OProperty)3 ODocumentSerializable (com.orientechnologies.orient.core.serialization.ODocumentSerializable)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 ParseException (java.text.ParseException)3