01: /**********************************************************************
02: Copyright (c) 2006 Andy Jefferson and others. All rights reserved.
03: Licensed under the Apache License, Version 2.0 (the "License");
04: you may not use this file except in compliance with the License.
05: You may obtain a copy of the License at
06:
07: http://www.apache.org/licenses/LICENSE-2.0
08:
09: Unless required by applicable law or agreed to in writing, software
10: distributed under the License is distributed on an "AS IS" BASIS,
11: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: See the License for the specific language governing permissions and
13: limitations under the License.
14:
15:
16: Contributors:
17: ...
18: **********************************************************************/package org.jpox.store.poid;
19:
20: import java.util.Properties;
21:
22: import org.jpox.util.JPOXLogger;
23:
24: /**
25: * Poid generator for a UID format.
26: * To be extended by implementations giving the UID in particular forms.
27: *
28: * @version $Revision: 1.6 $
29: */
30: public abstract class AbstractUIDPoidGenerator extends
31: AbstractPoidGenerator {
32: /**
33: * Constructor.
34: * @param name Symbolic name for this generator
35: * @param props Properties controlling its behaviour
36: */
37: public AbstractUIDPoidGenerator(String name, Properties props) {
38: super (name, props);
39: allocationSize = 1;
40: }
41:
42: /**
43: * Accessor for the storage class for POIDs generated with this generator.
44: * @return Storage class (in this case String.class)
45: */
46: public static Class getStorageClass() {
47: return String.class;
48: }
49:
50: /**
51: * Method to reserve "size" POIDs to the PoidBlock.
52: * @param size The block size
53: * @return The reserved block
54: */
55: protected PoidBlock reserveBlock(long size) {
56: Object[] ids = new Object[(int) size];
57: for (int i = 0; i < size; i++) {
58: ids[i] = getIdentifier();
59: }
60: if (JPOXLogger.POID.isDebugEnabled()) {
61: JPOXLogger.POID.debug(LOCALISER.msg("040004", "" + size));
62: }
63: return new PoidBlock(ids);
64: }
65:
66: /**
67: * Create an identifier in the UID format required.
68: * @return The identifier
69: */
70: protected abstract String getIdentifier();
71: }
|