initial public commit
This commit is contained in:
@ -0,0 +1,149 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* system-group-impl
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2021 EmDev LLC
|
||||
* ==========
|
||||
* 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.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.esb.system.groups.registry.jpa.impl;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import ru.entaxy.esb.system.groups.registry.jpa.SystemGroupRegistryService;
|
||||
import ru.entaxy.esb.system.groups.registry.jpa.entity.SystemGroupRegistry;
|
||||
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Root;
|
||||
import javax.transaction.Transactional;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Implementation of the SystemGroupRegistry service using the JPA entity manager service (provided by Karaf).
|
||||
*/
|
||||
@Transactional
|
||||
public class SystemGroupRegistryServiceImpl implements SystemGroupRegistryService {
|
||||
|
||||
private SessionFactory sessionFactory;
|
||||
|
||||
public void setSessionFactory(SessionFactory sessionFactory) {
|
||||
this.sessionFactory = sessionFactory;
|
||||
}
|
||||
|
||||
public Session getSession() {
|
||||
return sessionFactory.openSession();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SystemGroupRegistry> list() {
|
||||
List<SystemGroupRegistry> list;
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
CriteriaQuery<SystemGroupRegistry> cq = s.getCriteriaBuilder().createQuery(SystemGroupRegistry.class);
|
||||
cq.from(SystemGroupRegistry.class);
|
||||
list = s.createQuery(cq).getResultList();
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SystemGroupRegistry get(long id) {
|
||||
SystemGroupRegistry systemGroupRegistry;
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
|
||||
CriteriaBuilder builder = s.getCriteriaBuilder();
|
||||
CriteriaQuery<SystemGroupRegistry> criteriaQuery = builder.createQuery(SystemGroupRegistry.class);
|
||||
Root<SystemGroupRegistry> root = criteriaQuery.from(SystemGroupRegistry.class);
|
||||
criteriaQuery.where(builder.equal(root.get("id"), id));
|
||||
systemGroupRegistry = s.createQuery(criteriaQuery).getSingleResult();
|
||||
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
return systemGroupRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SystemGroupRegistry getByUuid(String uuid) {
|
||||
SystemGroupRegistry systemGroupRegistry;
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
|
||||
CriteriaBuilder builder = s.getCriteriaBuilder();
|
||||
CriteriaQuery<SystemGroupRegistry> criteriaQuery = builder.createQuery(SystemGroupRegistry.class);
|
||||
Root<SystemGroupRegistry> root = criteriaQuery.from(SystemGroupRegistry.class);
|
||||
criteriaQuery.where(builder.equal(root.get("uuid"), uuid));
|
||||
systemGroupRegistry = s.createQuery(criteriaQuery).getSingleResult();
|
||||
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
return systemGroupRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SystemGroupRegistry add(SystemGroupRegistry systemGroupRegistry) {
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
s.persist(systemGroupRegistry);
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
return systemGroupRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SystemGroupRegistry add(String uuid, String name, String description, Date createDate, Date editDate,
|
||||
String createdBy, String editedBy, double version, String type, String connectorId,
|
||||
String descriptionFileUrl, String endpointName, String address, String responseType) {
|
||||
SystemGroupRegistry systemGroupRegistry = new SystemGroupRegistry();
|
||||
systemGroupRegistry.setUuid(uuid);
|
||||
systemGroupRegistry.setName(name);
|
||||
systemGroupRegistry.setDescription(description);
|
||||
systemGroupRegistry.setCreateDate(createDate);
|
||||
systemGroupRegistry.setEditDate(editDate);
|
||||
systemGroupRegistry.setCreatedBy(createdBy);
|
||||
systemGroupRegistry.setVersion(version);
|
||||
systemGroupRegistry.setType(type);
|
||||
systemGroupRegistry.setConnectorId(connectorId);
|
||||
systemGroupRegistry.setDescriptionFileUrl(descriptionFileUrl);
|
||||
systemGroupRegistry.setEndpointName(endpointName);
|
||||
systemGroupRegistry.setAddress(address);
|
||||
systemGroupRegistry.setResponseType(responseType);
|
||||
|
||||
add(systemGroupRegistry);
|
||||
|
||||
return systemGroupRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(long id) {
|
||||
try (Session s = getSession()) {
|
||||
s.getTransaction().begin();
|
||||
|
||||
SystemGroupRegistry systemGroupRegistry = get(id);
|
||||
s.delete(SystemGroupRegistry.class.getName(), systemGroupRegistry);
|
||||
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~~~~~~licensing~~~~~~
|
||||
system-group-impl
|
||||
==========
|
||||
Copyright (C) 2020 - 2021 EmDev LLC
|
||||
==========
|
||||
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.
|
||||
~~~~~~/licensing~~~~~~
|
||||
-->
|
||||
|
||||
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
|
||||
xmlns:jpa="http://aries.apache.org/xmlns/jpa/v2.0.0"
|
||||
xmlns:tx="http://aries.apache.org/xmlns/transactions/v1.2.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
|
||||
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 https://osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
|
||||
|
||||
<jpa:enable/>
|
||||
<tx:enable-annotations/>
|
||||
|
||||
<cm:property-placeholder persistent-id="ru.entaxy.esb" update-strategy="reload">
|
||||
<cm:default-properties>
|
||||
</cm:default-properties>
|
||||
</cm:property-placeholder>
|
||||
|
||||
<reference id="sessionFactory"
|
||||
interface="org.hibernate.SessionFactory"
|
||||
timeout="30000"/>
|
||||
|
||||
<bean id="nsiResponseService" class="ru.entaxy.esb.system.groups.registry.jpa.impl.SystemGroupRegistryServiceImpl">
|
||||
<property name="sessionFactory" ref="sessionFactory"/>
|
||||
</bean>
|
||||
|
||||
<camelContext id="test-system-group-component"
|
||||
xmlns="http://camel.apache.org/schema/blueprint">
|
||||
|
||||
<route id="list" autoStartup="true">
|
||||
<from uri="timer:foo?period=5000&repeatCount=1"/>
|
||||
<log message=">>>>> TEST" loggingLevel="INFO"/>
|
||||
|
||||
<setBody>
|
||||
<simple>Hello!</simple>
|
||||
</setBody>
|
||||
|
||||
<doTry>
|
||||
<to uri="system-group:default?preferredConnector=default"/>
|
||||
<doCatch>
|
||||
<exception>ProfileNotFound</exception>
|
||||
<log message="${exception.stacktrace}" loggingLevel="ERROR"/>
|
||||
</doCatch>
|
||||
</doTry>
|
||||
</route>
|
||||
</camelContext>
|
||||
</blueprint>
|
@ -0,0 +1,40 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<!--
|
||||
~~~~~~licensing~~~~~~
|
||||
system-group-impl
|
||||
==========
|
||||
Copyright (C) 2020 - 2021 EmDev LLC
|
||||
==========
|
||||
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.
|
||||
~~~~~~/licensing~~~~~~
|
||||
-->
|
||||
|
||||
<!DOCTYPE hibernate-configuration PUBLIC
|
||||
"-//Hibernate/Hibernate Configuration DTD//EN"
|
||||
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
|
||||
|
||||
<hibernate-configuration>
|
||||
<session-factory>
|
||||
<property name="connection.datasource">osgi:service/entaxy.esb.storage</property>
|
||||
<property name="hibernate.hbm2ddl.auto">validate</property>
|
||||
|
||||
<property name="hibernate.enable_lazy_load_no_trans">true</property>
|
||||
|
||||
<property name="show_sql">${hibernate.show_sql}</property>
|
||||
<property name="format_sql">${hibernate.format_sql}</property>
|
||||
|
||||
<mapping class="ru.entaxy.esb.system.groups.registry.jpa.entity.SystemGroupRegistry"/>
|
||||
<mapping class="ru.entaxy.esb.system.groups.registry.jpa.entity.SystemGroupMethodRegistry"/>
|
||||
</session-factory>
|
||||
|
||||
</hibernate-configuration>
|
Reference in New Issue
Block a user