Comments (12)
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?
from playorm.
So an example would be:
boolean emailExists = NoSql.em().contains(User.class, "emailAddress", "[email protected]")
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.
from playorm.
There is no row key here though? If you are trying to answer the question is there a user with emailAddress=[email protected], would you mind if that was done like so..... select count(u) from User as u where u.emailAddress = '[email protected]' because I can add that AND it would only scan the index so it would not load the entire user object.
from playorm.
That looks great. Maybe instead of contains it could also be:
NoSql.em().count(User.class, "emailAddress", "[email protected]")
That way it could be generic and used in other situations. Either way is great.
from playorm.
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 = '[email protected]') 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???
from playorm.
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..
~Vikas
from playorm.
yup, that would be the one......any ideas how you can get taligent something he can use in this regard?
thanks,
Dean
from playorm.
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 protected]"";
QueryResult result = nosqlTypedSession.createQueryCursor(cmd, 100);
if (result.getAllViewsIter().iterator().hasNext())
//found it
OR
if (result.getAllViewsCursor().next())
//found it
OR
if (result.getPrimaryViewIter().iterator().hasNext())
//found it
from playorm.
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?
from playorm.
It would be nice to simplify it for the user as for most basic apps there is no need to access the cursor.
from playorm.
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.
from playorm.
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.
from playorm.
Related Issues (20)
- Too many single reads before batch update - performance penalty HOT 12
- do not require @NoSqlIndexed HOT 22
- add support for adhoc queries to EntityManager HOT 6
- RFE: Support for cassandra TTL HOT 11
- NPE on index pointing to nonexistent row HOT 22
- Scan all rows for MongoDb, inmemory and HBase too HOT 1
- protocol of=vfs is not supported for loading classfiles? HOT 6
- change version to 1.7-SNAPSHOT HOT 1
- better error handling in cli tool HOT 2
- NoAvailableHostsException on simple test HOT 3
- @NoSqlEmbedded doesn't work with List and Set of Long types HOT 32
- removing entity with field anotated @NoSqlId @NoSqlIndexed will not remove index entry HOT 13
- add inheritance to lower layer meta model
- RFE: search within collection with index HOT 6
- Support for marker (no columns) entity HOT 4
- orm always tries to remove index on @NoSqlId field even if it does not exists HOT 2
- gradle out of memory HOT 5
- Double class scanning HOT 4
- New Release HOT 3
- Exception when trying to seralize a loaded Entity HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from playorm.