You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@stratos.apache.org by JaneAarthy <gi...@git.apache.org> on 2015/07/28 14:47:13 UTC

[GitHub] stratos pull request: Adding database model files

GitHub user JaneAarthy opened a pull request:

    https://github.com/apache/stratos/pull/408

    Adding database model files

    Adding ER Model
    Adding SM database script
    Adding persistence.xml file
    Adding PersistenceManager class

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/JaneAarthy/stratos database-model

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/stratos/pull/408.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #408
    
----
commit 5c2def1ba6fb4f11f1b23035feed5174a1e4c558
Author: Jane Aarthy <ja...@wso2.com>
Date:   2015-07-28T12:27:16Z

    Adding database model files

----


---
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.
---

[GitHub] stratos pull request: Adding database model files

Posted by imesh <gi...@git.apache.org>.
Github user imesh commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/408#discussion_r35725447
  
    --- 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;
    --- End diff --
    
    We might not need to keep blank lines between variables.
    Thanks


---
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.
---

[GitHub] stratos pull request: Adding database model files

Posted by lahirus <gi...@git.apache.org>.
Github user lahirus commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/408#discussion_r35692814
  
    --- 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;
    --- End diff --
    
    Licence header is missing.


---
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.
---

[GitHub] stratos pull request: Adding database model files

Posted by lahirus <gi...@git.apache.org>.
Github user lahirus commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/408#discussion_r35692876
  
    --- 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
    +     */
    +
    +
    +    public List retrieveAll(String tableName)
    +    {
    +        List objectList=new ArrayList<Object>();
    +        try{
    +
    +            entityManager=this.entitymanagerFactory.createEntityManager();
    +            entityManager.getTransaction().begin();
    +            String msg="Successfully retrieved";
    +
    +            objectList= entityManager.createQuery("select obj  from "+tableName+" obj" ).getResultList();
    --- End diff --
    
    formatting is wrong here 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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] stratos pull request: Adding database model files

Posted by imesh <gi...@git.apache.org>.
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.
---

[GitHub] stratos pull request: Adding database model files

Posted by lahirus <gi...@git.apache.org>.
Github user lahirus commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/408#discussion_r35692726
  
    --- 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.
    --- End diff --
    
    Remove author tag.


---
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.
---

[GitHub] stratos pull request: Adding database model files

Posted by imesh <gi...@git.apache.org>.
Github user imesh commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/408#discussion_r35725674
  
    --- 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
    +     */
    +
    +
    +    public List retrieveAll(String tableName)
    +    {
    +        List objectList=new ArrayList<Object>();
    +        try{
    +
    +            entityManager=this.entitymanagerFactory.createEntityManager();
    +            entityManager.getTransaction().begin();
    +            String msg="Successfully retrieved";
    +
    +            objectList= entityManager.createQuery("select obj  from "+tableName+" obj" ).getResultList();
    +
    +            if(objectList!=null)
    +            {
    +                log.info(msg);
    +                return objectList;
    +            }
    +            else
    +                return null;
    +
    +        }
    +        catch (javax.persistence.PersistenceException e)
    +        {
    +            String msg="Object not found";
    +            System.out.println(msg);
    +            return null;
    +        }
    +
    +    }
    +
    +    /**
    +     *
    +     * @param object
    +     * @param primaryKey
    +     * @param setValues
    +     * @param whereValues
    +     */
    +
    +    public void update(Object object,Object primaryKey,Map<String,Object> setValues,Map<String,Object> whereValues)
    +    {
    +        String setQuery="";
    +        String updateQuery="";
    +        String whereQuery="";
    +
    +        try {
    +
    +            Object foundObject =retrieve(object,primaryKey);
    +
    +            if(foundObject!=null)
    +            {
    +
    +                String query ="Update "+ object +" obj Set ";
    +                int count =0;
    +                for (String key : setValues.keySet()) {
    +                    setQuery += "obj."+key + "=";
    +
    +                    if(setValues.get(key)instanceof String)
    +                    {
    +                        setQuery+="'"+setValues.get(key)+"'";
    +                    }
    +                    else
    +                    {
    +                        setQuery+=setValues.get(key);
    +                    }
    +
    +                    count++;
    +                    if(setValues.size()>1 && count!=setValues.size())
    +                    {
    +                        setQuery+=",";
    +                    }
    +                }
    +                updateQuery=query+setQuery+" Where ";
    +
    +                int pkCount=0;
    +                for (String key : whereValues.keySet()){
    +
    +                    whereQuery+="obj."+key+"=";
    +                    if(whereValues.get(key)instanceof String)
    +                    { whereQuery+="'"+whereValues.get(key)+"'";
    --- End diff --
    
    This logic might be vulnerable to SQL injection.


---
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.
---

[GitHub] stratos pull request: Adding database model files

Posted by lahirus <gi...@git.apache.org>.
Github user lahirus commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/408#discussion_r35693429
  
    --- 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");
    --- End diff --
    
    Remove sys.out s.


---
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.
---

[GitHub] stratos pull request: Adding database model files

Posted by imesh <gi...@git.apache.org>.
Github user imesh commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/408#discussion_r35725426
  
    --- Diff: components/org.apache.stratos.manager/src/main/database/Stratos-dbScript ---
    @@ -0,0 +1,91 @@
    +SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
    +SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
    +SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
    +
    +CREATE SCHEMA IF NOT EXISTS `StratosManager` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;
    +USE `StratosManager` ;
    +
    +-- -----------------------------------------------------
    +-- Table `StratosManager`.`Cluster`
    +-- -----------------------------------------------------
    +CREATE TABLE IF NOT EXISTS `StratosManager`.`Cluster` (
    --- End diff --
    
    Table names and column names might need to use the same naming convention we currently use: upper case letters with underscore separated words. Please refer existing database files (stratos-distribution/dbscripts/)
    Thanks


---
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.
---

[GitHub] stratos pull request: Adding database model files

Posted by imesh <gi...@git.apache.org>.
Github user imesh commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/408#discussion_r35725558
  
    --- 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
    +     */
    +
    +
    +    public List retrieveAll(String tableName)
    +    {
    +        List objectList=new ArrayList<Object>();
    +        try{
    +
    +            entityManager=this.entitymanagerFactory.createEntityManager();
    +            entityManager.getTransaction().begin();
    +            String msg="Successfully retrieved";
    +
    +            objectList= entityManager.createQuery("select obj  from "+tableName+" obj" ).getResultList();
    +
    +            if(objectList!=null)
    +            {
    +                log.info(msg);
    +                return objectList;
    +            }
    +            else
    +                return null;
    +
    +        }
    +        catch (javax.persistence.PersistenceException e)
    +        {
    +            String msg="Object not found";
    +            System.out.println(msg);
    +            return null;
    +        }
    +
    +    }
    +
    +    /**
    +     *
    +     * @param object
    +     * @param primaryKey
    +     * @param setValues
    +     * @param whereValues
    +     */
    +
    +    public void update(Object object,Object primaryKey,Map<String,Object> setValues,Map<String,Object> whereValues)
    +    {
    +        String setQuery="";
    +        String updateQuery="";
    +        String whereQuery="";
    +
    +        try {
    +
    +            Object foundObject =retrieve(object,primaryKey);
    +
    +            if(foundObject!=null)
    --- End diff --
    
    As Lahiru has mentioned above, code seems to be not formatted: if(foundObject != null)


---
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.
---

[GitHub] stratos pull request: Adding database model files

Posted by lahirus <gi...@git.apache.org>.
Github user lahirus commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/408#discussion_r35692977
  
    --- 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
    +     */
    +
    +
    +    public List retrieveAll(String tableName)
    +    {
    +        List objectList=new ArrayList<Object>();
    +        try{
    +
    +            entityManager=this.entitymanagerFactory.createEntityManager();
    +            entityManager.getTransaction().begin();
    +            String msg="Successfully retrieved";
    +
    +            objectList= entityManager.createQuery("select obj  from "+tableName+" obj" ).getResultList();
    +
    +            if(objectList!=null)
    +            {
    +                log.info(msg);
    +                return objectList;
    +            }
    +            else
    +                return null;
    +
    +        }
    +        catch (javax.persistence.PersistenceException e)
    +        {
    +            String msg="Object not found";
    +            System.out.println(msg);
    --- End diff --
    
    Use log instead of system.out.


---
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.
---

[GitHub] stratos pull request: Adding database model files

Posted by lahirus <gi...@git.apache.org>.
Github user lahirus commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/408#discussion_r35693372
  
    --- Diff: components/org.apache.stratos.manager/META-INF/persistence ---
    @@ -0,0 +1,20 @@
    +<?xml version="1.0" encoding="UTF-8"?>
    --- End diff --
    
    Add licence header


---
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.
---

[GitHub] stratos pull request: Adding database model files

Posted by lahirus <gi...@git.apache.org>.
Github user lahirus commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/408#discussion_r35692752
  
    --- 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.*;
    --- End diff --
    
    Could you format the code. It looks like it is not formatted.


---
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.
---

[GitHub] stratos pull request: Adding database model files

Posted by imesh <gi...@git.apache.org>.
Github user imesh commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/408#discussion_r35725691
  
    --- 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
    +     */
    +
    +
    +    public List retrieveAll(String tableName)
    +    {
    +        List objectList=new ArrayList<Object>();
    +        try{
    +
    +            entityManager=this.entitymanagerFactory.createEntityManager();
    +            entityManager.getTransaction().begin();
    +            String msg="Successfully retrieved";
    +
    +            objectList= entityManager.createQuery("select obj  from "+tableName+" obj" ).getResultList();
    +
    +            if(objectList!=null)
    +            {
    +                log.info(msg);
    +                return objectList;
    +            }
    +            else
    +                return null;
    +
    +        }
    +        catch (javax.persistence.PersistenceException e)
    +        {
    +            String msg="Object not found";
    +            System.out.println(msg);
    +            return null;
    +        }
    +
    +    }
    +
    +    /**
    +     *
    +     * @param object
    +     * @param primaryKey
    +     * @param setValues
    +     * @param whereValues
    +     */
    +
    +    public void update(Object object,Object primaryKey,Map<String,Object> setValues,Map<String,Object> whereValues)
    +    {
    +        String setQuery="";
    +        String updateQuery="";
    +        String whereQuery="";
    +
    +        try {
    +
    +            Object foundObject =retrieve(object,primaryKey);
    +
    +            if(foundObject!=null)
    +            {
    +
    +                String query ="Update "+ object +" obj Set ";
    +                int count =0;
    +                for (String key : setValues.keySet()) {
    +                    setQuery += "obj."+key + "=";
    +
    +                    if(setValues.get(key)instanceof String)
    +                    {
    +                        setQuery+="'"+setValues.get(key)+"'";
    +                    }
    +                    else
    +                    {
    +                        setQuery+=setValues.get(key);
    +                    }
    +
    +                    count++;
    +                    if(setValues.size()>1 && count!=setValues.size())
    +                    {
    +                        setQuery+=",";
    +                    }
    +                }
    +                updateQuery=query+setQuery+" Where ";
    +
    +                int pkCount=0;
    +                for (String key : whereValues.keySet()){
    +
    +                    whereQuery+="obj."+key+"=";
    +                    if(whereValues.get(key)instanceof String)
    +                    { whereQuery+="'"+whereValues.get(key)+"'";
    +                    }
    +                    else
    +                    {   whereQuery+=whereValues.get(key);
    +                    }
    +                    pkCount++;
    +                    if(whereValues.size()>1 && pkCount!=whereValues.size())
    +                    { whereQuery+=" and ";
    +                    }
    +                }
    +
    +                updateQuery+=whereQuery;
    +                entityManager=this.entitymanagerFactory.createEntityManager();
    +
    +                entityManager.getTransaction().begin();
    +
    +                Query queryString= entityManager.createQuery(updateQuery);
    +                int updatedCount =queryString.executeUpdate();
    +
    +                if (updatedCount==1)
    +                {
    +                    entityManager.getTransaction().commit();
    +                    String msg="updated Successfully";
    +                    log.info(msg);
    +                }
    +
    +                else
    +                {
    +                    String msg= "Error while Updating";
    +                    log.error(msg);
    +                }
    +            }
    +            else {
    +                String msg="Object not found";
    +                log.error(msg);
    +            }
    +
    +        }
    +        catch (PersistenceException e)
    +        {
    +            String msg="Error while updating";
    +            log.error(msg);
    +        }
    +
    --- End diff --
    
    It might be better to remove blank lines and format the code properly.
    Thanks


---
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.
---

[GitHub] stratos pull request: Adding database model files

Posted by imesh <gi...@git.apache.org>.
Github user imesh commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/408#discussion_r35725468
  
    --- 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);
    --- 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.
---

[GitHub] stratos pull request: Adding database model files

Posted by imesh <gi...@git.apache.org>.
Github user imesh commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/408#discussion_r35725683
  
    --- 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
    +     */
    +
    +
    +    public List retrieveAll(String tableName)
    +    {
    +        List objectList=new ArrayList<Object>();
    +        try{
    +
    +            entityManager=this.entitymanagerFactory.createEntityManager();
    +            entityManager.getTransaction().begin();
    +            String msg="Successfully retrieved";
    +
    +            objectList= entityManager.createQuery("select obj  from "+tableName+" obj" ).getResultList();
    +
    +            if(objectList!=null)
    +            {
    +                log.info(msg);
    +                return objectList;
    +            }
    +            else
    +                return null;
    +
    +        }
    +        catch (javax.persistence.PersistenceException e)
    +        {
    +            String msg="Object not found";
    +            System.out.println(msg);
    +            return null;
    +        }
    +
    +    }
    +
    +    /**
    +     *
    +     * @param object
    +     * @param primaryKey
    +     * @param setValues
    +     * @param whereValues
    +     */
    +
    +    public void update(Object object,Object primaryKey,Map<String,Object> setValues,Map<String,Object> whereValues)
    +    {
    +        String setQuery="";
    +        String updateQuery="";
    +        String whereQuery="";
    +
    +        try {
    +
    +            Object foundObject =retrieve(object,primaryKey);
    +
    +            if(foundObject!=null)
    +            {
    +
    +                String query ="Update "+ object +" obj Set ";
    +                int count =0;
    +                for (String key : setValues.keySet()) {
    +                    setQuery += "obj."+key + "=";
    +
    +                    if(setValues.get(key)instanceof String)
    +                    {
    +                        setQuery+="'"+setValues.get(key)+"'";
    +                    }
    +                    else
    +                    {
    +                        setQuery+=setValues.get(key);
    +                    }
    +
    +                    count++;
    +                    if(setValues.size()>1 && count!=setValues.size())
    +                    {
    +                        setQuery+=",";
    +                    }
    +                }
    +                updateQuery=query+setQuery+" Where ";
    +
    +                int pkCount=0;
    +                for (String key : whereValues.keySet()){
    +
    +                    whereQuery+="obj."+key+"=";
    +                    if(whereValues.get(key)instanceof String)
    +                    { whereQuery+="'"+whereValues.get(key)+"'";
    +                    }
    +                    else
    +                    {   whereQuery+=whereValues.get(key);
    +                    }
    +                    pkCount++;
    +                    if(whereValues.size()>1 && pkCount!=whereValues.size())
    +                    { whereQuery+=" and ";
    +                    }
    +                }
    +
    +                updateQuery+=whereQuery;
    +                entityManager=this.entitymanagerFactory.createEntityManager();
    +
    +                entityManager.getTransaction().begin();
    +
    +                Query queryString= entityManager.createQuery(updateQuery);
    +                int updatedCount =queryString.executeUpdate();
    +
    +                if (updatedCount==1)
    +                {
    +                    entityManager.getTransaction().commit();
    +                    String msg="updated Successfully";
    +                    log.info(msg);
    +                }
    +
    +                else
    +                {
    +                    String msg= "Error while Updating";
    +                    log.error(msg);
    +                }
    +            }
    +            else {
    +                String msg="Object not found";
    +                log.error(msg);
    +            }
    +
    +        }
    +        catch (PersistenceException e)
    +        {
    +            String msg="Error while updating";
    +            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.
---

[GitHub] stratos pull request: Adding database model files

Posted by imesh <gi...@git.apache.org>.
Github user imesh commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/408#discussion_r35725603
  
    --- 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
    +     */
    +
    +
    +    public List retrieveAll(String tableName)
    +    {
    +        List objectList=new ArrayList<Object>();
    +        try{
    +
    +            entityManager=this.entitymanagerFactory.createEntityManager();
    +            entityManager.getTransaction().begin();
    +            String msg="Successfully retrieved";
    +
    +            objectList= entityManager.createQuery("select obj  from "+tableName+" obj" ).getResultList();
    +
    +            if(objectList!=null)
    +            {
    +                log.info(msg);
    +                return objectList;
    +            }
    +            else
    +                return null;
    +
    +        }
    +        catch (javax.persistence.PersistenceException e)
    +        {
    +            String msg="Object not found";
    +            System.out.println(msg);
    +            return null;
    +        }
    +
    +    }
    +
    +    /**
    +     *
    +     * @param object
    +     * @param primaryKey
    +     * @param setValues
    +     * @param whereValues
    +     */
    +
    +    public void update(Object object,Object primaryKey,Map<String,Object> setValues,Map<String,Object> whereValues)
    +    {
    +        String setQuery="";
    +        String updateQuery="";
    +        String whereQuery="";
    +
    +        try {
    +
    +            Object foundObject =retrieve(object,primaryKey);
    +
    +            if(foundObject!=null)
    +            {
    +
    +                String query ="Update "+ object +" obj Set ";
    +                int count =0;
    +                for (String key : setValues.keySet()) {
    +                    setQuery += "obj."+key + "=";
    +
    +                    if(setValues.get(key)instanceof String)
    --- End diff --
    
    What would be the reason for this logic?


---
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.
---

[GitHub] stratos pull request: Adding database model files

Posted by lahirus <gi...@git.apache.org>.
Github user lahirus commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/408#discussion_r35693044
  
    --- 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
    +     */
    +
    +
    +    public List retrieveAll(String tableName)
    +    {
    +        List objectList=new ArrayList<Object>();
    +        try{
    +
    +            entityManager=this.entitymanagerFactory.createEntityManager();
    +            entityManager.getTransaction().begin();
    +            String msg="Successfully retrieved";
    +
    +            objectList= entityManager.createQuery("select obj  from "+tableName+" obj" ).getResultList();
    +
    +            if(objectList!=null)
    +            {
    +                log.info(msg);
    +                return objectList;
    +            }
    +            else
    +                return null;
    +
    +        }
    +        catch (javax.persistence.PersistenceException e)
    +        {
    +            String msg="Object not found";
    --- End diff --
    
    Have a more descriptive error message


---
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.
---

[GitHub] stratos pull request: Adding database model files

Posted by imesh <gi...@git.apache.org>.
Github user imesh commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/408#discussion_r35725641
  
    --- 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
    +     */
    +
    +
    +    public List retrieveAll(String tableName)
    +    {
    +        List objectList=new ArrayList<Object>();
    +        try{
    +
    +            entityManager=this.entitymanagerFactory.createEntityManager();
    +            entityManager.getTransaction().begin();
    +            String msg="Successfully retrieved";
    +
    +            objectList= entityManager.createQuery("select obj  from "+tableName+" obj" ).getResultList();
    +
    +            if(objectList!=null)
    +            {
    +                log.info(msg);
    +                return objectList;
    +            }
    +            else
    +                return null;
    +
    +        }
    +        catch (javax.persistence.PersistenceException e)
    +        {
    +            String msg="Object not found";
    +            System.out.println(msg);
    +            return null;
    +        }
    +
    +    }
    +
    +    /**
    +     *
    +     * @param object
    +     * @param primaryKey
    +     * @param setValues
    +     * @param whereValues
    +     */
    +
    +    public void update(Object object,Object primaryKey,Map<String,Object> setValues,Map<String,Object> whereValues)
    +    {
    +        String setQuery="";
    +        String updateQuery="";
    +        String whereQuery="";
    +
    +        try {
    +
    +            Object foundObject =retrieve(object,primaryKey);
    +
    +            if(foundObject!=null)
    +            {
    +
    +                String query ="Update "+ object +" obj Set ";
    +                int count =0;
    +                for (String key : setValues.keySet()) {
    +                    setQuery += "obj."+key + "=";
    +
    +                    if(setValues.get(key)instanceof String)
    +                    {
    +                        setQuery+="'"+setValues.get(key)+"'";
    +                    }
    +                    else
    +                    {
    +                        setQuery+=setValues.get(key);
    +                    }
    +
    +                    count++;
    +                    if(setValues.size()>1 && count!=setValues.size())
    +                    {
    +                        setQuery+=",";
    +                    }
    +                }
    +                updateQuery=query+setQuery+" Where ";
    --- End diff --
    
    Why do we construct SQL queries when using an ORM?


---
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.
---

[GitHub] stratos pull request: Adding database model files

Posted by imesh <gi...@git.apache.org>.
Github user imesh commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/408#discussion_r35725525
  
    --- 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);
    --- 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.
---

[GitHub] stratos pull request: Adding database model files

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

[GitHub] stratos pull request: Adding database model files

Posted by imesh <gi...@git.apache.org>.
Github user imesh commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/408#discussion_r35725366
  
    --- Diff: components/org.apache.stratos.manager/src/main/database/Stratos-dbScript ---
    @@ -0,0 +1,91 @@
    +SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
    --- End diff --
    
    It would be better to rename this file to something similar stratos.sql. Please refer existing database files.
    Thanks


---
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.
---

[GitHub] stratos pull request: Adding database model files

Posted by imesh <gi...@git.apache.org>.
Github user imesh commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/408#discussion_r35725521
  
    --- 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");
    --- End diff --
    
    As a convention we need to use braces when defining if statements even with one line.


---
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.
---