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.ColumnType;
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.transact.Transaction;
16:
17: /**
18: * Epoch Last Updated Generator - populate numeric field with epoch value:
19: * System.currentTimeMillis() / 1000L
20: *
21: * @author Gennady Krizhevsky
22: */
23: public class EpochLastUpdatedGenerator extends CreatedDateGenerator {
24:
25: /**
26: * @see CreatedDateGenerator#updateValue(com.completex.objective.components.persistency.transact.Transaction, com.completex.objective.components.persistency.Persistency, com.completex.objective.components.persistency.PersistentEntry, boolean)
27: */
28: public void updateValue(Transaction transaction,
29: Persistency persistency, PersistentEntry persistentEntry,
30: boolean complexDirty) throws OdalPersistencyException {
31: if (!ColumnType
32: .isNumeric(persistentEntry.getColumn().getType())) {
33: throw new OdalPersistencyException(
34: "Unsupported field type ["
35: + persistentEntry.getColumn().getType()
36: + "]");
37: }
38:
39: if (persistentEntry.getRecord().isDirty()) {
40: date(persistentEntry);
41: }
42: }
43:
44: /**
45: * @see CreatedDateGenerator#date(com.completex.objective.components.persistency.PersistentEntry)
46: */
47: protected void date(PersistentEntry persistentEntry) {
48: persistentEntry.setValue(new Long(
49: System.currentTimeMillis() / 1000L));
50: }
51: }
|