How to create porperty of type collection?

79 views
Skip to first unread message

Marc Tigges

unread,
May 6, 2014, 2:06:40 PM5/6/14
to orient-...@googlegroups.com
Hello,

i need a property for a vertex containing multiple values, so i tried to find out 
if i can create something like that. I found this:

this.graph.createProperty(vertexType, "name", OType.EMBEDDEDLIST);

But in the documentation is written:

this is a container and needs the parameter linked-type or linked-class

But i need to store Strings inside the list.

How can i create a property of a type like collection containing strings?

Luca Garulli

unread,
May 6, 2014, 3:45:22 PM5/6/14
to orient-database
Hi,
You should call:

g.getVertexType("MyType").createProperty("name", OType.EMBEDDEDLIST, OType.STRING);

Lvc@


Lvc@


--

---
You received this message because you are subscribed to the Google Groups "OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to orient-databa...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Valentin Popov

unread,
May 7, 2014, 2:10:40 AM5/7/14
to orient-...@googlegroups.com
Luca, hi

Is it possible to search in index via such properties, like OType.EMBEDDEDLIST  contains [admin, administrator, superuser] can I search record only by name = admin?

Regards,
Valentin

вторник, 6 мая 2014 г., 23:45:22 UTC+4 пользователь Lvc@ написал:

Montrazul

unread,
May 10, 2014, 8:34:33 AM5/10/14
to orient-...@googlegroups.com
I am also interested in indexing properites of type EMBEDDEDLIST.

Valentin Popov

unread,
May 10, 2014, 12:11:03 PM5/10/14
to orient-...@googlegroups.com
Yup, it is possible

But you need create properties before you add some values to such properties, other case ODB cant create index for properties that already stored on DB.

Something like that 


ItemType type = ItemType.USER;


OrientVertexType ovt = graph.getVertexType(type.getClassName());


IndexedProperty indexProperty = IndexedProperty.EMAIL;
String fieldName = indexProperty.getIndexKey();
String iName = type.getClassName()+"."+fieldName;


ovt.createProperty(fieldName, OType.EMBEDDEDLIST, OType.STRING);
graph.getRawGraph().commit();


ovt.createIndex(iName, INDEX_TYPE.UNIQUE, fieldName);

graph.getRawGraph().commit();



You received this message because you are subscribed to a topic in the Google Groups "OrientDB" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/orient-database/xWmAWQOPKwY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to orient-databa...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Regards,
Valentin Popov




Montrazul

unread,
May 11, 2014, 3:31:38 AM5/11/14
to orient-...@googlegroups.com
But if you do so, how do you add new values to your collection?

Without the index i did it like that:

public void setProperty(Vertex vertex, String key, String value) {
     Set<String> keys = vertex.getPropertyKeys();
List<String> values = null;
if(keys.contains(key)) {
values = (List<String>)vertex.getProperty(key);
values.add(value);
} else {
values = new ArrayList<String>();
values.add(value);
}
vertex.setProperty(key, values);
}

And with the index you cant do that:

Exception in thread "main" com.orientechnologies.orient.core.exception.ODatabaseException: Error on saving record in cluster #11
at com.orientechnologies.orient.core.db.record.ODatabaseRecordAbstract.executeSaveRecord(ODatabaseRecordAbstract.java:1052)
at com.orientechnologies.orient.core.tx.OTransactionNoTx.saveRecord(OTransactionNoTx.java:82)
at com.orientechnologies.orient.core.db.record.ODatabaseRecordTx.save(ODatabaseRecordTx.java:333)
at com.orientechnologies.orient.core.db.record.ODatabaseRecordTx.save(ODatabaseRecordTx.java:42)
at com.orientechnologies.orient.core.record.ORecordAbstract.save(ORecordAbstract.java:333)
at com.orientechnologies.orient.core.record.impl.ODocument.save(ODocument.java:1381)
at com.orientechnologies.orient.core.record.impl.ODocument.save(ODocument.java:1370)
at com.orientechnologies.orient.core.record.impl.ODocument.save(ODocument.java:1359)
at com.tinkerpop.blueprints.impls.orient.OrientElement.save(OrientElement.java:150)
at com.tinkerpop.blueprints.impls.orient.OrientElement.save(OrientElement.java:133)
at com.tinkerpop.blueprints.impls.orient.OrientElement.setProperty(OrientElement.java:99)
Caused by: java.lang.NullPointerException
at com.orientechnologies.orient.core.index.hashindex.local.OLocalHashTable.put(OLocalHashTable.java:212)
at com.orientechnologies.orient.core.index.engine.OLocalHashTableIndexEngine.put(OLocalHashTableIndexEngine.java:150)
at com.orientechnologies.orient.core.index.OIndexDictionary.put(OIndexDictionary.java:44)
at com.orientechnologies.orient.core.index.OIndexDictionary.put(OIndexDictionary.java:29)
at com.orientechnologies.orient.core.tx.OTransactionNoTx.addIndexEntry(OTransactionNoTx.java:186)
at com.orientechnologies.orient.core.index.OIndexTxAware.put(OIndexTxAware.java:80)
at com.orientechnologies.orient.core.index.OIndexTxAware.put(OIndexTxAware.java:36)
at com.orientechnologies.orient.core.index.OClassIndexManager.processIndexUpdateFieldAssignment(OClassIndexManager.java:398)
at com.orientechnologies.orient.core.index.OClassIndexManager.processSingleIndexUpdate(OClassIndexManager.java:369)
at com.orientechnologies.orient.core.index.OClassIndexManager.updateIndexEntries(OClassIndexManager.java:156)
at com.orientechnologies.orient.core.index.OClassIndexManager.onRecordAfterUpdate(OClassIndexManager.java:131)
at com.orientechnologies.orient.core.hook.ODocumentHookAbstract.onTrigger(ODocumentHookAbstract.java:266)
at com.orientechnologies.orient.core.db.record.ODatabaseRecordAbstract.callbackHooks(ODatabaseRecordAbstract.java:1274)
at com.orientechnologies.orient.core.db.record.ODatabaseRecordAbstract.executeSaveRecord(ODatabaseRecordAbstract.java:1029)
... 14 more
Exception in thread "Thread-1" java.lang.NullPointerException
at com.orientechnologies.orient.core.index.hashindex.local.OLocalHashTable.saveState(OLocalHashTable.java:369)
at com.orientechnologies.orient.core.index.hashindex.local.OLocalHashTable.flush(OLocalHashTable.java:1141)
at com.orientechnologies.orient.core.index.engine.OLocalHashTableIndexEngine.flush(OLocalHashTableIndexEngine.java:94)
at com.orientechnologies.orient.core.index.OIndexAbstract.flush(OIndexAbstract.java:116)
at com.orientechnologies.orient.core.index.OIndexManagerAbstract.flush(OIndexManagerAbstract.java:170)
at com.orientechnologies.orient.core.index.OIndexManagerAbstract.close(OIndexManagerAbstract.java:282)
at com.orientechnologies.orient.core.storage.OStorageAbstract.close(OStorageAbstract.java:120)
at com.orientechnologies.orient.core.storage.OStorageEmbedded.close(OStorageEmbedded.java:70)
at com.orientechnologies.orient.core.storage.impl.local.paginated.OLocalPaginatedStorage.doClose(OLocalPaginatedStorage.java:713)
at com.orientechnologies.orient.core.storage.impl.local.paginated.OLocalPaginatedStorage.close(OLocalPaginatedStorage.java:672)
at com.orientechnologies.orient.core.Orient.shutdown(Orient.java:155)
at com.orientechnologies.orient.core.OrientShutdownHook.run(OrientShutdownHook.java:28)



Artem Orobets

unread,
May 12, 2014, 2:34:35 AM5/12/14
to orient-...@googlegroups.com
Hi Montrazul,

What version of OrientDB do you use? is that reproducible on current snapshot?

Best regards,
Artem Orobets

Orient Technologies

the Company behind OrientDB

Montrazul

unread,
May 12, 2014, 4:02:20 AM5/12/14
to orient-...@googlegroups.com
I think i used the wrong index. I used this:

OrientVertexType instance = this.graph.createVertexType("instance", null);
instance.createProperty("property_id", OType.STRING);
instance.createProperty("property_names", OType.EMBEDDEDLIST, OType.STRING);
instance.createProperty("property_alias", OType.EMBEDDEDLIST, OType.STRING);
this.graph.createKeyIndex("property_id", Vertex.class, new Parameter<String, String>("class", "instance"), new Parameter<String, String>("type", "UNIQUE_HASH_INDEX"));
this.graph.createKeyIndex("property_names", Vertex.class, new Parameter<String, String>("class", "instance"), new Parameter<String, String>("type", "DICTIONARY_HASH_INDEX"));
this.graph.createKeyIndex("property_alias", Vertex.class, new Parameter<String, String>("class", "instance"), new Parameter<String, String>("type", "DICTIONARY_HASH_INDEX"));

What leads to the exception.

When i use createIndex instead it works on 1.7rc2 and with the lates 1.7-SNAPSHOT
Reply all
Reply to author
Forward
0 new messages