use of com.orientechnologies.orient.core.index.OIndex in project guice-persist-orient by xvik.
the class FulltextIndexFieldExtension method isIndexCorrect.
private boolean isIndexCorrect(final IndexValidationSupport support, final OClass.INDEX_TYPE type, final FulltextIndex annotation) {
final OIndex classIndex = support.getIndex();
final ODocument metadata = classIndex.getConfiguration();
final Iterable<String> field = metadata.field(STOP_WORDS);
return support.isIndexSigns(metadata.field(INDEX_RADIX), metadata.field(IGNORE_CHARS), metadata.field(SEPARATOR_CHARS), metadata.field(MIN_WORD_LENGTH), Sets.newHashSet(field)).matchRequiredSigns(type, annotation.indexRadix(), annotation.ignoreChars(), annotation.separatorChars(), annotation.minWordLength(), Sets.newHashSet(annotation.stopWords()));
}
use of com.orientechnologies.orient.core.index.OIndex in project wicket-orientdb by OrienteerBAP.
the class TestModels method testOIndexDataProvider.
@Test
public void testOIndexDataProvider() {
OSchema schema = wicket.getTester().getSchema();
OClass oClass = schema.getClass("OUser");
OIndexesDataProvider provider = new OIndexesDataProvider(oClass, true);
provider.setSort("name", SortOrder.ASCENDING);
Iterator<? extends OIndex<?>> it = provider.iterator(0, -1);
List<OIndex<?>> allIndexes = new ArrayList<OIndex<?>>(oClass.getIndexes());
while (it.hasNext()) {
OIndex<?> oIndex = it.next();
assertTrue(allIndexes.remove(provider.model(oIndex).getObject()));
}
assertTrue(allIndexes.size() == 0);
provider.detach();
}
use of com.orientechnologies.orient.core.index.OIndex in project wicket-orientdb by OrienteerBAP.
the class TestPrototypers method testOIndexPrototyper.
@Test
public void testOIndexPrototyper() throws Exception {
OClass newClass = wicket.getTester().getSchema().createClass("NewClass");
OProperty property = newClass.createProperty("name", OType.STRING);
OIndex<?> newIndex = OIndexPrototyper.newPrototype("NewClass", Arrays.asList("name"));
assertTrue(property.getAllIndexes().size() == 0);
PropertyResolver.setValue("type", newIndex, "notunique", null);
assertNotNull(newIndex.getDefinition());
assertTrue(newIndex.getDefinition().getFields().contains("name"));
assertTrue(newIndex instanceof IPrototype);
OIndex<?> realizedNewIndex = ((IPrototype<OIndex<?>>) newIndex).realizePrototype();
assertEquals(1, property.getAllIndexes().size());
assertEquals(1, newClass.getIndexes().size());
property = newClass.createProperty("description", OType.STRING);
newIndex = OIndexPrototyper.newPrototype("NewClass", Arrays.asList("description"));
PropertyResolver.setValue("type", newIndex, "notunique", null);
assertEquals(0, property.getAllIndexes().size());
PropertyResolver.setValue("algorithm", newIndex, ODefaultIndexFactory.SBTREE_ALGORITHM, null);
ODocument metadata = new ODocument();
metadata.field("test", "test123", OType.STRING);
PropertyResolver.setValue("metadata", newIndex, metadata, null);
realizedNewIndex = ((IPrototype<OIndex<?>>) newIndex).realizePrototype();
assertEquals(1, property.getAllIndexes().size());
assertEquals(2, newClass.getIndexes().size());
assertEquals("test123", realizedNewIndex.getMetadata().field("test"));
wicket.getTester().getSchema().dropClass(newClass.getName());
}
use of com.orientechnologies.orient.core.index.OIndex in project orientdb by orientechnologies.
the class OCommandExecutorSQLDropProperty method relatedIndexes.
private List<OIndex<?>> relatedIndexes(final String fieldName) {
final List<OIndex<?>> result = new ArrayList<OIndex<?>>();
final ODatabaseDocument database = getDatabase();
for (final OIndex<?> oIndex : database.getMetadata().getIndexManager().getClassIndexes(className)) {
if (OCollections.indexOf(oIndex.getDefinition().getFields(), fieldName, new OCaseInsentiveComparator()) > -1) {
result.add(oIndex);
}
}
return result;
}
use of com.orientechnologies.orient.core.index.OIndex in project orientdb by orientechnologies.
the class OCommandExecutorSQLDropProperty method execute.
/**
* Execute the CREATE PROPERTY.
*/
public Object execute(final Map<Object, Object> iArgs) {
if (fieldName == null)
throw new OCommandExecutionException("Cannot execute the command because it has not yet been parsed");
final ODatabaseDocument database = getDatabase();
final OClassImpl sourceClass = (OClassImpl) database.getMetadata().getSchema().getClass(className);
if (sourceClass == null)
throw new OCommandExecutionException("Source class '" + className + "' not found");
if (ifExists && !sourceClass.existsProperty(fieldName)) {
return null;
}
final List<OIndex<?>> indexes = relatedIndexes(fieldName);
if (!indexes.isEmpty()) {
if (force) {
dropRelatedIndexes(indexes);
} else {
final StringBuilder indexNames = new StringBuilder();
boolean first = true;
for (final OIndex<?> index : sourceClass.getClassInvolvedIndexes(fieldName)) {
if (!first) {
indexNames.append(", ");
} else {
first = false;
}
indexNames.append(index.getName());
}
throw new OCommandExecutionException("Property used in indexes (" + indexNames.toString() + "). Please drop these indexes before removing property or use FORCE parameter.");
}
}
// REMOVE THE PROPERTY
sourceClass.dropProperty(fieldName);
return null;
}
Aggregations