Supereka’s Weblog

July 4, 2009

grails dbunit-operator plugin usage

Filed under: Grails — Tags: , , — supereka @ 8:38 am

1. install

grails install-plugin dbunit-operator

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

2. conf/DataSource.groovy

   1: dataSource {

   2:     pooled = true

   3:     driverClassName = "net.sourceforge.jtds.jdbc.Driver"

   4:     username = "trainingadmin"

   5:     password = "trainingpw"

   6:     dbunitXmlType = "flat"

   7:     

   8: }

   9:  

  10: hibernate {

  11:     cache.use_second_level_cache=true

  12:     cache.use_query_cache=true

  13:     cache.provider_class='com.opensymphony.oscache.hibernate.OSCacheProvider'

  14: }

  15: // environment specific settings

  16: environments {

  17:     development {

  18:         dataSource {

  19:             dbCreate = "create-drop" // one of 'create', 'create-drop','update'

  20:             url = "jdbc:jtds:sqlserver://localhost:1433/TRAINING"

  21:             initialData = "data/dev/training.xml" // dbunit-operator Flat-XML or XML data file

  22:             initialOperation = "CLEAN_INSERT" // dbunit-operator operation

  23:         }

  24:     }

  25:     test {

  26:         dataSource {

  27:             dbCreate = "update"

  28:             url = "jdbc:hsqldb:mem:testDb"

  29:         }

  30:     }

  31:     production {

  32:         dataSource {

  33:             dbCreate = "update"

  34:             url = "jdbc:hsqldb:file:prodDb;shutdown=true"

  35:         }

  36:     }

  37: }

line

6: must specify like this to use xml data file

21: you can specific initial data here. WARNING this point you can only specific 1 data file. If you have any data file, specified at BootStrap.groovy, I will show you later in this post.

22: initialOperation: ???

3. conf/BootStrap.groovy : specific DbUnit action here, in init{}

  • you can put more data file here
  • can create object here

ex:BootStrap.groovy

   1: import com.nic.*

   2:  

   3: class BootStrap {

   4: /*

   5:   def init = { servletContext ->

   6:   }

   7: */

   8:  

   9:   def init = {servletContext ->

  10:     DbUnitOperator.create()

  11:     DbUnitOperator.operate("data/dev/employee.xml","CLEAN_INSERT")

  12:  

  13:     def bu1 = new BusinessUnit(buNo:'002', name: 'Accounting', buType:BusinessUnitType.DEPARTMENT)

  14:     bu1.save()

  15:  

  16:   }

  17:   def destroy = {

  18:   }

line

10 need let bootStrap to Create DbUnit (Need)
11 opt DbUnitOperator.operate("data/dev/employee.xml","CLEAN_INSERT")

// this is the way you can add more data file. each file can edit (just edit, cannot change structure) via Excel 2007.

13, 14 opt Another way you can create and save object. You can call object that already created by xml data file.

August 5, 2008

edit gsp page in Dreamweaver

Filed under: Grails — supereka @ 2:26 am

Reference and thank you:
http://www.bitwalker.nl/blog/using-groovyserver-pages-in-dreamweaver

Step:

1. Add .gsp file extension
file: \Documents and Settings\username\Application Data\Adobe\Dreamweaver 9\Configuration\Extension.txt

Then Restart Dreamweaver

2. DocumentType
file: C:\Program Files\Macromedia\Dreamweaver 8\Configuration\DocumentTypes\MMDocumentTypes.xml
(maybe on same path like 1.)

August 4, 2008

install Grails Test Environment Server

Filed under: Grails — Tags: , — supereka @ 9:14 am

1. Copy folder ของ Grails App ลง Server ที่ติดตั้ง Groovy, Grails เรียบร้อยแล้ว

2. set ‘test’ environment ใน /grails-app/conf/datasource.groovy โดยให้ test environment ใช้ user, password เดียวกันกับ development environment,
จุดแตกต่างอยู่ที่ JDBC URL ที่จะชี้ไปที่ Test Database Server แทน

3. Database logins: ทำการแก้ Database Logins ที่จะเข้าใช้ Database User โดยใช้ sp_change_users_login

4. Backup Developement Database, then restore to Test Database.

5. พบปัญหา hibernate query error,  NestedServletException โดยมี statck trace ตอนต้นมาจาก
org.hibernate.exception.SQLGrammarException: could not execute query

caused by: java.sql.SQLException: Invalid object name ‘requestmap’

ทดลองดูแล้วพบว่าเปลี่ยนจาก login ‘suparera’ เป็น login ‘transportuser2′ แล้วหาย

อาจเกิดเนื่องจาก login suparera ไปผูกใช้งานกับ database 2 ตัว ทำให้การ reference ถึง database อาจมีปัญหา

Theme: Shocking Blue Green. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.