1 | |
package org.apache.ojb.broker.util.sequence; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
import java.util.Properties; |
19 | |
|
20 | |
import org.apache.ojb.broker.PersistenceBroker; |
21 | |
import org.apache.ojb.broker.accesslayer.JdbcAccess; |
22 | |
import org.apache.ojb.broker.metadata.ClassDescriptor; |
23 | |
import org.apache.ojb.broker.metadata.FieldDescriptor; |
24 | |
import org.apache.ojb.broker.metadata.SequenceDescriptor; |
25 | |
import org.apache.ojb.broker.platforms.Platform; |
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
public abstract class AbstractSequenceManager implements SequenceManager |
38 | |
{ |
39 | |
|
40 | |
public static final String PROPERTY_AUTO_NAMING = "autoNaming"; |
41 | |
protected static final String GLOBAL_SEQUENCE_NAME = "ojb.global.sequence"; |
42 | |
|
43 | |
private PersistenceBroker brokerForClass; |
44 | |
private Platform platform; |
45 | |
private Properties configurationProperties; |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
public AbstractSequenceManager(PersistenceBroker broker) |
55 | |
{ |
56 | |
this.brokerForClass = broker; |
57 | |
this.configurationProperties = new Properties(); |
58 | |
this.platform = brokerForClass.serviceConnectionManager().getSupportedPlatform(); |
59 | |
SequenceDescriptor sd = brokerForClass.serviceConnectionManager(). |
60 | |
getConnectionDescriptor().getSequenceDescriptor(); |
61 | |
if (sd != null) |
62 | |
{ |
63 | |
this.configurationProperties.putAll(sd.getConfigurationProperties()); |
64 | |
} |
65 | |
} |
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
abstract protected long getUniqueLong(FieldDescriptor field) throws SequenceManagerException; |
72 | |
|
73 | |
|
74 | |
public Platform getPlatform() |
75 | |
{ |
76 | |
return platform; |
77 | |
} |
78 | |
|
79 | |
public PersistenceBroker getBrokerForClass() |
80 | |
{ |
81 | |
return brokerForClass; |
82 | |
} |
83 | |
|
84 | |
public Properties getConfigurationProperties() |
85 | |
{ |
86 | |
return this.configurationProperties; |
87 | |
} |
88 | |
|
89 | |
public void setConfigurationProperties(Properties prop) |
90 | |
{ |
91 | |
this.configurationProperties.putAll(prop); |
92 | |
} |
93 | |
|
94 | |
public String getConfigurationProperty(String key, String defaultValue) |
95 | |
{ |
96 | |
String result = this.configurationProperties.getProperty(key); |
97 | |
return result != null ? result : defaultValue; |
98 | |
} |
99 | |
|
100 | |
public void setConfigurationProperty(String key, String value) |
101 | |
{ |
102 | |
this.configurationProperties.setProperty(key, value); |
103 | |
} |
104 | |
|
105 | |
public boolean useAutoNaming() |
106 | |
{ |
107 | |
return (Boolean.valueOf(getConfigurationProperty(PROPERTY_AUTO_NAMING, "true"))).booleanValue(); |
108 | |
} |
109 | |
|
110 | |
public String calculateSequenceName(FieldDescriptor field) throws SequenceManagerException |
111 | |
{ |
112 | |
String seqName; |
113 | |
seqName = field.getSequenceName(); |
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
if(seqName == null) |
119 | |
{ |
120 | |
seqName = SequenceManagerHelper.buildSequenceName(getBrokerForClass(), field, useAutoNaming()); |
121 | |
|
122 | |
|
123 | |
} |
124 | |
return seqName; |
125 | |
} |
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
public Object getUniqueValue(FieldDescriptor field) throws SequenceManagerException |
139 | |
{ |
140 | |
Object result = field.getJdbcType().sequenceKeyConversion(new Long(getUniqueLong(field))); |
141 | |
|
142 | |
|
143 | |
result = field.getFieldConversion().sqlToJava(result); |
144 | |
return result; |
145 | |
} |
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
public void afterStore(JdbcAccess dbAccess, ClassDescriptor cld, Object obj) |
151 | |
throws SequenceManagerException |
152 | |
{ |
153 | |
|
154 | |
} |
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
public void setReferenceFKs(Object obj, ClassDescriptor cld) |
160 | |
throws SequenceManagerException |
161 | |
{ |
162 | |
|
163 | |
} |
164 | |
} |