Friday, May 22, 2015

Grails use an external properties file for datasource configuration

Grails use an external properties file for datasource configuration


1.configure the DataSource.groovy file like this:



import org.springframework.core.io.ClassPathResource
import org.springframework.core.io.support.PropertiesLoaderUtils

def properties = PropertiesLoaderUtils.loadProperties(new ClassPathResource('datasource.properties'))

dataSource
pooled = true
driverClassName = properties.getProperty("dataSource.driverClassName")
username = properties.getProperty("dataSource.username")
password = properties.getProperty("dataSource.password")
url = properties.getProperty("dataSource.url")

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 = "update" // one of 'create', 'create-drop', 'update', 'validate', ''


test
dataSource
dbCreate = "update"


production
dataSource
dbCreate = "update"



2.Create the external database configuration properties file, below is the contents of datasource.properties


dataSource.driverClassName = com.mysql.jdbc.Driver
dataSource.url=jdbc:mysql://localhost:3306/a5go?useUnicode=true&characterEncoding=utf-8
dataSource.username=root
dataSource.password=password


Grails use an external properties file for datasource configuration

Thursday, May 21, 2015

use an external properties file in grails

use an external properties file in grails


1.Create the properties file.


dbCreate=update
driverClassName=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/db?useUnicode=true&characterEncoding=UTF8
username=root
password=password

2.add following line in the Config.groovy:


grails.config.locations = ["classpath:test1.properties", "classpath:Test2.properties"]

if set variables in config use following line


def props = new Properties()

url= props.getProperty("url")

3.in controller/services


import org.codehaus.groovy.grails.commons.ConfigurationHolder


def grailsApplication


def test1= ConfigurationHolder.config.test

def url= grailsApplication.config.url


use an external properties file in grails

Sunday, April 26, 2015

grails compilation error encoded string too long

Compiling 71 GSP files for package [test]

java.io.UTFDataFormatException: encoded string too long: 292932 bytes

at java.io.DataOutputStream.writeUTF(DataOutputStream.java:347)

at java.io.DataOutputStream.writeUTF(DataOutputStream.java:306)

at java.lang.Thread.run(Thread.java:662)


You have two options upgrade or follow the below steps


1. Find all the gsp pages with file size greater than 64K.

2. Add to the middle of your static pages (add it to the end of html tags, for example after

etc).

grails compilation error encoded string too long

Tuesday, February 24, 2015

PHP - Fatal error: Call to undefined function curl_init()

PHP – Fatal error: Call to undefined function curl_init()


On current versions of Debian and Ubuntu, you can likely solve this by installing the Curl extension for PHP, and restarting the webserver.


sudo apt-get install php5-curl


It’s possible you’ll need to install more:


sudo apt-get install curl libcurl3 libcurl3-dev;



PHP - Fatal error: Call to undefined function curl_init()

Monday, January 12, 2015

"Restart computer" failed when installing SQL Server 2012

“Restart computer” failed when installing SQL Server 2012


cd sql server folder

run

setup.exe /SkipRules=RebootRequiredCheck /ACTION=install



"Restart computer" failed when installing SQL Server 2012

Sunday, January 4, 2015

How to setting "Custom Naming Strategy" in grails project

How to setting “Custom Naming Strategy” in grails project


By default Grails uses Hibernate’s ImprovedNamingStrategy to convert domain class Class and field names to SQL table and column names by converting from camel-cased Strings to ones that use underscores as word separators. You can customize these on a per-class basis in the mapping closure but if there’s a consistent pattern you can specify a different NamingStrategy class to use.

Configure the class name to be used in grails-app/conf/DataSource.groovy in the hibernate section, e.g.


hibernate

cache.use_second_level_cache = true

cache.use_query_cache = false

cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'

naming_strategy = com.a5go.CustomNamingStrategy


You can use an existing class or write your own, for example one that prefixes table names and column names:

package com.a5go


import org.hibernate.cfg.ImprovedNamingStrategy

import org.hibernate.util.StringHelper


class CustomNamingStrategy extends ImprovedNamingStrategy


String classToTableName(String className)

"T_" + StringHelper.unqualify(className)




How to setting "Custom Naming Strategy" in grails project

Thursday, December 4, 2014

How to make System command calls in Groovy?

package ping

import java.io.*
import java.util.*

class PingController

def index()
def sout = new StringBuffer(), serr = new StringBuffer()
def proc = 'ping 127.0.0.1'.execute()
proc.consumeProcessOutput(sout, serr)
proc.waitForOrKill(1000)
println "out> $sout err> $serr"

def ping()
StringBuffer buf = new StringBuffer();
String s = "";
Process process;
try

process = Runtime.getRuntime().exec( "cmd /c " + "ping 8.8.8.8" );
BufferedReader br = new BufferedReader( new InputStreamReader(
process.getInputStream() ) );
while ( ( s = br.readLine() ) != null )

buf.append( s + "\r\n" );


process.waitFor();
System.out.println( buf );
catch ( Exception ex )

ex.printStackTrace();





How to make System command calls in Groovy?