Package com.google.code.twig.annotation

Examples of com.google.code.twig.annotation.AnnotationObjectDatastore


    registration.setType(type);
    registration.setUsername(username);
    registration.setEmail(email);
   
    // store the registration
    ObjectDatastore datastore = new AnnotationObjectDatastore();
    datastore.store(registration);
   
    // load the registration again, to ensure its indexes are updated
    // TODO: does this actually work?...
    datastore.refresh(registration);
   
    return registration;
  }
View Full Code Here


      @Name("agent") @Required(false) String agent,
      @Name("type") @Required(false) String type,
      @Name("username") @Required(false) String username,
      @Name("email") @Required(false) String email)
      throws Exception {
    ObjectDatastore datastore = new AnnotationObjectDatastore();
   
    RootFindCommand<Registration> command = datastore.find()
      .type(Registration.class)
      .addFilter("directoryAgent", FilterOperator.EQUAL, getFirstUrl());
    if (agent != null) {
      command = command.addFilter("agent", FilterOperator.EQUAL, agent);
    }
View Full Code Here

  private void delete (String field, String value) throws Exception {
    if (field == null || value == null) {
      return;
    }   
   
    ObjectDatastore datastore = new AnnotationObjectDatastore();
   
    QueryResultIterator<Registration> it = datastore.find()
    .type(Registration.class)
    .addFilter("directoryAgent", FilterOperator.EQUAL, getFirstUrl())
    .addFilter(field, FilterOperator.EQUAL, value)
    .now();
 
    while (it.hasNext()) {
      Registration registration = it.next();
      datastore.delete(registration);
   
  }
View Full Code Here

  /**
   * Remove all registrations stored by this DirectoryAgent
   */
  @Override
  public void clear() throws Exception {
    ObjectDatastore datastore = new AnnotationObjectDatastore();
    QueryResultIterator<Registration> it = datastore.find()
      .type(Registration.class)
      .addFilter("directoryAgent", FilterOperator.EQUAL, getFirstUrl())
      .now();
   
    while (it.hasNext()) {
      Registration registration = it.next();
      datastore.delete(registration);
      // TODO: bulk delete all registrations instead of one by one
    }
  }
View Full Code Here

  public Map<String, Object> create(@Name("id") String id, @Name("type") String type)
      throws Exception {
    try {
      getAgentFactory().createAgent(type, id)
   
      ObjectDatastore datastore = new AnnotationObjectDatastore();
     
      // remove any old registration
      AgentMetaData meta = datastore.load(AgentMetaData.class, id);
      if (meta != null) {
        datastore.delete(meta);
      }
     
      // store new registration
      meta = new AgentMetaData(type, id);
      datastore.store(meta);
     
      try {
        trigger("create", toInfo(meta));
      }
      catch (Exception e) {}
View Full Code Here

   */
  public Map<String, Object> register(@Name("id") String id) throws Exception {
    AgentFactory factory = getAgentFactory();
    Agent agent = factory.getAgent(id);
    if (agent != null) {
      ObjectDatastore datastore = new AnnotationObjectDatastore();
     
      // remove any old registration
      AgentMetaData meta = datastore.load(AgentMetaData.class, id);
      if (meta != null) {
        datastore.delete(meta);
      }
     
      // store new registration
      meta = new AgentMetaData(agent.getClass().getName(), agent.getId());
      datastore.store(meta);
     
      try {
        trigger("register", toInfo(meta));
      }
      catch (Exception e) {}
View Full Code Here

   * Unregister an existing agent.
   * @param id
   * @throws Exception
   */
  public void unregister(@Name("id") String id) throws Exception {
    ObjectDatastore datastore = new AnnotationObjectDatastore();
    AgentMetaData meta = datastore.load(AgentMetaData.class, id);
    if (meta != null) {
      try {
        trigger("unregister", toInfo(meta));
        datastore.delete(meta);
      }
      catch (Exception e) {}
    }
  }
View Full Code Here

   * @param id
   * @return
   * @throws Exception
   */
  public void delete(@Name("id") String id) throws Exception {
    ObjectDatastore datastore = new AnnotationObjectDatastore();
    AgentMetaData meta = datastore.load(AgentMetaData.class, id);
    if (meta != null) {
      try {
        trigger("delete", toInfo(meta));
      }
      catch (Exception e) {}
     
      datastore.delete(meta);
    }   

    getAgentFactory().deleteAgent(id);
  }
View Full Code Here

   * @return agents     meta information of all agents: id, type, urls
   * @throws Exception
   */
  public List<Map<String, Object>> list(
      @Name("type") @Required(false) String type) throws Exception {
    ObjectDatastore datastore = new AnnotationObjectDatastore();
    RootFindCommand<AgentMetaData> command = datastore.find()
      .type(AgentMetaData.class);
    if (type != null) {
      command = command.addFilter("type", FilterOperator.EQUAL, type);
    }

    List<Map<String, Object>> info = new ArrayList<Map<String,Object>>();
    QueryResultIterator<AgentMetaData> it = command.now();
    while (it.hasNext()) {
      AgentMetaData meta = it.next();
      Map<String, Object> i = toInfo(meta);
      if (i != null) {
        info.add(i);
      }
      else {
        // agent does not exist anymore. Delete meta information.
        datastore.delete(meta);
      }
    }   
   
    return info;
  }
View Full Code Here

   * @param id
   * @return info
   * @throws Exception
   */
  public Map<String, Object> get(@Name("id") String id) throws Exception {
    ObjectDatastore datastore = new AnnotationObjectDatastore();
    AgentMetaData meta = datastore.load(AgentMetaData.class, id);
    if (meta != null) {
      return toInfo(meta);
    }
    else {
      Agent agent = getAgentFactory().getAgent(id);
View Full Code Here

TOP

Related Classes of com.google.code.twig.annotation.AnnotationObjectDatastore

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.