stratos-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From imesh <...@git.apache.org>
Subject [GitHub] stratos pull request: Adding database model files
Date Wed, 29 Jul 2015 03:39:04 GMT
Github user imesh commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/408#discussion_r35725473
  
    --- 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);
    --- End diff --
    
    Exception object is not included in the log: log.error(msg, e).


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message