Search in sources :

Example 1 with InumSqlEntry

use of org.gluu.oxtrust.model.sql.InumSqlEntry in project oxTrust by GluuFederation.

the class InumService method findInum.

/**
	 * get an inum from inum DB by inum value
	 * 
	 * @return InumSqlEntry
	 */
public InumSqlEntry findInum(EntityManager inumEntryManager, String inum) {
    boolean successs = false;
    EntityTransaction entityTransaction = inumEntryManager.getTransaction();
    entityTransaction.begin();
    InumSqlEntry result = null;
    try {
        @SuppressWarnings("unchecked") List<InumSqlEntry> inumList = inumEntryManager.createQuery("select u from inumTable u where u.inum = :inum").setParameter("inum", inum).setMaxResults(1).getResultList();
        if (inumList.size() == 0) {
            result = null;
        } else {
            result = inumList.get(0);
            successs = true;
        }
    } finally {
        if (successs) {
            // Commit transaction
            entityTransaction.commit();
        } else {
            // Rollback transaction
            entityTransaction.rollback();
        }
    }
    return result;
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) InumSqlEntry(org.gluu.oxtrust.model.sql.InumSqlEntry)

Example 2 with InumSqlEntry

use of org.gluu.oxtrust.model.sql.InumSqlEntry in project oxTrust by GluuFederation.

the class InumService method addInum.

/**
	 * Add an Inum to the DB
	 * 
	 * @return True if user exist
	 */
public boolean addInum(EntityManager inumEntryManager, String inum, String type) {
    boolean successs = false;
    EntityTransaction entityTransaction = inumEntryManager.getTransaction();
    entityTransaction.begin();
    try {
        // Prepare inum
        InumSqlEntry inumEntry = new InumSqlEntry();
        inumEntry.setInum(inum);
        inumEntry.setType(type);
        // add inum
        inumEntryManager.persist(inumEntry);
        successs = true;
    } finally {
        if (successs) {
            // Commit transaction
            entityTransaction.commit();
        } else {
            // Rollback transaction
            entityTransaction.rollback();
        }
    }
    return successs;
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) InumSqlEntry(org.gluu.oxtrust.model.sql.InumSqlEntry)

Example 3 with InumSqlEntry

use of org.gluu.oxtrust.model.sql.InumSqlEntry in project oxTrust by GluuFederation.

the class InumService method removeInum.

/**
	 * removes an inum from inum DB
	 * 
	 * @return List of InumSqlEntry
	 */
public boolean removeInum(EntityManager inumEntryManager, String inum) {
    boolean successs = false;
    EntityTransaction entityTransaction = inumEntryManager.getTransaction();
    InumSqlEntry inumEntry = null;
    try {
        inumEntry = findInum(inumEntryManager, inum);
    } catch (Exception ex) {
        log.error("an error occured : could not find inum", ex);
        ex.printStackTrace();
        return false;
    }
    if (inumEntry == null) {
        return false;
    }
    entityTransaction.begin();
    try {
        inumEntryManager.remove(inumEntry);
        successs = true;
    } finally {
        if (successs) {
            // Commit transaction
            entityTransaction.commit();
        } else {
            // Rollback transaction
            entityTransaction.rollback();
        }
    }
    return successs;
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) InumSqlEntry(org.gluu.oxtrust.model.sql.InumSqlEntry)

Example 4 with InumSqlEntry

use of org.gluu.oxtrust.model.sql.InumSqlEntry in project oxTrust by GluuFederation.

the class InumService method findInumByObject.

/**
	 * get an inum from inum DB by inum value
	 * 
	 * @return InumSqlEntry
	 */
public InumSqlEntry findInumByObject(EntityManager inumEntryManager, String inum) {
    boolean successs = false;
    EntityTransaction entityTransaction = inumEntryManager.getTransaction();
    entityTransaction.begin();
    InumSqlEntry result = null;
    try {
        InumSqlEntry tempInum = new InumSqlEntry();
        tempInum.setInum(inum);
        // find inum
        result = inumEntryManager.find(InumSqlEntry.class, tempInum);
        if (result != null) {
            successs = true;
        }
    } finally {
        if (successs) {
            // Commit transaction
            entityTransaction.commit();
        } else {
            // Rollback transaction
            entityTransaction.rollback();
        }
    }
    return result;
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) InumSqlEntry(org.gluu.oxtrust.model.sql.InumSqlEntry)

Aggregations

EntityTransaction (javax.persistence.EntityTransaction)4 InumSqlEntry (org.gluu.oxtrust.model.sql.InumSqlEntry)4