Search in sources :

Example 6 with ORecordId

use of com.orientechnologies.orient.core.id.ORecordId in project orientdb by orientechnologies.

the class ODatabaseDocumentTx method executeSaveEmptyRecord.

public <RET extends ORecord> RET executeSaveEmptyRecord(ORecord record, String clusterName) {
    ORecordId rid = (ORecordId) record.getIdentity();
    assert rid.isNew();
    ORecordInternal.onBeforeIdentityChanged(record);
    int id = assignAndCheckCluster(record, clusterName);
    clusterName = getClusterNameById(id);
    checkSecurity(ORule.ResourceGeneric.CLUSTER, ORole.PERMISSION_CREATE, clusterName);
    byte[] content = getSerializer().writeClassOnly(record);
    final OStorageOperationResult<OPhysicalPosition> ppos = storage.createRecord(rid, content, record.getVersion(), recordType, OPERATION_MODE.SYNCHRONOUS.ordinal(), null);
    ORecordInternal.setVersion(record, ppos.getResult().recordVersion);
    ((ORecordId) record.getIdentity()).copyFrom(rid);
    ORecordInternal.onAfterIdentityChanged(record);
    return (RET) record;
}
Also used : ORecordId(com.orientechnologies.orient.core.id.ORecordId)

Example 7 with ORecordId

use of com.orientechnologies.orient.core.id.ORecordId in project orientdb by orientechnologies.

the class ODatabaseDocumentTx method assignAndCheckCluster.

public int assignAndCheckCluster(ORecord record, String iClusterName) {
    ORecordId rid = (ORecordId) record.getIdentity();
    // if provided a cluster name use it.
    if (rid.getClusterId() <= ORID.CLUSTER_POS_INVALID && iClusterName != null) {
        rid.setClusterId(getClusterIdByName(iClusterName));
        if (rid.getClusterId() == -1)
            throw new IllegalArgumentException("Cluster name '" + iClusterName + "' is not configured");
    }
    OClass schemaClass = null;
    // if cluster id is not set yet try to find it out
    if (rid.getClusterId() <= ORID.CLUSTER_ID_INVALID && storage.isAssigningClusterIds()) {
        if (record instanceof ODocument) {
            schemaClass = ODocumentInternal.getImmutableSchemaClass(((ODocument) record));
            if (schemaClass != null) {
                if (schemaClass.isAbstract())
                    throw new OSchemaException("Document belongs to abstract class " + schemaClass.getName() + " and cannot be saved");
                rid.setClusterId(schemaClass.getClusterForNewInstance((ODocument) record));
            } else
                rid.setClusterId(getDefaultClusterId());
        } else {
            rid.setClusterId(getDefaultClusterId());
            if (record instanceof OBlob && rid.getClusterId() != ORID.CLUSTER_ID_INVALID) {
            // Set<Integer> blobClusters = getMetadata().getSchema().getBlobClusters();
            // if (!blobClusters.contains(rid.clusterId) && rid.clusterId != getDefaultClusterId() && rid.clusterId != 0) {
            // if (iClusterName == null)
            // iClusterName = getClusterNameById(rid.clusterId);
            // throw new IllegalArgumentException(
            // "Cluster name '" + iClusterName + "' (id=" + rid.clusterId + ") is not configured to store blobs, valid are "
            // + blobClusters.toString());
            // }
            }
        }
    } else if (record instanceof ODocument)
        schemaClass = ODocumentInternal.getImmutableSchemaClass(((ODocument) record));
    // If the cluster id was set check is validity
    if (rid.getClusterId() > ORID.CLUSTER_ID_INVALID) {
        if (schemaClass != null) {
            String messageClusterName = getClusterNameById(rid.getClusterId());
            checkRecordClass(schemaClass, messageClusterName, rid);
            if (!schemaClass.hasClusterId(rid.getClusterId())) {
                throw new IllegalArgumentException("Cluster name '" + messageClusterName + "' (id=" + rid.getClusterId() + ") is not configured to store the class '" + schemaClass.getName() + "', valid are " + Arrays.toString(schemaClass.getClusterIds()));
            }
        }
    }
    return rid.getClusterId();
}
Also used : OBlob(com.orientechnologies.orient.core.record.impl.OBlob) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ORecordId(com.orientechnologies.orient.core.id.ORecordId) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 8 with ORecordId

use of com.orientechnologies.orient.core.id.ORecordId in project orientdb by orientechnologies.

the class OIndexManagerRemote method createIndex.

public OIndex<?> createIndex(final String iName, final String iType, final OIndexDefinition iIndexDefinition, final int[] iClusterIdsToIndex, final OProgressListener progressListener, ODocument metadata, String engine) {
    String createIndexDDL;
    if (iIndexDefinition != null)
        createIndexDDL = iIndexDefinition.toCreateIndexDDL(iName, iType, engine);
    else
        createIndexDDL = new OSimpleKeyIndexDefinition().toCreateIndexDDL(iName, iType, engine);
    if (metadata != null)
        createIndexDDL += " " + OCommandExecutorSQLCreateIndex.KEYWORD_METADATA + " " + metadata.toJSON();
    acquireExclusiveLock();
    try {
        if (progressListener != null)
            progressListener.onBegin(this, 0, false);
        getDatabase().command(new OCommandSQL(createIndexDDL)).execute();
        ORecordInternal.setIdentity(document, new ORecordId(ODatabaseRecordThreadLocal.INSTANCE.get().getStorage().getConfiguration().indexMgrRecordId));
        if (progressListener != null)
            progressListener.onCompletition(this, true);
        reload();
        final Locale locale = getServerLocale();
        return preProcessBeforeReturn(indexes.get(iName.toLowerCase(locale)));
    } finally {
        releaseExclusiveLock();
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) Locale(java.util.Locale) ORecordId(com.orientechnologies.orient.core.id.ORecordId)

Example 9 with ORecordId

use of com.orientechnologies.orient.core.id.ORecordId in project orientdb by orientechnologies.

the class ODatabaseImport method importRecords.

private long importRecords() throws Exception {
    long total = 0;
    database.getMetadata().getIndexManager().dropIndex(EXPORT_IMPORT_MAP_NAME);
    OIndexFactory factory = OIndexes.getFactory(OClass.INDEX_TYPE.DICTIONARY_HASH_INDEX.toString(), OHashIndexFactory.HASH_INDEX_ALGORITHM);
    exportImportHashTable = (OIndex<OIdentifiable>) database.getMetadata().getIndexManager().createIndex(EXPORT_IMPORT_MAP_NAME, OClass.INDEX_TYPE.DICTIONARY_HASH_INDEX.toString(), new OSimpleKeyIndexDefinition(factory.getLastVersion(), OType.LINK), null, null, null);
    jsonReader.readNext(OJSONReader.BEGIN_COLLECTION);
    long totalRecords = 0;
    listener.onMessage("\n\nImporting records...");
    ORID rid;
    ORID lastRid = new ORecordId();
    final long begin = System.currentTimeMillis();
    long lastLapRecords = 0;
    long last = begin;
    Set<String> involvedClusters = new HashSet<String>();
    while (jsonReader.lastChar() != ']') {
        rid = importRecord();
        if (rid != null) {
            ++lastLapRecords;
            ++totalRecords;
            if (rid.getClusterId() != lastRid.getClusterId() || involvedClusters.isEmpty())
                involvedClusters.add(database.getClusterNameById(rid.getClusterId()));
            final long now = System.currentTimeMillis();
            if (now - last > IMPORT_RECORD_DUMP_LAP_EVERY_MS) {
                final List<String> sortedClusters = new ArrayList<String>(involvedClusters);
                Collections.sort(sortedClusters);
                listener.onMessage(String.format("\n- Imported %,d records into clusters: %s. Total records imported so far: %,d (%,.2f/sec)", lastLapRecords, sortedClusters, totalRecords, (float) lastLapRecords * 1000 / (float) IMPORT_RECORD_DUMP_LAP_EVERY_MS));
                // RESET LAP COUNTERS
                last = now;
                lastLapRecords = 0;
                involvedClusters.clear();
            }
            lastRid = rid;
        }
        record = null;
    }
    if (migrateLinks)
        migrateLinksInImportedDocuments();
    listener.onMessage(String.format("\n\nDone. Imported %,d records in %,.2f secs\n", totalRecords, ((float) (System.currentTimeMillis() - begin)) / 1000));
    jsonReader.readNext(OJSONReader.COMMA_SEPARATOR);
    return total;
}
Also used : ORID(com.orientechnologies.orient.core.id.ORID) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ORecordId(com.orientechnologies.orient.core.id.ORecordId)

Example 10 with ORecordId

use of com.orientechnologies.orient.core.id.ORecordId in project orientdb by orientechnologies.

the class ODatabaseImport method importInfo.

private void importInfo() throws IOException, ParseException {
    listener.onMessage("\nImporting database info...");
    jsonReader.readNext(OJSONReader.BEGIN_OBJECT);
    while (jsonReader.lastChar() != '}') {
        final String fieldName = jsonReader.readString(OJSONReader.FIELD_ASSIGNMENT);
        if (fieldName.equals("exporter-version"))
            exporterVersion = jsonReader.readInteger(OJSONReader.NEXT_IN_OBJECT);
        else if (fieldName.equals("schemaRecordId"))
            schemaRecordId = new ORecordId(jsonReader.readString(OJSONReader.NEXT_IN_OBJECT));
        else if (fieldName.equals("indexMgrRecordId"))
            indexMgrRecordId = new ORecordId(jsonReader.readString(OJSONReader.NEXT_IN_OBJECT));
        else
            jsonReader.readNext(OJSONReader.NEXT_IN_OBJECT);
    }
    jsonReader.readNext(OJSONReader.COMMA_SEPARATOR);
    if (schemaRecordId == null)
        schemaRecordId = new ORecordId(database.getStorage().getConfiguration().schemaRecordId);
    if (indexMgrRecordId == null)
        indexMgrRecordId = new ORecordId(database.getStorage().getConfiguration().indexMgrRecordId);
    listener.onMessage("OK");
}
Also used : ORecordId(com.orientechnologies.orient.core.id.ORecordId)

Aggregations

ORecordId (com.orientechnologies.orient.core.id.ORecordId)431 Test (org.testng.annotations.Test)153 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)139 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)120 ORID (com.orientechnologies.orient.core.id.ORID)71 HashSet (java.util.HashSet)63 OIndexCursor (com.orientechnologies.orient.core.index.OIndexCursor)42 ORidBag (com.orientechnologies.orient.core.db.record.ridbag.ORidBag)37 ORecord (com.orientechnologies.orient.core.record.ORecord)37 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)34 OIndexTxAwareMultiValue (com.orientechnologies.orient.core.index.OIndexTxAwareMultiValue)30 OIndexTxAwareOneValue (com.orientechnologies.orient.core.index.OIndexTxAwareOneValue)30 HashMap (java.util.HashMap)29 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)28 IOException (java.io.IOException)25 Child (com.orientechnologies.orient.test.domain.business.Child)24 OException (com.orientechnologies.common.exception.OException)23 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)23 Map (java.util.Map)22 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)21