Package com.alvazan.orm.api.base

Examples of com.alvazan.orm.api.base.NoSqlEntityManager


    sub.getSomeSet().add(20L);

    mgr.put(sub);
    mgr.flush();
   
    NoSqlEntityManager mgr2 = factory.createEntityManager();
    Email email = mgr2.find(Email.class, sub.getId());
    NoSqlEntityManager mgr3 = factory.createEntityManager();
    Email email2 = mgr3.find(Email.class, sub.getId());
   
    List<String> ids = email.getIds();
    Assert.assertEquals("one", ids.get(0));
   
    List<Integer> nums = email.getInts();
    Assert.assertEquals(new Integer(5), nums.get(0));
   
    email.getInts().remove(0);
    email.getIds().remove("one");
    email.getSomeSet().remove(20L);
    mgr2.put(email);
    mgr2.flush();
   
    email2.getInts().add(12);
    email2.getIds().add("zzzz");
    email2.getSomeSet().add(30L);
    mgr3.put(email2);
    mgr3.flush();
   
    NoSqlEntityManager mgr4 = factory.createEntityManager();
    Email emailF = mgr4.find(Email.class, sub.getId());
   
    Assert.assertEquals(2, emailF.getInts().size());
    Assert.assertEquals(2, emailF.getIds().size());
    Assert.assertEquals(2, emailF.getSomeSet().size());
View Full Code Here


    keyToVal.put("other", 6);
   
    mgr.put(sub);
    mgr.flush();
   
    NoSqlEntityManager mgr2 = factory.createEntityManager();
    Email email = mgr2.find(Email.class, sub.getId());

    Map<String, Integer> nextMap = email.getKeyToVal();
    Assert.assertEquals(2, nextMap.size());
    Assert.assertEquals(new Integer(5), nextMap.get("someVal"));

    nextMap.remove("someVal");
   
    mgr2.put(email);
    mgr2.flush();
   
    NoSqlEntityManager mgr3 = factory.createEntityManager();
    Email email3 = mgr3.find(Email.class, sub.getId());
   
    Map<String, Integer> finalMap = email3.getKeyToVal();
    Assert.assertEquals(1, finalMap.size());
  }
View Full Code Here

    keyToVal.put(6, "other");

    mgr.put(sub);
    mgr.flush();
   
    NoSqlEntityManager mgr2 = factory.createEntityManager();
    Email email = mgr2.find(Email.class, sub.getId());

    Map<Integer, String> nextMap = email.getSomeMap();
    Assert.assertEquals(2, nextMap.size());
    Assert.assertEquals("someVal", nextMap.get(5));

    nextMap.remove(6);
   
    mgr2.put(email);
    mgr2.flush();
   
    NoSqlEntityManager mgr3 = factory.createEntityManager();
    Email email3 = mgr3.find(Email.class, sub.getId());

    Map<Integer, String> finalMap = email3.getSomeMap();
    Assert.assertEquals(1, finalMap.size());
  }
View Full Code Here

    @Override
    public void run() {
      long count = 0;
     
      NoSqlEntityManager mgr = mgrFactory.createEntityManager();
      NoSqlSession session = mgr.getSession();
     
      while(shouldRun) {
       
        //let's write  rows for every flush we do..
        for(int i = 0; i < 1; i++) {
View Full Code Here

    } finally {
      inTryCatch = false;
    }
  }
  public void flushEventsImpl() {
    NoSqlEntityManager mgr = factory.createEntityManager();

    for (LogEvent evt : inMemoryBuffer) {
      mgr.put(evt, false);
    }

    ServersThatLog log = new ServersThatLog();
    log.setId(ServersThatLog.THE_ONE_KEY);
    log.getServers().add(hostname);
    mgr.put(log);
   
    mgr.flush();
    mgr.clear();
  }
View Full Code Here

  private static final Logger log = LoggerFactory.getLogger(NoSqlPlugin.class);
 
    @SuppressWarnings({ "unchecked", "rawtypes" })
  @Override
    public Object bind(RootParamNode rootParamNode, String name, Class clazz, java.lang.reflect.Type type, Annotation[] annotations) {
        NoSqlEntityManager em = NoSql.em();
        MetaLayer metaLayer = em.getMeta();
        if(!metaLayer.isManagedEntity(clazz))
          return null;
       
        ParamNode paramNode = rootParamNode.getChild(name, true);

        String keyFieldName = metaLayer.getKeyFieldName(clazz);
        ParamNode id = paramNode.getChild(keyFieldName);

        String idStr = NoSqlModel.retrieveValue(id);
        if(idStr == null)
          return NoSqlModel.create(rootParamNode, name, clazz, annotations);

        Object theId = metaLayer.convertIdFromString(clazz, idStr);
       
        //Read the entity in so that this entity is used instead...
      Object o = em.find(clazz, theId);
     
      return NoSqlModel.edit(rootParamNode, name, o, annotations);
    }
View Full Code Here

      return NoSqlModel.edit(rootParamNode, name, o, annotations);
    }

  @Override
    public Object bindBean(RootParamNode rootParamNode, String name, Object bean) {
      NoSqlEntityManager mgr = NoSql.em();
      MetaLayer meta = mgr.getMeta();
      if(meta.isManagedEntity(bean.getClass())) {
            return NoSqlModel.edit(rootParamNode, name, bean, null);
        }
        return null;
    }
View Full Code Here

    @Override
    public void beforeInvocation() {
        if (!NoSql.isEnabled())
            return;

        NoSqlEntityManager manager = NoSql.getEntityManagerFactory().createEntityManager();
        NoSql.createContext(manager);
    }
View Full Code Here

            ParamNode.restoreRemovedChildren( removedNodesList );
        }
    }

  private static void processField(Field field, ParamNode paramNode, List<RemovedNode> removedNodesList, Object o) {
      NoSqlEntityManager em = NoSql.em();
      MetaLayer meta = em.getMeta();
     
        boolean isEntity = false;
        Class<?> relation = null;
        boolean multiple = false;
        //
        if (field.isAnnotationPresent(NoSqlOneToOne.class) || field.isAnnotationPresent(NoSqlManyToOne.class)) {
            isEntity = true;
            relation = field.getType();
        } else if (field.isAnnotationPresent(NoSqlOneToMany.class) || field.isAnnotationPresent(NoSqlManyToMany.class)) {
          ParameterizedType p = (ParameterizedType) field.getGenericType();
          relation = (Class<?>) p.getActualTypeArguments()[0];
          if(field.getType().equals(Map.class)) {
            relation = (Class<?>) p.getActualTypeArguments()[1];
          }
            isEntity = true;
            multiple = true;
        }

        if (!isEntity)
          return;

        ParamNode fieldParamNode = paramNode.getChild(field.getName(), true);

        String keyName = meta.getKeyFieldName(relation);

        if (multiple && Collection.class.isAssignableFrom(field.getType())) {
//          Collection l = new ArrayList();
//          if (SortedSet.class.isAssignableFrom(field.getType())) {
//            l = new TreeSet();
//          } else if (Set.class.isAssignableFrom(field.getType())) {
//            l = new HashSet();
//          }
          log.trace("not implemented");
          //NOTE: for now we skip this
          return;
        }
       
        ParamNode idChild = fieldParamNode.getChild(keyName, true);
        String theIdStr = retrieveValue(idChild);
       
        if (theIdStr != null) {
          Object theId = meta.convertIdFromString(relation, theIdStr);
          Object to = em.find(relation, theId);
          if(to != null) {
            edit(paramNode, field.getName(), to, field.getAnnotations());
            // Remove it to prevent us from finding it again later
            paramNode.removeChild( field.getName(), removedNodesList);
            set(field, o, to);
View Full Code Here

  private static final Map<String, Object> PROPS = new HashMap<String, Object>();

  @SuppressWarnings({ "unchecked", "rawtypes" })
  @Override
    public Object bind(RootParamNode rootParamNode, String name, Class clazz, java.lang.reflect.Type type, Annotation[] annotations) {
        NoSqlEntityManager em = NoSql.em();
        MetaLayer metaLayer = em.getMeta();
        if(!metaLayer.isManagedEntity(clazz))
          return null;
       
        ParamNode paramNode = rootParamNode.getChild(name, true);

        String keyFieldName = metaLayer.getKeyFieldName(clazz);
        ParamNode id = paramNode.getChild(keyFieldName);

        String idStr = NoSqlModel.retrieveValue(id);
        if(idStr == null)
          return NoSqlModel.create(rootParamNode, name, clazz, annotations);

        Object theId = metaLayer.convertIdFromString(clazz, idStr);
       
        //Read the entity in so that this entity is used instead...
      Object o = em.find(clazz, theId);
      if(o == null)
        throw new RowNotFoundException("Row with rowkey="+theId+" was not found, but your page posted this id to lookup the row of class type="+clazz.getSimpleName());
      return NoSqlModel.edit(rootParamNode, name, o, annotations);
    }
View Full Code Here

TOP

Related Classes of com.alvazan.orm.api.base.NoSqlEntityManager

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.