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());
}
}
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;
}
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");
}
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);
}
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();
}
}
Aggregations