Skip to content

Package: ConnectionWrapper

ConnectionWrapper

nameinstructionbranchcomplexitylinemethod
ConnectionWrapper(Connection)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
close()
M: 6 C: 5
45%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 3
60%
M: 0 C: 1
100%
commit()
M: 6 C: 8
57%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 4
67%
M: 0 C: 1
100%
contains(Object, Class, Descriptor)
M: 0 C: 17
100%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 2
100%
M: 0 C: 1
100%
createStatement()
M: 6 C: 4
40%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 1
33%
M: 0 C: 1
100%
find(LoadingParameters)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getContexts()
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getPrimaryKeyAsUri(Object)
M: 0 C: 7
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
isConsistent(URI)
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
loadFieldValue(Object, Field, Descriptor)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
merge(Object, Field, Descriptor)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
persist(Object, Object, Descriptor)
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
remove(Object, Class, Descriptor)
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
rollback()
M: 6 C: 5
45%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 3
60%
M: 0 C: 1
100%
setUnitOfWork(UnitOfWorkImpl)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%

Coverage

1: /**
2: * Copyright (C) 2011 Czech Technical University in Prague
3: *
4: * This program is free software: you can redistribute it and/or modify it under
5: * the terms of the GNU General Public License as published by the Free Software
6: * Foundation, either version 3 of the License, or (at your option) any
7: * later version.
8: *
9: * This program is distributed in the hope that it will be useful, but WITHOUT
10: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12: * details. You should have received a copy of the GNU General Public License
13: * along with this program. If not, see <http://www.gnu.org/licenses/>.
14: */
15: package cz.cvut.kbss.jopa.sessions;
16:
17: import cz.cvut.kbss.jopa.exceptions.OWLPersistenceException;
18: import cz.cvut.kbss.jopa.model.descriptors.Descriptor;
19: import cz.cvut.kbss.jopa.oom.ObjectOntologyMapper;
20: import cz.cvut.kbss.jopa.oom.ObjectOntologyMapperImpl;
21: import cz.cvut.kbss.jopa.utils.EntityPropertiesUtils;
22: import cz.cvut.kbss.ontodriver.Connection;
23: import cz.cvut.kbss.ontodriver.Statement;
24: import cz.cvut.kbss.ontodriver.exception.OntoDriverException;
25:
26: import java.lang.reflect.Field;
27: import java.net.URI;
28: import java.util.List;
29:
30: public class ConnectionWrapper {
31:
32: private final Connection connection;
33: private ObjectOntologyMapper mapper;
34:
35: public ConnectionWrapper(Connection connection) {
36: this.connection = connection;
37: }
38:
39: void setUnitOfWork(UnitOfWorkImpl uow) {
40: this.mapper = new ObjectOntologyMapperImpl(uow, connection);
41: }
42:
43: <T> boolean contains(Object primaryKey, Class<T> cls, Descriptor descriptor) {
44: final URI pkUri = getPrimaryKeyAsUri(primaryKey);
45:• return pkUri != null && mapper.containsEntity(cls, pkUri, descriptor);
46: }
47:
48: <T> T find(LoadingParameters<T> loadingParameters) {
49: return mapper.loadEntity(loadingParameters);
50: }
51:
52: <T> void merge(T entity, Field field, Descriptor descriptor) {
53: mapper.updateFieldValue(entity, field, descriptor);
54: }
55:
56: <T> void persist(Object primaryKey, T entity, Descriptor descriptor) {
57: final URI pkUri = getPrimaryKeyAsUri(primaryKey);
58: mapper.persistEntity(pkUri, entity, descriptor);
59: }
60:
61: <T> void remove(Object primaryKey, Class<T> cls, Descriptor descriptor) {
62: final URI pkUri = getPrimaryKeyAsUri(primaryKey);
63: mapper.removeEntity(pkUri, cls, descriptor);
64: }
65:
66: <T> void loadFieldValue(T entity, Field field, Descriptor descriptor) {
67: mapper.loadFieldValue(entity, field, descriptor);
68: }
69:
70: void commit() {
71: try {
72: mapper.checkForUnpersistedChanges();
73: connection.commit();
74: } catch (OntoDriverException e) {
75: throw new OWLPersistenceException(e);
76: }
77: }
78:
79: void rollback() {
80: try {
81: connection.rollback();
82: } catch (OntoDriverException e) {
83: throw new OWLPersistenceException(e);
84: }
85: }
86:
87: void close() {
88: try {
89: connection.close();
90: } catch (Exception e) {
91: throw new OWLPersistenceException(e);
92: }
93: }
94:
95: boolean isConsistent(URI context) {
96: try {
97: return connection.isConsistent(context);
98: } catch (OntoDriverException e) {
99: throw new OWLPersistenceException(e);
100: }
101: }
102:
103: List<URI> getContexts() {
104: try {
105: return connection.getContexts();
106: } catch (OntoDriverException e) {
107: throw new OWLPersistenceException(e);
108: }
109: }
110:
111: public Statement createStatement() {
112: try {
113: return connection.createStatement();
114: } catch (OntoDriverException e) {
115: throw new OWLPersistenceException(e);
116: }
117: }
118:
119: private URI getPrimaryKeyAsUri(Object primaryKey) {
120:• return primaryKey == null ? null : EntityPropertiesUtils.getValueAsURI(primaryKey);
121: }
122: }