The fact is Groovy doesn’t support all anonymous inner classes. There is a huge limit on the same. Users have to make sure that they are first considering them in another manner for the compatibility. Through closures, it is possible for the users, the process of determining the action listeners becomes extremely easier. Listener's closures can be considered as the adapter for listeners in Groovy while there is no time limit for the same.
Posted Date:- 2021-12-01 02:06:12
Using Groovy is simple as it doesn’t have complex requirements. It doesn’t matter which OS you use and what are the components of a server, this can easily be made to perform its function in every situation. In addition to this, there are features that make it run smoothly with all applications that are based on Java.
Posted Date:- 2021-12-01 02:04:05
Constraints let you define the rules for validating a domain object. They are defined under the static constraints closure in a domain object. Three examples might be nullable, blank and email.
Posted Date:- 2021-12-01 02:02:42
Gorm events are methods that you can insert into your domain objects and are executed before and after the domain object is saved into the database. Two examples are beforeInsert and afterDelete.
Posted Date:- 2021-12-01 02:01:55
All three are used to query domain objects.
•Dynamic finders are methods of the form findAllByName( “pancho” ) added to domain classes.
•Criterias are a DSL based on Hibernate Criterias and Groovy builders, they look like this: c { like(“name”, “pancho” ) }.
•HQL is a query language that looks like SQL but is fully object-oriented. It looks like this: “select distinct s.name from Student.s”
Posted Date:- 2021-12-01 02:00:26
It needs Java 1.4 and the Groovy jar. Also, an ASM library needs to be defined before programmers proceed with it.
Posted Date:- 2021-12-01 01:59:44
Yes, this can be done. However, the only problem is the features in such a case are limited Groovy cannot be made to handle all the tasks in a manner it has to.
Posted Date:- 2021-12-01 01:59:00
Yes, it’s quite true that Groovy is simple to use when compared to other similar Object-Oriented languages. There are certain reasons for same. The biggest factor is users can enjoy a simple declaration of all the arrays, expressions, maps, as well as ranges. Probably this makes it easy for the programmers to proceed with their task simply and have the most expected outcomes in a very reliable manner.
Posted Date:- 2021-12-01 01:58:27
Name queries are aliases written using the criteria builder DSL that allow us to re-use commonly used queries. You put them in the domain classes’ namedQueries static property.
Posted Date:- 2021-12-01 01:57:41
Whenever you have a one-many relationship between a and b, calling a.removeFrom(b) destroys the back reference between a and b. This is the reverse of the addTo() method.
Posted Date:- 2021-12-01 01:57:07
read() gets the object in read-only mode. get() retrieves the object and allows it to be modified. One consequence of this is that get() might automatically save changes to the database via hibernate dirty checking while read() will not.
Posted Date:- 2021-12-01 01:56:32
Sometimes when many people are working on the same set of data, Hibernate will throw a StaleObjectStateException and die.
The lock() method makes sure that nobody else can change your domain class by issuing a pessimistic lock on the database row until you commit your transaction.
Posted Date:- 2021-12-01 01:55:43
The joinTable domain class mapping allows us to customize the table that gets generated for associations. It lets me change the name, primary key and inverse column used in the database to map a list of primitives, enum, one-to-many or many-to-many relationship.
Posted Date:- 2021-12-01 01:53:39
•Not having a dbCreate / null – don’t mess with the database
•create-drop- nuke the database and create a new one
•create – if the database is there, don’t change it. Otherwise make a new one.
•update – change the database but keep the data if it is there, create a new one if you can’t find anything.
Posted Date:- 2021-12-01 01:52:55
This file allows us to define event hooks that get called whenever grails scripts fire events. For example, if I wanted to have a utility method that gets fired whenever compilation is finished, I can add it to the CompileEnd method in _Events.groovy.
Posted Date:- 2021-12-01 01:52:01
Call grails create-script myPackage.myScript . This will create a new Gant script file under the scripts directory that you can then run via grails my-script.
Posted Date:- 2021-12-01 01:50:32
Run-war will compile and build a war file that it runs from the embedded container ( Tomcat unless you’ve changed it ), run-app runs the application from compiled sources in the file system. This means that any change to controllers, views, etc will be reflected immediately by run-app, but not by run-war. It also means that scripts that get run at application packaging time ( such as the ui-performance plugin’s zip and minify process ) won’t happen at run-app time.
Posted Date:- 2021-12-01 01:49:49
Grails generates a dehydrated timestamped minimal zip file that can be attached to JIRA reports. One way to hydrate these into full projects is to call grails upgrade on them.
Posted Date:- 2021-12-01 01:49:08
The bootstrap files don’t get loaded. So if your database is in dbCreate = ‘create[-drop]’ mode, you might not get the same data that you would expect.The console also reloads on code change the same way that grails run-app does. So the code that you have typed in might get lost.
Posted Date:- 2021-12-01 01:48:33
Save indicates to hibernate that the object should be persisted, validate simply runs all the validation commands and check it. Save runs validate.
Posted Date:- 2021-12-01 01:48:01
Command objects are intermediate domain objects that are not saved in the database. You should use them whenever you are just interested in updating a subset of properties from a domain object, or when there is a form that does not map one-to-one with a domain object.
Command objects support both validation and data binding, so you can use these to validate the data entered into forms easily.
Posted Date:- 2021-12-01 01:47:30
1. nullable: true will cause the database schema to mark the column as nullable.
2. unique: true will cause the column index to be marked as unique
3. maxSize: number will set the length of the field to the number.
Posted Date:- 2021-12-01 01:46:54
1. widget: ‘textarea’ will make the field display in a text area instead of a one line input field.
2. display: ‘none’ will hide the constraint from being shown.
Posted Date:- 2021-12-01 01:45:43
Constraints let you define the rules for validating a domain object. They are defined under the static constraints closure in a domain object. Three examples might be nullable, blank and email.
Posted Date:- 2021-12-01 01:45:09
You can use the DatabaseManager or DatabaseManagerSwing included with the hsqldb database. Just call the following either in grails console or within your app:
org.hsqldb.util.DatabaseManagerSwing.main( ['--url', 'jdbc:hsqldb:mem:devDB'] as String[] )
Posted Date:- 2021-12-01 01:44:42
Grails console injects a ctx variable, which represents the Spring context. You can then just use ctx.getBean( ‘myServiceName’ ) to get a hold of your beans.
Posted Date:- 2021-12-01 01:43:44
You need to create a directory under grails-app/conf/hibernate. Copy your mapping files and create the appropriate hibernate.cfg.xml file there.
Posted Date:- 2021-12-01 01:43:22
You can mark it as such using the static transient = [ ‘cantSaveThis’ ] mechanism.
Posted Date:- 2021-12-01 01:41:18
Gorm events are methods that you can insert into your domain objects and are executed before and after the domain object is saved into the database. Two examples are beforeInsert and afterDelete
Posted Date:- 2021-12-01 01:40:40
Inject the dataSource and pass this as a connection to GSQL ( groovy.sql.Sql ).
1
new Sql( dataSource ).execute mySqlStatement
Posted Date:- 2021-12-01 01:40:21
•Grails interactive is interactive mode of the grails command line interface. It lets you run Gant scripts in the script runner one after another.
•Grails console is a Swing-based command console similar to the Groovy console. It let’s you execute code against a full environment that has access to all your domain classes and quickly test out code that would go into controllers and services.
•Grails shell is the headless version of Grails console. This is useful when you want to access and test out code in a remote SSH-based server. One of the advantages of the Grails shell is that it does not reload when domain classes change like the console does, so it is useful also for long-running scripts, although the new run – script command in Grails 1.3.6 might be better suited for those.
Posted Date:- 2021-12-01 01:39:29
•The Config.groovy file contains configuration properties and information needed when running your application. It contains properties used by your services, controllers, etc.
•The BuildConfig.groovy file contains information relevant to building and deploying your application, such as repositories, jar file dependencies and war file name.
Posted Date:- 2021-12-01 01:39:04
•Externalized configurations let me define other config and .properties files that don’t live within the grails-app/conf directory.
•To enable this, I need to define locations for the application to look for configuration files via the grails.config.locations in Config.groovy in relation to the classpath or filesystem.
•The most popular uses of externalized configurations is to enable configuration changes without having to rebuild a war file. By planning ahead, configurations can even be reloaded without restarting the application container via this mechanism.
Posted Date:- 2021-12-01 01:38:21
First, I need to generate the template files via grails install-templates. The web.xml template will be under src/templates/war directory.
Alternatively, I could also create a plugin and use the doWithWebDescriptor method to add or remove nodes from my web.xml file.
Posted Date:- 2021-12-01 01:37:59
In a controller, I can inject grailsApplication via def grailsApplication and access this variable via grailsApplication.config.layer1.prop. Anywhere else, I can use the ConfigurationHolder and access it via ConfigurationHolder.config.layer1.prop1
Posted Date:- 2021-12-01 01:37:29
Metaprogramming is the ability of adding new methods or variables to the classes dynamically at run time. You can add methods or variables whenever and wherever you want. This is a very powerful ability. Be it the use of code production, unit tests, or anything in between, these capabilities increases the curiosity of the java developers. These are the programs that write or manipulate other programs. These are responsible for dynamic string execution. These help in exposing the internal runtime engine to the programming codes through API’s. The meta object protocols make the program semantics explicit and extensible.
Posted Date:- 2021-12-01 01:37:06
As Groovy is an object-oriented programming language used for JVM, it is quite useful. Advantages of groovy are provided below:
* Its syntax is similar to the Java language syntax.
* Because it is based on Java, so it has access to a rich collection of Java libraries.
* It is fully object-oriented.
* It can be easily integrated with the existing interface.
* Groovy code is reusable and assignable.
* Groovy supports operator overloading.
* With Groovy’s declaration of Maps, arrays, ranges, and regular expressions are possible.
* It ensures efficient navigation of objects.
Posted Date:- 2021-12-01 01:36:33
All three are used to query domain objects.
Dynamic finders are methods of the form findAllByName( “pancho” ) added to domain classes.
Criterias are a DSL based on Hibernate Criterias and Groovy builders, they look like this: c { like(“name”, “pancho” ) }.
HQL is a query language that looks like SQL but is fully object-oriented. It looks like this: “select distinct s.name from Student.s”
Posted Date:- 2021-12-01 01:35:42
Name queries are aliases written using the criteria builder DSL that allow us to re-use commonly used queries. You put them in the domain classes’ namedQueries static property.
Posted Date:- 2021-12-01 01:35:08
Whenever you have a one-many relationship between a and b, calling a.removeFrom(b) destroys the back reference between a and b. This is the reverse of the addTo() method.
Posted Date:- 2021-12-01 01:34:41
read() gets the object in read-only mode. get() retrieves the object and allows it to be modified. One consequence of this is that get() might automatically save changes to the database via hibernate dirty checking while read() will not.
Posted Date:- 2021-12-01 01:33:59
Sometimes when many people are working on the same set of data, Hibernate will throw a StaleObjectStateException and die.
The lock() method makes sure that nobody else can change your domain class by issuing a pessimistic lock on the database row until you commit your transaction.
Posted Date:- 2021-12-01 01:33:27
The joinTable domain class mapping allows us to customize the table that gets generated for associations. It lets me change the name, primary key and inverse column used in the databse to map a list of primitives, enum, one-to-many or many-to-many relationship.
Posted Date:- 2021-12-01 01:33:07
define my shoes in the domain object as List shoes.
Posted Date:- 2021-12-01 01:32:54
Dynamic finders are methods that are created automatically based on domain class properties by Grails and GORM. They provide a simple way to query domain classes using the power of groovy metaprogramming.
If my domain class Movie has a date called ReleaseDate, I can call Movie.findByReleaseDateGreaterThan( today ) and GORM will automatically resolve this and generate the correct query in the background.
Posted Date:- 2021-12-01 01:32:30
I would pass in the verboseCompile flag and see what kind of monsters lurk in my code. grails compile -verboseCompile
Posted Date:- 2021-12-01 01:32:15
This file allows us to define event hooks that get called whenever grails scripts fire events. For example, if I wanted to have a utility method that gets fired whenever compilation is finished, I can add it to the CompileEnd metho in _Events.groovy.
Posted Date:- 2021-12-01 01:31:58
Call grails create-script myPackage.myScript . This will create a new Gant script file under the scripts directory that you can then run via grails my-script.
Posted Date:- 2021-12-01 01:31:29
Run-war will compile and builds a war file that it runs from the embedded container ( Tomcat unless you’ve changed it ), run-app runs the application from compiled sources in the file system.
This means that any change to controllers, views, etc will be reflected immediately by run-app, but not by run-war. It also means that scripts that get ran at application packaging time ( such as the ui-performance plugin’s zip and minify process ) won’t happen at run-app time.
Posted Date:- 2021-12-01 01:31:00
grails -Dserver.port=666 run-app or via the grails.server.port configuration value
Posted Date:- 2021-12-01 01:30:47