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%
unwrap(Class)
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%

Coverage

1: /**
2: * Copyright (C) 2016 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.jopa.utils.Wrapper;
23: import cz.cvut.kbss.ontodriver.Connection;
24: import cz.cvut.kbss.ontodriver.Statement;
25: import cz.cvut.kbss.ontodriver.exception.OntoDriverException;
26:
27: import java.lang.reflect.Field;
28: import java.net.URI;
29: import java.util.List;
30:
31: public class ConnectionWrapper implements Wrapper {
32:
33: private final Connection connection;
34: private ObjectOntologyMapper mapper;
35:
36: public ConnectionWrapper(Connection connection) {
37: this.connection = connection;
38: }
39:
40: void setUnitOfWork(UnitOfWorkImpl uow) {
41: this.mapper = new ObjectOntologyMapperImpl(uow, connection);
42: }
43:
44: <T> boolean contains(Object primaryKey, Class<T> cls, Descriptor descriptor) {
45: final URI pkUri = getPrimaryKeyAsUri(primaryKey);
46:• return pkUri != null && mapper.containsEntity(cls, pkUri, descriptor);
47: }
48:
49: <T> T find(LoadingParameters<T> loadingParameters) {
50: return mapper.loadEntity(loadingParameters);
51: }
52:
53: <T> void merge(T entity, Field field, Descriptor descriptor) {
54: mapper.updateFieldValue(entity, field, descriptor);
55: }
56:
57: <T> void persist(Object primaryKey, T entity, Descriptor descriptor) {
58: final URI pkUri = getPrimaryKeyAsUri(primaryKey);
59: mapper.persistEntity(pkUri, entity, descriptor);
60: }
61:
62: <T> void remove(Object primaryKey, Class<T> cls, Descriptor descriptor) {
63: final URI pkUri = getPrimaryKeyAsUri(primaryKey);
64: mapper.removeEntity(pkUri, cls, descriptor);
65: }
66:
67: <T> void loadFieldValue(T entity, Field field, Descriptor descriptor) {
68: mapper.loadFieldValue(entity, field, descriptor);
69: }
70:
71: void commit() {
72: try {
73: mapper.checkForUnpersistedChanges();
74: connection.commit();
75: } catch (OntoDriverException e) {
76: throw new OWLPersistenceException(e);
77: }
78: }
79:
80: void rollback() {
81: try {
82: connection.rollback();
83: } catch (OntoDriverException e) {
84: throw new OWLPersistenceException(e);
85: }
86: }
87:
88: void close() {
89: try {
90: connection.close();
91: } catch (Exception e) {
92: throw new OWLPersistenceException(e);
93: }
94: }
95:
96: boolean isConsistent(URI context) {
97: try {
98: return connection.isConsistent(context);
99: } catch (OntoDriverException e) {
100: throw new OWLPersistenceException(e);
101: }
102: }
103:
104: List<URI> getContexts() {
105: try {
106: return connection.getContexts();
107: } catch (OntoDriverException e) {
108: throw new OWLPersistenceException(e);
109: }
110: }
111:
112: public Statement createStatement() {
113: try {
114: return connection.createStatement();
115: } catch (OntoDriverException e) {
116: throw new OWLPersistenceException(e);
117: }
118: }
119:
120: private URI getPrimaryKeyAsUri(Object primaryKey) {
121:• return primaryKey == null ? null : EntityPropertiesUtils.getValueAsURI(primaryKey);
122: }
123:
124: @Override
125: public <T> T unwrap(Class<T> cls) {
126: try {
127: return connection.unwrap(cls);
128: } catch (OntoDriverException e) {
129: throw new OWLPersistenceException(e);
130: }
131: }
132: }