use of com.orientechnologies.orient.core.index.OIndex 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.index.OIndex in project orientdb by orientechnologies.
the class OLuceneIndexFactory method onDrop.
@Override
public void onDrop(final ODatabaseInternal db) {
try {
if (db.isClosed())
return;
OLogManager.instance().debug(this, "Dropping Lucene indexes...");
for (OIndex idx : db.getMetadata().getIndexManager().getIndexes()) {
if (idx.getInternal() instanceof OLuceneFullTextIndex) {
OLogManager.instance().debug(this, "- index '%s'", idx.getName());
idx.delete();
}
}
} catch (Exception e) {
OLogManager.instance().warn(this, "Error on dropping Lucene indexes", e);
}
}
use of com.orientechnologies.orient.core.index.OIndex in project orientdb by orientechnologies.
the class RemoteIndexSupportTest method testOneValueIndexInTxLookup.
@Test
public void testOneValueIndexInTxLookup() throws IOException {
ODatabaseDocumentTx db = new ODatabaseDocumentTx("remote:localhost/test");
db.open("admin", "admin");
OClass clazz = db.getMetadata().getSchema().createClass("TestIndex");
clazz.createProperty("test", OType.STRING).createIndex(OClass.INDEX_TYPE.NOTUNIQUE);
db.begin();
ODocument doc = new ODocument("TestIndex");
doc.field("test", "testKey");
db.save(doc);
OIndex<Collection<OIdentifiable>> idx = (OIndex<Collection<OIdentifiable>>) db.getMetadata().getIndexManager().getIndex("TestIndex.test");
Collection<OIdentifiable> res = idx.get("testKey");
assertEquals(1, res.size());
db.close();
}
use of com.orientechnologies.orient.core.index.OIndex in project orientdb by orientechnologies.
the class SQLTruncateRecordTest method truncateRecord.
@Test
public void truncateRecord() {
if (!database.getMetadata().getSchema().existsClass("Person"))
database.command(new OCommandSQL("create class Profile")).execute();
database.command(new OCommandSQL("insert into Profile (sex, salary) values ('female', 2100)")).execute();
final Long total = database.countClass("Profile");
final List<ODocument> resultset = database.query(new OSQLSynchQuery<Object>("select from Profile where sex = 'female' and salary = 2100"));
final Number records = (Number) database.command(new OCommandSQL("truncate record [" + resultset.get(0).getIdentity() + "]")).execute();
Assert.assertEquals(records.intValue(), 1);
OClass cls = database.getMetadata().getSchema().getClass("Profile");
Set<OIndex<?>> indexes = cls.getIndexes();
for (OIndex<?> index : indexes) {
index.rebuild();
}
Assert.assertEquals(database.countClass("Profile"), total - records.intValue());
}
use of com.orientechnologies.orient.core.index.OIndex in project orientdb by orientechnologies.
the class OrientIndex method create.
private void create(final String indexName, final Class<? extends Element> indexClass, OType iKeyType) {
this.indexClass = indexClass;
if (iKeyType == null)
iKeyType = OType.STRING;
final OIndexFactory factory = OIndexes.getFactory(OClass.INDEX_TYPE.DICTIONARY.toString(), null);
this.recordKeyValueIndex = new OIndexTxAwareOneValue(graph.getRawGraph(), (OIndex<OIdentifiable>) graph.getRawGraph().getMetadata().getIndexManager().createIndex("__@recordmap@___" + indexName, OClass.INDEX_TYPE.DICTIONARY.toString(), new OSimpleKeyIndexDefinition(factory.getLastVersion(), OType.LINK, OType.STRING), null, null, null));
final String className;
if (Vertex.class.isAssignableFrom(indexClass))
className = VERTEX;
else if (Edge.class.isAssignableFrom(indexClass))
className = EDGE;
else
className = indexClass.getName();
final ODocument metadata = new ODocument();
metadata.field(CONFIG_CLASSNAME, className);
metadata.field(CONFIG_RECORD_MAP_NAME, recordKeyValueIndex.getName());
final OIndexFactory nuFactory = OIndexes.getFactory(OClass.INDEX_TYPE.NOTUNIQUE.toString(), null);
// CREATE THE MAP
this.underlying = new OIndexTxAwareMultiValue(graph.getRawGraph(), (OIndex<Set<OIdentifiable>>) graph.getRawGraph().getMetadata().getIndexManager().createIndex(indexName, OClass.INDEX_TYPE.NOTUNIQUE.toString(), new OSimpleKeyIndexDefinition(nuFactory.getLastVersion(), iKeyType), null, null, metadata));
}
Aggregations