background preloader

Grails

Facebook Twitter

Batch Import Performance with Grails and MySQL - Ted Naleid. I’ve spent some time over the last couple of weeks working on a Grails service that allows us to import new records into our MySQL database. A number of interesting techniques have popped out of this that I think would be useful for others doing similar types of importing using GORM/Hibernate/MySQL. Background For background, the imports in our app happen a few times a week, and range in size from less than a hundred up to a few hundred thousand new records. It is also possible for us to get updates on previous data that we’ve imported, if a record in the import matches a record in our database, we want to update the existing record rather than inserting a duplicate.

We had a desire to use a Grails service to do the importing as we could leverage our existing data model, plus, there are some special cases where the import logic can get a bit hairy and having access to all of our domain methods is nice. Example Naive Import Application The Domain class: Yikes! MySQL Database Performance Tweaks. Bulk Insert With Grails | The Geek Credential. Importing data from a text or CSV file into a database with Grails seems like it should be a simple thing. As it turns out, however, some approaches perform dramatically better than others. Simple GORM Let’s assume that we’ve created a Grails domain class called MyDomain to represent the table we’re importing into, and a parseLine() method to parse one line of file data (CSV or whatever) into values. You might try something like this: void loadTable(File file) { file.eachLine() { line ->MyDomain dom = new MyDomain(parseLine(line))dom.save()} } Unfortunately, you would find this code to run very slowly and you might even run out of memory.

So it’s better to try a different approach. Call an External Tool If your database platform offers a command line bulk import tool, you could simply call and execute it outside of Grails. But you may not have such a command line tool, or it may not be available to you in all environments. Groovy SQL Hibernate StatelessSession Like this: Like Loading... Cassandra vs MongoDB vs CouchDB vs Redis vs Riak vs HBase vs Couchbase vs Hypertable vs ElasticSearch vs Accumulo vs VoltDB vs Scalaris comparison :: Software architect Kristof Kovacs.

While SQL databases are insanely useful tools, their monopoly in the last decades is coming to an end. And it's just time: I can't even count the things that were forced into relational databases, but never really fitted them. (That being said, relational databases will always be the best for the stuff that has relations.) But, the differences between NoSQL databases are much bigger than ever was between one SQL database and another. This means that it is a bigger responsibility on software architects to choose the appropriate one for a project right at the beginning. In this light, here is a comparison of Open Source NOSQL databases: The most popular ones # Redis # Best used: For rapidly changing data with a foreseeable database size (should fit mostly in memory).

For example: To store real-time stock prices. Cassandra # Best used: When you need to store data so huge that it doesn't fit on server, but still want a friendly familiar interface to it. MongoDB # ElasticSearch # CouchDB # Accumulo # 15 Reasons Why You Should Use The Grails Web Application Framework » IndicThreads : Software Developer Station. Grails. Grails: Using Hibernate Filters. The Grails Hibernate Filters plugin makes it possible to use Hibernate Filters with GORM. Hibernate Filters provide additional restriction rules that can be applied to classes and collections.

The Hibernate Filters plugin makes it possible to use this functionality with GORM inside Grails applications. Let's look at an example to see how filters can help us. Assume we have the following Grails domain class: 1.class User { 2.String username 3.boolean locked The locked flag indicates if an User has been locked by an administrator for some reason. Plugin installationTo install the Hibernate Filters Plugin in a Grails application we have to do two things: Add the plugin dependency to BuildConfig.groovy: 1.compile ":hibernate-filter:0.3.2" Add the following configuration property to our dataSource definition: 1.dataSource { 3.configClass = HibernateFilterDomainConfiguration Filter configurationNow we can add filters to our domain class using the static hibernateFilters property: 1.class Image {

Grails - Is there any solution to get g:pagination and g:sortableColumn for children elements in parents show view working. Deploy a Grails application on AWS Elastic Beanstalk. Complete guide on how to configure and deploy a Grails application on Amazon Web Services Elastic Beanstalk. Elastic Beanstalk Elastic Beanstalk is AWS platform-as-a-service solution. It’s based on Amazon Elastic Cloud Compute (Amazon EC2), Amazon Simple Storage Service (Amazon S3), Amazon Simple Notification Service (Amazon SNS), Elastic Load Balancing, and Auto Scaling. The advantage over other platform-as-a-service solution is that you can still take control over your instance through SSH if you have a specific need for your project. Also this service is free to use, you only pay for AWS usage (could be free the first year if you stay under the free tier usage).

The stack used to deploy a Grails app is a classic and proven Java stack composed of an Apache and Tomcat on an Amazon Linux (32 or 64). Begin with AWS Create an account or login to your Amazon Console Navigate to Elastic Beanstalk console: US East (N. To deploy a Grails app choose: As seen below: Securing a Grails Application with Acegi Security. Table of Contents IntroductionSetting up the RaceTrack sample applicationInstalling the Grails Acegi pluginCreating the Acegi Security componentsConfiguring Acegi Security to secure the applicationTesting Introduction This article discusses the integration of the grails-acegi plugin with a sample Grails application.

As part of this integration, there are three major components which will be used – Groovy, Grails and Acegi Security. Groovy is a powerful, high level language for the Java platform which compiles down to Java bytecode. It is similar in concept to Ruby or Python, however it is tightly integrated with the Java platform.

Grails is a full stack framework implemented in Groovy. Acegi Security is a powerful, flexible security solution for enterprise software, with a particular emphasis on applications that use Spring. Setting up the RaceTrack sample application First, you will need to download Grails 1.0, the grails-acegi-0.2 plugin and Java SE JDK 5.0 or greater. Testing. A Pattern to Simplify Grails Controllers | Mr Paul Woods's Weblog. Grails Best Practices. I work at IntelliGrape, a company which specializes in Groovy & Grails development.

This article is a basic list of best practices that our Grails projects follow, gathered from mailing lists, Stack Overflow, blogs, podcasts and internal discussions at IntelliGrape. They are categorized under controller, service, domain, views, taglibs, testing and general. The advice here is specifically for Grails 2.0, although much of it is generally applicable. Controller Don’t allow the controller to take over another role. Service A service is the right candidate for complex business logic or coarse grained code. Views Keep views as simple as possible - avoid the temptation to put business or database logic in this layer. Domain Favor placing model domain specific logic in its own domain. TagLib Keep an individual tag light. Testing Favor units tests over integration tests. Config.groovy Some Other Tips Understand and stick to Grails conventions, as Grails is convention driven.

Have I missed anything? Excel, Excel 2007 & CSV Importer Using Apache POI. Excel-Import plugin uses Apache POI library (v 3.7) to parse Excel files. It's useful for either bootstrapping data, or when you want to allow your users to enter some data using Excel spreadsheets, or CSV. You can also export data into Excel using very similar configuration to importing. Note: This was tested with Grails 1.3. stream (Tomcat 6 7), not tested with 2.* yet. It also currently has a dependency on Joda-Time plugin (1.2), though it should work with both Joda and java.util.Date. . The core of the plugin is a service class ExcelImportService, which contains a number of useful methods for dealing with Excel, which you should dependency inject. _org.grails.plugins.excelimport.ExcelImportService_ There is also an _AbstractExcelImporter_, which is a class you can extend - it opens and stores the workbook reference. Reading Information Contained in Rows: The plugin is designed to parse data out of spreadsheets into format that can then be used to create objects.

Add filter pane to your scaffolding list template | RRZK – Regionales Rechenzentrum. The filter pane plugin is one of my favorite plugins, to give the user the capability to filter lists. But it’s a boring task, to add the filter pane to each scaffolded view. Especially you’ve to redo all this work, after regenerating the list view. But Customizing the Scaffolding templates will get you rid of this. All you have to do is: Install the filter pane plugin, if not already done:grails install-plugin filterpaneCopy the the templates used by Grails during code generation to your project directory, if not already done:grails install-templatesCustomize the controller template src/templates/scaffolding/Controller.groovy: Customize the list template viewsrc/templates/scaffolding/list.gsp: That’s all!

Grails on AWS Elastic Beanstalk | Greg Stephens Blog. Here are the steps I took to deploy a Grails app on AWS Elastic Beanstalk for the first time using the AWS Free Tier using Grails 2.2.3. I’m using Bobby Warner’s post from October 2011 as a guide to setting up the AWS services. Some field locations and the order of the setup has changed since Bobby did this in 2011. Create Free AWS Account Follow this link and sign-up for the free tier which gives you 12 months of free use from the time you sign-up. Create a Key Pair for SSH Access Before launching into creating our AWS instance, it will save several steps to create a Key Pair that we’ll use for SSH access. - Go to the EC2 Console - Look in the upper right hand corner of the window and make sure you are in the desired region - Click on Key Pair - Click on the Create Key Pair button – Enter a Key Pair Name to be used for the SSH access We’ll use the Key Pair Name in a few minutes when we create the new instance.

Setup Elastic Beanstalk & MySQL Instance Java Memory Settings (2) Server URL. Thoughts on grails: in-line editing in scaffolded show.gsp. In the default pages created by the scaffolding mechanism of grails, it is quite cumbersome that whenever you want to change a value of a domain class you have to go to the edit page and afterwards back to the show page. Two complete site loads that do not fit into the web 2.0 paradigm. Usually one would apply in-line editing to bring in a cool and useful AJAX feature and in fact every JS library seems to have built-in support. It is however quite labourous if you have to add this feature manually to every field even if you make things easier with a tag lib as suggested in the book "Beginning Groovy and Grails" by Christopher M.

Judd, Joseph Faisal Nusairat and James Shingler. I thought about the problem and then decided to try to combine scaffolding with this technique. I changed the following entry within show.gsp: to: One can use the TagLib given by the book, but you have to modify the action in order to work with arbitrary fields. Course Outline | Grails Example. Bobby Warner » Grails Setup. Did you know that you can have a complete modular enterprise application up and running in under 5 minutes with Grails? The architecture will be a lot more flexible and maintainable than any “Enterprise Java” structure with Ant or Maven too! First things first, how many different modules should an application have? Well, every application probably needs three essential things these days: website, mobile website and API.

Wait, why do you need an API if you don’t necessarily have any plans of sharing data? Well, the answer is you might need native Android and iPhone apps in the future, so you might as well plan for them right away. The HTML5 frameworks are getting pretty good though! First, create a parent folder for the entire application. Grails create-app sampleapp-webgrails create-app sampleapp-apigrails create-app sampleapp-mobile Next, create a Grails plugin for the core part of the application. Grails create-plugin sampleapp-core grails.plugin.location.’sampleapp-core’ = “.. Tutorial for Beginners – Setup Your Windows Development Environment | Grails Cookbook. Grails. Tutorial for Beginners – Introduction to GORM | Grails Cookbook.