Tuesday, 12 February 2013


HI THIS TOUTORIAL WILL HELP FULL FOR STARTUP IN GRAILS CREATED BY NAVEENRAJU
Part8: Ternery RelationShip in sql  by using  Grails views
Part9:Gsp Tags And there Implimentation in gsp Pages






DEMO1:One-Many UniDirectional in my sql:


Step1:Create Domain Class  Face

Face.groovy

package many.many.unidrectional


class Face {


String name

Integer age

Nose nose

    static constraints = {

name(nullable:false,blank:false)

age(nullable:false,blank:false)

nose(nullable:true,blank:true)


    }



}


Step2:Create Controller Face Controller

FaceController.groovy

package ont.many.unidirectional
class FaceController {
static scaffold=Face
}

Step3:Create Domain Class  Nose

Nose.groovy

package many.many.unidrectional


class Nose {


String country




    String toString()

    {


return country


    }

    static constraints = {



    }

}

Step4:Create Controller Book Controller

NoseController.groovy


package ont.many.unidirectional
class NoseController {
static scaffold=Nose
}


Step5:Create DataSource.groovy


DataSource.groovy
dataSource {
    pooled = true
    driverClassName = "com.mysql.jdbc.Driver"
    username = "root"
    password = ""
}
hibernate {
    cache.use_second_level_cache = true
    cache.use_query_cache = false
    cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
// environment specific settings
environments {
    development {
        dataSource {
            dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
            url = "jdbc:mysql://localhost/Relation1"
        }
    }
    test {
        dataSource {
            dbCreate = "update"
            url = "jdbc:mysql://localhost/Relation1"
        }
    }
    production {
        dataSource {
            dbCreate = "update"
            url = "jdbc:mysql://localhost/Relation1"
            pooled = true
            properties {
               maxActive = -1
               minEvictableIdleTimeMillis=1800000
               timeBetweenEvictionRunsMillis=1800000
               numTestsPerEvictionRun=3
               testOnBorrow=true
               testWhileIdle=true
               testOnReturn=true
               validationQuery="SELECT 1"
            }
        }
    }
}

Step6:BuildConfig.groovy


BuildConfig.groovy

grails.servlet.version = "2.5" // Change depending on target container compliance (2.5 or 3.0)grails.project.class.dir = "target/classes"grails.project.test.class.dir = "target/test-classes"grails.project.test.reports.dir = "target/test-reports"grails.project.target.level = 1.6grails.project.source.level = 1.6//grails.project.war.file = "target/${appName}-${appVersion}.war"
grails.project.dependency.resolution = {    // inherit Grails' default dependencies    inherits("global") {        // specify dependency exclusions here; for example, uncomment this to disable ehcache:        // excludes 'ehcache'    }    log "error" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'    checksums true // Whether to verify checksums on resolve
    repositories {        inherits true // Whether to inherit repository definitions from plugins
        grailsPlugins()        grailsHome()        grailsCentral()
        mavenLocal()        mavenCentral()
        // uncomment these (or add new ones) to enable remote dependency resolution from public Maven repositories        //mavenRepo "http://snapshots.repository.codehaus.org"        //mavenRepo "http://repository.codehaus.org"        //mavenRepo "http://download.java.net/maven/2/"        //mavenRepo "http://repository.jboss.com/maven2/"    }    dependencies {        // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
         runtime 'mysql:mysql-connector-java:5.1.20'    }
    plugins {        runtime ":hibernate:$grailsVersion"        runtime ":jquery:1.7.2"        runtime ":resources:1.1.6"
        // Uncomment these (or add new ones) to enable additional resources capabilities        //runtime ":zipped-resources:1.0"        //runtime ":cached-resources:1.0"        //runtime ":yui-minify-resources:0.1.4"
        build ":tomcat:$grailsVersion"
        runtime ":database-migration:1.1"
        compile ':cache:1.0.0'    }}


Step7:

go to mysql create schema Relation1use relation1


step8:


grails run-app


Step9:o/p
                                       
                                      





















DEMO2:One-Many BIiDirectional in my sql:


Step1:Create Domain Class  Face

Face.groovy

package many.many.bidirectional


class Face {

    String name

    Integer age

    Nose nose





    static constraints = {

name(nullabule:false,blank:false)

age(nullable:false,blank:false)

    nose(nullable:true,blank:true)


    }


    String toString()

    {


    return name

    }

}


Step2:Create Controller Face Controller

FaceController.groovy

package ont.many.unidirectional
class FaceController {
static scaffold=Face
}

Step3:Create Domain Class  Nose

Nose.groovy

package many.many.bidirectional


class Nose {


String country

static belongsTo=[face:Face]

    static constraints = {




    //face(nullable:true,blank:true)

    }



String toString()

{


return country


}


}

Step4:Create Controller Book Controller

NoseController.groovy


package ont.many.unidirectional
class NoseController {
static scaffold=Nose
}


Step5:Create DataSource.groovy


DataSource.groovy
dataSource {
    pooled = true
    driverClassName = "com.mysql.jdbc.Driver"
    username = "root"
    password = ""
}
hibernate {
    cache.use_second_level_cache = true
    cache.use_query_cache = false
    cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
// environment specific settings
environments {
    development {
        dataSource {
            dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
            url = "jdbc:mysql://localhost/Relation1"
        }
    }
    test {
        dataSource {
            dbCreate = "update"
            url = "jdbc:mysql://localhost/Relation1"
        }
    }
    production {
        dataSource {
            dbCreate = "update"
            url = "jdbc:mysql://localhost/Relation1"
            pooled = true
            properties {
               maxActive = -1
               minEvictableIdleTimeMillis=1800000
               timeBetweenEvictionRunsMillis=1800000
               numTestsPerEvictionRun=3
               testOnBorrow=true
               testWhileIdle=true
               testOnReturn=true
               validationQuery="SELECT 1"
            }
        }
    }
}

Step6:BuildConfig.groovy


BuildConfig.groovy

grails.servlet.version = "2.5" // Change depending on target container compliance (2.5 or 3.0)grails.project.class.dir = "target/classes"grails.project.test.class.dir = "target/test-classes"grails.project.test.reports.dir = "target/test-reports"grails.project.target.level = 1.6grails.project.source.level = 1.6//grails.project.war.file = "target/${appName}-${appVersion}.war"
grails.project.dependency.resolution = {    // inherit Grails' default dependencies    inherits("global") {        // specify dependency exclusions here; for example, uncomment this to disable ehcache:        // excludes 'ehcache'    }    log "error" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'    checksums true // Whether to verify checksums on resolve
    repositories {        inherits true // Whether to inherit repository definitions from plugins
        grailsPlugins()        grailsHome()        grailsCentral()
        mavenLocal()        mavenCentral()
        // uncomment these (or add new ones) to enable remote dependency resolution from public Maven repositories        //mavenRepo "http://snapshots.repository.codehaus.org"        //mavenRepo "http://repository.codehaus.org"        //mavenRepo "http://download.java.net/maven/2/"        //mavenRepo "http://repository.jboss.com/maven2/"    }    dependencies {        // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
         runtime 'mysql:mysql-connector-java:5.1.20'    }
    plugins {        runtime ":hibernate:$grailsVersion"        runtime ":jquery:1.7.2"        runtime ":resources:1.1.6"
        // Uncomment these (or add new ones) to enable additional resources capabilities        //runtime ":zipped-resources:1.0"        //runtime ":cached-resources:1.0"        //runtime ":yui-minify-resources:0.1.4"
        build ":tomcat:$grailsVersion"
        runtime ":database-migration:1.1"
        compile ':cache:1.0.0'    }}


Step7:

go to mysql create schema Relation1use relation1


step8:


grails run-app


Step9:o/p






                                   



















DEMO3:One-Many UniDirectional in my sql:


Step1:Create Domain Class  Author

Author.groovy

package ont.many.unidirectional
class Author {


String name
Integer age
static hasMany=[books:Book]

}


Step2:Create Controller Author Controller

AuthorController.groovy

package ont.many.unidirectional
class AuthorController {
static scaffold=Book
}

Step3:Create Domain Class  Book

Book.groovy

package ont.many.unidirectional
class Book {
        String coutry}


Step4:Create Controller Book Controller

BookController.groovy


package ont.many.unidirectional
class BookController {
static scaffold=Book
}


Step5:Create DataSource.groovy


DataSource.groovy
dataSource {
    pooled = true
    driverClassName = "com.mysql.jdbc.Driver"
    username = "root"
    password = ""
}
hibernate {
    cache.use_second_level_cache = true
    cache.use_query_cache = false
    cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
// environment specific settings
environments {
    development {
        dataSource {
            dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
            url = "jdbc:mysql://localhost/Relation1"
        }
    }
    test {
        dataSource {
            dbCreate = "update"
            url = "jdbc:mysql://localhost/Relation1"
        }
    }
    production {
        dataSource {
            dbCreate = "update"
            url = "jdbc:mysql://localhost/Relation1"
            pooled = true
            properties {
               maxActive = -1
               minEvictableIdleTimeMillis=1800000
               timeBetweenEvictionRunsMillis=1800000
               numTestsPerEvictionRun=3
               testOnBorrow=true
               testWhileIdle=true
               testOnReturn=true
               validationQuery="SELECT 1"
            }
        }
    }
}

Step6:BuildConfig.groovy


BuildConfig.groovy

grails.servlet.version = "2.5" // Change depending on target container compliance (2.5 or 3.0)grails.project.class.dir = "target/classes"grails.project.test.class.dir = "target/test-classes"grails.project.test.reports.dir = "target/test-reports"grails.project.target.level = 1.6grails.project.source.level = 1.6//grails.project.war.file = "target/${appName}-${appVersion}.war"
grails.project.dependency.resolution = {    // inherit Grails' default dependencies    inherits("global") {        // specify dependency exclusions here; for example, uncomment this to disable ehcache:        // excludes 'ehcache'    }    log "error" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'    checksums true // Whether to verify checksums on resolve
    repositories {        inherits true // Whether to inherit repository definitions from plugins
        grailsPlugins()        grailsHome()        grailsCentral()
        mavenLocal()        mavenCentral()
        // uncomment these (or add new ones) to enable remote dependency resolution from public Maven repositories        //mavenRepo "http://snapshots.repository.codehaus.org"        //mavenRepo "http://repository.codehaus.org"        //mavenRepo "http://download.java.net/maven/2/"        //mavenRepo "http://repository.jboss.com/maven2/"    }    dependencies {        // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
         runtime 'mysql:mysql-connector-java:5.1.20'    }
    plugins {        runtime ":hibernate:$grailsVersion"        runtime ":jquery:1.7.2"        runtime ":resources:1.1.6"
        // Uncomment these (or add new ones) to enable additional resources capabilities        //runtime ":zipped-resources:1.0"        //runtime ":cached-resources:1.0"        //runtime ":yui-minify-resources:0.1.4"
        build ":tomcat:$grailsVersion"
        runtime ":database-migration:1.1"
        compile ':cache:1.0.0'    }}


Step7:

go to mysql create schema Relation1use relation1


step8:


grails run-app


Step9:o/p




























DEMO4:One-Many BIiDirectional in my sql:


Step1:Create Domain Class  Author

Author.groovy

package one.many.biderectional


class Author {


static hasMany=[books:Book]

String name

    static constraints = {

    }

}


Step2:Create Controller Author Controller

AuthorController.groovy

package ont.many.unidirectional
class AuthorController {
static scaffold=Book
}

Step3:Create Domain Class  Book

Book.groovy

package one.many.biderectional


class Book {


static belongsTo=[author:Author]

String title

    static constraints = {

    }

}


Step4:Create Controller Book Controller

BookController.groovy


package ont.many.unidirectional
class BookController {
static scaffold=Book
}


Step5:Create DataSource.groovy


DataSource.groovy
dataSource {
    pooled = true
    driverClassName = "com.mysql.jdbc.Driver"
    username = "root"
    password = ""
}
hibernate {
    cache.use_second_level_cache = true
    cache.use_query_cache = false
    cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
// environment specific settings
environments {
    development {
        dataSource {
            dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
            url = "jdbc:mysql://localhost/Relation1"
        }
    }
    test {
        dataSource {
            dbCreate = "update"
            url = "jdbc:mysql://localhost/Relation1"
        }
    }
    production {
        dataSource {
            dbCreate = "update"
            url = "jdbc:mysql://localhost/Relation1"
            pooled = true
            properties {
               maxActive = -1
               minEvictableIdleTimeMillis=1800000
               timeBetweenEvictionRunsMillis=1800000
               numTestsPerEvictionRun=3
               testOnBorrow=true
               testWhileIdle=true
               testOnReturn=true
               validationQuery="SELECT 1"
            }
        }
    }
}

Step6:BuildConfig.groovy


BuildConfig.groovy

grails.servlet.version = "2.5" // Change depending on target container compliance (2.5 or 3.0)grails.project.class.dir = "target/classes"grails.project.test.class.dir = "target/test-classes"grails.project.test.reports.dir = "target/test-reports"grails.project.target.level = 1.6grails.project.source.level = 1.6//grails.project.war.file = "target/${appName}-${appVersion}.war"
grails.project.dependency.resolution = {    // inherit Grails' default dependencies    inherits("global") {        // specify dependency exclusions here; for example, uncomment this to disable ehcache:        // excludes 'ehcache'    }    log "error" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'    checksums true // Whether to verify checksums on resolve
    repositories {        inherits true // Whether to inherit repository definitions from plugins
        grailsPlugins()        grailsHome()        grailsCentral()
        mavenLocal()        mavenCentral()
        // uncomment these (or add new ones) to enable remote dependency resolution from public Maven repositories        //mavenRepo "http://snapshots.repository.codehaus.org"        //mavenRepo "http://repository.codehaus.org"        //mavenRepo "http://download.java.net/maven/2/"        //mavenRepo "http://repository.jboss.com/maven2/"    }    dependencies {        // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
         runtime 'mysql:mysql-connector-java:5.1.20'    }
    plugins {        runtime ":hibernate:$grailsVersion"        runtime ":jquery:1.7.2"        runtime ":resources:1.1.6"
        // Uncomment these (or add new ones) to enable additional resources capabilities        //runtime ":zipped-resources:1.0"        //runtime ":cached-resources:1.0"        //runtime ":yui-minify-resources:0.1.4"
        build ":tomcat:$grailsVersion"
        runtime ":database-migration:1.1"
        compile ':cache:1.0.0'    }}


Step7:

go to mysql create schema Relation1use relation1


step8:


grails run-app


Step9:o/p

















DEMO5:Many-Many BIiDirectional in my sql:


Step1:Create Domain Class  Author

Author.groovy

package many.many


class Author {


    

static hasMany=[books:Book]

String name;


}


Step2:Create Controller Author Controller

AuthorController.groovy

package ont.many.unidirectional
class AuthorController {
static scaffold=Book
}

Step3:Create Domain Class  Book

Book.groovy

package many.many


class Book {



static belongsTo=Author

static hasMany=[author:Author]

String title

  static constraints = {

    }

}


Step4:Create Controller Book Controller

BookController.groovy


package ont.many.unidirectional
class BookController {
static scaffold=Book
}


Step5:Create DataSource.groovy


DataSource.groovy
dataSource {
    pooled = true
    driverClassName = "com.mysql.jdbc.Driver"
    username = "root"
    password = ""
}
hibernate {
    cache.use_second_level_cache = true
    cache.use_query_cache = false
    cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
// environment specific settings
environments {
    development {
        dataSource {
            dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
            url = "jdbc:mysql://localhost/Relation1"
        }
    }
    test {
        dataSource {
            dbCreate = "update"
            url = "jdbc:mysql://localhost/Relation1"
        }
    }
    production {
        dataSource {
            dbCreate = "update"
            url = "jdbc:mysql://localhost/Relation1"
            pooled = true
            properties {
               maxActive = -1
               minEvictableIdleTimeMillis=1800000
               timeBetweenEvictionRunsMillis=1800000
               numTestsPerEvictionRun=3
               testOnBorrow=true
               testWhileIdle=true
               testOnReturn=true
               validationQuery="SELECT 1"
            }
        }
    }
}

Step6:BuildConfig.groovy


BuildConfig.groovy

grails.servlet.version = "2.5" // Change depending on target container compliance (2.5 or 3.0)grails.project.class.dir = "target/classes"grails.project.test.class.dir = "target/test-classes"grails.project.test.reports.dir = "target/test-reports"grails.project.target.level = 1.6grails.project.source.level = 1.6//grails.project.war.file = "target/${appName}-${appVersion}.war"
grails.project.dependency.resolution = {    // inherit Grails' default dependencies    inherits("global") {        // specify dependency exclusions here; for example, uncomment this to disable ehcache:        // excludes 'ehcache'    }    log "error" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'    checksums true // Whether to verify checksums on resolve
    repositories {        inherits true // Whether to inherit repository definitions from plugins
        grailsPlugins()        grailsHome()        grailsCentral()
        mavenLocal()        mavenCentral()
        // uncomment these (or add new ones) to enable remote dependency resolution from public Maven repositories        //mavenRepo "http://snapshots.repository.codehaus.org"        //mavenRepo "http://repository.codehaus.org"        //mavenRepo "http://download.java.net/maven/2/"        //mavenRepo "http://repository.jboss.com/maven2/"    }    dependencies {        // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
         runtime 'mysql:mysql-connector-java:5.1.20'    }
    plugins {        runtime ":hibernate:$grailsVersion"        runtime ":jquery:1.7.2"        runtime ":resources:1.1.6"
        // Uncomment these (or add new ones) to enable additional resources capabilities        //runtime ":zipped-resources:1.0"        //runtime ":cached-resources:1.0"        //runtime ":yui-minify-resources:0.1.4"
        build ":tomcat:$grailsVersion"
        runtime ":database-migration:1.1"
        compile ':cache:1.0.0'    }}


Step7:

go to mysql create schema Relation1use relation1


step8:


grails run-app


Step9:o/p