0
appengine
java night #2
  Low-Level API ~   ~

 shin1ogawa@
...shin1ogawa
Google, Java, AppEngine, Eclipse,
Wicket, Maven, Hudson,        ...
•               OSS

    •   [SF.jp]Jiem...
Low-Level API
  #1
) Key
• Key          EntityGroup
    • Entity          EntityGroup      …


• Key
    • ApplicationID
    • Entity Key,   ...
) KeyFactory

•         createKey()         Key


• keyToString()         Key


• stringToKey()
          Key
) Entity
• setProperty(“           ”, Object          )
• Object getProperty(“            ”)
• boolean hasProperty(“      ...
) DatastoreService
•
    • Key put(Entity)
    • List<Key> put(Iterable<Entity>)
•
    • void delete(Key... keys)
    • vo...
) DatastoreService
•
    • Entity get(Key key)
     •           Key
         EntityNotFoundException

    • Map<Key, Entit...
) DatastoreService
• Transaction    ,
  • beginTransaction()
  • getCurrentTransaction()
  • ...
 • Transaction
  • commit...
) DatastoreService
• 1.2.5        Key
 Entity                   Key
           1.2.5
     Key
  • KeyRange allocalteIds(
 ...
Datastore Service
                 (Entity           )
KeyRange parentKeys =
  service.allocateIds("Parent", 1);
Key paren...
Datastore Service
                (      )

Transaction tx = service.beginTransaction();
try {
  List<Entity> entities =
 ...
Low-Level API
      #2
Datastore Service
Query
• new Query(String kind)
  • JDO
• new Query(String kind, Key ancestorKey)
  •       Kind


• new ...
Datastore Service
Query
•
    • Query addFilter(String propertyName,
        FilterOperator operator, Object value)
•
    ...
Datastore Service
PreparedQuery
• DatastoreService#prepare()       Query
                  PreaparedQuery
•
    • int coun...
Datastore Service
PreparedQuery
•
    • List<Entity> asList(FetchOptions)
      •
    • Iterator<Entity> asIterator([Fetch...
Datastore Service
Query
Query query = new Query(“Entity”);
query.addFilter(“name”,
  FilterOperator.GREATER_THAN_OR_EQUAL,...
Datastore Service
Query              : EntityGroup
Iterator<Entity> entityGroup =
  service.prepare(new Query(rootKey)
   ...
Datastore Service
          JDO
JDO

class MyEntity {
  List<Child> children1;
  List<Child> children2;
}
myEntity.getChil...
Datastore Service
            JDO
MyEntity myEntity =
  manager.getObjectById(MyEntity.class, key);
List<Child> children1 ...
Datastore Service
       JDO

MyEntiy(1)                    Child
                      (A-D)
MyEntiy(1)/Child(A)

MyEntiy...
shin1ogawa@
Upcoming SlideShare
Loading in...5
×

Appengine Java Night #2a

2,307

Published on

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,307
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
42
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Transcript of "Appengine Java Night #2a"

  1. 1. appengine java night #2 Low-Level API ~ ~ shin1ogawa@
  2. 2. ...shin1ogawa Google, Java, AppEngine, Eclipse, Wicket, Maven, Hudson, ... • OSS • [SF.jp]Jiemamy... • [SF.jp]gae-j-samples...GAE/J GAE/J/Maven • [SF.jp]gaejtools...GAE/J • [SF.jp]asclipse...Amateras AIR GEAR AS3 • java-ja, wicket-ja, (http://www.topgate.co.jp) GoogleAppEngine GoogleApps
  3. 3. Low-Level API #1
  4. 4. ) Key • Key EntityGroup • Entity EntityGroup … • Key • ApplicationID • Entity Key, Kind • name or long •
  5. 5. ) KeyFactory • createKey() Key • keyToString() Key • stringToKey() Key
  6. 6. ) Entity • setProperty(“ ”, Object ) • Object getProperty(“ ”) • boolean hasProperty(“ ”) • <missing> • • HashSet Collection ArrayList • int Long…
  7. 7. ) DatastoreService • • Key put(Entity) • List<Key> put(Iterable<Entity>) • • void delete(Key... keys) • void delete(Iterable<Key>) • Transaction
  8. 8. ) DatastoreService • • Entity get(Key key) • Key EntityNotFoundException • Map<Key, Entity> get( Iterable<Key> key) • Key Map
  9. 9. ) DatastoreService • Transaction , • beginTransaction() • getCurrentTransaction() • ... • Transaction • commit() • rollback() • isActive()
  10. 10. ) DatastoreService • 1.2.5 Key Entity Key 1.2.5 Key • KeyRange allocalteIds( [ Key], Kind, ) • KeyRange • getStart(), getEnd(), iterator()
  11. 11. Datastore Service (Entity ) KeyRange parentKeys = service.allocateIds("Parent", 1); Key parentKey = parentKeys.getStart(); KeyRange childKeys = service.allocateIds(parentKey, "Child", 2); Iterator<Key> childKeysIterator = childKeys.iterator(); Entity parent = new Entity(parentKey); Entity child1 = new Entity(childKeys.next()); Entity child2 = new Entity(childKeys.next());
  12. 12. Datastore Service ( ) Transaction tx = service.beginTransaction(); try { List<Entity> entities = Arrays.asList(parent, child1, child2 service.put(tx, entities); tx.commit(); } finally { if (tx.isActive()) { tx.rollback(); } }
  13. 13. Low-Level API #2
  14. 14. Datastore Service Query • new Query(String kind) • JDO • new Query(String kind, Key ancestorKey) • Kind • new Query(Key ancestorKey) • Kind •
  15. 15. Datastore Service Query • • Query addFilter(String propertyName, FilterOperator operator, Object value) • • Query addSort(String propertyName, SortDirection direction) • • Query setKeysOnly() • Key Entity.KEY_RESERVED_PROPERTY
  16. 16. Datastore Service PreparedQuery • DatastoreService#prepare() Query PreaparedQuery • • int countEntities() • • Entity asSingleResult() • null • Entity TooManyResultsException
  17. 17. Datastore Service PreparedQuery • • List<Entity> asList(FetchOptions) • • Iterator<Entity> asIterator([FetchOptions]) • • Iterable<Entity> asIterable([FetchOptions]) • iterator() Datastore asIterator() • FetchOptions • offset, limit
  18. 18. Datastore Service Query Query query = new Query(“Entity”); query.addFilter(“name”, FilterOperator.GREATER_THAN_OR_EQUAL, “hoge”) .addSort("name", SortDirection.ASCENDING) .addSort("__key__", SortDirection.ASCENDING); DatastoreService service = DatastoreServiceFactory.getDatastoreService(); List<Entity> entities = service.prepare(query).asList( FetchOptions.Builder.withOffset(0).limit(100));
  19. 19. Datastore Service Query : EntityGroup Iterator<Entity> entityGroup = service.prepare(new Query(rootKey) .addSort(“__key__”)).asIterator( FetchOptions.Builder.withOffset(0).limit(100)); Parent parent = null; while (entityGroup.hasNext) { Entity entity = entityGroup.next(); if (entity.getKind().equals(“Parent”)) parent = EntityUtil.toBean(entity,Parent.class); else if (entity.getKind().equals(“Child”)) parent.getChidren().add( EntityUtil.toBean(entity, Child.class); ...
  20. 20. Datastore Service JDO JDO class MyEntity { List<Child> children1; List<Child> children2; } myEntity.getChildren1().addAll(childA, childB); myEntity.getChildren2().addAll(childC, childD); manager.makePersistent(myEntity); List
  21. 21. Datastore Service JDO MyEntity myEntity = manager.getObjectById(MyEntity.class, key); List<Child> children1 = myEntity.getChildren1(); List<Child> children2 = myEntity.getChildren2(); children1 childA childB childC childD children2 null
  22. 22. Datastore Service JDO MyEntiy(1) Child (A-D) MyEntiy(1)/Child(A) MyEntiy(1)/Child(B) MyEntiy(1)/Child(C) MyEntiy(1)/Child(D)
  23. 23. shin1ogawa@
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×