01: /**
02: * Copyright (C) 2007 NetMind Consulting Bt.
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 3 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */package hu.netmind.persistence;
18:
19: import java.util.*;
20: import hu.netmind.persistence.parser.*;
21:
22: /**
23: * List handler implementation.
24: * @author Brautigam Robert
25: * @version Revision: $Revision$
26: */
27: public class ListHandler extends CollectionHandler {
28: /**
29: * Constructor.
30: */
31: public ListHandler(StoreContext context, Class collectionClass) {
32: super (context, collectionClass);
33: }
34:
35: /**
36: * Create the subtable for the list.
37: */
38: public void ensureTableExists(ClassInfo parentInfo,
39: String attributeName, boolean create) {
40: Transaction tx = context.getTransactionTracker()
41: .getTransaction(TransactionTracker.TX_REQUIRED);
42: tx.begin();
43: try {
44: // Ensure map helper table
45: HashMap listAttributeTypes = new HashMap();
46: listAttributeTypes.put("persistence_id", Long.class);
47: listAttributeTypes.put("persistence_start", Long.class);
48: listAttributeTypes.put("persistence_end", Long.class);
49: listAttributeTypes.put("persistence_txstartid", Long.class);
50: listAttributeTypes.put("persistence_txstart", Long.class);
51: listAttributeTypes.put("persistence_txendid", Long.class);
52: listAttributeTypes.put("persistence_txend", Long.class);
53: listAttributeTypes.put("value", Long.class);
54: listAttributeTypes.put("container_index", Long.class);
55: Vector listKeys = new Vector();
56: listKeys.add("persistence_id");
57: listKeys.add("persistence_txstart");
58: listKeys.add("container_index");
59: context.getDatabase().ensureTable(tx,
60: parentInfo.getSubTableName(attributeName),
61: listAttributeTypes, listKeys, create);
62: } catch (StoreException e) {
63: tx.markRollbackOnly();
64: throw e;
65: } catch (Throwable e) {
66: tx.markRollbackOnly();
67: throw new StoreException("Unknown exception", e);
68: } finally {
69: tx.commit();
70: }
71: }
72:
73: }
|