什麼是 GAE ? (1/2) Google: Google App Engine 讓你得以在和 Google 自身應用程式所處的相同系統上,開發並且運行 Web 應用程式 Wikipedia: Google App Engine 是個在 Google 所管理的資料中心之上開發及運行 Web 應用程式的平台
20.
什麼是 GAE ?(2/2) GAE 讓你在 Google 所打造的基礎設施之上運行 Web 應用程式 在 GAE 上開發應用程式 開發容易 維護容易 擴充規模也很容易
GAE 上的 Java執行環境 (2/2) API Java 標準 APIs Java Data Objects (JDO)/ Java Persistence API (JPA) JavaMail API java.net HTTP API Google Accounts APIs 程式語言 Java JavaScript Ruby Scala Go
Kind 、 Entity、 Key 、 Property User 傳統關聯式資料庫 Datastore *Cloud Tu @TWJUG User Sport Null Null Favor2 Movie Null Null Favor3 Music Cloud 1 Music Tom 3 Null John 2 Favor1 Name PK Music Favor Cloud Name 1 Key John Name 2 Key Music , Sport , Movie Favor Tom Name 3 Key Kind Table Key PK Property Field Entity Row
35.
Native Datastore 操作DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); Entity employee = new Entity("Employee"); employee.setProperty("firstName", "Antonio"); employee.setProperty("lastName", "Salieri"); Date hireDate = new Date(); employee.setProperty("hireDate", hireDate); employee.setProperty("attendedHrTraining", true); datastore.put(employee); Kind Entity Key Property *Cloud Tu @TWJUG 在 Entity 的 constructor 中指定。未指定時,系統會自動指派一個 UUID 的 key
36.
用 JDO 的方式描述資料 (1/2) @PersistenceCapable(identityType = IdentityType.APPLICATION) public class Album { @PrimaryKey @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) private Long id; @Persistent private String albumURL; @Persistent private String owner; …
37.
用 JDO 的方式描述資料 (2/2) public Album(String _albumURL, String _owner, String _siteProvider) { albumURL = _albumURL; owner = _owner; siteProvider = _siteProvider; status = 0; submitDate = new Date(); } public Long getId() { return id; } public String getAlbumURL() { return albumURL; } …
JDO/Query Language publicbyte[] getPhoto(long id) { PersistenceManager pm = PMF.get().getPersistenceManager(); String query = "select from " + Photo.class.getName() + " where id == "+id; List<Photo> photos = (List<Photo>) pm.newQuery(query).execute(); if( photos.isEmpty() ) { pm.close(); return null; } Photo p = photos.get(0); Blob content = p.getContent(); byte[] b = content.getBytes(); pm.close(); return b; }
40.
EntityGroup 擁有相同 ParentKey的 Entity 即屬於同一 EntityGroup 對位在同一 EntityGroup 內 Entity 所進行的操作可在同一 transaction 裡 適合 One to Many 的資料表示方式
41.
EntityGroup User *CloudTu @TWJUG 自動產生 RootKey ParentKey Cloud Name 1 Key 自動產生 RootKey ParentKey John Name 2 Key 2 ParentKey Mary Name 3 Key 2 ParentKey Mary Name 4 Key 2 ParentKey Joe Name 5 Key A EntityGroup B EntityGroup
同與異 (1/2)基於 GAE 開發 Web 應用系統和傳統非雲端平台的開發幾乎是相同的 同樣的程式語言 同樣的標準 API 同樣的 Web 技術及框架
52.
同與異 (2/2)因應雲端平台所需的特性,也有一些差異 掌握這些差異,就能順利的遷移至雲端開發 Sandbox 中的限制 Web 端執行時間的限制 操作資料的方式大異於傳統關聯式資料庫的存取
53.
GAE SDK 下載http://code.google.com/intl/zh-TW/appengine/downloads.html 內含一個 Web server 在本地端模擬 GAE 的所有 service 在本地端模擬 sandbox 的行為 小細節處略有差異 提供在 GAE 上可取用的所有 API 及 library
54.
GAE 開發流程 (1/3)編譯方式 Google Plugin for Eclipse Ant build tool 開發 使用 GAE SDK 中的 API 及 library 搭配標準的 Java 開發環境 部署至本地端的 Web server 進行測試