Java documentation은 트랜잭션 중에 쿼리를 수행 할 수 있지만 조상 필터가 포함되어 있지만 수행 방법에 대한 문서가없는 경우에만 쿼리를 수행 할 수 있다고 말합니다. 해. 누구나 가능한 가장 간결한 방법으로이를 수행하는 방법을 보여주는 몇 가지 예제 코드를 제공 할 수 있습니까?Google App Engine (Java)에서 조상 필터가있는 트랜잭션 쿼리
답변
낮은 수준의 데이터 저장소를 사용하는 경우 쉽습니다. "조상 (ancestor)"은 데이터 저장소 개념이며 JDO/JPA 개념 AFAIK가 아니기 때문에 쉽습니다.
는이 방법보십시오 키 조상 걸리는 쿼리 생성자를 보여주는 javadoc에 대한 링크입니다 :
// PersistenceManager pm = ...;
Transaction tx = pm.currentTransaction();
User user = userService.currentUser();
List<Account> accounts = new ArrayList<Account>();
try {
tx.begin();
Query query = pm.newQuery("select from Customer " +
"where user == userParam " +
"parameters User userParam");
List<Customer> customers = (List<Customer>)
query.execute(user);
query = pm.newQuery("select from Account " +
"where parent-pk == keyParam " +
"parameters Key keyParam");
for (Customer customer : customers) {
accounts.addAll((List<Account>)
query.execute(customer.key));
}
} finally {
if (tx.isActive()) {
tx.rollback();
}
}
더 많은 정보를 여기에 있습니다 : 나는 고투 http://code.google.com/appengine/docs/java/datastore/transactions.html#Uses_For_Transactions
이것은 잠시 동안이지만, 다음은 작동합니다! 짧은 대답은 App Engine에 사용 된 JDO가 Ancestor Queries를 확실히 지원할 수 있으므로 App Engine 고유의 저수준 API에 의존 할 필요가 없다는 것입니다. 특히 애플리케이션 전반에 걸쳐 JDO를 사용하려는 경우에 특히 그렇습니다.
1 단계 :
자식 클래스에서 다음과 같은 인스턴스 변수를 가지고 있는지 확인하십시오. 변수의 실제 이름은 중요하지 않습니다. 중요한 것은 주석입니다.
@Persistent
@Extension(vendorName="datanucleus", key="gae.parent-pk", value="true")
private String mParentEncKey;
2 단계 :
상위 키에 의해 자식 객체 (들)를 쿼리, 당신은 당신이 만든 인스턴스 변수의 이름을 통해 parentKey에 필터링 ...이 원하는 case이 예제는 부모 키와 해당 속성을 알고있는 경우 속성이있는 하위 객체 집합을 쿼리하려는 경우에 사용됩니다.
public static List<ChildObject> queryYourChildObjects(String parentKey, String someProperty) {
PersistenceManager pm = PMF.get().getPersistenceManager();
Query q = pm.newQuery(ChildObject.class);
q.setFilter("mParentEncKey == parentKeyParam && property == propertyParam");
q.declareParameters("String parentKeyParam, String propertyParam");
List<ChildObject> results = (List<ChildObject>) q.execute(parentKey, someProperty);
return results;
}
그게 전부 야! 잘하면 도움이됩니다.
또한이 관련 답변에서와 같이 Objectify를 사용할 수 있습니다. http://stackoverflow.com/a/11365390/305689 – wescpy
- 1. Google App Engine : GeoPtProperty 쿼리
- 2. Silverlight의 Google App Engine
- 3. Google App Engine MemcacheException
- 4. Google App Engine Memcache
- 5. Google App Engine 인증
- 6. Google App Engine 데이터베이스
- 7. Google App Engine 인증
- 8. Google App Engine Appstats
- 9. Google App Engine : DeadlineExceededError
- 10. Google App Engine
- 11. Google App Engine : get_or_create()?
- 12. Google App Engine 문제
- 13. Google App Engine - Deadlocking?
- 14. Google App Engine 프록시
- 15. Google App Engine - JDODetachedFieldAccessException
- 16. Google App Engine 데이터베이스 인덱스
- 17. Google App Engine - 작업 대기열 이름 및 트랜잭션
- 18. Google App Engine : 두 번째 트랜잭션 전에 개체를 "닫는 방법"?
- 19. Google App Engine/Java의 기본 문서
- 20. iPhone App with Google App Engine
- 21. Google App Engine에서의 JDO 트랜잭션
- 22. Google App Engine/Java에서 와일드 카드 검색 구현
- 23. Google App Engine 작업 대기열
- 24. Google App Engine 프로젝트 계층
- 25. template.render() Google App Engine (python)
- 26. Google App Engine 대량 다운로드
- 27. Google App Engine 업로드 자동화하기
- 28. Google App Engine - 속도가 빠름
- 29. Google App Engine self.redirect 게시물
- 30. Google App Engine Geo Query
아무 데나 트랜잭션을 커밋하지 않았습니다. – Price