Package org.jrest4guice.dao.hibernate

Source Code of org.jrest4guice.dao.hibernate.CreateAction

package org.jrest4guice.dao.hibernate;

import org.hibernate.Session;
import org.jrest4guice.dao.actions.ActionTemplate;
import org.jrest4guice.dao.annotations.Create;

import com.google.inject.Inject;

public class CreateAction extends ActionTemplate<Create, HibernateContext> {

  @Override
  public Object execute(Object[] parameters) {
    if (parameters.length == 0)
      return null;
    Session session = getContext().getSession();
    if (parameters[0].getClass().isArray()) {
      for (Object obj : (Object[]) parameters[0]) {
        session.save(obj);
      }
    } else {
      session.save(parameters[0]);
    }
    return null;
  }

  @Override
  protected void initialize() {
    annotationClass = Create.class;
    contextClass = HibernateContext.class;
  }

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

Related Classes of org.jrest4guice.dao.hibernate.CreateAction

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.