I don't know the best way to do this but it would be nice if there was a method in NoSqlEntityManager:
public boolean contains(Class entityType, String key, String value)
That didn't load in any data.
I am not sure at all what that function does? You say "That didn't load in any data" so you mean do not read from the database? and where is the key stored and this value, where am I supposed to check for those? Can you explain a bit more here?
So an example would be:
boolean emailExists = NoSql.em().contains(User.class, "emailAddress", "firstname.lastname@example.org")
And it would only check if the email exists not load any of the other attributes for the User class e.g. name, age etc.
There is no row key here though? If you are trying to answer the question is there a user with emailAddressemail@example.com, would you mind if that was done like so..... select count(u) from User as u where u.emailAddress = 'firstname.lastname@example.org' because I can add that AND it would only scan the index so it would not load the entire user object.
That looks great. Maybe instead of contains it could also be:
NoSql.em().count(User.class, "emailAddress", "email@example.com")
That way it could be generic and used in other situations. Either way is great.
hmmmm, I am rethinking this right now.....currently, we could just use the index and I believe you may be able to do this with today's api...it would only read in the primary key of the user itself. If you use TypedSession.runQuery("select t from User as t where t.emailAddress = 'firstname.lastname@example.org') it does NOT run the query but returns and object that you iterate over.....well, actually returns 1 object and you can request one of 3 iterators. Anyways, I am wondering if we can put an abstraction on top of that to do what you want but in a general way for all users in different situations.
Vikas, I would love to hear your thoughts here as well???
Yes, I agree with Dean as we have added support to query on primary/row key as well, it makes sense to use the existing APIs and then see if it is returning anything.
Dean: Here, I am sure, you meant NoSqlTypedSession.createQueryCursor(sql,batchsize) as there is no API like runQuery..
yup, that would be the one......any ideas how you can get taligent something he can use in this regard?
So, you will have to take latest code from master branch if you want to query on primary key(rowkey). Please note that you can still query on primary key or on an indexed column... you can do use any of the 3 iterator as Dean mentioned and do something like:
String sql = "select * from User where emailAddress = \"email@example.com\"";
QueryResult result = nosqlTypedSession.createQueryCursor(cmd, 100);
thanks for adding that exact code. there is one better method that reads in no rows which is using that same result object above, call result.getCursor() which gives the index cursor so no rows are read and only the index is read. It returns the IndexColumnInfo. If anything exists you know your user exists all without reading the row. hmmmmm, any ideas on what to do with this issue from a more usable perspective or should we close it?
It would be nice to simplify it for the user as for most basic apps there is no need to access the cursor.
ok, I am trying to figure out if this belongs on the EntityManager(ie. JPA has no count method on the EntityManager) or maybe we just throw it on TypedSession so it is NoSql.em().getTypedSession().count(User.class, "emailAddress", "myemail");......in fact, I think that might be best. Are you good with that solution? If so, I think we will proceed once the play 2.x plugin is complete.
One method is added in NoSqlTypedSession
public int count(String columnFamily, String indexedColName, Object value)
I hope that will solve the purpose. I am closing this issue as of now. However, please re-open it if you face any issue in using that.