Is it possible to set a scope to a domain class?
I'd like to know if it's possible with grails to specify a scope for the domain classes.
Few words to explain how my application is working at the moment: - database access is done through an external "module" using SQLJ. This module is user by controllers in my grails app. - a user ask for specific information submitting forms -> request submitted to the external module -> information extra开发者_如何学编程cted from the database -> information loaded into grails mem DB (HSQL) -> information displayed in views.
It works fine in development environment as i'm the only one using the application. But i'm wondering how the application would behave with two or more users. I mean, do the information loaded into grails memory database will be shared between users or not? And how not to shared information requested by one user with the others?
Thanks in advance for any help about this subject.
Regards.
All data in the database is shared across all users of the grails application. You would have to write a custom query to limit the data returned to a specific user. Based on your application maybe something similar to the following.
class DomainClass1 {
//fields you get from SQLJ go here
int userId
}
To get data into an instance of your domain class.
def domInstance=new DomainClass1()
domInstance.loadFromSQLJ() //call the SQLJ module and put it's data in the domain class
domInstance.userId=5 //assign the user associated with this info
domInstance.save()
Then when you want to display info for the user with the userId 5
def domInstance2=DomainClass1.findByUserId(5)
//Do stuff with domInstance2
It will be shared between all users.
But it depends on you, as for any other database, there must be some criteria (db column) by which you can choose only information related to current user.
In our project, we overrode domain classes' get()
, list()
that take into account domain aggregate root (a User
or whatever), and also check all the named queries.
This leaves off all the other means of accessing instances, like findBy*()
, criteria, findWhere()
(though you can also override the dynamic methods), or HQL, but anyway reduces the amount of security review by 80%.
Suddenly it turned out to be OK to use DomainClass.list()
in scaffolding.
精彩评论