Github user lahirus commented on a diff in the pull request: https://github.com/apache/stratos/pull/408#discussion_r35693178 --- Diff: components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/Persistence/PersistenceManager.java --- @@ -0,0 +1,259 @@ +package org.apache.stratos.manager.Persistence; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.persistence.*; + +import java.util.*; +/** + * Created by aarthy on 7/27/15. + */ +public class PersistenceManager { + + private static final Log log; + + static { + log = LogFactory.getLog(PersistenceManager.class); + } + + private EntityManagerFactory entitymanagerFactory = Persistence.createEntityManagerFactory("PersistenceUnit"); + + private static final PersistenceManager instance = new PersistenceManager(); + + EntityManager entityManager = null; + + + public static PersistenceManager getInstance() { + return instance; + } + + + /** + * Add object to persist + * @param object + * @throws PersistenceException + */ + public void add(Object object) + { + System.out.printf("entered"); + + System.out.printf("true"); + try { + entityManager = this.entitymanagerFactory.createEntityManager(); + entityManager.getTransaction().begin(); + entityManager.persist(object); + entityManager.flush(); + entityManager.getTransaction().commit(); + String msg="Added Successfully"; + log.info(msg); + } + catch (PersistenceException e) + { + String msg="Error while adding"; + log.error(msg); + } + + } + + + /** + * remove object by primary key + * @param object + * @param primaryKey + * @throws PersistenceException + */ + + public void remove(Object object,Object primaryKey) + { + try { + entityManager = this.entitymanagerFactory.createEntityManager(); + entityManager.getTransaction().begin(); + Object found=entityManager.find(object.getClass(), primaryKey); + if(found!=null) { + entityManager.remove(found); + entityManager.getTransaction().commit(); + String msg = "Deleted sucessfully"; + log.info(msg); + } + else + { + String msg ="Object does not exists"; + log.error(msg); + } + } + catch (PersistenceException e) + { + + String msg="Error while Deleting"; + log.error(msg); + } + + } + + /** + * retrieve an object by primary key + * @param object + * @param primaryKey + * @return + */ + + public Object retrieve(Object object,Object primaryKey) + { + Object found=null; + try{ + + entityManager=this.entitymanagerFactory.createEntityManager(); + entityManager.getTransaction().begin(); + found= entityManager.find(found.getClass(), primaryKey); + if(found!=null) + log.info("Object Found"); + else + log.error("Object not Found"); + return found; + + } + catch (PersistenceException e) + { + + String msg="Error while retrieving"; + log.error(msg); + return found; + } + + } + + /** + * + * @param tableName + * @return --- End diff -- Better to explain @return as well.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---