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.log.Log;
12: import com.completex.objective.components.persistency.OdalPersistencyException;
13: import com.completex.objective.components.persistency.Persistency;
14: import com.completex.objective.components.persistency.PersistentEntry;
15: import com.completex.objective.components.persistency.core.DatabasePolicy;
16: import com.completex.objective.components.persistency.key.AutoKeyGenerator;
17: import com.completex.objective.components.persistency.transact.Transaction;
18:
19: import java.util.Date;
20:
21: /**
22: * Created date auto key generator
23: *
24: * @author Gennady Krizhevsky
25: */
26: public class CreatedDateGenerator implements AutoKeyGenerator {
27:
28: public void setStaticParameters(Object staticParameters) {
29: }
30:
31: /**
32: * @see com.completex.objective.components.persistency.key.AutoKeyGenerator#getStaticParameters()
33: */
34: public Object getStaticParameters() {
35: return null;
36: }
37:
38: /**
39: * @see com.completex.objective.components.persistency.key.AutoKeyGenerator#insertValue(com.completex.objective.components.persistency.transact.Transaction, com.completex.objective.components.persistency.Persistency, com.completex.objective.components.persistency.PersistentEntry)
40: */
41: public void insertValue(Transaction transaction,
42: Persistency persistency, PersistentEntry persistentEntry)
43: throws OdalPersistencyException {
44: if (persistentEntry.getRecord().isSkipInsertForKeysOnly()
45: && persistentEntry.getRecord().hasDirtyNonKeyFields()) {
46: date(persistentEntry);
47: } else if (persistentEntry.getRecord().isDirty()) {
48: date(persistentEntry);
49: }
50: }
51:
52: /**
53: * @see com.completex.objective.components.persistency.key.AutoKeyGenerator#updateValue(com.completex.objective.components.persistency.transact.Transaction, com.completex.objective.components.persistency.Persistency, com.completex.objective.components.persistency.PersistentEntry, boolean)
54: */
55: public void updateValue(Transaction transaction,
56: Persistency persistency, PersistentEntry persistentEntry,
57: boolean complexDirty) throws OdalPersistencyException {
58: }
59:
60: /**
61: * Generate date & populate it into persistentEntry
62: *
63: * @param persistentEntry
64: */
65: protected void date(PersistentEntry persistentEntry) {
66: Date date = (Date) persistentEntry.getValue();
67: if (!persistentEntry.isDirty() || date == null) {
68: date = new Date();
69: persistentEntry.setValue(date);
70: }
71: }
72:
73: /**
74: * @see AutoKeyGenerator#setDatabasePolicy
75: */
76: public void setDatabasePolicy(DatabasePolicy databasePolicy) {
77: }
78:
79: /**
80: * @see AutoKeyGenerator#setLogger
81: */
82: public void setLogger(Log log) {
83: }
84: }
|