Archive data in Grails - grails

In my grails application I have some domain objects with lots of data in it. I now want to archive the old data in a seperate table, but the user should have access to it.
Do I have to make an extra domain class? Or is there some plugin which will help me to solve this problem?

There is no plugin that would meet your requirements. You would need to model this with a new Domain class (or something similar) in order to address your requirements.

Related

managing AspNetIdentity DbContext in n-tier application

Hi. I’m working on a solution which consists of layered mvc application using entity framework. I want to use AspNet Identity to manage user accounts and logins. Which has its own model and dbcontext classes embedded in it and all of these are inside my UI MVC project.
But I don’t want this. I want to be able to manage my database interactions through data layer which is entity framework and my own DB context. Now for a simple user account in order to be related with my custom Person class, I should do two separate database insert commands. One for create user and one for its related person object. I did merged two separate databases as one, but for contexts I still don’t know what to do.
Am I in the right direction or I’m missing something? Is there any best practices for this type of problems? I’m sure this has been solved for many people but I can’t figure it out how. I searched around for solutions on this problem but I couldn’t find anything useful. Thanks in advanced.
have you tried inheriting your context from IdentityDbContext?

Indentify unused grails domain classes

I have to identify all domain classes which are not used in my grails application the project has approximately 300+ domain classes, is there any(plugin) way to identify the domain which are currently not used
There isn't any plugin or tool that will do this for you. It's going to be up to you to determine if a domain class is used. Some ways to approach this would be:
Does it exist persisted in your data store? If not, it may not be used.
Remove it from the system. Do all the tests pass?
Aside from auditing the code (searching for domain classes by name) there isn't going to be a definitive way to determine this.

Grails: Using two databases (one created using domain class, other is an existing DB)

I recently finished an application using just standard grails way (GORM-domain classes, etc.), but the company is asking me to to include an existing DB from an open source project. Both are just using mySQL DB, which is good, but I'm not sure how to approach this. I've seen some posts regarding grails connecting to multiple DB.
I guess my question is: Is it possible to connect to two databases: one mapped to domain classes and the other not? My primary reason to do this is to keep all the code in one project and reuse code without gutting the project and making a plugin.
Thanks for any insight.
Yes. It is possible - http://grails.org/doc/latest/guide/single.html#multipleDatasources
Whether you map the other database to your domain classes or use it through a service layer is up to your design.
Thanks for the answer. I was also able to find a tool that helps generate the domain class from an existing DB. The tool is called GRAG (Grails Application Generator) which although is not perfect, it is a bit of a help getting me started faster.
I hope this helps others as well.

What’s the best approach to work with in memory domain objects in Grails?

I’m working on a Grail’s project that has some Domain objects not persisted on the database. They are managed thru a REST API, so all their CRUD operations will be done with this API instead of the database.
The point is to still be able to use some interesting Grails plug-ins (like searching using Compass).
For instance, the administration the Domain objects Users is going to be managed with the REST API, so when the Users list is displayed a the REST method to retrieve the list of users will be invoked on the remote server. I hope this use case is clear enough :)
I can think on several ways to design that but I'm not sure what’s the best:
Should I create the Domain Objects in the controller (and delete the
previous Users stored in memory)?
It seems it’s possible to define a Domain Class not persistable (with
mapping I think) but I’m not sure if this is the best approach or
where to load the data.
It is better not to model as a Grails the User as Domain object?
Thanks in advance!
I would wrap the REST interactions in a service, and call the service from a controller. In that case, the service would get the response and create its objects, passing the list back to the controller. Controllers should just handle incoming requests, invoke application components, and return responses.
It seems you want models to represent the data in the other application, which is a good idea. Since you don't need GORM, you might want to define them in the 'groovy' folder of your app instead of the domain models folder. Then I think they will just be objects.
I'd go with non-domain objects in src folder - though, need to check if it's possible to use the mentioned plugins with them.
I wonder what domain class functionality you wish to get out of non-persistent classes?

Do grails domain classes have to be tied to a database?

I am a complete noob when it comes to grails (and still very noobish when it comes to groovy) so I apologise if this is a dumb question.
I am building a simple web app and I want to control portions of the domain in my app based on file system objects (i.e. directory structure and file type) rather than database data. How easy is it to do this or are the domain objects so entwined with GORM that it is not worth the effort to try?
I ran into this question myself a couple of weeks ago.
You can just add the following snippet to the Domain Class.
def isAttached()
{
return false
}
Now it isn't connected to your database. Voila!
You can also use:
class YourDomainClass {
static mapWith = "none" // disable persistence for this domain class
See grails documentation and this answer. Appears to have been added in Grails 2.0.1 but not documented until version 2.3.0.
There is no built-in way to map domain classes to file system objects as you've described, but equally there is no requirement that your domain classes map to a relational database. The subject of how to create a Grails app that doesn't use a relational database is addressed
here and here (and possibly elsewhere).
A couple of ways to do this.
First, you can declare your properties that map to file system data as transient, and go to file system when getters / setters are called (you have to override them). You can also load them using onLoad if you need them to be in memory always.
Second - Hibernate handles the persistence. Hibernate allows for you to define your own user type, which can handle the persistence whichever way you want. This way it might happen for you more transparently (though you'd have to make sure you understand hibernate fairly well, to make sure there aren't any side effects, I am not sure).
http://i-proving.com/space/Technologies/Hibernate/User+Types+in+Hibernate

Resources