Search in sources :

Example 1 with OMetadata

use of com.orientechnologies.orient.core.metadata.OMetadata in project orientdb by orientechnologies.

the class ODatabaseDocumentTx method reloadUser.

public void reloadUser() {
    if (user != null) {
        activateOnCurrentThread();
        OMetadata metadata = getMetadata();
        if (metadata != null) {
            final OSecurity security = metadata.getSecurity();
            OUser secGetUser = security.getUser(user.getName());
            if (secGetUser != null)
                user = new OImmutableUser(security.getVersion(), secGetUser);
            else
                user = new OImmutableUser(-1, new OUser());
        } else
            user = new OImmutableUser(-1, new OUser());
    }
}
Also used : OMetadata(com.orientechnologies.orient.core.metadata.OMetadata)

Example 2 with OMetadata

use of com.orientechnologies.orient.core.metadata.OMetadata in project orientdb by orientechnologies.

the class ODatabaseDocumentTx method setUser.

/**
   * {@inheritDoc}
   */
public void setUser(final OSecurityUser user) {
    checkIfActive();
    if (user instanceof OUser) {
        OMetadata metadata = getMetadata();
        if (metadata != null) {
            final OSecurity security = metadata.getSecurity();
            this.user = new OImmutableUser(security.getVersion(), (OUser) user);
        } else
            this.user = new OImmutableUser(-1, (OUser) user);
    } else
        this.user = (OImmutableUser) user;
}
Also used : OMetadata(com.orientechnologies.orient.core.metadata.OMetadata)

Example 3 with OMetadata

use of com.orientechnologies.orient.core.metadata.OMetadata in project orientdb by orientechnologies.

the class OBonsaiTreeRepair method repairDatabaseRidbags.

public void repairDatabaseRidbags(ODatabaseDocument db, OCommandOutputListener outputListener) {
    message(outputListener, "Repair of ridbags is started ...\n");
    final OMetadata metadata = db.getMetadata();
    final OSchema schema = metadata.getSchema();
    final OClass edgeClass = schema.getClass(OrientEdgeType.CLASS_NAME);
    if (edgeClass != null) {
        final HashMap<String, Set<ORID>> processedVertexes = new HashMap<String, Set<ORID>>();
        final long countEdges = db.countClass(edgeClass.getName());
        message(outputListener, countEdges + " will be processed.");
        long counter = 0;
        for (ODocument edge : db.browseClass(edgeClass.getName())) {
            try {
                final String label;
                if (edge.field(OrientElement.LABEL_FIELD_NAME) != null) {
                    label = edge.field(OrientElement.LABEL_FIELD_NAME);
                } else if (!edge.getClassName().equals(edgeClass.getName())) {
                    label = edge.getClassName();
                } else {
                    counter++;
                    continue;
                }
                final ODocument inVertex = edge.<OIdentifiable>field(OrientBaseGraph.CONNECTION_IN).getRecord();
                final ODocument outVertex = edge.<OIdentifiable>field(OrientBaseGraph.CONNECTION_OUT).getRecord();
                final String inVertexName = OrientVertex.getConnectionFieldName(Direction.IN, label, true);
                final String outVertexName = OrientVertex.getConnectionFieldName(Direction.OUT, label, true);
                Set<ORID> inVertexes = processedVertexes.get(inVertexName);
                if (inVertexes == null) {
                    inVertexes = new HashSet<ORID>();
                    processedVertexes.put(inVertexName, inVertexes);
                }
                Set<ORID> outVertexes = processedVertexes.get(outVertexName);
                if (outVertexes == null) {
                    outVertexes = new HashSet<ORID>();
                    processedVertexes.put(outVertexName, outVertexes);
                }
                if (inVertex.field(inVertexName) instanceof ORidBag) {
                    if (inVertexes.add(inVertex.getIdentity())) {
                        inVertex.field(inVertexName, new ORidBag());
                    }
                    final ORidBag inRidBag = inVertex.field(inVertexName);
                    inRidBag.add(edge.getIdentity());
                    inVertex.save();
                }
                if (outVertex.field(outVertexName) instanceof ORidBag) {
                    if (outVertexes.add(outVertex.getIdentity())) {
                        outVertex.field(outVertexName, new ORidBag());
                    }
                    final ORidBag outRidBag = outVertex.field(outVertexName);
                    outRidBag.add(edge.getIdentity());
                    outVertex.save();
                }
                counter++;
                if (counter > 0 && counter % 1000 == 0)
                    message(outputListener, counter + " edges were processed out of " + countEdges + " \n.");
            } catch (Exception e) {
                e.printStackTrace();
                message(outputListener, "Error during processing of edge with id " + edge.getIdentity() + "\n");
            }
        }
        message(outputListener, "Processed " + counter + " from " + countEdges + ".");
    }
    message(outputListener, "repair of ridbags is completed\n");
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) OMetadata(com.orientechnologies.orient.core.metadata.OMetadata) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ORID(com.orientechnologies.orient.core.id.ORID) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 4 with OMetadata

use of com.orientechnologies.orient.core.metadata.OMetadata in project orientdb by orientechnologies.

the class OrientJdbcDatabaseMetaData method getIndexInfo.

@Override
public ResultSet getIndexInfo(String catalog, String schema, String table, boolean unique, boolean approximate) throws SQLException {
    database.activateOnCurrentThread();
    OMetadata metadata = database.getMetadata();
    if (!approximate) {
        metadata.getIndexManager().reload();
    }
    final Set<OIndex<?>> classIndexes = metadata.getIndexManager().getClassIndexes(table);
    final Set<OIndex<?>> indexes = new HashSet<OIndex<?>>();
    for (OIndex<?> oIndex : classIndexes) {
        if (!unique || oIndex.getType().equals(INDEX_TYPE.UNIQUE.name()))
            indexes.add(oIndex);
    }
    final List<ODocument> records = new ArrayList<ODocument>();
    for (OIndex<?> idx : indexes) {
        boolean notUniqueIndex = !(idx.getType().equals(INDEX_TYPE.UNIQUE.name()));
        final String fieldNames = idx.getDefinition().getFields().toString();
        ODocument doc = new ODocument().field("TABLE_CAT", catalog).field("TABLE_SCHEM", schema).field("TABLE_NAME", table).field("NON_UNIQUE", notUniqueIndex).field("INDEX_QUALIFIER", (Object) null).field("INDEX_NAME", idx.getName()).field("TYPE", idx.getType()).field("ORDINAL_POSITION", 0).field("COLUMN_NAME", fieldNames.substring(1, fieldNames.length() - 1)).field("ASC_OR_DESC", "ASC");
        records.add(doc);
    }
    return new OrientJdbcResultSet(new OrientJdbcStatement(connection), records, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
}
Also used : OIndex(com.orientechnologies.orient.core.index.OIndex) OMetadata(com.orientechnologies.orient.core.metadata.OMetadata) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 5 with OMetadata

use of com.orientechnologies.orient.core.metadata.OMetadata in project orientdb by orientechnologies.

the class OIndexManagerAbstract method releaseExclusiveLock.

protected void releaseExclusiveLock() {
    lock.writeLock().unlock();
    final ODatabaseDocument databaseRecord = getDatabaseIfDefined();
    if (databaseRecord != null && !databaseRecord.isClosed()) {
        final OMetadata metadata = databaseRecord.getMetadata();
        if (metadata != null)
            ((OMetadataInternal) metadata).clearThreadLocalSchemaSnapshot();
    }
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) OMetadata(com.orientechnologies.orient.core.metadata.OMetadata)

Aggregations

OMetadata (com.orientechnologies.orient.core.metadata.OMetadata)7 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)4 ORidBag (com.orientechnologies.orient.core.db.record.ridbag.ORidBag)3 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)3 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)3 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)2 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)2 ORID (com.orientechnologies.orient.core.id.ORID)2 Collection (java.util.Collection)2 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)1 ORecordNotFoundException (com.orientechnologies.orient.core.exception.ORecordNotFoundException)1 OIndex (com.orientechnologies.orient.core.index.OIndex)1 Direction (com.tinkerpop.blueprints.Direction)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 Set (java.util.Set)1