1 | // SECTION-START[License Header] |
2 | // <editor-fold defaultstate="collapsed" desc=" Generated License "> |
3 | /* |
4 | * Copyright (c) 2010 The JOMC Project |
5 | * Copyright (c) 2005 Christian Schulte <schulte2005@users.sourceforge.net> |
6 | * All rights reserved. |
7 | * |
8 | * Redistribution and use in source and binary forms, with or without |
9 | * modification, are permitted provided that the following conditions |
10 | * are met: |
11 | * |
12 | * o Redistributions of source code must retain the above copyright |
13 | * notice, this list of conditions and the following disclaimer. |
14 | * |
15 | * o Redistributions in binary form must reproduce the above copyright |
16 | * notice, this list of conditions and the following disclaimer in |
17 | * the documentation and/or other materials provided with the |
18 | * distribution. |
19 | * |
20 | * THIS SOFTWARE IS PROVIDED BY THE JOMC PROJECT AND CONTRIBUTORS "AS IS" |
21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
22 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE JOMC PROJECT OR |
24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
27 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
28 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
30 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
31 | * |
32 | * $Id: DefaultSequenceDirectory.java 2247 2010-06-29 08:01:42Z schulte2005 $ |
33 | * |
34 | */ |
35 | // </editor-fold> |
36 | // SECTION-END |
37 | package org.jomc.sequences.ri; |
38 | |
39 | import java.math.BigInteger; |
40 | import java.util.Calendar; |
41 | import java.util.HashSet; |
42 | import java.util.List; |
43 | import java.util.Set; |
44 | import javax.persistence.NoResultException; |
45 | import javax.persistence.Query; |
46 | import org.jomc.sequences.CapacityLimitException; |
47 | import org.jomc.sequences.ConcurrentModificationException; |
48 | import org.jomc.sequences.SequenceExistsException; |
49 | import org.jomc.sequences.SequenceVetoException; |
50 | import org.jomc.sequences.Sequence; |
51 | import org.jomc.sequences.SequenceChangeEvent; |
52 | import org.jomc.sequences.SequenceChangeListener; |
53 | import org.jomc.sequences.SequenceDirectory; |
54 | import org.jomc.sequences.SequenceLimitException; |
55 | import org.jomc.sequences.SequenceNotFoundException; |
56 | import org.jomc.sequences.SequenceOperations; |
57 | import org.jomc.sequences.SequencesSystemException; |
58 | import org.jomc.sequences.VetoableSequenceChangeListener; |
59 | import org.jomc.sequences.model.SequenceType; |
60 | import org.jomc.sequences.model.SequencesType; |
61 | |
62 | // SECTION-START[Documentation] |
63 | // <editor-fold defaultstate="collapsed" desc=" Generated Documentation "> |
64 | /** |
65 | * SequenceDirectory reference implementation. |
66 | * <p><b>Specifications</b><ul> |
67 | * <li>{@code 'org.jomc.sequences.SequenceDirectory'} {@code (org.jomc.sequences.SequenceDirectory)} {@code 1.0} {@code Singleton}</li> |
68 | * <li>{@code 'org.jomc.sequences.SequenceOperations'} {@code (org.jomc.sequences.SequenceOperations)} {@code 1.0} {@code Singleton}</li> |
69 | * </ul></p> |
70 | * <p><b>Properties</b><ul> |
71 | * <li>"{@link #getDefaultSequenceDirectoryCapacityLimit defaultSequenceDirectoryCapacityLimit}" |
72 | * <blockquote>Property of type {@code java.math.BigInteger}. |
73 | * <p>Default capacity limit when creating new sequence directory entities and no default value is provided otherwise.</p> |
74 | * </blockquote></li> |
75 | * <li>"{@link #getSequenceDirectoryName sequenceDirectoryName}" |
76 | * <blockquote>Property of type {@code java.lang.String}. |
77 | * <p>Name uniquely identifying the directory in a set of directories.</p> |
78 | * </blockquote></li> |
79 | * <li>"{@link #getSequenceDirectoryNameQueryParameterName sequenceDirectoryNameQueryParameterName}" |
80 | * <blockquote>Property of type {@code java.lang.String}. |
81 | * <p>Name of a JPA query parameter denoting the name of a sequence directory entity.</p> |
82 | * </blockquote></li> |
83 | * <li>"{@link #getSequenceNameQueryParameterName sequenceNameQueryParameterName}" |
84 | * <blockquote>Property of type {@code java.lang.String}. |
85 | * <p>Name of a JPA query parameter denoting the name of a sequence entity.</p> |
86 | * </blockquote></li> |
87 | * </ul></p> |
88 | * <p><b>Dependencies</b><ul> |
89 | * <li>"{@link #getEntityManager EntityManager}"<blockquote> |
90 | * Dependency on {@code 'javax.persistence.EntityManager'} {@code (javax.persistence.EntityManager)}.</blockquote></li> |
91 | * <li>"{@link #getLocale Locale}"<blockquote> |
92 | * Dependency on {@code 'java.util.Locale'} {@code (java.util.Locale)} at specification level 1.1 bound to an instance.</blockquote></li> |
93 | * <li>"{@link #getLogger Logger}"<blockquote> |
94 | * Dependency on {@code 'org.jomc.logging.Logger'} {@code (org.jomc.logging.Logger)} at specification level 1.0 bound to an instance.</blockquote></li> |
95 | * <li>"{@link #getSelectAllSequencesQuery SelectAllSequencesQuery}"<blockquote> |
96 | * Dependency on {@code 'javax.persistence.Query'} {@code (javax.persistence.Query)}.</blockquote></li> |
97 | * <li>"{@link #getSelectSequenceCountQuery SelectSequenceCountQuery}"<blockquote> |
98 | * Dependency on {@code 'javax.persistence.Query'} {@code (javax.persistence.Query)}.</blockquote></li> |
99 | * <li>"{@link #getSelectSequenceDirectoryQuery SelectSequenceDirectoryQuery}"<blockquote> |
100 | * Dependency on {@code 'javax.persistence.Query'} {@code (javax.persistence.Query)}.</blockquote></li> |
101 | * <li>"{@link #getSelectSequenceQuery SelectSequenceQuery}"<blockquote> |
102 | * Dependency on {@code 'javax.persistence.Query'} {@code (javax.persistence.Query)}.</blockquote></li> |
103 | * <li>"{@link #getSelectSequencesQuery SelectSequencesQuery}"<blockquote> |
104 | * Dependency on {@code 'javax.persistence.Query'} {@code (javax.persistence.Query)}.</blockquote></li> |
105 | * <li>"{@link #getSequenceChangeListener SequenceChangeListener}"<blockquote> |
106 | * Dependency on {@code 'org.jomc.sequences.SequenceChangeListener'} {@code (org.jomc.sequences.SequenceChangeListener)} at specification level 1.0 bound to an instance.</blockquote></li> |
107 | * <li>"{@link #getSequenceMapper SequenceMapper}"<blockquote> |
108 | * Dependency on {@code 'org.jomc.sequences.ri.SequenceMapper'} {@code (org.jomc.sequences.ri.SequenceMapper)} at specification level 1.0 bound to an instance.</blockquote></li> |
109 | * <li>"{@link #getVetoableSequenceChangeListener VetoableSequenceChangeListener}"<blockquote> |
110 | * Dependency on {@code 'org.jomc.sequences.VetoableSequenceChangeListener'} {@code (org.jomc.sequences.VetoableSequenceChangeListener)} at specification level 1.0 bound to an instance.</blockquote></li> |
111 | * </ul></p> |
112 | * <p><b>Messages</b><ul> |
113 | * <li>"{@link #getIllegalArgumentMessage illegalArgumentMessage}"<table> |
114 | * <tr><td valign="top">English:</td><td valign="top"><pre>Illegal value ''{1}'' for argument ''{0}''.</pre></td></tr> |
115 | * <tr><td valign="top">Deutsch:</td><td valign="top"><pre>Ungültiger Wert ''{1}'' für Parameter ''{0}''.</pre></td></tr> |
116 | * </table> |
117 | * <li>"{@link #getSuccessfullyCreatedSequenceDirectoryMessage successfullyCreatedSequenceDirectoryMessage}"<table> |
118 | * <tr><td valign="top">English:</td><td valign="top"><pre>Sequence directory ''{0}'' created.</pre></td></tr> |
119 | * <tr><td valign="top">Deutsch:</td><td valign="top"><pre>Sequenzverzeichnis ''{0}'' erstellt.</pre></td></tr> |
120 | * </table> |
121 | * </ul></p> |
122 | * |
123 | * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a> 1.0 |
124 | * @version $Id: DefaultSequenceDirectory.java 2247 2010-06-29 08:01:42Z schulte2005 $ |
125 | */ |
126 | // </editor-fold> |
127 | // SECTION-END |
128 | // SECTION-START[Annotations] |
129 | // <editor-fold defaultstate="collapsed" desc=" Generated Annotations "> |
130 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) |
131 | // </editor-fold> |
132 | // SECTION-END |
133 | public class DefaultSequenceDirectory |
134 | implements SequenceDirectory, SequenceOperations |
135 | { |
136 | // SECTION-START[SequenceDirectory] |
137 | |
138 | public BigInteger getSequenceCount() |
139 | { |
140 | final Query query = this.getSelectSequenceCountQuery(); |
141 | query.setParameter( this.getSequenceDirectoryNameQueryParameterName(), |
142 | this.getSequencesType( this.getSequenceDirectoryName() ).getName() ); |
143 | |
144 | return BigInteger.valueOf( ( (Long) query.getSingleResult() ).longValue() ); |
145 | } |
146 | |
147 | public BigInteger getCapacityLimit() |
148 | { |
149 | return this.getSequencesType( this.getSequenceDirectoryName() ).getCapacityLimit(); |
150 | } |
151 | |
152 | public Sequence getSequence( final String name ) |
153 | { |
154 | if ( name == null ) |
155 | { |
156 | throw new SequencesSystemException( this.getIllegalArgumentMessage( this.getLocale(), "name", null ) ); |
157 | } |
158 | |
159 | final SequenceType sequenceType = this.getSequenceType( name ); |
160 | if ( sequenceType != null ) |
161 | { |
162 | return this.getSequenceMapper().map( sequenceType, new Sequence() ); |
163 | } |
164 | |
165 | return null; |
166 | } |
167 | |
168 | public Sequence addSequence( final Sequence sequence ) |
169 | { |
170 | if ( sequence == null ) |
171 | { |
172 | throw new SequencesSystemException( this.getIllegalArgumentMessage( this.getLocale(), "sequence", null ) ); |
173 | } |
174 | |
175 | final BigInteger capacityLimit = this.getCapacityLimit(); |
176 | if ( this.getSequenceCount().compareTo( capacityLimit ) >= 0 ) |
177 | { |
178 | throw new CapacityLimitException( capacityLimit ); |
179 | } |
180 | |
181 | this.fireVetoableSequenceChange( null, sequence ); |
182 | |
183 | SequenceType sequenceType = this.getSequenceType( sequence.getName() ); |
184 | |
185 | if ( sequenceType != null ) |
186 | { |
187 | throw new SequenceExistsException( this.getSequenceMapper().map( sequenceType, new Sequence() ) ); |
188 | } |
189 | |
190 | sequenceType = this.getSequenceMapper().map( sequence, new SequenceType() ); |
191 | sequenceType.setJpaDate( Calendar.getInstance() ); |
192 | |
193 | final SequencesType sequences = this.getSequencesType( this.getSequenceDirectoryName() ); |
194 | this.getEntityManager().persist( sequenceType ); |
195 | sequences.getSequence().add( sequenceType ); |
196 | this.getEntityManager().merge( sequences ); |
197 | |
198 | final Sequence persistent = this.getSequenceMapper().map( sequenceType, new Sequence() ); |
199 | this.fireSequenceChange( null, persistent ); |
200 | return persistent; |
201 | } |
202 | |
203 | public Sequence editSequence( final String name, final long revision, final Sequence sequence ) |
204 | { |
205 | if ( name == null ) |
206 | { |
207 | throw new SequencesSystemException( this.getIllegalArgumentMessage( this.getLocale(), "name", null ) ); |
208 | } |
209 | if ( sequence == null ) |
210 | { |
211 | throw new SequencesSystemException( this.getIllegalArgumentMessage( this.getLocale(), "sequence", null ) ); |
212 | } |
213 | |
214 | SequenceType sequenceType = this.getSequenceType( name ); |
215 | |
216 | if ( sequenceType == null ) |
217 | { |
218 | throw new SequenceNotFoundException( name ); |
219 | } |
220 | if ( sequenceType.getRevision() != revision ) |
221 | { |
222 | throw new ConcurrentModificationException( |
223 | this.getSequenceMapper().map( sequenceType, new Sequence() ) ); |
224 | |
225 | } |
226 | |
227 | final Sequence oldValue = this.getSequenceMapper().map( sequenceType, new Sequence() ); |
228 | this.fireVetoableSequenceChange( oldValue, sequence ); |
229 | |
230 | sequenceType = this.getSequenceMapper().map( sequence, sequenceType ); |
231 | sequenceType.setRevision( sequenceType.getRevision() + 1L ); |
232 | sequenceType.setJpaDate( Calendar.getInstance() ); |
233 | this.getEntityManager().merge( sequenceType ); |
234 | |
235 | final Sequence edited = this.getSequenceMapper().map( sequenceType, new Sequence() ); |
236 | this.fireSequenceChange( oldValue, edited ); |
237 | return edited; |
238 | } |
239 | |
240 | public Sequence deleteSequence( final String name, final long revision ) |
241 | { |
242 | if ( name == null ) |
243 | { |
244 | throw new SequencesSystemException( this.getIllegalArgumentMessage( this.getLocale(), "name", null ) ); |
245 | } |
246 | |
247 | final SequenceType sequenceType = this.getSequenceType( name ); |
248 | |
249 | if ( sequenceType == null ) |
250 | { |
251 | throw new SequenceNotFoundException( name ); |
252 | } |
253 | if ( sequenceType.getRevision() != revision ) |
254 | { |
255 | throw new ConcurrentModificationException( |
256 | this.getSequenceMapper().map( sequenceType, new Sequence() ) ); |
257 | |
258 | } |
259 | |
260 | final Sequence deleted = this.getSequenceMapper().map( sequenceType, new Sequence() ); |
261 | this.fireVetoableSequenceChange( deleted, null ); |
262 | |
263 | final SequencesType sequences = this.getSequencesType( this.getSequenceDirectoryName() ); |
264 | sequences.getSequence().remove( sequenceType ); |
265 | this.getEntityManager().remove( sequenceType ); |
266 | |
267 | if ( sequences.getSequence().isEmpty() ) |
268 | { |
269 | this.getEntityManager().remove( sequences ); |
270 | } |
271 | else |
272 | { |
273 | this.getEntityManager().merge( sequences ); |
274 | } |
275 | |
276 | final Sequence s = this.getSequenceMapper().map( sequenceType, new Sequence() ); |
277 | this.fireSequenceChange( s, null ); |
278 | return deleted; |
279 | } |
280 | |
281 | public Set<Sequence> searchSequences( final String name ) |
282 | { |
283 | final Query query = name == null ? this.getSelectAllSequencesQuery() : this.getSelectSequencesQuery(); |
284 | query.setParameter( this.getSequenceDirectoryNameQueryParameterName(), |
285 | this.getSequencesType( this.getSequenceDirectoryName() ).getName() ); |
286 | |
287 | if ( name != null ) |
288 | { |
289 | query.setParameter( this.getSequenceNameQueryParameterName(), name ); |
290 | } |
291 | |
292 | final List<SequenceType> resultList = (List<SequenceType>) query.getResultList(); |
293 | final Set<Sequence> sequences = new HashSet<Sequence>( resultList.size() ); |
294 | |
295 | for ( SequenceType s : resultList ) |
296 | { |
297 | sequences.add( this.getSequenceMapper().map( s, new Sequence() ) ); |
298 | } |
299 | |
300 | return sequences; |
301 | } |
302 | |
303 | // SECTION-END |
304 | // SECTION-START[SequenceOperations] |
305 | public long getNextSequenceValue( final String sequenceName ) |
306 | { |
307 | if ( sequenceName == null ) |
308 | { |
309 | throw new SequencesSystemException( this.getIllegalArgumentMessage( |
310 | this.getLocale(), "sequenceName", null ) ); |
311 | |
312 | } |
313 | |
314 | final SequenceType sequenceType = this.getSequenceType( sequenceName ); |
315 | |
316 | if ( sequenceType == null ) |
317 | { |
318 | throw new SequenceNotFoundException( sequenceName ); |
319 | } |
320 | |
321 | final Sequence oldValue = this.getSequenceMapper().map( sequenceType, new Sequence() ); |
322 | final Long nextValue = sequenceType.getValue() + sequenceType.getIncrement(); |
323 | |
324 | if ( nextValue < sequenceType.getValue() || nextValue > sequenceType.getMaximum() ) |
325 | { |
326 | throw new SequenceLimitException( sequenceType.getValue() ); |
327 | } |
328 | |
329 | sequenceType.setValue( nextValue ); |
330 | sequenceType.setRevision( sequenceType.getRevision() + 1L ); |
331 | sequenceType.setJpaDate( Calendar.getInstance() ); |
332 | |
333 | this.getEntityManager().merge( sequenceType ); |
334 | |
335 | final Sequence s = this.getSequenceMapper().map( sequenceType, new Sequence() ); |
336 | this.fireSequenceChange( oldValue, s ); |
337 | return s.getValue(); |
338 | } |
339 | |
340 | public long[] getNextSequenceValues( final String sequenceName, final int numValues ) |
341 | { |
342 | if ( sequenceName == null ) |
343 | { |
344 | throw new SequencesSystemException( this.getIllegalArgumentMessage( |
345 | this.getLocale(), "sequenceName", null ) ); |
346 | |
347 | } |
348 | if ( numValues < 0 ) |
349 | { |
350 | throw new SequencesSystemException( this.getIllegalArgumentMessage( |
351 | this.getLocale(), "numValues", Integer.toString( numValues ) ) ); |
352 | |
353 | } |
354 | |
355 | final SequenceType sequenceType = this.getSequenceType( sequenceName ); |
356 | |
357 | if ( sequenceType == null ) |
358 | { |
359 | throw new SequenceNotFoundException( sequenceName ); |
360 | } |
361 | |
362 | final long[] values = new long[ numValues ]; |
363 | final Sequence oldValue = this.getSequenceMapper().map( sequenceType, new Sequence() ); |
364 | |
365 | for ( int i = values.length - 1; i >= 0; i-- ) |
366 | { |
367 | final long nextValue = sequenceType.getValue() + sequenceType.getIncrement(); |
368 | |
369 | if ( nextValue < sequenceType.getValue() || nextValue > sequenceType.getMaximum() ) |
370 | { |
371 | throw new SequenceLimitException( sequenceType.getValue() ); |
372 | } |
373 | |
374 | sequenceType.setValue( nextValue ); |
375 | values[i] = nextValue; |
376 | } |
377 | |
378 | sequenceType.setRevision( sequenceType.getRevision() + 1L ); |
379 | sequenceType.setJpaDate( Calendar.getInstance() ); |
380 | |
381 | this.getEntityManager().merge( sequenceType ); |
382 | |
383 | final Sequence s = this.getSequenceMapper().map( sequenceType, new Sequence() ); |
384 | this.fireSequenceChange( oldValue, s ); |
385 | return values; |
386 | } |
387 | |
388 | // SECTION-END |
389 | // SECTION-START[DefaultSequenceDirectory] |
390 | /** |
391 | * Gets a sequence entity for a given name. |
392 | * |
393 | * @param name The name of the sequence entity to return. |
394 | * |
395 | * @return The sequence entity with name {@code name}, or {@code null} if no sequence entity matching {@code name} |
396 | * is found. |
397 | */ |
398 | protected SequenceType getSequenceType( final String name ) |
399 | { |
400 | try |
401 | { |
402 | final Query query = this.getSelectSequenceQuery(); |
403 | query.setParameter( this.getSequenceDirectoryNameQueryParameterName(), |
404 | this.getSequencesType( this.getSequenceDirectoryName() ).getName() ); |
405 | |
406 | query.setParameter( this.getSequenceNameQueryParameterName(), name ); |
407 | |
408 | return (SequenceType) query.getSingleResult(); |
409 | } |
410 | catch ( final NoResultException e ) |
411 | { |
412 | if ( this.getLogger().isDebugEnabled() ) |
413 | { |
414 | this.getLogger().debug( e.getMessage() ); |
415 | } |
416 | |
417 | return null; |
418 | } |
419 | } |
420 | |
421 | /** |
422 | * Gets a sequence directory entity for a given name. |
423 | * |
424 | * @param name The name of the sequence directory entity to return. |
425 | * |
426 | * @return The sequence directory entity matching {@code name}; if no such sequence directory entity is found, a |
427 | * new entity is created. |
428 | */ |
429 | protected SequencesType getSequencesType( final String name ) |
430 | { |
431 | final Query query = this.getSelectSequenceDirectoryQuery(); |
432 | query.setParameter( this.getSequenceDirectoryNameQueryParameterName(), name ); |
433 | |
434 | SequencesType sequencesType = null; |
435 | |
436 | try |
437 | { |
438 | sequencesType = (SequencesType) query.getSingleResult(); |
439 | } |
440 | catch ( final NoResultException e ) |
441 | { |
442 | if ( this.getLogger().isDebugEnabled() ) |
443 | { |
444 | this.getLogger().debug( e.getMessage() ); |
445 | } |
446 | |
447 | sequencesType = new SequencesType(); |
448 | sequencesType.setName( name ); |
449 | |
450 | BigInteger defaultCapacityLimit = sequencesType.getCapacityLimit(); |
451 | if ( defaultCapacityLimit == null ) |
452 | { |
453 | defaultCapacityLimit = this.getDefaultSequenceDirectoryCapacityLimit(); |
454 | } |
455 | |
456 | sequencesType.setCapacityLimit( defaultCapacityLimit ); |
457 | sequencesType.setJpaDate( Calendar.getInstance() ); |
458 | |
459 | this.getEntityManager().persist( sequencesType ); |
460 | |
461 | if ( this.getLogger().isInfoEnabled() ) |
462 | { |
463 | this.getLogger().info( this.getSuccessfullyCreatedSequenceDirectoryMessage( this.getLocale(), name ) ); |
464 | } |
465 | } |
466 | |
467 | return sequencesType; |
468 | } |
469 | |
470 | /** |
471 | * Notifies all available {@code SequenceChangeListener}s about a changed sequence. |
472 | * |
473 | * @param oldValue The entity having been changed or {@code null} if {@code newValue} got added to the directory. |
474 | * @param newValue The value {@code oldValue} got changed to or {@code null} if {@code oldValue} got removed from |
475 | * the directory. |
476 | */ |
477 | protected void fireSequenceChange( final Sequence oldValue, final Sequence newValue ) |
478 | { |
479 | SequenceChangeEvent sequenceChange = null; |
480 | for ( SequenceChangeListener l : this.getSequenceChangeListener() ) |
481 | { |
482 | if ( sequenceChange == null ) |
483 | { |
484 | sequenceChange = new SequenceChangeEvent( this, oldValue, newValue ); |
485 | } |
486 | |
487 | l.sequenceChange( sequenceChange ); |
488 | } |
489 | } |
490 | |
491 | /** |
492 | * Notifies all available {@code SequenceChangeListener}s about a sequence about to change. |
493 | * |
494 | * @param oldValue The entity about to change or {@code null} if {@code newValue} is about to be added to the |
495 | * directory. |
496 | * @param newValue The value {@code oldValue} will change to or {@code null} if {@code oldValue} will be removed |
497 | * from the directory. |
498 | * |
499 | * @throws SequenceVetoException if any available {@code SequenceChangeListener} chooses to veto the sequence |
500 | * change. |
501 | */ |
502 | protected void fireVetoableSequenceChange( final Sequence oldValue, final Sequence newValue ) |
503 | { |
504 | SequenceChangeEvent sequenceChange = null; |
505 | boolean vetoed = false; |
506 | |
507 | for ( VetoableSequenceChangeListener l : this.getVetoableSequenceChangeListener() ) |
508 | { |
509 | if ( sequenceChange == null ) |
510 | { |
511 | sequenceChange = new SequenceChangeEvent( this, oldValue, newValue ); |
512 | } |
513 | |
514 | try |
515 | { |
516 | l.vetoableSequenceChange( sequenceChange ); |
517 | } |
518 | catch ( final SequenceVetoException e ) |
519 | { |
520 | this.getLogger().error( e.getMessage() ); |
521 | vetoed = true; |
522 | } |
523 | } |
524 | |
525 | if ( vetoed ) |
526 | { |
527 | throw new SequenceVetoException( sequenceChange ); |
528 | } |
529 | } |
530 | |
531 | // SECTION-END |
532 | // SECTION-START[Constructors] |
533 | // <editor-fold defaultstate="collapsed" desc=" Generated Constructors "> |
534 | |
535 | /** Creates a new {@code DefaultSequenceDirectory} instance. */ |
536 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) |
537 | public DefaultSequenceDirectory() |
538 | { |
539 | // SECTION-START[Default Constructor] |
540 | super(); |
541 | // SECTION-END |
542 | } |
543 | // </editor-fold> |
544 | // SECTION-END |
545 | // SECTION-START[Dependencies] |
546 | // <editor-fold defaultstate="collapsed" desc=" Generated Dependencies "> |
547 | |
548 | /** |
549 | * Gets the {@code EntityManager} dependency. |
550 | * <p>This method returns the {@code 'JOMC SDK JPA'} object of the {@code 'javax.persistence.EntityManager'} {@code (javax.persistence.EntityManager)} specification.</p> |
551 | * <p>That specification does not apply to any scope. A new object is returned whenever requested.</p> |
552 | * @return The {@code EntityManager} dependency. |
553 | * @throws org.jomc.ObjectManagementException if getting the dependency instance fails. |
554 | */ |
555 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) |
556 | private javax.persistence.EntityManager getEntityManager() |
557 | { |
558 | final javax.persistence.EntityManager _d = (javax.persistence.EntityManager) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "EntityManager" ); |
559 | assert _d != null : "'EntityManager' dependency not found."; |
560 | return _d; |
561 | } |
562 | |
563 | /** |
564 | * Gets the {@code Locale} dependency. |
565 | * <p>This method returns the {@code 'default'} object of the {@code 'java.util.Locale'} {@code (java.util.Locale)} specification at specification level 1.1.</p> |
566 | * <p>That specification does not apply to any scope. A new object is returned whenever requested and bound to this instance.</p> |
567 | * @return The {@code Locale} dependency. |
568 | * @throws org.jomc.ObjectManagementException if getting the dependency instance fails. |
569 | */ |
570 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) |
571 | private java.util.Locale getLocale() |
572 | { |
573 | final java.util.Locale _d = (java.util.Locale) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "Locale" ); |
574 | assert _d != null : "'Locale' dependency not found."; |
575 | return _d; |
576 | } |
577 | |
578 | /** |
579 | * Gets the {@code Logger} dependency. |
580 | * <p>This method returns any available object of the {@code 'org.jomc.logging.Logger'} {@code (org.jomc.logging.Logger)} specification at specification level 1.0.</p> |
581 | * <p>That specification does not apply to any scope. A new object is returned whenever requested and bound to this instance.</p> |
582 | * <p><b>Properties</b><dl> |
583 | * <dt>"{@code name}"</dt> |
584 | * <dd>Property of type {@code java.lang.String}. |
585 | * </dd> |
586 | * </dl> |
587 | * @return The {@code Logger} dependency. |
588 | * @throws org.jomc.ObjectManagementException if getting the dependency instance fails. |
589 | */ |
590 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) |
591 | private org.jomc.logging.Logger getLogger() |
592 | { |
593 | final org.jomc.logging.Logger _d = (org.jomc.logging.Logger) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "Logger" ); |
594 | assert _d != null : "'Logger' dependency not found."; |
595 | return _d; |
596 | } |
597 | |
598 | /** |
599 | * Gets the {@code SelectAllSequencesQuery} dependency. |
600 | * <p>This method returns the {@code 'JOMC Sequences Model - Select All Sequences Query'} object of the {@code 'javax.persistence.Query'} {@code (javax.persistence.Query)} specification.</p> |
601 | * <p>That specification does not apply to any scope. A new object is returned whenever requested.</p> |
602 | * @return The {@code SelectAllSequencesQuery} dependency. |
603 | * @throws org.jomc.ObjectManagementException if getting the dependency instance fails. |
604 | */ |
605 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) |
606 | private javax.persistence.Query getSelectAllSequencesQuery() |
607 | { |
608 | final javax.persistence.Query _d = (javax.persistence.Query) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "SelectAllSequencesQuery" ); |
609 | assert _d != null : "'SelectAllSequencesQuery' dependency not found."; |
610 | return _d; |
611 | } |
612 | |
613 | /** |
614 | * Gets the {@code SelectSequenceCountQuery} dependency. |
615 | * <p>This method returns the {@code 'JOMC Sequences Model - Select Sequence Count Query'} object of the {@code 'javax.persistence.Query'} {@code (javax.persistence.Query)} specification.</p> |
616 | * <p>That specification does not apply to any scope. A new object is returned whenever requested.</p> |
617 | * @return The {@code SelectSequenceCountQuery} dependency. |
618 | * @throws org.jomc.ObjectManagementException if getting the dependency instance fails. |
619 | */ |
620 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) |
621 | private javax.persistence.Query getSelectSequenceCountQuery() |
622 | { |
623 | final javax.persistence.Query _d = (javax.persistence.Query) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "SelectSequenceCountQuery" ); |
624 | assert _d != null : "'SelectSequenceCountQuery' dependency not found."; |
625 | return _d; |
626 | } |
627 | |
628 | /** |
629 | * Gets the {@code SelectSequenceDirectoryQuery} dependency. |
630 | * <p>This method returns the {@code 'JOMC Sequences Model - Select Sequence Directory Query'} object of the {@code 'javax.persistence.Query'} {@code (javax.persistence.Query)} specification.</p> |
631 | * <p>That specification does not apply to any scope. A new object is returned whenever requested.</p> |
632 | * @return The {@code SelectSequenceDirectoryQuery} dependency. |
633 | * @throws org.jomc.ObjectManagementException if getting the dependency instance fails. |
634 | */ |
635 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) |
636 | private javax.persistence.Query getSelectSequenceDirectoryQuery() |
637 | { |
638 | final javax.persistence.Query _d = (javax.persistence.Query) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "SelectSequenceDirectoryQuery" ); |
639 | assert _d != null : "'SelectSequenceDirectoryQuery' dependency not found."; |
640 | return _d; |
641 | } |
642 | |
643 | /** |
644 | * Gets the {@code SelectSequenceQuery} dependency. |
645 | * <p>This method returns the {@code 'JOMC Sequences Model - Select Sequence Query'} object of the {@code 'javax.persistence.Query'} {@code (javax.persistence.Query)} specification.</p> |
646 | * <p>That specification does not apply to any scope. A new object is returned whenever requested.</p> |
647 | * @return The {@code SelectSequenceQuery} dependency. |
648 | * @throws org.jomc.ObjectManagementException if getting the dependency instance fails. |
649 | */ |
650 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) |
651 | private javax.persistence.Query getSelectSequenceQuery() |
652 | { |
653 | final javax.persistence.Query _d = (javax.persistence.Query) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "SelectSequenceQuery" ); |
654 | assert _d != null : "'SelectSequenceQuery' dependency not found."; |
655 | return _d; |
656 | } |
657 | |
658 | /** |
659 | * Gets the {@code SelectSequencesQuery} dependency. |
660 | * <p>This method returns the {@code 'JOMC Sequences Model - Select Sequences Query'} object of the {@code 'javax.persistence.Query'} {@code (javax.persistence.Query)} specification.</p> |
661 | * <p>That specification does not apply to any scope. A new object is returned whenever requested.</p> |
662 | * @return The {@code SelectSequencesQuery} dependency. |
663 | * @throws org.jomc.ObjectManagementException if getting the dependency instance fails. |
664 | */ |
665 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) |
666 | private javax.persistence.Query getSelectSequencesQuery() |
667 | { |
668 | final javax.persistence.Query _d = (javax.persistence.Query) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "SelectSequencesQuery" ); |
669 | assert _d != null : "'SelectSequencesQuery' dependency not found."; |
670 | return _d; |
671 | } |
672 | |
673 | /** |
674 | * Gets the {@code SequenceChangeListener} dependency. |
675 | * <p>This method returns any available object of the {@code 'org.jomc.sequences.SequenceChangeListener'} {@code (org.jomc.sequences.SequenceChangeListener)} specification at specification level 1.0.</p> |
676 | * <p>That specification does not apply to any scope. A new object is returned whenever requested and bound to this instance.</p> |
677 | * @return The {@code SequenceChangeListener} dependency. |
678 | * @throws org.jomc.ObjectManagementException if getting the dependency instance fails. |
679 | */ |
680 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) |
681 | private org.jomc.sequences.SequenceChangeListener[] getSequenceChangeListener() |
682 | { |
683 | final org.jomc.sequences.SequenceChangeListener[] _d = (org.jomc.sequences.SequenceChangeListener[]) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "SequenceChangeListener" ); |
684 | assert _d != null : "'SequenceChangeListener' dependency not found."; |
685 | return _d; |
686 | } |
687 | |
688 | /** |
689 | * Gets the {@code SequenceMapper} dependency. |
690 | * <p>This method returns the {@code 'JOMC Sequences RI'} object of the {@code 'org.jomc.sequences.ri.SequenceMapper'} {@code (org.jomc.sequences.ri.SequenceMapper)} specification at specification level 1.0.</p> |
691 | * <p>That specification does not apply to any scope. A new object is returned whenever requested and bound to this instance.</p> |
692 | * @return The {@code SequenceMapper} dependency. |
693 | * @throws org.jomc.ObjectManagementException if getting the dependency instance fails. |
694 | */ |
695 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) |
696 | private org.jomc.sequences.ri.SequenceMapper getSequenceMapper() |
697 | { |
698 | final org.jomc.sequences.ri.SequenceMapper _d = (org.jomc.sequences.ri.SequenceMapper) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "SequenceMapper" ); |
699 | assert _d != null : "'SequenceMapper' dependency not found."; |
700 | return _d; |
701 | } |
702 | |
703 | /** |
704 | * Gets the {@code VetoableSequenceChangeListener} dependency. |
705 | * <p>This method returns any available object of the {@code 'org.jomc.sequences.VetoableSequenceChangeListener'} {@code (org.jomc.sequences.VetoableSequenceChangeListener)} specification at specification level 1.0.</p> |
706 | * <p>That specification does not apply to any scope. A new object is returned whenever requested and bound to this instance.</p> |
707 | * @return The {@code VetoableSequenceChangeListener} dependency. |
708 | * @throws org.jomc.ObjectManagementException if getting the dependency instance fails. |
709 | */ |
710 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) |
711 | private org.jomc.sequences.VetoableSequenceChangeListener[] getVetoableSequenceChangeListener() |
712 | { |
713 | final org.jomc.sequences.VetoableSequenceChangeListener[] _d = (org.jomc.sequences.VetoableSequenceChangeListener[]) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "VetoableSequenceChangeListener" ); |
714 | assert _d != null : "'VetoableSequenceChangeListener' dependency not found."; |
715 | return _d; |
716 | } |
717 | // </editor-fold> |
718 | // SECTION-END |
719 | // SECTION-START[Properties] |
720 | // <editor-fold defaultstate="collapsed" desc=" Generated Properties "> |
721 | |
722 | /** |
723 | * Gets the value of the {@code defaultSequenceDirectoryCapacityLimit} property. |
724 | * @return Default capacity limit when creating new sequence directory entities and no default value is provided otherwise. |
725 | * @throws org.jomc.ObjectManagementException if getting the property instance fails. |
726 | */ |
727 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) |
728 | private java.math.BigInteger getDefaultSequenceDirectoryCapacityLimit() |
729 | { |
730 | final java.math.BigInteger _p = (java.math.BigInteger) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "defaultSequenceDirectoryCapacityLimit" ); |
731 | assert _p != null : "'defaultSequenceDirectoryCapacityLimit' property not found."; |
732 | return _p; |
733 | } |
734 | |
735 | /** |
736 | * Gets the value of the {@code sequenceDirectoryName} property. |
737 | * @return Name uniquely identifying the directory in a set of directories. |
738 | * @throws org.jomc.ObjectManagementException if getting the property instance fails. |
739 | */ |
740 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) |
741 | private java.lang.String getSequenceDirectoryName() |
742 | { |
743 | final java.lang.String _p = (java.lang.String) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "sequenceDirectoryName" ); |
744 | assert _p != null : "'sequenceDirectoryName' property not found."; |
745 | return _p; |
746 | } |
747 | |
748 | /** |
749 | * Gets the value of the {@code sequenceDirectoryNameQueryParameterName} property. |
750 | * @return Name of a JPA query parameter denoting the name of a sequence directory entity. |
751 | * @throws org.jomc.ObjectManagementException if getting the property instance fails. |
752 | */ |
753 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) |
754 | private java.lang.String getSequenceDirectoryNameQueryParameterName() |
755 | { |
756 | final java.lang.String _p = (java.lang.String) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "sequenceDirectoryNameQueryParameterName" ); |
757 | assert _p != null : "'sequenceDirectoryNameQueryParameterName' property not found."; |
758 | return _p; |
759 | } |
760 | |
761 | /** |
762 | * Gets the value of the {@code sequenceNameQueryParameterName} property. |
763 | * @return Name of a JPA query parameter denoting the name of a sequence entity. |
764 | * @throws org.jomc.ObjectManagementException if getting the property instance fails. |
765 | */ |
766 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) |
767 | private java.lang.String getSequenceNameQueryParameterName() |
768 | { |
769 | final java.lang.String _p = (java.lang.String) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "sequenceNameQueryParameterName" ); |
770 | assert _p != null : "'sequenceNameQueryParameterName' property not found."; |
771 | return _p; |
772 | } |
773 | // </editor-fold> |
774 | // SECTION-END |
775 | // SECTION-START[Messages] |
776 | // <editor-fold defaultstate="collapsed" desc=" Generated Messages "> |
777 | |
778 | /** |
779 | * Gets the text of the {@code illegalArgumentMessage} message. |
780 | * <p><b>Templates</b><br/><table> |
781 | * <tr><td valign="top">English:</td><td valign="top"><pre>Illegal value ''{1}'' for argument ''{0}''.</pre></td></tr> |
782 | * <tr><td valign="top">Deutsch:</td><td valign="top"><pre>Ungültiger Wert ''{1}'' für Parameter ''{0}''.</pre></td></tr> |
783 | * </table></p> |
784 | * @param locale The locale of the message to return. |
785 | * @param argumentName Format argument. |
786 | * @param argumentValue Format argument. |
787 | * @return The text of the {@code illegalArgumentMessage} message. |
788 | * |
789 | * @throws org.jomc.ObjectManagementException if getting the message instance fails. |
790 | */ |
791 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) |
792 | private String getIllegalArgumentMessage( final java.util.Locale locale, final java.lang.String argumentName, final java.lang.String argumentValue ) |
793 | { |
794 | final String _m = org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getMessage( this, "illegalArgumentMessage", locale, argumentName, argumentValue ); |
795 | assert _m != null : "'illegalArgumentMessage' message not found."; |
796 | return _m; |
797 | } |
798 | |
799 | /** |
800 | * Gets the text of the {@code successfullyCreatedSequenceDirectoryMessage} message. |
801 | * <p><b>Templates</b><br/><table> |
802 | * <tr><td valign="top">English:</td><td valign="top"><pre>Sequence directory ''{0}'' created.</pre></td></tr> |
803 | * <tr><td valign="top">Deutsch:</td><td valign="top"><pre>Sequenzverzeichnis ''{0}'' erstellt.</pre></td></tr> |
804 | * </table></p> |
805 | * @param locale The locale of the message to return. |
806 | * @param name Format argument. |
807 | * @return The text of the {@code successfullyCreatedSequenceDirectoryMessage} message. |
808 | * |
809 | * @throws org.jomc.ObjectManagementException if getting the message instance fails. |
810 | */ |
811 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) |
812 | private String getSuccessfullyCreatedSequenceDirectoryMessage( final java.util.Locale locale, final java.lang.String name ) |
813 | { |
814 | final String _m = org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getMessage( this, "successfullyCreatedSequenceDirectoryMessage", locale, name ); |
815 | assert _m != null : "'successfullyCreatedSequenceDirectoryMessage' message not found."; |
816 | return _m; |
817 | } |
818 | // </editor-fold> |
819 | // SECTION-END |
820 | } |