package net.okjsp.gmy;

import java.util.Date;
import java.util.List;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.FetchOptions;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import com.google.appengine.api.datastore.Query;

public class GawiDao {
	private static final String KEY_KIND = "Game";
	
	DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
	String keyName = "games";

	public void save(Game game) {
        Key employeeKey = KeyFactory.createKey(KEY_KIND, keyName);
		
		Entity employee = new Entity(KEY_KIND, employeeKey);
		
		User firstUser = game.getFirstUser();
		User secondUser = game.getSecondUser();

		employee.setProperty("first", firstUser.getName());
		employee.setProperty("firstchoice", firstUser.getChoice());
		employee.setProperty("second", secondUser.getName());
		employee.setProperty("secondchoice", secondUser.getChoice());

		employee.setProperty("datetime", new Date());
		employee.setProperty("ip", game.getIp());

		datastore.put(employee);
	}
	
	public List<Entity> fetchAll() {
        Key employeeKey = KeyFactory.createKey(KEY_KIND, keyName);
        Query query = new Query(KEY_KIND, employeeKey).addSort("datetime", Query.SortDirection.DESCENDING);
        List<Entity> greetings = datastore.prepare(query).asList(FetchOptions.Builder.withLimit(5));

		return greetings;
	}
}

@@ -519,17 +519,16 @@
 %22Game%22;%0A
-%09
 %0A%09Datast
@@ -656,36 +656,28 @@
 game) %7B%0A
-        Key employee
+%09%09Key entity
 Key = Ke
@@ -715,18 +715,16 @@
 yName);%0A
-%09%09
 %0A%09%09Entit
@@ -726,23 +726,21 @@
 Entity e
-mployee
+ntity
  = new E
@@ -760,23 +760,19 @@
 D, e
-mployee
+ntity
 Key);%0A
-%09%09
 %0A%09%09U
@@ -850,31 +850,29 @@
 User();%0A%0A%09%09e
-mployee
+ntity
 .setProperty
@@ -898,39 +898,37 @@
 .getName());%0A%09%09e
-mployee
+ntity
 .setProperty(%22fi
@@ -958,39 +958,37 @@
 etChoice());%0A%09%09e
-mployee
+ntity
 .setProperty(%22se
@@ -1012,39 +1012,37 @@
 .getName());%0A%09%09e
-mployee
+ntity
 .setProperty(%22se
@@ -1079,31 +1079,29 @@
 ice());%0A%0A%09%09e
-mployee
+ntity
 .setProperty
@@ -1129,23 +1129,21 @@
 ());%0A%09%09e
-mployee
+ntity
 .setProp
@@ -1190,22 +1190,19 @@
 ut(e
-mployee
+ntity
 );%0A%09%7D%0A
-%09
 %0A%09pu
@@ -1236,28 +1236,20 @@
 ) %7B%0A
-        Key employee
+%09%09Key entity
 Key 
@@ -1291,24 +1291,18 @@
 yName);%0A
-        
+%09%09
 Query qu
@@ -1332,15 +1332,13 @@
 D, e
-mployee
+ntity
 Key)
@@ -1357,17 +1357,21 @@
 tetime%22,
- 
+%0A%09%09%09%09
 Query.So
@@ -1399,16 +1399,10 @@
 G);%0A
-        
+%09%09
 List
@@ -1454,16 +1454,21 @@
 .asList(
+%0A%09%09%09%09
 FetchOpt

rename refactoring