• Grails에서 생성한 GORM에 대한 쿼리는 dynamic finder로 원하는 데이터를 얻을 수 있다.
  • 아래 메소드들은 콘솔을 띄워서 연습하면 효과적이다.
    • grails console
  • 관련 메소드
    • find()
    • findAll()
    • findAll( query, param)
      • ex) User.findAll( “FROM User u WHERE u.id=:user_id”, [user_id:‘gilbird’])
    • findBy*()
    • findAllBy*()
      • LessThan, LessThanEqual
      • GreaterThan, GreaterThanEqual
      • Like, Ilike
      • NotEqual
      • Between
      • IsNotNull, IsNull
      • And, Or
    • list( option_list)
      • max, sort, order, ignoreCase, fetch, offset
    • listOrderBy*()
    • countBy*()
    • 복잡한 쿼리는 도메인 클래스의 withCriteria 클로저로 작성하면 된다.
      (참고: http://www.grails.org/doc/latest/guide/single.html#5.4.2 Criteria)

 

준비사항

  • Google App Engine SDK
  • Grails 1.1.1 (상위버전은 아직 동작안함)

Grails App 생성

grails create-app gae_demo

App-Engine 플러그인 설치

cd gae_demo

grails install-plugin app-engine

  • 플러그인 설치 과정 중 jpa 선택

도메인 클래스 생성

grails create-domain-class gae.Note

  • 패키지 명을 넣지 않으면 구글 앱 엔진이 동작하지 않는다.

Note에 대한 컨트롤러와 뷰 생성

grails generate-all gae.Note

도메인 클래스 어노테이션 변경

  • @Entity, @Id, @GeneratedValue 등은 Grails에서 추가한 어노테이션임
  • @Basic 어노테이션을 추가

package gae

import javax.persistence.*
//import com.google.appengine.api.datastore.Key

@Entity
class Note implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    Long id

    @Basic
    String message
}

뷰와 컨트롤러 생성

grails generate-all gae.Note

구글 앱 엔진 배포

  • 구글 앱 엔진 웹사이트에서 애플리케이션을 생성한다.
  • 애플리케이션 생성시 이름을 넣고 이 이름을 grails-app/conf/config.groovy에 다음 라인을 추가

google.appengine.application = “<애플리케이션명>”

호스팅을 위하여 버전을 명시하고 패키징

grails set-version 1
grails app-engine package
$APPENGINE_HOME/bin/appconfig.sh update ./target/war

배포 실행

grails app-engine deploy

참고

+ Recent posts