01: /**
02: * Objective Database Abstraction Layer (ODAL)
03: * Copyright (c) 2004, The ODAL Development Group
04: * All rights reserved.
05: * For definition of the ODAL Development Group please refer to LICENCE.txt file
06: *
07: * Distributable under LGPL license.
08: * See terms of license at gnu.org.
09: */package com.completex.objective.components.persistency.key.impl;
10:
11: import com.completex.objective.components.persistency.OdalPersistencyException;
12: import com.completex.objective.components.persistency.Persistency;
13: import com.completex.objective.components.persistency.Record;
14: import com.completex.objective.components.persistency.transact.Transaction;
15:
16: import java.sql.SQLException;
17:
18: /**
19: * Sequence Key Generator deriving sequence name from the table name with prefix and suffix
20: *
21: * @author Gennady Krizhevsky
22: */
23: public class TableSequenceKeyGeneratorImpl extends
24: AbstractSimpleSequenceKeyGenerator {
25:
26: protected String sequencePrefix;
27: protected String sequenceSuffix;
28:
29: public TableSequenceKeyGeneratorImpl(String sequencePrefix,
30: String sequenceSuffix) {
31: this .sequencePrefix = sequencePrefix;
32: this .sequenceSuffix = sequenceSuffix;
33: }
34:
35: protected Object getNextKey(Transaction transaction)
36: throws SQLException {
37: throw new UnsupportedOperationException(
38: "getNextKey is not supported for SimpleTableSequenceKeyGeneratorImpl");
39: }
40:
41: public void setStaticParameters(Object staticParameters) {
42: }
43:
44: public Object getNextKey(Transaction transaction,
45: Persistency persistency, Record record, Object objectName)
46: throws OdalPersistencyException {
47: return getNextKey(transaction, persistency, record);
48: }
49:
50: /**
51: * Generate new sequence value based on sequence contraucted as
52: * sequencePrefix + tableName + sequenceSuffix
53: *
54: * @param transaction
55: * @param persistency
56: * @param record
57: * @return new key
58: * @throws OdalPersistencyException
59: */
60: public Object getNextKey(Transaction transaction,
61: Persistency persistency, Record record)
62: throws OdalPersistencyException {
63: String seqName = sequencePrefix + record.getTableName()
64: + sequenceSuffix;
65: return getNextKeyPlain(transaction, persistency, seqName);
66: }
67: }
|