diff options
author | liamfallon <liam.fallon@est.tech> | 2019-04-10 16:18:43 +0000 |
---|---|---|
committer | liamfallon <liam.fallon@est.tech> | 2019-04-10 16:18:43 +0000 |
commit | 5f3e975966a0eaa247ee0eac0148da2f8755e777 (patch) | |
tree | 6061d6b50c27ff0981618127740ec59a39fce046 /plugins/plugins-persistence/plugins-persistence-jpa/plugins-persistence-jpa-hibernate/src/main/java | |
parent | 4e55d4e186ce4dfdcd49f992841a52abe1b62369 (diff) |
Remove hibernate from apex
Issue-ID: POLICY-1368
Change-Id: I67f448fc9d89eef4829cd6f999f5c21ac8ebff12
Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'plugins/plugins-persistence/plugins-persistence-jpa/plugins-persistence-jpa-hibernate/src/main/java')
2 files changed, 0 insertions, 303 deletions
diff --git a/plugins/plugins-persistence/plugins-persistence-jpa/plugins-persistence-jpa-hibernate/src/main/java/org/onap/policy/apex/plugins/persistence/jpa/hibernate/HibernateApexDao.java b/plugins/plugins-persistence/plugins-persistence-jpa/plugins-persistence-jpa-hibernate/src/main/java/org/onap/policy/apex/plugins/persistence/jpa/hibernate/HibernateApexDao.java deleted file mode 100644 index 19ad01054..000000000 --- a/plugins/plugins-persistence/plugins-persistence-jpa/plugins-persistence-jpa-hibernate/src/main/java/org/onap/policy/apex/plugins/persistence/jpa/hibernate/HibernateApexDao.java +++ /dev/null @@ -1,275 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.plugins.persistence.jpa.hibernate; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import javax.persistence.EntityManager; - -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.impl.DefaultApexDao; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -/** - * The Class HibernateApexDao is the Hibernate JPA implementation of the Apex DAO. - * - * @author Sergey Sachkov (sergey.sachkov@ericsson.com) - */ -public class HibernateApexDao extends DefaultApexDao { - private static final XLogger LOGGER = XLoggerFactory.getXLogger(HibernateApexDao.class); - - private static final String FROM = "FROM "; - private static final String DELETE_FROM = "DELETE FROM "; - private static final String WHERE_KEY_NAME = " WHERE key.name='"; - private static final String AND_KEY_VERSION = "' AND key.version='"; - private static final String WHERE_KEY_PARENT_KEY_NAME = " WHERE key.parentKeyName='"; - private static final String AND_KEY_PARENT_KEY_VERSION = "' AND key.parentKeyVersion='"; - private static final String AND_KEY_LOCAL_NAME = "' AND key.localName='"; - - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.model.basicmodel.dao.impl.DefaultApexDao#delete(java.lang.Class, - * org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey) - */ - @Override - public <T extends AxConcept> void delete(final Class<T> clazz, final AxArtifactKey key) { - if (key == null) { - return; - } - final EntityManager mg = getEntityManager(); - try { - mg.getTransaction().begin(); - mg.createQuery(DELETE_FROM + clazz.getSimpleName() + WHERE_KEY_NAME + key.getName() + AND_KEY_VERSION - + key.getVersion() + "'").executeUpdate(); - mg.getTransaction().commit(); - } finally { - mg.close(); - } - } - - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.model.basicmodel.dao.impl.DefaultApexDao#delete(java.lang.Class, - * org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey) - */ - @Override - public <T extends AxConcept> void delete(final Class<T> clazz, final AxReferenceKey key) { - if (key == null) { - return; - } - final EntityManager mg = getEntityManager(); - try { - mg.getTransaction().begin(); - mg.createQuery(DELETE_FROM + clazz.getSimpleName() + WHERE_KEY_PARENT_KEY_NAME + key.getParentKeyName() - + AND_KEY_PARENT_KEY_VERSION + key.getParentKeyVersion() + AND_KEY_LOCAL_NAME - + key.getLocalName() + "'").executeUpdate(); - mg.getTransaction().commit(); - } finally { - mg.close(); - } - } - - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.model.basicmodel.dao.impl.DefaultApexDao#deleteByArtifactKey(java.lang.Class, - * java.util.Collection) - */ - @Override - public <T extends AxConcept> int deleteByArtifactKey(final Class<T> clazz, final Collection<AxArtifactKey> keys) { - if (keys == null || keys.isEmpty()) { - return 0; - } - int deletedCount = 0; - final EntityManager mg = getEntityManager(); - try { - mg.getTransaction().begin(); - for (final AxArtifactKey key : keys) { - deletedCount += mg.createQuery(DELETE_FROM + clazz.getSimpleName() + WHERE_KEY_NAME + key.getName() - + AND_KEY_VERSION + key.getVersion() + "'").executeUpdate(); - } - mg.getTransaction().commit(); - } finally { - mg.close(); - } - return deletedCount; - } - - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.core.model.dao.ApexDao#deleteByContextUsageKey(java.lang.Class, java.util.Collection) - */ - @Override - public <T extends AxConcept> int deleteByReferenceKey(final Class<T> clazz, final Collection<AxReferenceKey> keys) { - if (keys == null || keys.isEmpty()) { - return 0; - } - int deletedCount = 0; - final EntityManager mg = getEntityManager(); - try { - mg.getTransaction().begin(); - for (final AxReferenceKey key : keys) { - deletedCount += mg.createQuery(DELETE_FROM + clazz.getSimpleName() + WHERE_KEY_PARENT_KEY_NAME - + key.getParentKeyName() + AND_KEY_PARENT_KEY_VERSION + key.getParentKeyVersion() - + AND_KEY_LOCAL_NAME + key.getLocalName() + "'").executeUpdate(); - } - mg.getTransaction().commit(); - } finally { - mg.close(); - } - return deletedCount; - } - - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.core.model.dao.ApexDao#deleteAll(java.lang.Class) - */ - @Override - public <T extends AxConcept> void deleteAll(final Class<T> clazz) { - final EntityManager mg = getEntityManager(); - try { - mg.getTransaction().begin(); - mg.createQuery(DELETE_FROM + clazz.getSimpleName()).executeUpdate(); - mg.getTransaction().commit(); - } finally { - mg.close(); - } - } - - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.core.model.dao.ApexDao#getAll(java.lang.Class) - */ - @Override - public <T extends AxConcept> List<T> getAll(final Class<T> clazz) { - if (clazz == null) { - return Collections.emptyList(); - } - final EntityManager mg = getEntityManager(); - try { - final List<T> result = mg.createQuery(FROM + clazz.getSimpleName(), clazz).getResultList(); - final List<T> cloneResult = new ArrayList<>(); - for (final T t : result) { - try { - final T clonedT = clazz.newInstance(); - t.copyTo(clonedT); - cloneResult.add(clonedT); - } catch (final Exception e) { - LOGGER.warn("Could not clone object of class \"" + clazz.getCanonicalName() + "\"", e); - return cloneResult; - } - } - return cloneResult; - } finally { - mg.close(); - } - } - - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.core.model.dao.ApexDao#getAll(java.lang.Class, - * org.onap.policy.apex.core.model.concepts.AxArtifactKey) - */ - @Override - public <T extends AxConcept> List<T> getAll(final Class<T> clazz, final AxArtifactKey parentKey) { - if (clazz == null) { - return Collections.emptyList(); - } - final EntityManager mg = getEntityManager(); - try { - return mg.createQuery(FROM + clazz.getSimpleName() + WHERE_KEY_PARENT_KEY_NAME + parentKey.getName() - + AND_KEY_PARENT_KEY_VERSION + parentKey.getVersion() + "'", clazz).getResultList(); - } finally { - mg.close(); - } - } - - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.core.model.dao.ApexDao#getArtifact(java.lang.Class, - * org.onap.policy.apex.core.model.concepts.AxArtifactKey) - */ - @Override - public <T extends AxConcept> T getArtifact(final Class<T> clazz, final AxArtifactKey key) { - if (clazz == null || key == null) { - return null; - } - final EntityManager mg = getEntityManager(); - List<T> ret; - try { - ret = mg.createQuery(FROM + clazz.getSimpleName() + WHERE_KEY_NAME + key.getName() + AND_KEY_VERSION - + key.getVersion() + "'", clazz).getResultList(); - } finally { - mg.close(); - } - if (ret == null || ret.isEmpty()) { - return null; - } - if (ret.size() > 1) { - throw new IllegalArgumentException("More than one result was returned for search for " + clazz - + " with key " + key.getId() + ": " + ret); - } - return ret.get(0); - } - - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.core.model.dao.ApexDao#getArtifact(java.lang.Class, - * org.onap.policy.apex.core.model.concepts.AxReferenceKey) - */ - @Override - public <T extends AxConcept> T getArtifact(final Class<T> clazz, final AxReferenceKey key) { - if (clazz == null || key == null) { - return null; - } - final EntityManager mg = getEntityManager(); - List<T> ret; - try { - ret = mg.createQuery(FROM + clazz.getSimpleName() + WHERE_KEY_PARENT_KEY_NAME + key.getParentKeyName() - + AND_KEY_PARENT_KEY_VERSION + key.getParentKeyVersion() + AND_KEY_LOCAL_NAME - + key.getLocalName() + "'", clazz).getResultList(); - } finally { - mg.close(); - } - if (ret == null || ret.isEmpty()) { - return null; - } - if (ret.size() > 1) { - throw new IllegalArgumentException("More than one result was returned for search for " + clazz - + " with key " + key.getId() + ": " + ret); - } - return ret.get(0); - } -} diff --git a/plugins/plugins-persistence/plugins-persistence-jpa/plugins-persistence-jpa-hibernate/src/main/java/org/onap/policy/apex/plugins/persistence/jpa/hibernate/package-info.java b/plugins/plugins-persistence/plugins-persistence-jpa/plugins-persistence-jpa-hibernate/src/main/java/org/onap/policy/apex/plugins/persistence/jpa/hibernate/package-info.java deleted file mode 100644 index 036d45d5d..000000000 --- a/plugins/plugins-persistence/plugins-persistence-jpa/plugins-persistence-jpa-hibernate/src/main/java/org/onap/policy/apex/plugins/persistence/jpa/hibernate/package-info.java +++ /dev/null @@ -1,28 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -/** - * Provides the <a href="http://hibernate.org/">Hibernate</a> implementation on the APEX DAO for persistence over - * <a href="https://en.wikipedia.org/wiki/Java_Database_Connectivity">JDBC</a>. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ - -package org.onap.policy.apex.plugins.persistence.jpa.hibernate; |