Package com.alvazan.orm.api.base

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


  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);
      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


      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;
        else if(multiple)
          return; //we don't do multiple collections yet(like editing in a table)
       
        ParamNode fieldParamNode = paramNode.getChild(field.getName(), true);

        String keyName = meta.getKeyFieldName(relation);
       
        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

          println(e.getMessage());
      }
    }
  }
  private void processCommand(String cmd) {
    NoSqlEntityManager mgr = factory.createEntityManager();
   
    if("help".equals(cmd)) {
      println("Getting around");
      println("help;            Display this help");
      println("help <command>   Display command-specific help.");
View Full Code Here

    WebNodeDbo node = new WebNodeDbo();
    node.setLastSeen(new DateTime());
    node.setWebServerName(host);
    node.setUp(true);
   
    NoSqlEntityManager mgr = factory.createEntityManager();
    mgr.put(node);
    mgr.flush();
   
    clusterRunnable.setFactory(factory);
    svc.scheduleAtFixedRate(clusterRunnable, 30000, config.getRate(), TimeUnit.MILLISECONDS);
  }
View Full Code Here

  }

  @Override
  public void saveMonitor(PlayOrmMonitor monitor) {
    MonitorDbo m = CopyUtil.copy(monitor);
    NoSqlEntityManager mgr = factory.createEntityManager();
    mgr.put(m);
    mgr.flush();
  }
View Full Code Here

    mgr.flush();
  }

  @Override
  public PlayOrmMonitor getMonitor(String id) {
    NoSqlEntityManager mgr = factory.createEntityManager();
    MonitorDbo mon = mgr.find(MonitorDbo.class, id);
    return CopyUtil.copy(mon);
  }
View Full Code Here

    MonitorDbo mon = mgr.find(MonitorDbo.class, id);
    return CopyUtil.copy(mon);
  }
 
  public List<PlayOrmMonitor> getMonitors(List<String> ids) {
    NoSqlEntityManager mgr = factory.createEntityManager();
    Cursor<KeyValue<MonitorDbo>> cursor = mgr.findAll(MonitorDbo.class, ids);
    List<PlayOrmMonitor> monitors = new ArrayList<PlayOrmMonitor>();
    while(cursor.next()) {
      KeyValue<MonitorDbo> kv = cursor.getCurrent();
      MonitorDbo mon = kv.getValue();
      monitors.add(CopyUtil.copy(mon));
View Full Code Here

  }
  public void runImpl() {
    if(listener == null)
      return; //no need to do anything
   
    NoSqlEntityManager mgr = factory.createEntityManager();
    Cursor<KeyValue<WebNodeDbo>> cursor = WebNodeDbo.findAllNodes(mgr);
    List<WebNodeDbo> all = new ArrayList<WebNodeDbo>();
    List<WebNodeDbo> servers = new ArrayList<WebNodeDbo>();
    while(cursor.next()) {
      KeyValue<WebNodeDbo> kv = cursor.getCurrent();
      WebNodeDbo val = kv.getValue();
      all.add(val);
      if(isServerUp(mgr, val))
        servers.add(val);
      if(val.getWebServerName().equals(config.getHostName()))
        saveNodeIsUp(mgr, val);
    }

    mgr.clear();
   
    Collections.sort(servers, new ServerComparator());
    int serverNumber = -1;
    for(int i = 0; i < servers.size(); i++) {
      WebNodeDbo node = servers.get(i);
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.