SlideShare ist ein Scribd-Unternehmen logo
1 von 60
Downloaden Sie, um offline zu lesen
appengine
java night #1
               Low-Level API
  # Low-Level API

 shin1ogawa@
...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
1.Low-Level API
 1.1.
 1.2.
 1.3.DatastoreService
2.
 2.1.AppEngine
3.
Low-Level API
High-Level API(         )
               )




       API(    )>>>>>       (   )
                        API




   Datastore
Low-Level API

AppEngine
                  2
                             JDO/JPA
                                       Low-
Level API




 Low-Level API(       API)
Low-Level API


AppEngine


                      Low-Level API




Framework


            ※   LowLevelAPI           …
High           Low        (         )

   JDO           API


  shin1ogawa           Low-Level API
                              API
High                Low            (       )
•
•




•            ApiProxy#Delegate    makeSyncCall()
                  Low-Level API
• Low-Level API

Low-Level API
Low-Level API

Low-Level API               API                      …


                                       Javadoc


    API
                        …


           shin1ogawa
 https://sites.google.com/a/topgate.co.jp/systemsolution/Home/
             googleappengine/datastore-lowlevelapi
Low-Level API
Low-Level API
1.                XXXService#hogeMethod()


2.XXXService         ApiProxy#getDelegate()
 Delegate
3.XXXService
 ProtocolBuffer                (byte[]
      )             Delgate#makeSyncCall(
     String serviceName, String methodName,
     byte[] request)
Low-Level API
4.Delegate        serviceName,
 methodName


5.                 (ProtocolBuffer
              )   byte[] request


6.
        (?)
Low-Level API
7.                           ProtocolBuffer
                        byte[] response
     Delegate
8.Delegate            byte[] response
 ProtocolBuffer
 XXXService
9.XXXService      ProtocolBuffer
 Java
Low-Level API

1.DatastoreService#put(Entity entity)
 1.        entity
  DatastorePb.PutRequest requestPb
 2.byte[] ApiProxy#getDelegate(
     “datastore_v3”, “PUT”,
     requestPb.toByteArray())
 3.      byte
  DatastorePb.PutResponse responsePb
 4.responsePb.getKey(0)
Low-Level API
DatastoreService
Datastore Service

• Key, KeyFactory
• Entity
• DatastoreService
 • Transaction
• Query
 • FilterOperator/SortDirection
• PreparedQuery
 • FetchOptions
Datastore Service
Key
               Key       ApplicationID, Kind,
Entity      Key(ancestorKey        )
            RootEntity   Key    Entity   Key

      Key         EntityGroup
Key              Owned         Unonwed
 EntityGroup

      Key         EntityGroup
Datastore Service
Key

 Parent(1)       prop1      prop2      children




                                       }
      Child(1)      prop1      prop2

      Child(2)      prop1      prop2

      Child(3)      prop1      prop2
Datastore Service
Key

 Parent(1)       prop1      prop2      children




                                       }
      Child(1)      prop1      prop2

      Child(2)      prop1      prop2

      Child(3)      prop1      prop2
Datastore Service
Key

 Parent(1)             prop1   prop2

 Parent(1)/Child(1)    prop1   prop2

 Parent(1)/Child(2)    prop1   prop2

 Parent(1)/Child(3)    prop1   prop2


  Key        EntityGroup
Datastore Service
Key

 Parent(1)              prop1   prop2

 Parent(1)/Parent(2)    prop3   prop4

 Parent(1)/Parent(3)    prop1   prop3

 Parent(1)/Parent(4)    prop2   prop4


      Kind    EntityGroup
Datastore Service
Key, KeyFactory
• Key#getKind()    Kind
• Key#getParent()      Entity   Key
•
    • JDO    ”encoded-pkey”
    • KeyFactory#keyToString(Key)     Key


    • KeyFactory#stringToKey(String)
Datastore Service
Key, KeyFactory
• KeyFactory#createKey(String kind, Stirng name)


 • Key#getName()              String name


 • 1.2.5             name
• Key
 • 1.2.5                              Key
 • Key#getId()              Long id
 • id      Kind
Datastore Service
Entity
•
• JDO/JPA         Pojo
• Entity#getKey()
• getKey()
    • Key Entity#getParent()
    • String Entity#getKind()
Datastore Service
Entity
•            Map              =
    • setProperty(String          , Obejct   )
    • setUnindexedProperty(         ,   )
     • setUnindexedProperty(“p”, String|
       Long|...)
            index

JDO                Entity
                              "
Datastore Service
Entity
• getProperty(String         )
    • Object                 "      cast
    •


•
    • Integer       "       Long       /
    • Set       "       ArrayList          /
Datastore Service
Entity
• hasProperty(String              )
    •
    •                null   (viewer   ”<null>”)
      • getProperty() " null
      • hasProperty() " true
    •             (viewer    ”<missing>”)
        • getProperty() " null
        • hasProperty() " false
•
Datastore Service
Entity
•
    • new Entity(kind   )
    • new Entity(kind   ,   Key)
    • new Entity(kind   , key      name   )
    • new Entity(kind   , key      name   ,   Key)
    • new Entity(Key primaryKey) ... 1.2.5
•
    • KEY_RESERVED_PROPERTY ... “__key__”
      • PrimaryKey
Datastore Service
DatastoreService
•                       Factory
 • DatastoreServiceFactory#getDatastoreService()
• Key     Entity
     • Entity get([Transaction tx,] Key key)
     • Map<Key, Entity> get(
         [Transaction tx,] Iterable<Key> key)
       •         Key
          EntityNotFoundException
• Query        Entity
    • "   (Query           )
Datastore Service
DatastoreService
• Entity
 • Key put([Transaction tx,] Entity entity)
 • List<Key> put(
     [Transaction tx], Iterable<Entity> entity)
   •                        Kind        …
             Entity             …        k
• Entity
 • delete([Transaction tx,] Key... keys)
 • delete([Transaction tx,] Iterable<Key> keys)
   • Key
Datastore Service
DatastoreService
•            Key                   ...1.2.5
   • KeyRange allocateIds(
       [Key parentKey,] String kind, long num)
   • KeyRange
     • Key getStart()
     • Key getEnd()
     • Iterator<Key> iterator()
• Transaction
 • Transaction beginTransaction()
 • Transcation getCurrentTransaction()
 •
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());
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(); }
}
Datastore Service
Query
• new Query(String kind)
  • JDO
• new Query(String kind, Key ancestorKey)
  •       Kind


• new Query(Key ancestorKey)
  •                                         Kind


   •
Datastore Service
Query
•
    • Query addFilter(String propertyName,
        FilterOperator operator, Object value)
•
    • Query addSort(String propertyName,
        SortDirection direction)
•
    • Query setKeysOnly()
      • Key

                      Entity.KEY_RESERVED_PROPERTY
Datastore Service
PreparedQuery
• DatastoreService#prepare()       Query
                  PreaparedQuery
•
    • int countEntities()
•
    • Entity asSingleResult()
      •                            null
     •       Entity
         TooManyResultsException
Datastore Service
PreparedQuery
•
    • List<Entity> asList(FetchOptions)
      •
    • Iterator<Entity> asIterator([FetchOptions])
      •
    • Iterable<Entity> asIterable([FetchOptions])
      • iterator()             Datastore
                     asIterator()
• FetchOptions
  •                          offset, limit
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));
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);
 ...
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
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
Datastore Service
       JDO

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

MyEntiy(1)/Child(B)

MyEntiy(1)/Child(C)

MyEntiy(1)/Child(D)
AppEngine
                          AppEngine

        ApiProxy#getDelegate()
            Delegate
      Web          Delegate
        Web

               ApiProxy
       #getCurrentEnvironment()
            Environment
(ApplicationID, versionID      )
AppEngine
JUnit    SDK    Web
                       ApiProy


• Environment
 ApiProxy#setEnvironmentForCurrentThread()


• Delegate               ApiProxyLocalImpl
               ApiProxy#setDelegate()
Environment
•
    •          SingleThread


        •


    • ApplicationID, versionID,
ApiProxyLocalImpl(Delegate                    )
• Delegate


    Delegate
•


    •                     WEB-INF/queue.xml
        datastore-indexes.xml
Delegate
• ApiProxyLocalImpl


      Delegate
 •         …ApiProxyLocalImpl


 • ApiProxy#getDelegate()       ApiProxy
                                  Delegate
         ApiProxy
                        AOP
Delegate
class MyDelegate implements Delegate {
  Delegate original = ApiProxy.getDelegate();
  public byte[] makeSyncCall(
    Environment environment,
    String service, String method,
    byte[] request) throws ApiProxyException {
    System.out.println(service+”:”+method);
    return original.makeSyncCall(
       environment, service, method, requst);
  }
}
1
1
makeSyncCall()

byte[] Delegate#makeSyncCall(
    Environment environment,
    String service,
    String method,
    byte[] request)
    throws ApiProxyException
2
makeSyncCall()

byte[] Delegate#makeSyncCall(
    Environment environment,
    String service,
    String method,
    byte[] request)
    throws ApiProxyException
2
makeSyncCall()
•            datastore_v3#GET
    •        : DatastorePb.GetRequest
        • new GetRequest().mergeFrom(byte[])
        • GetRequest#keyIterator()       Key
         Iterator
    •        : DatastorePb.GetResponse
        • new GetResponse().mergeFrom(byte[])
        • GetResponse#entityIterator()
         Entity   Iterator
2
makeSyncCall()
•                               Delegate
         …
    • datastore_v3#GET
     • memcache#GET                 datastore
                 mamcache#GET
    • datastore_v3#PUT/DELETE
     • memcache#DELETE          datastore
2
2
com.google.apphosting.utils.remot
eapi.RemoteApiServlet
• Google            admin
• HttpServlet            GET    POST
 • GET
           yaml
 •         API                 POST
     • POST       Http           “X-appcfg-api-
      version”
2
com.google.apphosting.utils.remot
eapi.RemoteApiPb

• RemoteApiServlet      API   POST
      ProtocolBuffer
 • Request
 • TransactionRequest
 • Response
 • ApplicationError
2
                    ...!!!

•               Datastore
    RemoteApiDelegate       RemoteApiServlet


• Eclipse Plug-in


•         CUI                   Memcache   stats
shin1ogawa@

Weitere ähnliche Inhalte

Was ist angesagt?

AIWolfPy v0.4.9
AIWolfPy v0.4.9AIWolfPy v0.4.9
AIWolfPy v0.4.9Harada Kei
 
jQuery Rescue Adventure
jQuery Rescue AdventurejQuery Rescue Adventure
jQuery Rescue AdventureAllegient
 
Tutorial, Part 3: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
Tutorial, Part 3: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...Tutorial, Part 3: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
Tutorial, Part 3: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...SPTechCon
 
MySQLConf2009: Taking ActiveRecord to the Next Level
MySQLConf2009: Taking ActiveRecord to the Next LevelMySQLConf2009: Taking ActiveRecord to the Next Level
MySQLConf2009: Taking ActiveRecord to the Next LevelBlythe Dunham
 
Scala ActiveRecord
Scala ActiveRecordScala ActiveRecord
Scala ActiveRecordscalaconfjp
 
An introduction into Spring Data
An introduction into Spring DataAn introduction into Spring Data
An introduction into Spring DataOliver Gierke
 
The journey of an (un)orthodox optimization
The journey of an (un)orthodox optimizationThe journey of an (un)orthodox optimization
The journey of an (un)orthodox optimizationSian Lerk Lau
 
Restful App Engine
Restful App EngineRestful App Engine
Restful App EngineRyan Morlok
 
Building High Performance and Reliable Windows Phone 8 Apps
Building High Performance and Reliable Windows Phone 8 AppsBuilding High Performance and Reliable Windows Phone 8 Apps
Building High Performance and Reliable Windows Phone 8 AppsMichele Capra
 
ERRest - Designing a good REST service
ERRest - Designing a good REST serviceERRest - Designing a good REST service
ERRest - Designing a good REST serviceWO Community
 
Let's talk about NoSQL Standard
Let's talk about NoSQL StandardLet's talk about NoSQL Standard
Let's talk about NoSQL StandardOtavio Santana
 
.NET Database Toolkit
.NET Database Toolkit.NET Database Toolkit
.NET Database Toolkitwlscaudill
 
Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...Thinqloud
 

Was ist angesagt? (20)

AIWolfPy v0.4.9
AIWolfPy v0.4.9AIWolfPy v0.4.9
AIWolfPy v0.4.9
 
Spring data requery
Spring data requerySpring data requery
Spring data requery
 
jQuery Rescue Adventure
jQuery Rescue AdventurejQuery Rescue Adventure
jQuery Rescue Adventure
 
Tutorial, Part 3: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
Tutorial, Part 3: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...Tutorial, Part 3: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
Tutorial, Part 3: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
 
MySQLConf2009: Taking ActiveRecord to the Next Level
MySQLConf2009: Taking ActiveRecord to the Next LevelMySQLConf2009: Taking ActiveRecord to the Next Level
MySQLConf2009: Taking ActiveRecord to the Next Level
 
Scala ActiveRecord
Scala ActiveRecordScala ActiveRecord
Scala ActiveRecord
 
An introduction into Spring Data
An introduction into Spring DataAn introduction into Spring Data
An introduction into Spring Data
 
The journey of an (un)orthodox optimization
The journey of an (un)orthodox optimizationThe journey of an (un)orthodox optimization
The journey of an (un)orthodox optimization
 
ERRest
ERRestERRest
ERRest
 
Restful App Engine
Restful App EngineRestful App Engine
Restful App Engine
 
Building High Performance and Reliable Windows Phone 8 Apps
Building High Performance and Reliable Windows Phone 8 AppsBuilding High Performance and Reliable Windows Phone 8 Apps
Building High Performance and Reliable Windows Phone 8 Apps
 
Scala in practice
Scala in practiceScala in practice
Scala in practice
 
ERRest in Depth
ERRest in DepthERRest in Depth
ERRest in Depth
 
Php forum2015 tomas_final
Php forum2015 tomas_finalPhp forum2015 tomas_final
Php forum2015 tomas_final
 
ERRest - Designing a good REST service
ERRest - Designing a good REST serviceERRest - Designing a good REST service
ERRest - Designing a good REST service
 
Green dao
Green daoGreen dao
Green dao
 
Architecure components by Paulina Szklarska
Architecure components by Paulina SzklarskaArchitecure components by Paulina Szklarska
Architecure components by Paulina Szklarska
 
Let's talk about NoSQL Standard
Let's talk about NoSQL StandardLet's talk about NoSQL Standard
Let's talk about NoSQL Standard
 
.NET Database Toolkit
.NET Database Toolkit.NET Database Toolkit
.NET Database Toolkit
 
Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...
 

Ähnlich wie appengine java night #1

PHP security audits
PHP security auditsPHP security audits
PHP security auditsDamien Seguy
 
Painless Persistence in a Disconnected World
Painless Persistence in a Disconnected WorldPainless Persistence in a Disconnected World
Painless Persistence in a Disconnected WorldChristian Melchior
 
初心者向けGAE/Java説明資料
初心者向けGAE/Java説明資料初心者向けGAE/Java説明資料
初心者向けGAE/Java説明資料Shinichi Ogawa
 
Data Access Options in SharePoint 2010
Data Access Options in SharePoint 2010Data Access Options in SharePoint 2010
Data Access Options in SharePoint 2010Rob Windsor
 
Introducing CakeEntity
Introducing CakeEntityIntroducing CakeEntity
Introducing CakeEntityBasuke Suzuki
 
RIAs Done Right: Grails, Flex, and EXT GWT
RIAs Done Right: Grails, Flex, and EXT GWTRIAs Done Right: Grails, Flex, and EXT GWT
RIAs Done Right: Grails, Flex, and EXT GWTMichael Galpin
 
Cross platform Mobile development on Titanium
Cross platform Mobile development on TitaniumCross platform Mobile development on Titanium
Cross platform Mobile development on TitaniumYiguang Hu
 
Phoenix + Reactで 社内システムを 密かに作ってる
Phoenix + Reactで 社内システムを 密かに作ってるPhoenix + Reactで 社内システムを 密かに作ってる
Phoenix + Reactで 社内システムを 密かに作ってるTakahiro Kobaru
 
Take Data Validation Seriously - Paul Milham, WildWorks
Take Data Validation Seriously - Paul Milham, WildWorksTake Data Validation Seriously - Paul Milham, WildWorks
Take Data Validation Seriously - Paul Milham, WildWorksNodejsFoundation
 
How to write easy-to-test JavaScript
How to write easy-to-test JavaScriptHow to write easy-to-test JavaScript
How to write easy-to-test JavaScriptYnon Perek
 
Spring Data for KSDG 2012/09
Spring Data for KSDG 2012/09Spring Data for KSDG 2012/09
Spring Data for KSDG 2012/09永昇 陳
 
Javascript Everywhere
Javascript EverywhereJavascript Everywhere
Javascript EverywherePascal Rettig
 
Solr's Search Relevancy (Understand Solr's query debug)
Solr's Search Relevancy (Understand Solr's query debug)Solr's Search Relevancy (Understand Solr's query debug)
Solr's Search Relevancy (Understand Solr's query debug)Wongnai
 
Java EE 7, what's in it for me?
Java EE 7, what's in it for me?Java EE 7, what's in it for me?
Java EE 7, what's in it for me?Alex Soto
 

Ähnlich wie appengine java night #1 (20)

Gaej For Beginners
Gaej For BeginnersGaej For Beginners
Gaej For Beginners
 
PHP security audits
PHP security auditsPHP security audits
PHP security audits
 
Painless Persistence in a Disconnected World
Painless Persistence in a Disconnected WorldPainless Persistence in a Disconnected World
Painless Persistence in a Disconnected World
 
初心者向けGAE/Java説明資料
初心者向けGAE/Java説明資料初心者向けGAE/Java説明資料
初心者向けGAE/Java説明資料
 
Data Access Options in SharePoint 2010
Data Access Options in SharePoint 2010Data Access Options in SharePoint 2010
Data Access Options in SharePoint 2010
 
Real World MVC
Real World MVCReal World MVC
Real World MVC
 
Introducing CakeEntity
Introducing CakeEntityIntroducing CakeEntity
Introducing CakeEntity
 
Requery overview
Requery overviewRequery overview
Requery overview
 
RIAs Done Right: Grails, Flex, and EXT GWT
RIAs Done Right: Grails, Flex, and EXT GWTRIAs Done Right: Grails, Flex, and EXT GWT
RIAs Done Right: Grails, Flex, and EXT GWT
 
Cross platform Mobile development on Titanium
Cross platform Mobile development on TitaniumCross platform Mobile development on Titanium
Cross platform Mobile development on Titanium
 
Phoenix + Reactで 社内システムを 密かに作ってる
Phoenix + Reactで 社内システムを 密かに作ってるPhoenix + Reactで 社内システムを 密かに作ってる
Phoenix + Reactで 社内システムを 密かに作ってる
 
Take Data Validation Seriously - Paul Milham, WildWorks
Take Data Validation Seriously - Paul Milham, WildWorksTake Data Validation Seriously - Paul Milham, WildWorks
Take Data Validation Seriously - Paul Milham, WildWorks
 
How to write easy-to-test JavaScript
How to write easy-to-test JavaScriptHow to write easy-to-test JavaScript
How to write easy-to-test JavaScript
 
#ajn3.lt.marblejenka
#ajn3.lt.marblejenka#ajn3.lt.marblejenka
#ajn3.lt.marblejenka
 
Jquery
JqueryJquery
Jquery
 
Solr @ Etsy - Apache Lucene Eurocon
Solr @ Etsy - Apache Lucene EuroconSolr @ Etsy - Apache Lucene Eurocon
Solr @ Etsy - Apache Lucene Eurocon
 
Spring Data for KSDG 2012/09
Spring Data for KSDG 2012/09Spring Data for KSDG 2012/09
Spring Data for KSDG 2012/09
 
Javascript Everywhere
Javascript EverywhereJavascript Everywhere
Javascript Everywhere
 
Solr's Search Relevancy (Understand Solr's query debug)
Solr's Search Relevancy (Understand Solr's query debug)Solr's Search Relevancy (Understand Solr's query debug)
Solr's Search Relevancy (Understand Solr's query debug)
 
Java EE 7, what's in it for me?
Java EE 7, what's in it for me?Java EE 7, what's in it for me?
Java EE 7, what's in it for me?
 

Mehr von Shinichi Ogawa

2011 12-07 ragtech2011
2011 12-07 ragtech20112011 12-07 ragtech2011
2011 12-07 ragtech2011Shinichi Ogawa
 
Appengine ja-night#13bt
Appengine ja-night#13btAppengine ja-night#13bt
Appengine ja-night#13btShinichi Ogawa
 
Devlove hangar flight-wintersortie-shin1ogawa
Devlove hangar flight-wintersortie-shin1ogawaDevlove hangar flight-wintersortie-shin1ogawa
Devlove hangar flight-wintersortie-shin1ogawaShinichi Ogawa
 
Appengine ja-night-sapporo#1 bt
Appengine ja-night-sapporo#1 btAppengine ja-night-sapporo#1 bt
Appengine ja-night-sapporo#1 btShinichi Ogawa
 
Appengine ja-night-sapporo#1
Appengine ja-night-sapporo#1Appengine ja-night-sapporo#1
Appengine ja-night-sapporo#1Shinichi Ogawa
 
Java cloud-meeting-2010tokyo-shin1ogawa
Java cloud-meeting-2010tokyo-shin1ogawaJava cloud-meeting-2010tokyo-shin1ogawa
Java cloud-meeting-2010tokyo-shin1ogawaShinichi Ogawa
 
Java Cloud Meeting Fukuoka 2010
Java Cloud Meeting Fukuoka 2010Java Cloud Meeting Fukuoka 2010
Java Cloud Meeting Fukuoka 2010Shinichi Ogawa
 
Appengine Java Night #2 LT
Appengine Java Night #2 LTAppengine Java Night #2 LT
Appengine Java Night #2 LTShinichi Ogawa
 
Appengine Java Night #2 Lt
Appengine Java Night #2 LtAppengine Java Night #2 Lt
Appengine Java Night #2 LtShinichi Ogawa
 

Mehr von Shinichi Ogawa (9)

2011 12-07 ragtech2011
2011 12-07 ragtech20112011 12-07 ragtech2011
2011 12-07 ragtech2011
 
Appengine ja-night#13bt
Appengine ja-night#13btAppengine ja-night#13bt
Appengine ja-night#13bt
 
Devlove hangar flight-wintersortie-shin1ogawa
Devlove hangar flight-wintersortie-shin1ogawaDevlove hangar flight-wintersortie-shin1ogawa
Devlove hangar flight-wintersortie-shin1ogawa
 
Appengine ja-night-sapporo#1 bt
Appengine ja-night-sapporo#1 btAppengine ja-night-sapporo#1 bt
Appengine ja-night-sapporo#1 bt
 
Appengine ja-night-sapporo#1
Appengine ja-night-sapporo#1Appengine ja-night-sapporo#1
Appengine ja-night-sapporo#1
 
Java cloud-meeting-2010tokyo-shin1ogawa
Java cloud-meeting-2010tokyo-shin1ogawaJava cloud-meeting-2010tokyo-shin1ogawa
Java cloud-meeting-2010tokyo-shin1ogawa
 
Java Cloud Meeting Fukuoka 2010
Java Cloud Meeting Fukuoka 2010Java Cloud Meeting Fukuoka 2010
Java Cloud Meeting Fukuoka 2010
 
Appengine Java Night #2 LT
Appengine Java Night #2 LTAppengine Java Night #2 LT
Appengine Java Night #2 LT
 
Appengine Java Night #2 Lt
Appengine Java Night #2 LtAppengine Java Night #2 Lt
Appengine Java Night #2 Lt
 

appengine java night #1

  • 1. appengine java night #1 Low-Level API # Low-Level API shin1ogawa@
  • 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. 1.Low-Level API 1.1. 1.2. 1.3.DatastoreService 2. 2.1.AppEngine 3.
  • 5. High-Level API( ) ) API( )>>>>> ( ) API Datastore
  • 6. Low-Level API AppEngine 2 JDO/JPA Low- Level API Low-Level API( API)
  • 7. Low-Level API AppEngine Low-Level API Framework ※ LowLevelAPI …
  • 8. High Low ( ) JDO API shin1ogawa Low-Level API API
  • 9. High Low ( ) • • • ApiProxy#Delegate makeSyncCall() Low-Level API • Low-Level API Low-Level API
  • 10. Low-Level API Low-Level API API … Javadoc API … shin1ogawa https://sites.google.com/a/topgate.co.jp/systemsolution/Home/ googleappengine/datastore-lowlevelapi
  • 12. Low-Level API 1. XXXService#hogeMethod() 2.XXXService ApiProxy#getDelegate() Delegate 3.XXXService ProtocolBuffer (byte[] ) Delgate#makeSyncCall( String serviceName, String methodName, byte[] request)
  • 13. Low-Level API 4.Delegate serviceName, methodName 5. (ProtocolBuffer ) byte[] request 6. (?)
  • 14. Low-Level API 7. ProtocolBuffer byte[] response Delegate 8.Delegate byte[] response ProtocolBuffer XXXService 9.XXXService ProtocolBuffer Java
  • 15. Low-Level API 1.DatastoreService#put(Entity entity) 1. entity DatastorePb.PutRequest requestPb 2.byte[] ApiProxy#getDelegate( “datastore_v3”, “PUT”, requestPb.toByteArray()) 3. byte DatastorePb.PutResponse responsePb 4.responsePb.getKey(0)
  • 17. Datastore Service • Key, KeyFactory • Entity • DatastoreService • Transaction • Query • FilterOperator/SortDirection • PreparedQuery • FetchOptions
  • 18. Datastore Service Key Key ApplicationID, Kind, Entity Key(ancestorKey ) RootEntity Key Entity Key Key EntityGroup Key Owned Unonwed EntityGroup Key EntityGroup
  • 19. Datastore Service Key Parent(1) prop1 prop2 children } Child(1) prop1 prop2 Child(2) prop1 prop2 Child(3) prop1 prop2
  • 20. Datastore Service Key Parent(1) prop1 prop2 children } Child(1) prop1 prop2 Child(2) prop1 prop2 Child(3) prop1 prop2
  • 21. Datastore Service Key Parent(1) prop1 prop2 Parent(1)/Child(1) prop1 prop2 Parent(1)/Child(2) prop1 prop2 Parent(1)/Child(3) prop1 prop2 Key EntityGroup
  • 22. Datastore Service Key Parent(1) prop1 prop2 Parent(1)/Parent(2) prop3 prop4 Parent(1)/Parent(3) prop1 prop3 Parent(1)/Parent(4) prop2 prop4 Kind EntityGroup
  • 23. Datastore Service Key, KeyFactory • Key#getKind() Kind • Key#getParent() Entity Key • • JDO ”encoded-pkey” • KeyFactory#keyToString(Key) Key • KeyFactory#stringToKey(String)
  • 24. Datastore Service Key, KeyFactory • KeyFactory#createKey(String kind, Stirng name) • Key#getName() String name • 1.2.5 name • Key • 1.2.5 Key • Key#getId() Long id • id Kind
  • 25. Datastore Service Entity • • JDO/JPA Pojo • Entity#getKey() • getKey() • Key Entity#getParent() • String Entity#getKind()
  • 26. Datastore Service Entity • Map = • setProperty(String , Obejct ) • setUnindexedProperty( , ) • setUnindexedProperty(“p”, String| Long|...) index JDO Entity "
  • 27. Datastore Service Entity • getProperty(String ) • Object " cast • • • Integer " Long / • Set " ArrayList /
  • 28. Datastore Service Entity • hasProperty(String ) • • null (viewer ”<null>”) • getProperty() " null • hasProperty() " true • (viewer ”<missing>”) • getProperty() " null • hasProperty() " false •
  • 29. Datastore Service Entity • • new Entity(kind ) • new Entity(kind , Key) • new Entity(kind , key name ) • new Entity(kind , key name , Key) • new Entity(Key primaryKey) ... 1.2.5 • • KEY_RESERVED_PROPERTY ... “__key__” • PrimaryKey
  • 30. Datastore Service DatastoreService • Factory • DatastoreServiceFactory#getDatastoreService() • Key Entity • Entity get([Transaction tx,] Key key) • Map<Key, Entity> get( [Transaction tx,] Iterable<Key> key) • Key EntityNotFoundException • Query Entity • " (Query )
  • 31. Datastore Service DatastoreService • Entity • Key put([Transaction tx,] Entity entity) • List<Key> put( [Transaction tx], Iterable<Entity> entity) • Kind … Entity … k • Entity • delete([Transaction tx,] Key... keys) • delete([Transaction tx,] Iterable<Key> keys) • Key
  • 32. Datastore Service DatastoreService • Key ...1.2.5 • KeyRange allocateIds( [Key parentKey,] String kind, long num) • KeyRange • Key getStart() • Key getEnd() • Iterator<Key> iterator() • Transaction • Transaction beginTransaction() • Transcation getCurrentTransaction() •
  • 33. 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());
  • 34. 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(); } }
  • 35. Datastore Service Query • new Query(String kind) • JDO • new Query(String kind, Key ancestorKey) • Kind • new Query(Key ancestorKey) • Kind •
  • 36. Datastore Service Query • • Query addFilter(String propertyName, FilterOperator operator, Object value) • • Query addSort(String propertyName, SortDirection direction) • • Query setKeysOnly() • Key Entity.KEY_RESERVED_PROPERTY
  • 37. Datastore Service PreparedQuery • DatastoreService#prepare() Query PreaparedQuery • • int countEntities() • • Entity asSingleResult() • null • Entity TooManyResultsException
  • 38. Datastore Service PreparedQuery • • List<Entity> asList(FetchOptions) • • Iterator<Entity> asIterator([FetchOptions]) • • Iterable<Entity> asIterable([FetchOptions]) • iterator() Datastore asIterator() • FetchOptions • offset, limit
  • 39. 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));
  • 40. 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); ...
  • 41. 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
  • 42. 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
  • 43. Datastore Service JDO MyEntiy(1) Child (A-D) MyEntiy(1)/Child(A) MyEntiy(1)/Child(B) MyEntiy(1)/Child(C) MyEntiy(1)/Child(D)
  • 44.
  • 45. AppEngine AppEngine ApiProxy#getDelegate() Delegate Web Delegate Web ApiProxy #getCurrentEnvironment() Environment (ApplicationID, versionID )
  • 46. AppEngine JUnit SDK Web ApiProy • Environment ApiProxy#setEnvironmentForCurrentThread() • Delegate ApiProxyLocalImpl ApiProxy#setDelegate()
  • 47. Environment • • SingleThread • • ApplicationID, versionID,
  • 48. ApiProxyLocalImpl(Delegate ) • Delegate Delegate • • WEB-INF/queue.xml datastore-indexes.xml
  • 49. Delegate • ApiProxyLocalImpl Delegate • …ApiProxyLocalImpl • ApiProxy#getDelegate() ApiProxy Delegate ApiProxy AOP
  • 50. Delegate class MyDelegate implements Delegate { Delegate original = ApiProxy.getDelegate(); public byte[] makeSyncCall( Environment environment, String service, String method, byte[] request) throws ApiProxyException { System.out.println(service+”:”+method); return original.makeSyncCall( environment, service, method, requst); } }
  • 51. 1
  • 52. 1 makeSyncCall() byte[] Delegate#makeSyncCall( Environment environment, String service, String method, byte[] request) throws ApiProxyException
  • 53. 2 makeSyncCall() byte[] Delegate#makeSyncCall( Environment environment, String service, String method, byte[] request) throws ApiProxyException
  • 54. 2 makeSyncCall() • datastore_v3#GET • : DatastorePb.GetRequest • new GetRequest().mergeFrom(byte[]) • GetRequest#keyIterator() Key Iterator • : DatastorePb.GetResponse • new GetResponse().mergeFrom(byte[]) • GetResponse#entityIterator() Entity Iterator
  • 55. 2 makeSyncCall() • Delegate … • datastore_v3#GET • memcache#GET datastore mamcache#GET • datastore_v3#PUT/DELETE • memcache#DELETE datastore
  • 56. 2
  • 57. 2 com.google.apphosting.utils.remot eapi.RemoteApiServlet • Google admin • HttpServlet GET POST • GET yaml • API POST • POST Http “X-appcfg-api- version”
  • 58. 2 com.google.apphosting.utils.remot eapi.RemoteApiPb • RemoteApiServlet API POST ProtocolBuffer • Request • TransactionRequest • Response • ApplicationError
  • 59. 2 ...!!! • Datastore RemoteApiDelegate RemoteApiServlet • Eclipse Plug-in • CUI Memcache stats