當前位置: 首頁>>代碼示例>>Java>>正文


Java ObjectifyService.ofy方法代碼示例

本文整理匯總了Java中com.googlecode.objectify.ObjectifyService.ofy方法的典型用法代碼示例。如果您正苦於以下問題:Java ObjectifyService.ofy方法的具體用法?Java ObjectifyService.ofy怎麽用?Java ObjectifyService.ofy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.googlecode.objectify.ObjectifyService的用法示例。


在下文中一共展示了ObjectifyService.ofy方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doPost_notMyTurn_move

import com.googlecode.objectify.ObjectifyService; //導入方法依賴的package包/類
@Ignore // TODO: this wasn't running, and I've turned it off.
public void doPost_notMyTurn_move() throws Exception {
  // Insert a game
  Objectify ofy = ObjectifyService.ofy();
  Game game = new Game(USER_ID, "my-opponent", "         ", false);
  ofy.save().entity(game).now();
  String gameKey = game.getId();

  when(mockRequest.getParameter("gameKey")).thenReturn(gameKey);
  when(mockRequest.getParameter("cell")).thenReturn("1");

  servletUnderTest.doPost(mockRequest, mockResponse);

  verify(mockResponse).sendError(401);
}
 
開發者ID:GoogleCloudPlatform,項目名稱:java-docs-samples,代碼行數:16,代碼來源:MoveServletTest.java

示例2: doPost_myTurn_move

import com.googlecode.objectify.ObjectifyService; //導入方法依賴的package包/類
@Test
public void doPost_myTurn_move() throws Exception {
  // Insert a game
  Objectify ofy = ObjectifyService.ofy();
  Game game = new Game(USER_ID, "my-opponent", "         ", true);
  ofy.save().entity(game).now();
  String gameKey = game.getId();

  when(mockRequest.getParameter("gameKey")).thenReturn(gameKey);
  when(mockRequest.getParameter("cell")).thenReturn("1");

  // Mock out the firebase response. See
  // http://g.co/dv/api-client-library/java/google-http-java-client/unit-testing
  MockHttpTransport mockHttpTransport =
      spy(
          new MockHttpTransport() {
            @Override
            public LowLevelHttpRequest buildRequest(String method, String url)
                throws IOException {
              return new MockLowLevelHttpRequest() {
                @Override
                public LowLevelHttpResponse execute() throws IOException {
                  MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
                  response.setStatusCode(200);
                  return response;
                }
              };
            }
          });
  FirebaseChannel.getInstance().httpTransport = mockHttpTransport;

  servletUnderTest.doPost(mockRequest, mockResponse);

  game = ofy.load().type(Game.class).id(gameKey).safe();
  assertThat(game.board).isEqualTo(" X       ");

  verify(mockHttpTransport, times(2))
      .buildRequest(eq("PATCH"), Matchers.matches(FIREBASE_DB_URL + "/channels/[\\w-]+.json$"));
}
 
開發者ID:GoogleCloudPlatform,項目名稱:java-docs-samples,代碼行數:40,代碼來源:MoveServletTest.java

示例3: doPost

import com.googlecode.objectify.ObjectifyService; //導入方法依賴的package包/類
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
  // TODO(you): In practice, you should validate the user has permission to post to the given Game
  String gameId = request.getParameter("gameKey");
  Objectify ofy = ObjectifyService.ofy();
  Game game = ofy.load().type(Game.class).id(gameId).safe();
  game.sendUpdateToClients();
}
 
開發者ID:GoogleCloudPlatform,項目名稱:java-docs-samples,代碼行數:9,代碼來源:OpenedServlet.java

示例4: doPost

import com.googlecode.objectify.ObjectifyService; //導入方法依賴的package包/類
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws IOException {
  String gameId = request.getParameter("gameKey");
  Objectify ofy = ObjectifyService.ofy();
  Game game = ofy.load().type(Game.class).id(gameId).safe();

  UserService userService = UserServiceFactory.getUserService();
  String currentUserId = userService.getCurrentUser().getUserId();

  // TODO(you): In practice, first validate that the user has permission to delete the Game
  game.deleteChannel(getServletContext(), currentUserId);
}
 
開發者ID:GoogleCloudPlatform,項目名稱:java-docs-samples,代碼行數:14,代碼來源:DeleteServlet.java

示例5: doPost

import com.googlecode.objectify.ObjectifyService; //導入方法依賴的package包/類
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws IOException {
  // TODO(you): In practice, you should validate the user has permission to post to the given Game
  String gameId = request.getParameter("gameKey");
  Objectify ofy = ObjectifyService.ofy();
  Game game = ofy.load().type(Game.class).id(gameId).safe();
  game.sendUpdateToClients(getServletContext());
}
 
開發者ID:GoogleCloudPlatform,項目名稱:java-docs-samples,代碼行數:10,代碼來源:OpenedServlet.java

示例6: doGet_noGameKey

import com.googlecode.objectify.ObjectifyService; //導入方法依賴的package包/類
@Test
public void doGet_noGameKey() throws Exception {
  // Mock out the firebase response. See
  // http://g.co/dv/api-client-library/java/google-http-java-client/unit-testing
  MockHttpTransport mockHttpTransport = spy(new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
      return new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
          MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
          response.setStatusCode(200);
          return response;
        }
      };
    }
  });
  FirebaseChannel.getInstance(null).httpTransport = mockHttpTransport;

  Mockito.doReturn(null).when(servletUnderTest).getServletContext();

  servletUnderTest.doGet(mockRequest, mockResponse);

  // Make sure the game object was created for a new game
  Objectify ofy = ObjectifyService.ofy();
  Game game = ofy.load().type(Game.class).first().safe();
  assertEquals(game.userX, USER_ID);

  verify(mockHttpTransport, times(1)).buildRequest(
      eq("PATCH"), Matchers.matches(FIREBASE_DB_URL + "/channels/[\\w-]+.json$"));
  verify(requestDispatcher).forward(mockRequest, mockResponse);
  verify(mockRequest).setAttribute(eq("token"), anyString());
  verify(mockRequest).setAttribute("game_key", game.id);
  verify(mockRequest).setAttribute("me", USER_ID);
  verify(mockRequest).setAttribute("channel_id", USER_ID + game.id);
  verify(mockRequest).setAttribute(eq("initial_message"), anyString());
  verify(mockRequest).setAttribute(eq("game_link"), anyString());
}
 
開發者ID:GoogleCloudPlatform,項目名稱:java-docs-samples,代碼行數:39,代碼來源:TicTacToeServletTest.java

示例7: doPost_open

import com.googlecode.objectify.ObjectifyService; //導入方法依賴的package包/類
@Test
public void doPost_open() throws Exception {
  // Insert a game
  Objectify ofy = ObjectifyService.ofy();
  Game game = new Game(USER_ID, "my-opponent", "         ", true);
  ofy.save().entity(game).now();
  String gameKey = game.getId();

  when(mockRequest.getParameter("gameKey")).thenReturn(gameKey);

  // Mock out the firebase response. See
  // http://g.co/dv/api-client-library/java/google-http-java-client/unit-testing
  MockHttpTransport mockHttpTransport = spy(new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
      return new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
          MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
          response.setStatusCode(200);
          return response;
        }
      };
    }
  });
  FirebaseChannel.getInstance(null).httpTransport = mockHttpTransport;
  Mockito.doReturn(null).when(servletUnderTest).getServletContext();
  servletUnderTest.doPost(mockRequest, mockResponse);

  verify(mockHttpTransport, times(2)).buildRequest(
      eq("PATCH"), Matchers.matches(FIREBASE_DB_URL + "/channels/[\\w-]+.json$"));
}
 
開發者ID:GoogleCloudPlatform,項目名稱:java-docs-samples,代碼行數:33,代碼來源:OpenedServletTest.java

示例8: ofy

import com.googlecode.objectify.ObjectifyService; //導入方法依賴的package包/類
@Override
public Objectify ofy() {
    return ObjectifyService.ofy();
}
 
開發者ID:n15g,項目名稱:spring-boot-gae,代碼行數:5,代碼來源:EntityManagerTest.java

示例9: ofy

import com.googlecode.objectify.ObjectifyService; //導入方法依賴的package包/類
public static Objectify ofy() {
    return ObjectifyService.ofy();
}
 
開發者ID:dreaminglion,項目名稱:iosched-reader,代碼行數:4,代碼來源:OfyService.java

示例10: ofy

import com.googlecode.objectify.ObjectifyService; //導入方法依賴的package包/類
public static Objectify ofy() {
	return ObjectifyService.ofy();
}
 
開發者ID:LabPLC,項目名稱:MapatonAPI,代碼行數:4,代碼來源:OfyService.java

示例11: doGet

import com.googlecode.objectify.ObjectifyService; //導入方法依賴的package包/類
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
  String gameKey = request.getParameter("gameKey");

  // 1. Create or fetch a Game object from the datastore
  Objectify ofy = ObjectifyService.ofy();
  Game game = null;
  String userId = UserServiceFactory.getUserService().getCurrentUser().getUserId();
  if (gameKey != null) {
    game = ofy.load().type(Game.class).id(gameKey).now();
    if (null == game) {
      response.sendError(HttpServletResponse.SC_NOT_FOUND);
      return;
    }
    if (game.getUserO() == null && !userId.equals(game.getUserX())) {
      game.setUserO(userId);
    }
    ofy.save().entity(game).now();
  } else {
    // Initialize a new board. The board is represented as a String of 9 spaces, one for each
    // blank spot on the tic-tac-toe board.
    game = new Game(userId, null, "         ", true);
    ofy.save().entity(game).now();
    gameKey = game.getId();
  }

  // 2. Create this Game in the firebase db
  game.sendUpdateToClients(getServletContext());

  // 3. Inject a secure token into the client, so it can get game updates

  // [START pass_token]
  // The 'Game' object exposes a method which creates a unique string based on the game's key
  // and the user's id.
  String token = FirebaseChannel.getInstance(getServletContext())
      .createFirebaseToken(game, userId);
  request.setAttribute("token", token);

  // 4. More general template values
  request.setAttribute("game_key", gameKey);
  request.setAttribute("me", userId);
  request.setAttribute("channel_id", game.getChannelKey(userId));
  request.setAttribute("initial_message", new Gson().toJson(game));
  request.setAttribute("game_link", getGameUriWithGameParam(request, gameKey));
  request.getRequestDispatcher("/WEB-INF/view/index.jsp").forward(request, response);
  // [END pass_token]
}
 
開發者ID:GoogleCloudPlatform,項目名稱:java-docs-samples,代碼行數:49,代碼來源:TicTacToeServlet.java

示例12: provide

import com.googlecode.objectify.ObjectifyService; //導入方法依賴的package包/類
public static Objectify provide () {
	return ObjectifyService.ofy();
}
 
開發者ID:billy1380,項目名稱:blogwt,代碼行數:4,代碼來源:PersistenceServiceProvider.java

示例13: doGet_existingGame

import com.googlecode.objectify.ObjectifyService; //導入方法依賴的package包/類
@Test
public void doGet_existingGame() throws Exception {
  // Mock out the firebase response. See
  // http://g.co/dv/api-client-library/java/google-http-java-client/unit-testing
  MockHttpTransport mockHttpTransport = spy(new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
      return new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
          MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
          response.setStatusCode(200);
          return response;
        }
      };
    }
  });
  FirebaseChannel.getInstance(null).httpTransport = mockHttpTransport;

  // Insert a game
  Objectify ofy = ObjectifyService.ofy();
  Game game = new Game("some-other-user-id", null, "         ", true);
  ofy.save().entity(game).now();
  String gameKey = game.getId();

  when(mockRequest.getParameter("gameKey")).thenReturn(gameKey);

  Mockito.doReturn(null).when(servletUnderTest).getServletContext();

  servletUnderTest.doGet(mockRequest, mockResponse);

  // Make sure the game object was updated with the other player
  game = ofy.load().type(Game.class).first().safe();
  assertEquals(game.userX, "some-other-user-id");
  assertEquals(game.userO, USER_ID);

  verify(mockHttpTransport, times(2)).buildRequest(
      eq("PATCH"), Matchers.matches(FIREBASE_DB_URL + "/channels/[\\w-]+.json$"));
  verify(requestDispatcher).forward(mockRequest, mockResponse);
  verify(mockRequest).setAttribute(eq("token"), anyString());
  verify(mockRequest).setAttribute("game_key", game.id);
  verify(mockRequest).setAttribute("me", USER_ID);
  verify(mockRequest).setAttribute("channel_id", USER_ID + gameKey);
  verify(mockRequest).setAttribute(eq("initial_message"), anyString());
  verify(mockRequest).setAttribute(eq("game_link"), anyString());
}
 
開發者ID:GoogleCloudPlatform,項目名稱:java-docs-samples,代碼行數:47,代碼來源:TicTacToeServletTest.java

示例14: ofy

import com.googlecode.objectify.ObjectifyService; //導入方法依賴的package包/類
/**
 * Get an objectify instance.
 * Equivalent to calling {@link ObjectifyService#ofy()}
 *
 * @return Objectify instance.
 */
default Objectify ofy() {
    return ObjectifyService.ofy();
}
 
開發者ID:n15g,項目名稱:spring-boot-gae,代碼行數:10,代碼來源:ObjectifyProxy.java

示例15: ofy

import com.googlecode.objectify.ObjectifyService; //導入方法依賴的package包/類
/**
 * Use this static method for getting the Objectify service object in order to make sure the
 * above static block is executed before using Objectify.
 * @return Objectify service object.
 */
public static Objectify ofy() {
    return ObjectifyService.ofy();
}
 
開發者ID:mzdu,項目名稱:AdSearch_Endpoints,代碼行數:9,代碼來源:OfyService.java


注:本文中的com.googlecode.objectify.ObjectifyService.ofy方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。