이 블로그 검색

레이블이 appengine인 게시물을 표시합니다. 모든 게시물 표시
레이블이 appengine인 게시물을 표시합니다. 모든 게시물 표시

2012년 1월 24일 화요일

defaultFetchGroup = "true"

@Persistent(defaultFetchGroup = "true")

자식값도 기본으로 가져오게 하기 위한 설정

If you want to load the child, you can either "touch" it before closing the PersistenceManager (e.g. by calling getContactInfo() in the above example) or explicitly add the child field to the default fetch group so it's retrieved and loaded with the parent:

2012년 1월 16일 월요일

org.datanucleus.exceptions.NucleusUserException: Object Manager has been closed

  • 리스트를 가져온후 곧바로 guestList.size()를 사용했을 경우 나는 오류
  • List<GuestBookTable> detached = pm.detachCopy(guestBookList); if(detached.size()>0)...이렇게 사용
  • 해결책이 이것이 아닌 것 같음 일단 보류...
While learning to use JDO with datanucleus for a project to be run in app engine I tried to implement a method that gets a collection of persistant objects from the database. Trying to test the results I used the size()method on the collection. The result was following exception:

org.datanucleus.exceptions.NucleusUserException: Object Manager has been closed
at org.datanucleus.ObjectManagerImpl.assertIsOpen(ObjectManagerImpl.java:3816)
at org.datanucleus.ObjectManagerImpl.findObjectUsingAID(ObjectManagerImpl.java:2073)
....

The solution is simple. To iterate throw the objects of the collection, they have to be in a detached state, not in persistant state.

So the code in the dao class would look like:
public Collection getAllValueObjects() {
Collection results = Collections.checkedCollection(getJdoTemplate().find(ValueObject.class), ValueObject.class);
 
// To iterate the collection it has to be detached
getPersistenceManager().detachCopyAll(results);
 
return results;
}

request factory + jdo

jdo객체의 키
 - relation을 사용할 경우 : 인코딩된 스트링을 써야 함.
                                      (Key타입은 request factory에서 지원하지 않음,
                                        long타입은 jdo에서 reation을 지원하지 않음)
 - relation이 없을 경우 : long타입 또는 인코딩된 스트링을 사용하면 됨
                                   (인코딩되지 않은 스트링도 사용가능 할 것같음)

request factory 주의 사항
  - proxy 객체이 사용가능한 type이 정해 져 있음
  - 서버측에서 구현해야하는 필수 메소드를 구현해야함(getId,getVersion등)

2012년 1월 15일 일요일

appengine

Error in meta-data for com.google.gwt.homepage.lovelicense.server.GuestBookAnswerTable.id: Cannot have a java.lang.Long primary key and be a child object (owning field is com.google.gwt.homepage.lovelicense.server.GuestBookTable.answer).

1:n관계등을 표현할 때는 Key or 인코딩된 Key만 사용가능하다.

appengine datastore

an entity : 한 행
kind : 테이블


1:n등의 관계를 사용할려면 키는  Key, or a Key value encoded as a string

2012년 1월 14일 토요일

serializable versions of Text

I currently have some time before starting with my Master thesis project which will bring me back to Android programming. So to make use of that, I started to develop a project I already wanted to implement a couple of years ago, but due to my Master studies I didn't have the time to. I'll need some beta testers soon, so keep track of my blog here to catch the moment when everything goes online.
What I can reveal so far is that it will be a web application, using Google's GWT and it will be hosted on Google's cloud computing platform App Engine.

Today I was finishing the implementation of the basic CRUD operations, using JDO and App Engine's DataNucleus DataStore. Now the app possibly needs to store large strings surely more than 255 characters. You'd think that shouldn't be a problem, but App Engine's DataStore has some implications one should be aware of. Beside these, there are some well defined core value types, under which there is the restriction that you have to use thecom.google.appengine.api.datastore.Text instead of the String datatype if you plan to store more than 255 character strings. Ok, that shouldn't be a problem for us, should it? Well...not exactly. If you plan to use App Engine together with plain old JSP or whatever view technology that it won't be a problem, but if you use GWT you have to keep in mind that you're implementing a client-server system. The difference: the GWT client lives within the browser. So the data has to be transferred between the two end-points and has to be serializable accordingly.com.google.appengine.api.datastore.Text isn't serializable though. This means youcannot share your POJOs between your GWT client app and server-side code. Now you have different possibilities. Some that come to my mind right now are..
  • using DTOs (Data Transfer Objects) which isn't that comfortable 'cause it causes a lot of boilerplate code
  • writing a serializable version of com.google.appengine.api.datastore.Text data class.
Fortunately a guy has already implemented such a serializable version of Text and provides it for free. I just tried it out and it works seamlessly, without writing a single additional line of code. Here some steps on how to use it (available descriptions on the web are really bad).
  1. Download the necessary jar files from http://www.resmarksystems.com/code/:
    appengine-utils-client-1.0.jar
    appengine-utils-server-1.0.jar
  2. Include the appengine-utils-client-1.0.jar in your build path. Copy the appengine-utils-server-1.0.jar to your WEB-INF/lib folder.
  3. On your GWT module file add the following:

    <inherits name="com.resmarksystems.AppEngineDataTypes"/>
    
  4. Restart your GWT app or compile it and everything should work as expected.
Resmarksystem's version doesn't just provide serializable versions of Text but also for Key,ShortBlobBlobLinkUser.
If you get exceptions like
java.lang.ClassCastException: java.lang.String cannot be cast to com.google.appengine.api.datastore.Text
or
An IncompatibleRemoteServiceException was thrown while processing this call. 
then it's probably because you didn't correctly include the jar files as mentioned in step 2 above.

2011년 9월 21일 수요일

enhancer error


SajuDataTable does not seem to have been enhanced.

You may want to rerun the enhancer and check for errors in the output." has no table in the database, but the operation requires it. Please check the specification of the MetaData for this class.

2011년 9월 17일 토요일

appengine jdo + gwt(requestFactory) 오류

  • 오류메시지

Primary key for type Account is of unexpected type java.lang.String
(must be String, Long, or com.google.appengine.api.datastore.Key) 






  • 해결책



Try to add this line to your id:
        @Extension(vendorName="datanucleus", key="gae.encoded-pk",
value="true") 

2011년 4월 5일 화요일

JDO 객체에 null값과 "" 값

JDO 객체에 새로운 필드 추가시 기존데이터는
추가된 필드에 대해 null값을 가진다.
null체크를 해서 처리를 해주어야한다.

JDO 객체에 내용없는 ""을 저장했을 경우 null이 아니라 ""이다.

2011년 4월 2일 토요일