1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.portals.graffito.jcr.persistence.collectionconverter.impl; |
18 |
|
|
19 |
|
import java.util.Map; |
20 |
|
|
21 |
|
import javax.jcr.ItemExistsException; |
22 |
|
import javax.jcr.Node; |
23 |
|
import javax.jcr.PathNotFoundException; |
24 |
|
import javax.jcr.RepositoryException; |
25 |
|
import javax.jcr.Session; |
26 |
|
import javax.jcr.lock.LockException; |
27 |
|
import javax.jcr.nodetype.ConstraintViolationException; |
28 |
|
import javax.jcr.version.VersionException; |
29 |
|
|
30 |
|
import org.apache.portals.graffito.jcr.exception.JcrMappingException; |
31 |
|
import org.apache.portals.graffito.jcr.exception.PersistenceException; |
32 |
|
import org.apache.portals.graffito.jcr.mapper.Mapper; |
33 |
|
import org.apache.portals.graffito.jcr.mapper.model.CollectionDescriptor; |
34 |
|
import org.apache.portals.graffito.jcr.persistence.collectionconverter.CollectionConverter; |
35 |
|
import org.apache.portals.graffito.jcr.persistence.collectionconverter.ManageableCollection; |
36 |
|
import org.apache.portals.graffito.jcr.persistence.objectconverter.ObjectConverter; |
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
public abstract class AbstractCollectionConverterImpl implements CollectionConverter { |
45 |
|
protected Map atomicTypeConverters; |
46 |
|
protected ObjectConverter objectConverter; |
47 |
|
|
48 |
|
protected Mapper mapper; |
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
public AbstractCollectionConverterImpl(Map atomicTypeConverters, |
58 |
|
ObjectConverter objectConverter, |
59 |
0 |
Mapper mapper) { |
60 |
0 |
this.atomicTypeConverters = atomicTypeConverters; |
61 |
0 |
this.objectConverter = objectConverter; |
62 |
0 |
this.mapper = mapper; |
63 |
0 |
} |
64 |
|
|
65 |
|
protected abstract void doInsertCollection(Session session, |
66 |
|
Node parentNode, |
67 |
|
CollectionDescriptor descriptor, |
68 |
|
ManageableCollection collection) throws RepositoryException; |
69 |
|
|
70 |
|
protected abstract void doUpdateCollection(Session session, |
71 |
|
Node parentNode, |
72 |
|
CollectionDescriptor descriptor, |
73 |
|
ManageableCollection collection) throws RepositoryException; |
74 |
|
|
75 |
|
protected abstract ManageableCollection doGetCollection(Session session, |
76 |
|
Node parentNode, |
77 |
|
CollectionDescriptor collectionDescriptor, |
78 |
|
Class collectionFieldClass) throws RepositoryException; |
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
public void insertCollection(Session session, |
84 |
|
Node parentNode, |
85 |
|
CollectionDescriptor collectionDescriptor, |
86 |
|
ManageableCollection collection) { |
87 |
|
try { |
88 |
0 |
doInsertCollection(session, parentNode, collectionDescriptor, collection); |
89 |
|
} |
90 |
0 |
catch(ItemExistsException iee) { |
91 |
0 |
throw new PersistenceException("Cannot insert collection field : " |
92 |
|
+ collectionDescriptor.getFieldName() + " of class " |
93 |
|
+ collectionDescriptor.getClassDescriptor().getClassName() |
94 |
|
+ ". An item already exists.", iee); |
95 |
|
} |
96 |
0 |
catch(PathNotFoundException pnfe) { |
97 |
0 |
throw new PersistenceException("Cannot insert collection field : " |
98 |
|
+ collectionDescriptor.getFieldName() |
99 |
|
+ " of class " |
100 |
|
+ collectionDescriptor.getClassDescriptor().getClassName(), pnfe); |
101 |
|
} |
102 |
0 |
catch(VersionException ve) { |
103 |
0 |
throw new PersistenceException("Cannot insert collection field : " |
104 |
|
+ collectionDescriptor.getFieldName() |
105 |
|
+ " of class " |
106 |
|
+ collectionDescriptor.getClassDescriptor().getClassName(), ve); |
107 |
|
} |
108 |
0 |
catch(ConstraintViolationException cve) { |
109 |
0 |
throw new PersistenceException("Cannot insert collection field : " |
110 |
|
+ collectionDescriptor.getFieldName() |
111 |
|
+ " of class " |
112 |
|
+ collectionDescriptor.getClassDescriptor().getClassName() |
113 |
|
+ ". Constraint violation.", cve); |
114 |
|
} |
115 |
0 |
catch(LockException le) { |
116 |
0 |
throw new PersistenceException("Cannot insert collection field : " |
117 |
|
+ collectionDescriptor.getFieldName() |
118 |
|
+ " of class " |
119 |
|
+ collectionDescriptor.getClassDescriptor().getClassName() |
120 |
|
+ " on locked parent.", le); |
121 |
|
} |
122 |
0 |
catch(RepositoryException re) { |
123 |
0 |
throw new org.apache.portals.graffito.jcr.exception.RepositoryException( |
124 |
|
"Cannot insert collection field : " |
125 |
|
+ collectionDescriptor.getFieldName() |
126 |
|
+ " of class " |
127 |
|
+ collectionDescriptor.getClassDescriptor().getClassName(), re); |
128 |
0 |
} |
129 |
0 |
} |
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
public void updateCollection(Session session, |
136 |
|
Node parentNode, |
137 |
|
CollectionDescriptor collectionDescriptor, |
138 |
|
ManageableCollection collection) { |
139 |
|
try { |
140 |
0 |
doUpdateCollection(session, parentNode, collectionDescriptor, collection); |
141 |
|
} |
142 |
0 |
catch(VersionException ve) { |
143 |
0 |
throw new PersistenceException("Cannot insert collection field : " |
144 |
|
+ collectionDescriptor.getFieldName() |
145 |
|
+ " of class " |
146 |
|
+ collectionDescriptor.getClassDescriptor().getClassName(), |
147 |
|
ve); |
148 |
|
} |
149 |
0 |
catch(LockException le) { |
150 |
0 |
throw new PersistenceException("Cannot insert collection field : " |
151 |
|
+ collectionDescriptor.getFieldName() |
152 |
|
+ " of class " |
153 |
|
+ collectionDescriptor.getClassDescriptor().getClassName() |
154 |
|
+ " on locked node", |
155 |
|
le); |
156 |
|
} |
157 |
0 |
catch(ConstraintViolationException cve) { |
158 |
0 |
throw new PersistenceException("Cannot insert collection field : " |
159 |
|
+ collectionDescriptor.getFieldName() |
160 |
|
+ " of class " |
161 |
|
+ collectionDescriptor.getClassDescriptor().getClassName() |
162 |
|
+ " Constraint violation.", |
163 |
|
cve); |
164 |
|
} |
165 |
0 |
catch(RepositoryException re) { |
166 |
0 |
throw new org.apache.portals.graffito.jcr.exception.RepositoryException( |
167 |
|
"Cannot insert collection field : " |
168 |
|
+ collectionDescriptor.getFieldName() |
169 |
|
+ " of class " |
170 |
|
+ collectionDescriptor.getClassDescriptor().getClassName(), |
171 |
|
re); |
172 |
0 |
} |
173 |
0 |
} |
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
|
178 |
|
public ManageableCollection getCollection(Session session, |
179 |
|
Node parentNode, |
180 |
|
CollectionDescriptor collectionDescriptor, |
181 |
|
Class collectionFieldClass) { |
182 |
|
try { |
183 |
0 |
return doGetCollection(session, parentNode, collectionDescriptor, collectionFieldClass); |
184 |
|
} |
185 |
0 |
catch(RepositoryException re) { |
186 |
0 |
throw new org.apache.portals.graffito.jcr.exception.RepositoryException( |
187 |
|
"Cannot get collection field : " + collectionDescriptor.getFieldName() |
188 |
|
+ "for " + collectionDescriptor.getClassDescriptor().getClassName(), |
189 |
|
re); |
190 |
|
} |
191 |
|
} |
192 |
|
|
193 |
|
protected String getCollectionJcrName(CollectionDescriptor descriptor) { |
194 |
0 |
String jcrName = descriptor.getJcrName(); |
195 |
|
|
196 |
0 |
if (null == jcrName) { |
197 |
0 |
throw new JcrMappingException("The JcrName attribute is not defined for the CollectionDescriptor : " |
198 |
|
+ descriptor.getFieldName()); |
199 |
|
} |
200 |
|
|
201 |
0 |
return jcrName; |
202 |
|
} |
203 |
|
} |