diff options
Diffstat (limited to 'model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/impl/DefaultApexDao.java')
-rw-r--r-- | model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/impl/DefaultApexDao.java | 124 |
1 files changed, 62 insertions, 62 deletions
diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/impl/DefaultApexDao.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/impl/DefaultApexDao.java index 228362bce..7945a0837 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/impl/DefaultApexDao.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/dao/impl/DefaultApexDao.java @@ -34,7 +34,7 @@ import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; import org.onap.policy.apex.model.basicmodel.concepts.AxConcept; import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; import org.onap.policy.apex.model.basicmodel.dao.ApexDao; -import org.onap.policy.apex.model.basicmodel.dao.DAOParameters; +import org.onap.policy.apex.model.basicmodel.dao.DaoParameters; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; @@ -66,7 +66,7 @@ public class DefaultApexDao implements ApexDao { * org.onap.policy.apex.model.basicmodel.dao.ApexDao#init(org.onap.policy.apex.model.basicmodel.dao.DAOParameters) */ @Override - public void init(final DAOParameters daoParameters) throws ApexException { + public void init(final DaoParameters daoParameters) throws ApexException { if (daoParameters == null || daoParameters.getPersistenceUnit() == null) { LOGGER.error("Apex persistence unit parameter not set"); throw new ApexException("Apex persistence unit parameter not set"); @@ -75,11 +75,12 @@ public class DefaultApexDao implements ApexDao { LOGGER.debug("Creating Apex persistence unit \"" + daoParameters.getPersistenceUnit() + "\" . . ."); try { emf = Persistence.createEntityManagerFactory(daoParameters.getPersistenceUnit(), - daoParameters.getJdbcProperties()); + daoParameters.getJdbcProperties()); } catch (final Exception e) { LOGGER.warn("Creation of Apex persistence unit \"" + daoParameters.getPersistenceUnit() + "\" failed", e); throw new ApexException( - "Creation of Apex persistence unit \"" + daoParameters.getPersistenceUnit() + "\" failed", e); + "Creation of Apex persistence unit \"" + daoParameters.getPersistenceUnit() + "\" failed", + e); } LOGGER.debug("Created Apex persistence unit \"" + daoParameters.getPersistenceUnit() + "\""); } @@ -159,15 +160,15 @@ public class DefaultApexDao implements ApexDao { * org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey) */ @Override - public <T extends AxConcept> void delete(final Class<T> aClass, final AxArtifactKey key) { + public <T extends AxConcept> void delete(final Class<T> someClass, final AxArtifactKey key) { if (key == null) { return; } final EntityManager mg = getEntityManager(); try { mg.getTransaction().begin(); - mg.createQuery(DELETE_FROM + aClass.getSimpleName() + C_WHERE_C_KEY_NAME + key.getName() + AND_C_KEY_VERSION - + key.getVersion() + "'", aClass).executeUpdate(); + mg.createQuery(DELETE_FROM + someClass.getSimpleName() + C_WHERE_C_KEY_NAME + key.getName() + + AND_C_KEY_VERSION + key.getVersion() + "'", someClass).executeUpdate(); mg.getTransaction().commit(); } finally { mg.close(); @@ -181,16 +182,16 @@ public class DefaultApexDao implements ApexDao { * org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey) */ @Override - public <T extends AxConcept> void delete(final Class<T> aClass, final AxReferenceKey key) { + public <T extends AxConcept> void delete(final Class<T> someClass, final AxReferenceKey key) { if (key == null) { return; } final EntityManager mg = getEntityManager(); try { mg.getTransaction().begin(); - mg.createQuery(DELETE_FROM + aClass.getSimpleName() + C_WHERE_C_KEY_PARENT_KEY_NAME + key.getParentKeyName() - + AND_C_KEY_PARENT_KEY_VERSION + key.getParentKeyVersion() + AND_C_KEY_LOCAL_NAME - + key.getLocalName() + "'", aClass).executeUpdate(); + mg.createQuery(DELETE_FROM + someClass.getSimpleName() + C_WHERE_C_KEY_PARENT_KEY_NAME + + key.getParentKeyName() + AND_C_KEY_PARENT_KEY_VERSION + key.getParentKeyVersion() + + AND_C_KEY_LOCAL_NAME + key.getLocalName() + "'", someClass).executeUpdate(); mg.getTransaction().commit(); } finally { mg.close(); @@ -203,7 +204,7 @@ public class DefaultApexDao implements ApexDao { * @see org.onap.policy.apex.model.basicmodel.dao.ApexDao#create(java.util.Collection) */ @Override - public <T extends AxConcept> void create(final Collection<T> objs) { + public <T extends AxConcept> void createCollection(final Collection<T> objs) { if (objs == null || objs.isEmpty()) { return; } @@ -225,7 +226,7 @@ public class DefaultApexDao implements ApexDao { * @see org.onap.policy.apex.model.basicmodel.dao.ApexDao#delete(java.util.Collection) */ @Override - public <T extends AxConcept> void delete(final Collection<T> objs) { + public <T extends AxConcept> void deleteCollection(final Collection<T> objs) { if (objs == null || objs.isEmpty()) { return; } @@ -247,7 +248,8 @@ public class DefaultApexDao implements ApexDao { * @see org.onap.policy.apex.model.basicmodel.dao.ApexDao#deleteByArtifactKey(java.lang.Class, java.util.Collection) */ @Override - public <T extends AxConcept> int deleteByArtifactKey(final Class<T> aClass, final Collection<AxArtifactKey> keys) { + public <T extends AxConcept> int deleteByArtifactKey(final Class<T> someClass, + final Collection<AxArtifactKey> keys) { if (keys == null || keys.isEmpty()) { return 0; } @@ -256,8 +258,10 @@ public class DefaultApexDao implements ApexDao { try { mg.getTransaction().begin(); for (final AxArtifactKey key : keys) { - deletedCount += mg.createQuery(DELETE_FROM + aClass.getSimpleName() + C_WHERE_C_KEY_NAME + key.getName() - + AND_C_KEY_VERSION + key.getVersion() + "'", aClass).executeUpdate(); + deletedCount += mg + .createQuery(DELETE_FROM + someClass.getSimpleName() + C_WHERE_C_KEY_NAME + + key.getName() + AND_C_KEY_VERSION + key.getVersion() + "'", someClass) + .executeUpdate(); } mg.getTransaction().commit(); } finally { @@ -273,8 +277,8 @@ public class DefaultApexDao implements ApexDao { * java.util.Collection) */ @Override - public <T extends AxConcept> int deleteByReferenceKey(final Class<T> aClass, - final Collection<AxReferenceKey> keys) { + public <T extends AxConcept> int deleteByReferenceKey(final Class<T> someClass, + final Collection<AxReferenceKey> keys) { if (keys == null || keys.isEmpty()) { return 0; } @@ -283,12 +287,9 @@ public class DefaultApexDao implements ApexDao { try { mg.getTransaction().begin(); for (final AxReferenceKey key : keys) { - deletedCount += - mg.createQuery( - DELETE_FROM + aClass.getSimpleName() + C_WHERE_C_KEY_PARENT_KEY_NAME - + key.getParentKeyName() + AND_C_KEY_PARENT_KEY_VERSION - + key.getParentKeyVersion() + AND_C_KEY_LOCAL_NAME + key.getLocalName() + "'", - aClass).executeUpdate(); + deletedCount += mg.createQuery(DELETE_FROM + someClass.getSimpleName() + C_WHERE_C_KEY_PARENT_KEY_NAME + + key.getParentKeyName() + AND_C_KEY_PARENT_KEY_VERSION + key.getParentKeyVersion() + + AND_C_KEY_LOCAL_NAME + key.getLocalName() + "'", someClass).executeUpdate(); } mg.getTransaction().commit(); } finally { @@ -303,11 +304,11 @@ public class DefaultApexDao implements ApexDao { * @see org.onap.policy.apex.model.basicmodel.dao.ApexDao#deleteAll(java.lang.Class) */ @Override - public <T extends AxConcept> void deleteAll(final Class<T> aClass) { + public <T extends AxConcept> void deleteAll(final Class<T> someClass) { final EntityManager mg = getEntityManager(); try { mg.getTransaction().begin(); - mg.createQuery(DELETE_FROM + aClass.getSimpleName() + " c ", aClass).executeUpdate(); + mg.createQuery(DELETE_FROM + someClass.getSimpleName() + " c ", someClass).executeUpdate(); mg.getTransaction().commit(); } finally { mg.close(); @@ -321,21 +322,21 @@ public class DefaultApexDao implements ApexDao { * org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey) */ @Override - public <T extends AxConcept> T get(final Class<T> aClass, final AxArtifactKey key) { - if (aClass == null) { + public <T extends AxConcept> T get(final Class<T> someClass, final AxArtifactKey key) { + if (someClass == null) { return null; } final EntityManager mg = getEntityManager(); try { - final T t = mg.find(aClass, key); + final T t = mg.find(someClass, key); if (t != null) { // This clone is created to force the JPA DAO to recurse down through the object try { - final T clonedT = aClass.newInstance(); + final T clonedT = someClass.newInstance(); t.copyTo(clonedT); return clonedT; } catch (final Exception e) { - LOGGER.warn("Could not clone object of class \"" + aClass.getCanonicalName() + "\"", e); + LOGGER.warn("Could not clone object of class \"" + someClass.getCanonicalName() + "\"", e); return null; } } else { @@ -353,20 +354,20 @@ public class DefaultApexDao implements ApexDao { * org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey) */ @Override - public <T extends AxConcept> T get(final Class<T> aClass, final AxReferenceKey key) { - if (aClass == null) { + public <T extends AxConcept> T get(final Class<T> someClass, final AxReferenceKey key) { + if (someClass == null) { return null; } final EntityManager mg = getEntityManager(); try { - final T t = mg.find(aClass, key); + final T t = mg.find(someClass, key); if (t != null) { try { - final T clonedT = aClass.newInstance(); + final T clonedT = someClass.newInstance(); t.copyTo(clonedT); return clonedT; } catch (final Exception e) { - LOGGER.warn("Could not clone object of class \"" + aClass.getCanonicalName() + "\"", e); + LOGGER.warn("Could not clone object of class \"" + someClass.getCanonicalName() + "\"", e); return null; } } else { @@ -383,13 +384,13 @@ public class DefaultApexDao implements ApexDao { * @see org.onap.policy.apex.model.basicmodel.dao.ApexDao#getAll(java.lang.Class) */ @Override - public <T extends AxConcept> List<T> getAll(final Class<T> aClass) { - if (aClass == null) { + public <T extends AxConcept> List<T> getAll(final Class<T> someClass) { + if (someClass == null) { return Collections.emptyList(); } final EntityManager mg = getEntityManager(); try { - return mg.createQuery(SELECT_C_FROM + aClass.getSimpleName() + " c", aClass).getResultList(); + return mg.createQuery(SELECT_C_FROM + someClass.getSimpleName() + " c", someClass).getResultList(); } finally { mg.close(); } @@ -402,16 +403,15 @@ public class DefaultApexDao implements ApexDao { * org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey) */ @Override - public <T extends AxConcept> List<T> getAll(final Class<T> aClass, final AxArtifactKey parentKey) { - if (aClass == null) { + public <T extends AxConcept> List<T> getAll(final Class<T> someClass, final AxArtifactKey parentKey) { + if (someClass == null) { return Collections.emptyList(); } final EntityManager mg = getEntityManager(); try { - return mg - .createQuery(SELECT_C_FROM + aClass.getSimpleName() + C_WHERE_C_KEY_PARENT_KEY_NAME - + parentKey.getName() + AND_C_KEY_PARENT_KEY_VERSION + parentKey.getVersion() + "'", aClass) - .getResultList(); + return mg.createQuery(SELECT_C_FROM + someClass.getSimpleName() + C_WHERE_C_KEY_PARENT_KEY_NAME + + parentKey.getName() + AND_C_KEY_PARENT_KEY_VERSION + parentKey.getVersion() + "'", + someClass).getResultList(); } finally { mg.close(); } @@ -424,15 +424,15 @@ public class DefaultApexDao implements ApexDao { * org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey) */ @Override - public <T extends AxConcept> T getArtifact(final Class<T> aClass, final AxArtifactKey key) { - if (aClass == null || key == null) { + public <T extends AxConcept> T getArtifact(final Class<T> someClass, final AxArtifactKey key) { + if (someClass == null || key == null) { return null; } final EntityManager mg = getEntityManager(); List<T> ret; try { - ret = mg.createQuery(SELECT_C_FROM + aClass.getSimpleName() + C_WHERE_C_KEY_NAME + key.getName() - + AND_C_KEY_VERSION + key.getVersion() + "'", aClass).getResultList(); + ret = mg.createQuery(SELECT_C_FROM + someClass.getSimpleName() + C_WHERE_C_KEY_NAME + key.getName() + + AND_C_KEY_VERSION + key.getVersion() + "'", someClass).getResultList(); } finally { mg.close(); } @@ -440,8 +440,8 @@ public class DefaultApexDao implements ApexDao { return null; } if (ret.size() > 1) { - throw new IllegalArgumentException("More than one result was returned for search for " + aClass - + " with key " + key.getID() + ": " + ret); + throw new IllegalArgumentException("More than one result was returned for search for " + someClass + + " with key " + key.getId() + ": " + ret); } return ret.get(0); } @@ -453,16 +453,16 @@ public class DefaultApexDao implements ApexDao { * org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey) */ @Override - public <T extends AxConcept> T getArtifact(final Class<T> aClass, final AxReferenceKey key) { - if (aClass == null || key == null) { + public <T extends AxConcept> T getArtifact(final Class<T> someClass, final AxReferenceKey key) { + if (someClass == null || key == null) { return null; } final EntityManager mg = getEntityManager(); List<T> ret; try { - ret = mg.createQuery(SELECT_C_FROM + aClass.getSimpleName() + C_WHERE_C_KEY_PARENT_KEY_NAME - + key.getParentKeyName() + AND_C_KEY_PARENT_KEY_VERSION + key.getParentKeyVersion() - + AND_C_KEY_LOCAL_NAME + key.getLocalName() + "'", aClass).getResultList(); + ret = mg.createQuery(SELECT_C_FROM + someClass.getSimpleName() + C_WHERE_C_KEY_PARENT_KEY_NAME + + key.getParentKeyName() + AND_C_KEY_PARENT_KEY_VERSION + key.getParentKeyVersion() + + AND_C_KEY_LOCAL_NAME + key.getLocalName() + "'", someClass).getResultList(); } finally { mg.close(); } @@ -470,8 +470,8 @@ public class DefaultApexDao implements ApexDao { return null; } if (ret.size() > 1) { - throw new IllegalArgumentException("More than one result was returned for search for " + aClass - + " with key " + key.getID() + ": " + ret); + throw new IllegalArgumentException("More than one result was returned for search for " + someClass + + " with key " + key.getId() + ": " + ret); } return ret.get(0); } @@ -503,15 +503,15 @@ public class DefaultApexDao implements ApexDao { * @see org.onap.policy.apex.model.basicmodel.dao.ApexDao#size(java.lang.Class) */ @Override - public <T extends AxConcept> long size(final Class<T> aClass) { - if (aClass == null) { + public <T extends AxConcept> long size(final Class<T> someClass) { + if (someClass == null) { return 0; } final EntityManager mg = getEntityManager(); long size = 0; try { - size = mg.createQuery("SELECT COUNT(c) FROM " + aClass.getSimpleName() + " c", Long.class) - .getSingleResult(); + size = mg.createQuery("SELECT COUNT(c) FROM " + someClass.getSimpleName() + " c", Long.class) + .getSingleResult(); } finally { mg.close(); } |