Package org.jrest4guice.dao.jpa

Source Code of org.jrest4guice.dao.jpa.UpdateAction

package org.jrest4guice.dao.jpa;

import javax.persistence.EntityManager;

import org.jrest4guice.dao.actions.ActionTemplate;
import org.jrest4guice.dao.annotations.Update;

import com.google.inject.Inject;

public class UpdateAction extends ActionTemplate<Update, JpaContext> {

  @Override
  public Object execute(Object[] parameters) {
    if (parameters.length == 0)
      return null;
    EntityManager em = getContext().getEntityManager();
    if (parameters[0].getClass().isArray()) {
      for (Object entity : (Object[]) parameters[0]) {
        entity = em.merge(entity);
      }
    } else {
      parameters[0] = em.merge(parameters[0]);
    }
    return null;
  }

  @Override
  protected void initialize() {
    annotationClass = Update.class;
    contextClass = JpaContext.class;
  }

  @Inject
  @Override
  public void setContext(JpaContext context) {
    this.context = context;
  }

}
TOP

Related Classes of org.jrest4guice.dao.jpa.UpdateAction

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.