I am doing some research on Grails and writing about what the future holds for it..
Something interesting jumped out in the RoadMap (http://grails.org/Roadmap)
GORM for REST
Anyone with more experience with Grails than me know what this would entail?
I am guessing some sort of CRUD operations through Web Services instead of using Hibernate to connect to an SQL database?
there is a JSON RESTful API for GORM which gives some insight on what GORM for REST is like:
GET on /context/api/domain-class-name returns a list of domain objects (possible arguments are the same as for the DomainClass.list() method argument map)
POST on /context/api/domain-class-name creates a new instance
GET on /context/api/domain-class-name/id retrieves the given instance
PUT on /context/api/domain-class-name/id updates the given instance by ID
DELETE on /context/api/domain-class-name/id deletes the given instance
As far as to RESTy GORM that is scheduled for Grails 2.0, here is the GORM Virtual REST domain objects discussion on Grails mailing list:
I am currently evaluating the use of grails to connect to other backend systems. Would it be possible to let the domain layer talk to CRUD REST services instead of a Database? It would be a bit like a XML backend.... We have got a very big backend where it is difficult to implement business logic, but we can manage to provide restful services. My idea is to have grails as a business / web application layer on top to deploy various systems to cross platform
This feature is scheduled for development for Grails 2.0
-- Graeme Rocher
I think the intent is to apply the scaffolding pattern to a RESTful API out of the box. There has been a JIRA entry around for several years for this.
Resulting JIRA: http://jira.grails.org/browse/GRAILS-2823
I also wouldn't be surprised if they took the dynamic finder idea and applied it to URL patterns.
GET /book/findByTitle/Dune
or
GET /book/findByTitle?title=Dune&format=json
or something like that.
I don't know exactly what is on the roadmap, but I imagine that the final product will have scaffold functionality (list,view,create,update,delete) through a RESTful interface plus some URL patterns that correspond to what you can currently do with the dynamic finders that GORM provides.
Take a look at the JAX-RS plugin. I suspect that will be the kind of thing they use.
Not that I want to rain on the parade but why would I use REST for accessing database rather than directly through hibernate. It's bound to slow down the DB access.
Related
I'd like to make my usage of open-dolphin in grails sever as easy as possible. So, I'm looking for way to handle CRUD actions on domain classes(on the server side) automaticaly. In demos from open-dolphin project I havent found any idea how to achieve this(if I missed something, please point me where I should study). Instances are pulled from server on request and until it would be pulled/updated again there is no way to recognize changes that happen on server(I've been investigating mainly crudDemo in open-dolphin project).
Since CRUD actions can come not only from user via web or remote client, but also as consequence of other actions, cascade deletes, from services etc.(changes made to the database via sql, are probably untreatable), I thing that handle actions in classes controllers is not enough.
I came up with idea of handling CRUD actions using GORM events, with those I can keep dolphin models persistent with database, check PMs before update or delete, and probably handle all changes on domain classes instances that grails is doing. But, I have to write very similar logic to each class, be sure I havent missed any event on any class(scaffolding may help) and there are probably other consequences that I do not realize now..
So my question is: Is there any documentation, pattern, plugin, open-source code, etc., where open-dolphin is implemented into grails that way, that it autamaticaly propagates CRUD actions on domain classes instances to its presentation models? Or anything that aims to achieve this, using scaffolding, observing instances lists and properties, or something else?
Maybe, I misunderstood concept of using open-dolphin with grails, if so, I appreciate any good advice.
Thanks a lot!
for some reason I haven't seen your question before.
You can happily use Grails domain classes and GORM with OpenDolphin on the server side. The "CrudDemo" in OpenDolphin does exactly that.
Here are the domain classes: https://github.com/canoo/open-dolphin/tree/master/dolphin-grails/grails-app/domain/dolphin/grails
Here are the actions: https://github.com/canoo/open-dolphin/tree/master/subprojects/demo-javafx/server/src/main/groovy/org/opendolphin/demo/crud
Note that when we do testing and client and server-side actions run in-memory, there is no grails support available. Therefore, the server-side actions use service interfaces with DTOs instead of Grails domain classes. The implementation as a Grails service then uses Grails domain classes and GORM.
enjoy
Dierk
I have an existing application that is a front end application which retrieves all of its information from external Web Services. I want to re-create this application using the Grails framework, however the use case is a bit odd. Grails is Model driven. In this case I really have no Database tables. My data is received real time through a web service call. My question to the community is how would you go about implementing the following use case:
Employee Search:
All employee data will come from a web service call. I need to allow the user to enter for example an "EmployeeID" and select a "Customer".
The Grails application then makes a web service query to the appropriate web service and pulls back the results.
HERE IS THE UNKOWN PART: What is the best way to take these results and fit them into the Grails model? In other words, I need to display a Data Grid of the results (Search Results). The grid should work like the Grails list action, allowing the user to sort on particular columns, pagination etc.
I would have to think that this use case is a common? What is the best way to lay a project like this down? Should I use external javaScript libraries like Dojo or JQuery to provide the grid functionality?
Performance is also a concern to an approach
There is no one single way to create Grails applications. Often applications do make use of domain classes that provide easy access to data in relational database tables, but you can easily switch to a NoSQL datastore or even use no direct persistence like in your application.
The simple answer to your question is that you should just create non-persistent data classes in src/groovy and src/java that represent the data you're working with from your web service calls. You can still use Grails for its controllers and GSPs, taglibs, services (non-transactional of course since there won't be database access), and also take advantage of the many available plugins.
You shouldn't have to do much to use the standard generated controllers and GSPs to display data with sorting and pagination. The generation scripts do expect domain classes, but you can cheat a bit to get those generated (and of course you can always code stuff by hand). For example if you have a Person class in src/groovy/com/yourcompany, move it to grails-app/domain:
package com.yourcompany
class Person {
String firstName
String lastName
}
Then run grails generate-all com.yourcompany.Person and it will create the controller and its unit test, and the GSPs. Now move it back to src/groovy and use it as you want. The GSPs don't expect domain classes, they just expect individual class instances or lists of instances.
You'll need to convert controller calls to stuff like person.save() to use your web services instead, but much of the code should be reusable.
One thing you can take advantage of is validation. You can annotate your classes with #Validateable and define constraints to take advantage of Grails validation for non-persistent classes - see the documentation for more details.
I'm building a new SAAS application and was looking for some advice on the most appropriate framework to use. I realize that no single framework will likely be able to do all this, but I thought I'd ask the community and try to find one that solves the hardest problems.
Requirements
Single code source. (each customer will have either a subdomain, or a distinct domain, but everyone should be running off the same code base and same servers)
Should be able to update the programming source once and have all the tenants pick it up
Session information should either be kept in a cached store, or just in cookies (no shared state)
Multi-tenant database functionality built in. (Based on the domain used to reach the application, the framework should automatically use the database connection information assigned to that domain)
Each customer/domain may have their own template for the web pages. Templates need to be assignable on a per-customer basis and kept outside the application code
Security and rapid prototyping is more important than speed
There will be a lot of CRUD type screens, so simple built in functionality for this is desired
I have pretty lengthy Java and PHP experience, but would only consider PHP as a last resort for this. My Scala, Python and Ruby experience is a bit rustier, but I would not mind coming up to speed if they offer a significant advantage. I've looked at the Play! Framework and like it (fulfills #1, #2,#6 very well), but the multi-tenant aspects are not very strong. I've done several projects using Grails and it handles everything except #3 and #5, and can be hacked to do the rest.
I would say that the third point is rather independent of grails/play/whatever in general. If you need a shared cache there is a multitude of providers for this and there are plugins for most of them in Grails.
The multi-tenancy in grails is pretty mature and much less intrusive than the solution from the blogpost in Sebastiens answer. Whether or not you use single tenancy (multiple databases) or multi tenancy is more or less transparent to your code and most of the headaches are abstracted away. Do be aware that you need to do some smart indexing (like including the tenant id in a multi column index etc) to not get very sad speeds when your data starts to grow.
As for externalized views, you can either slap them in the database or symlink them into your webapp and just keep them in separate numbered folders. Then from the tenant plugin, you can use TenantUtils.getCurrentTenant() and simply render from the appropiate folder "/" + (tenantID ?: "default") + "/whatever/view/path". This way, layouts etc can be shared across tenants if you so please and you simply put tenant specific stuff in the tenant specific folders.
You can probably do this in play too, or , but I don't see anything hindering you from doing this just fine in Grails.
My $0.02 on this question.
Actually Play! fits well to what you'r looking for.
Read this post:
http://www.lunatech-research.com/archives/2011/03/04/play-framework-writing-multitenancy-application-hibernate-filters
It works great. You can even make this filter work so that you can expose the crud module to customers and they'll only get their own data...
For very large applications, sharding seems not supported yet (no hibernate shards handled yet i think).
There's a multidb plugin to work with multiple db, but it seems not working very well yet...
I've heard that Grails' Multi-Tenant plugin offers some good tooling for several different methods of multi-tenancy.
"Each customer/domain may have their own template for the web pages.
Templates need to be assignable on a per-customer basis and kept
outside the application code"
I assume you mean they each have their own layout/skin. There are several techniques to execute this:
You could manually assign layouts based on tenant. <meta name="layout" content="${tenantName}/main" />
Write your own tenancy aware LayoutDecoratorMapper and override the default GrailsLayoutDecoratorMapper in sitemesh.xml
Figure out how to override and enhance Some internal tools dynamically resolve views(per tenant) or resources (GrailsViewResolver, GrailsConventionGroovyPageLocator, GrailsResourceLoader, etc.)
In PHP you can use Innomatic Platform for building multi-tenant (isolated databases) applications:
http://www.innomatic.org
Im building a Grails app that will have multiple similar websites (each it's own domain name) with the same code but different design and configuration. (think of blogger)
What is the best method for using different view and even some different logic on a single app without too much hacking?
I'm new to Grails and the method I have in mind is to check all the time to see what the domain name is and to serve the right controller/view. Is there a better way?
I would have a go with the MultiTenant plugin. You mention that views and logic differ, but I'm guessing what will differ most is the data? Use MultiTenant to cleanly separate the data for each site without too much hazzle, and if you store the configuration of views and logic in the DB you get that unique per site as well.
I think MultiTenant is being updated to the latest Grails release, at least I've seen that mentioned in the Grails mail list. I think you need to use an 1.2 release until then.
I'm doing something similar to separate data using the Hibernate Filter plugin. My views are the same but I have per-site texts and messages by looking up message "SITE-A.hello.world" first and if not found the default message "hello.world" is retrieved. Just to give you an idea how views may be customized, though you probably need to take it further than that for your system...
I'm getting started on a new MVC project where there are some peculiar rules and a little bit of strangeness, and it has me puzzled. Specifically, I have access to a database containing all of my data, but it has to be handled entirely through an external web service. Don't ask me why, I don't understand the reasons. That's just how it is.
So the CRUD will be handled via this API. I'm planning on creating a service layer that will wrap up all the calls, but I'm having trouble wrapping my head around the model... To create my model-based domain objects (customers, orders, so on..) should I:
Create them all manually
Create a dummy database and point an ORM at it
Point an ORM at the existing database but ignore the ORM's persistence in lieu of the API.
I feel like I've got all the information I need to build this out, but I'm getting caught up with the API. Any pointers or advice would be greatly appreciated.
Depending on the scale of what you're doing option 3 is dangerous as you're assuming the database model is the same as that exposed by the external service. Options 1 and 2 aren't IMHO much different from each other - in either case you'll have to decide what your objects, properties and behaviours are going to be - it just boils down to whether you're more comfortable doing it in classes or database tables.
The key thing is to make sure that the external service calls are hidden behind some sort of wrapper. Personally I'd then put a repository on top of that to handle querying the external service wrapper and return domain objects.
In general, ORMs are not known for their ability to generate clean domain model classes. ORMs are known for creating data layers, which you don't appear to need in this case.
You could probably use a code generation tool like T4 to code generate a first pass at your domain model classes, based on either the web service or the database, if that would save you time. Otherwise, you probably would just manually create the domain objects. Even if you code generate a first pass at your domain objects, it's unlikely there is a clean 1-1 mapping to your domain objects from either the database or web service, so you will likely need to spend significant time manually editing your code generated domain classes anyway.