Package com.google.appengine.api.datastore

Examples of com.google.appengine.api.datastore.PreparedQuery


        // cursor not yet created
        switch(fetchType.fetchType){
        case ITER:
        default:
          {
            PreparedQuery pq = prepare(query);
           
            if(pag.isPaginating()){
              // in case of pagination, we need to allow asynchronous calls such as:
              // QueryAsync<MyClass> query = pm.createQuery(MyClass).paginate(5).stateful().order("name");
              // SienaFuture<Iterable<MyClass>> future1 = query.iter();
              // SienaFuture<Iterable<MyClass>> future2 = query.nextPage().iter();
              // Iterable<MyClass> it = future1.get().iterator();
              // while(it.hasNext()) { // do it }
              // it = future2.get().iterator();
              // while(it.hasNext()) { // do it }
             
              // so we can't use the asQueryResultIterable as the cursor is not moved to the end of the current page
              // but moved at each call of iterable.iterator().next()
              // thus we use the List in this case to be able to move directly to the next page with cursors
              QueryResultList<Entity> entities = pq.asQueryResultList(fetchOptions);

              // activates the GaeCtx now that it is initialised
              gaeCtx.activate();
              // sets the current cursor (in stateful mode, cursor is always kept for further use)
              //if(gaeCtx.useCursor){
              Cursor cursor = entities.getCursor();
              if(cursor!=null){
                gaeCtx.addCursor(cursor.toWebSafeString());
              }
              //}
              return new GaeSienaIterable<T>(this, entities, query);
            }else {
              // if not paginating, we simply use the queryresultiterable and moves the current cursor
              // while iterating
              QueryResultIterable<Entity> entities = pq.asQueryResultIterable(fetchOptions);
              // activates the GaeCtx now that it is initialised
              gaeCtx.activate();
              return new GaeSienaIterableWithCursor<T>(this, entities, query);
            }
           
          }
        }
       
      }else {
        switch(fetchType.fetchType){
        case ITER:
        default:
          {
            PreparedQuery pq = prepare(query);
            if(pag.isPaginating()){
              // in case of pagination, we need to allow asynchronous calls such as:
              // QueryAsync<MyClass> query = pm.createQuery(MyClass).paginate(5).stateful().order("name");
              // SienaFuture<Iterable<MyClass>> future1 = query.iter();
              // SienaFuture<Iterable<MyClass>> future2 = query.nextPage().iter();
              // Iterable<MyClass> it = future1.get().iterator();
              // while(it.hasNext()) { // do it }
              // it = future2.get().iterator();
              // while(it.hasNext()) { // do it }
             
              // so we can't use the asQueryResultIterable as the cursor is not moved to the end of the current page
              // but moved at each call of iterable.iterator().next()
              // thus we use the List in this case to be able to move directly to the next page with cursors
              QueryResultList<Entity> entities;
              if(!gaeCtx.useCursor){
                // then uses offset (in case of IN or != operators)
                //if(offset.isActive()){
                //  fetchOptions.offset(gaeCtx.realOffset);
                //}
                fetchOptions.offset(gaeCtx.realOffset);
                entities = pq.asQueryResultList(fetchOptions);
              }else {
                String cursor = gaeCtx.currentCursor();
                if(cursor!=null){
                  entities = pq.asQueryResultList(
                    fetchOptions.startCursor(Cursor.fromWebSafeString(cursor)));
                }else {
                  entities = pq.asQueryResultList(fetchOptions);
                }
               
                // sets the current cursor (in stateful mode, cursor is always kept for further use)
                //if(gaeCtx.useCursor){
                gaeCtx.addCursor(entities.getCursor().toWebSafeString());
                //}
              }
              return new GaeSienaIterable<T>(this, entities, query);
            }else {
              // if not paginating, we simply use the queryresultiterable and moves the current cursor
              // while iterating
              QueryResultIterable<Entity> entities;
              if(!gaeCtx.useCursor){
                // then uses offset (in case of IN or != operators)
                //if(offset.isActive()){
                //  fetchOptions.offset(gaeCtx.realOffset);
                //}
                fetchOptions.offset(gaeCtx.realOffset);
                entities = pq.asQueryResultIterable(fetchOptions);
              }else {
                String cursor = gaeCtx.currentCursor();
                if(cursor!=null){
                  entities = pq.asQueryResultIterable(
                    fetchOptions.startCursor(Cursor.fromWebSafeString(gaeCtx.currentCursor())));
                }else {
                  entities = pq.asQueryResultIterable(fetchOptions)
                }
              }
              return new GaeSienaIterableWithCursor<T>(this, entities, query);
            }
          }
View Full Code Here


   * @param dio
   *            DepartmentInformationObject - department to be checked
   * @return boolean value whether the department exists or not
   */
  public boolean checkDepartmentExists(DepartmentInformationObject dio) {
    PreparedQuery pq = queryDepartment(dio);
    if (pq.countEntities(FetchOptions.Builder.withDefaults()) == 0)
      return false;
    return true;

  }
View Full Code Here

   * @param cio
   *            CourseInformationObject - course to be checked
   * @return boolean value whether the course exists or not
   */
  public boolean checkCourseExists(CourseInformationObject cio) {
    PreparedQuery pq = queryCourse(cio);
    if (pq.countEntities(FetchOptions.Builder.withDefaults()) == 0)
      return false;
    return true;

  }
View Full Code Here

   * @param sio
   *            SectionInformationObject - section to be checked
   * @return
   */
  public boolean checkSectionExists(SectionInformationObject sio) {
    PreparedQuery pq = querySection(sio);
    if (pq.countEntities(FetchOptions.Builder.withDefaults()) == 0)
      return false;
    return true;
  }
View Full Code Here

    }
    return false;
  }

  public boolean checkBookExists(BookInformationObject bio) {
    PreparedQuery pq = queryBook(bio);
    if (pq.countEntities(FetchOptions.Builder.withDefaults()) == 0)
      return false;
    return true;
  }
View Full Code Here

  private Key makeParentKey(CourseInformationObject cio) {
    Query q = new Query(DEPARTMENT_KIND);
    q.setKeysOnly();
    q.addFilter(DEPARTMENT_ID_PROPERTY, FilterOperator.EQUAL,
        cio.getDepartmentId());
    PreparedQuery pq = datastore.prepare(q);
    return pq.asSingleEntity().getKey();
  }
View Full Code Here

    Query q = new Query(COURSE_KIND);
    q.setKeysOnly();
    q.addFilter(DEPARTMENT_ID_PROPERTY, FilterOperator.EQUAL,
        sio.getDepartmentId());
    q.addFilter(COURSE_ID_PROPERTY, FilterOperator.EQUAL, sio.getCourseId());
    PreparedQuery pq = datastore.prepare(q);
    return pq.asSingleEntity().getKey();
  }
View Full Code Here

    q.addFilter(DEPARTMENT_ID_PROPERTY, FilterOperator.EQUAL,
        bio.getDepartmentId());
    q.addFilter(COURSE_ID_PROPERTY, FilterOperator.EQUAL, bio.getCourseId());
    q.addFilter(SECTION_ID_PROPERTY, FilterOperator.EQUAL,
        bio.getSectionId());
    PreparedQuery pq = datastore.prepare(q);
    return pq.asSingleEntity().getKey();
  }
View Full Code Here

  }

  public DepartmentInformationObject queryDepartmentFromId(String departmentId) {
    Query q = new Query(DEPARTMENT_KIND);
    q.addFilter(DEPARTMENT_ID_PROPERTY, FilterOperator.EQUAL, departmentId);
    PreparedQuery pq = datastore.prepare(q);
    Entity e = pq.asSingleEntity();
    if (e == null)
      return null;
    return getDepartmentFromEntity(e);
  }
View Full Code Here

  public CourseInformationObject queryCourseFromId(String departmentId,
      String courseId) {
    Query q = new Query(COURSE_KIND);
    q.addFilter(DEPARTMENT_ID_PROPERTY, FilterOperator.EQUAL, departmentId);
    q.addFilter(COURSE_ID_PROPERTY, FilterOperator.EQUAL, courseId);
    PreparedQuery pq = datastore.prepare(q);
    Entity e = pq.asSingleEntity();
    if (e == null)
      return null;
    return getCourseFromEntity(e);
  }
View Full Code Here

TOP

Related Classes of com.google.appengine.api.datastore.PreparedQuery

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.