Search in sources :

Example 1 with ORecordSerializerSchemaAware2CSV

use of com.orientechnologies.orient.core.serialization.serializer.record.string.ORecordSerializerSchemaAware2CSV in project orientdb by orientechnologies.

the class TestDistributeConfigSerialization method executeTest.

@Override
protected void executeTest() throws Exception {
    ODatabaseDocumentTx db = new ODatabaseDocumentTx("plocal:target/server0/databases/" + getDatabaseName());
    try {
        db.setSerializer(new ORecordSerializerSchemaAware2CSV());
        db.create();
        db.getMetadata().getSchema().createClass("TestMessaging");
        db.activateOnCurrentThread();
        db.save(new ODocument("TestMessaging").field("test", "test"));
        db.query(new OSQLSynchQuery("select from TestMessaging "));
        db.close();
    } catch (OException e) {
        e.printStackTrace();
        Assert.fail("error on creating a csv database in distributed environment");
    }
    try {
        db = new ODatabaseDocumentTx("remote:localhost/" + getDatabaseName());
        db.open("admin", "admin");
        db.query(new OSQLSynchQuery("select from TestMessaging "));
        db.close();
    } catch (OException e) {
        e.printStackTrace();
        Assert.fail("error on creating a csv database in distributed environment");
    }
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OException(com.orientechnologies.common.exception.OException) ORecordSerializerSchemaAware2CSV(com.orientechnologies.orient.core.serialization.serializer.record.string.ORecordSerializerSchemaAware2CSV) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 2 with ORecordSerializerSchemaAware2CSV

use of com.orientechnologies.orient.core.serialization.serializer.record.string.ORecordSerializerSchemaAware2CSV in project orientdb by orientechnologies.

the class OClassImpl method setNameInternal.

private void setNameInternal(final String name) {
    getDatabase().checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_UPDATE);
    acquireSchemaWriteLock();
    try {
        checkEmbedded();
        final String oldName = this.name;
        owner.changeClassName(this.name, name, this);
        this.name = name;
        ODatabaseDocumentInternal database = getDatabase();
        final OStorage storage = database.getStorage();
        if (!database.getStorageVersions().classesAreDetectedByClusterId()) {
            for (int clusterId : clusterIds) {
                long[] range = storage.getClusterDataRange(clusterId);
                OPhysicalPosition[] positions = storage.ceilingPhysicalPositions(clusterId, new OPhysicalPosition(range[0]));
                do {
                    for (OPhysicalPosition position : positions) {
                        final ORecordId identity = new ORecordId(clusterId, position.clusterPosition);
                        final ORawBuffer record = storage.readRecord(identity, null, true, false, null).getResult();
                        if (record.recordType == ODocument.RECORD_TYPE) {
                            final ORecordSerializerSchemaAware2CSV serializer = (ORecordSerializerSchemaAware2CSV) ORecordSerializerFactory.instance().getFormat(ORecordSerializerSchemaAware2CSV.NAME);
                            String persName = new String(record.buffer, "UTF-8");
                            if (serializer.getClassName(persName).equalsIgnoreCase(name)) {
                                final ODocument document = new ODocument();
                                document.setLazyLoad(false);
                                document.fromStream(record.buffer);
                                ORecordInternal.setVersion(document, record.version);
                                ORecordInternal.setIdentity(document, identity);
                                document.setClassName(name);
                                document.setDirty();
                                document.save();
                            }
                        }
                        if (positions.length > 0)
                            positions = storage.higherPhysicalPositions(clusterId, positions[positions.length - 1]);
                    }
                } while (positions.length > 0);
            }
        }
        renameCluster(oldName, this.name);
    } catch (UnsupportedEncodingException e) {
        throw OException.wrapException(new OSchemaException("Error reading schema"), e);
    } finally {
        releaseSchemaWriteLock();
    }
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) OSchemaException(com.orientechnologies.orient.core.exception.OSchemaException) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) ORecordId(com.orientechnologies.orient.core.id.ORecordId) ORecordSerializerSchemaAware2CSV(com.orientechnologies.orient.core.serialization.serializer.record.string.ORecordSerializerSchemaAware2CSV) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

ODocument (com.orientechnologies.orient.core.record.impl.ODocument)2 ORecordSerializerSchemaAware2CSV (com.orientechnologies.orient.core.serialization.serializer.record.string.ORecordSerializerSchemaAware2CSV)2 OException (com.orientechnologies.common.exception.OException)1 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)1 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)1 OSchemaException (com.orientechnologies.orient.core.exception.OSchemaException)1 ORecordId (com.orientechnologies.orient.core.id.ORecordId)1 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1