Examples of DatastoreService


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

    verify(input, inputReader, output, outputWriter);
  }

  @Test
  public void testDatastoreData() throws Exception {
    final DatastoreService datastoreService = DatastoreServiceFactory.getDatastoreService();
    // Datastore restriction: id cannot be zero.
    for (long i = 1; i <= 100; ++i) {
      datastoreService.put(new Entity(KeyFactory.createKey("Test", i)));
    }
    runTest(new MapReduceSpecification.Builder<>(new DatastoreInput("Test", 5), new TestMapper(),
        new TestReducer(), new InMemoryOutput<KeyValue<String, List<Long>>>())
        .setKeyMarshaller(Marshallers.getStringMarshaller())
        .setValueMarshaller(Marshallers.getLongMarshaller()).setJobName("Test MR").build(),
        new Verifier<List<List<KeyValue<String, List<Long>>>>>() {
          @Override
          public void verify(MapReduceResult<List<List<KeyValue<String, List<Long>>>>> result)
              throws Exception {
            Counters counters = result.getCounters();
            log.info("counters=" + counters);
            assertNotNull(counters);

            assertEquals(100, counters.getCounter("map").getValue());
            assertEquals(5, counters.getCounter("beginShard").getValue());
            assertEquals(5, counters.getCounter("endShard").getValue());
            assertEquals(5, counters.getCounter("beginSlice").getValue());
            assertEquals(5, counters.getCounter("endSlice").getValue());

            assertEquals(100, counters.getCounter(CounterNames.MAPPER_CALLS).getValue());
            assertTrue(counters.getCounter(CounterNames.MAPPER_WALLTIME_MILLIS).getValue() > 0);

            Query query = new Query("Test");
            for (Entity e : datastoreService.prepare(query).asIterable()) {
              Object mark = e.getProperty("mark");
              assertNotNull(mark);
            }

            List<KeyValue<String, List<Long>>> output =
View Full Code Here

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

@SuppressWarnings("serial")
public class TestServlet extends HttpServlet {
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws IOException {
    DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
    String token = req.getParameter(Constant.TOKEN);

    Key k = KeyFactory.stringToKey(token);
    try {
      System.out.println(k.getId());
      Entity e = ds.get(k);
      resp.getWriter().print(e.getProperty("LoginDate"));
    } catch (EntityNotFoundException e) {
      e.printStackTrace();
    }
  }
View Full Code Here

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

    public static JGNameValuePairs get(String kind,String id)throws JGException
  {
   
     checkThread();
     DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();

     Key key = KeyFactory.createKey(kind,id);
     Entity entity = null;
     try{
    
             entity =    datastore.get(key);
     }catch (com.google.appengine.api.datastore.EntityNotFoundException enf){
       return null;
     }
            if (entity == null)return null;
            JGNameValuePairs jn = new JGNameValuePairs(new Hashtable(entity.getProperties()));
View Full Code Here

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

         
           public static void transUpdate(String kind,Hashtable columns,long id,Key pk,jiqlConnection conn)throws Exception
  {


DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Transaction trans = datastore.beginTransaction();
conn.setTransaction(trans);

          Key key = KeyFactory.createKey(pk,kind,id);
        Entity e = datastore.get(key);
     Enumeration en = columns.keys();
     String cn = null;
     Object o = null;
     while (en.hasMoreElements()){
        cn = en.nextElement().toString()
           o = columns.get(cn);

         if (o instanceof String)
        {
         if (((String)o).length() > maxCL)
        o = new com.google.appengine.api.datastore.Text((String)o);
       }
         e.setProperty(cn,convert(o));
         }
       datastore.put(trans,e);

        }
View Full Code Here

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

        }
static int maxCL = 500;
    public static void update(String kind,Hashtable columns,long id)throws Exception
  {
     checkThread();
     DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();

     //Entity e = new Entity(kind,id);
          Key key = KeyFactory.createKey(kind,id);
        Entity e = datastore.get(key);
     Enumeration en = columns.keys();
     String cn = null;
     Object o = null;
     while (en.hasMoreElements()){
        cn = en.nextElement().toString()
           o = columns.get(cn);

         if (o instanceof String)
        {
          if (((String)o).length() > maxCL)
          o = new com.google.appengine.api.datastore.Text((String)o);
       }
         e.setProperty(cn,convert(o));
         }
       datastore.put(e);

               
        }
View Full Code Here

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

  public static void deleteWhere(String table,String field,Object value,Query.FilterOperator qf,Transaction trans)throws JGException
  {
    checkThread();
    Query q = new Query(table);
    q = q.addFilter(field,qf,value);
     DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
        PreparedQuery pq = datastore.prepare(q) ;
    //EZArrayList ez = new EZArrayList();
    //ez.addEnumeration(pq.asIterator());
   
    Iterator lst = pq.asIterator();
    Entity entity = null;
        ArrayList<Key> keys = new ArrayList<Key>();
    int ct = 0;
    while (lst.hasNext())
    {
      ct = ct + 1;
      checkThread(ct);
      entity = (Entity)lst.next();
      keys.add(entity.getKey());
    }
    checkThread();
    if (trans != null)
      datastore.delete(trans,keys);
    else
         datastore.delete(keys);
        }
View Full Code Here

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

    //(" listWhere: " + ":" + qf + ":" + field + ":" + value + ":" + value.getClass().getName());


    Query q = new Query(table);
    q = q.addFilter(field,qf,convert(value));
     DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
        PreparedQuery pq = datastore.prepare(q) ;
    int ezt = pq.countEntities();
    if (ezt > fLimit)
      throw JGException.get("result_too_large",table + " Result too LARGE. Try narrowing query by adding more filters: " + ezt + ":" + qf + ":" + field + ":" + value + ":" + value.getClass().getName());

    Iterator lst = pq.asIterator();
View Full Code Here

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

        o = new com.google.appengine.api.datastore.Text((String)o);
       
        }
         e.setProperty(cn,convert(o));
     }
     DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
       datastore.put(e);
         return e.getKey().getId();



  }
View Full Code Here

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

            if (((String)o).length() > maxCL)
          o = new com.google.appengine.api.datastore.Text((String)o);
       }
         e.setProperty(cn,convert(o));
     }
     DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
       datastore.put(e);

  }
View Full Code Here

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

            if (((String)o).length() > maxCL)
          o = new com.google.appengine.api.datastore.Text((String)o);
       }
         e.setProperty(cn,convert(o));
         }
     DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
   
              Throwable ex = null;  
   for (int ct = 0; ct < readTries;ct++)
{
try{
         //(entit + " put 2 " + columns);
//          EntityManager em = EMF.get().createEntityManager();
//Entity  tx = em.get ();

  Transaction trans = datastore.beginTransaction()  ;
  boolean suc = false;


try{

//tx.begin();
       datastore.put(e);

         long k = e.getKey().getId();
trans.commit();
suc = true;
return k;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.