| 1 | /** |
| 2 | * Copyright (C) 2007 NetMind Consulting Bt. |
| 3 | * |
| 4 | * This library is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU Lesser General Public |
| 6 | * License as published by the Free Software Foundation; either |
| 7 | * version 3 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * 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 | */ |
| 18 | |
| 19 | package hu.netmind.beankeeper.type.impl; |
| 20 | |
| 21 | import java.util.*; |
| 22 | import hu.netmind.beankeeper.parser.*; |
| 23 | import hu.netmind.beankeeper.common.StoreException; |
| 24 | import hu.netmind.beankeeper.model.*; |
| 25 | import hu.netmind.beankeeper.transaction.Transaction; |
| 26 | import hu.netmind.beankeeper.transaction.TransactionTracker; |
| 27 | import hu.netmind.beankeeper.db.Database; |
| 28 | import hu.netmind.beankeeper.schema.SchemaManager; |
| 29 | |
| 30 | /** |
| 31 | * List handler implementation. |
| 32 | * @author Brautigam Robert |
| 33 | * @version Revision: $Revision$ |
| 34 | */ |
| 35 | public class ListHandler extends CollectionHandler |
| 36 | { |
| 37 | private TransactionTracker transactionTracker = null; // Injected |
| 38 | private Database database = null; // Injected |
| 39 | private SchemaManager schemaManager = null; // Injected |
| 40 | |
| 41 | /** |
| 42 | * Constructor. |
| 43 | */ |
| 44 | public ListHandler(Class collectionClass) |
| 45 | { |
| 46 | super(collectionClass); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Create the subtable for the list. |
| 51 | */ |
| 52 | public void ensureTableExists(ClassInfo parentInfo, String attributeName, boolean create) |
| 53 | { |
| 54 | Transaction tx = transactionTracker.getTransaction(TransactionTracker.TX_REQUIRED); |
| 55 | tx.begin(); |
| 56 | try |
| 57 | { |
| 58 | // Ensure map helper table |
| 59 | HashMap listAttributeTypes = new HashMap(); |
| 60 | listAttributeTypes.put("persistence_id",Long.class); |
| 61 | listAttributeTypes.put("persistence_start",Long.class); |
| 62 | listAttributeTypes.put("persistence_end",Long.class); |
| 63 | listAttributeTypes.put("persistence_txstartid",Long.class); |
| 64 | listAttributeTypes.put("persistence_txstart",Long.class); |
| 65 | listAttributeTypes.put("persistence_txendid",Long.class); |
| 66 | listAttributeTypes.put("persistence_txend",Long.class); |
| 67 | listAttributeTypes.put("value",Long.class); |
| 68 | listAttributeTypes.put("container_index",Long.class); |
| 69 | ArrayList listKeys = new ArrayList(); |
| 70 | listKeys.add("persistence_id"); |
| 71 | listKeys.add("persistence_txstart"); |
| 72 | listKeys.add("container_index"); |
| 73 | database.ensureTable( |
| 74 | tx,schemaManager.getTableName( |
| 75 | parentInfo.getAttributeClassEntry(attributeName),attributeName), |
| 76 | listAttributeTypes,listKeys,create); |
| 77 | } catch ( StoreException e ) { |
| 78 | tx.markRollbackOnly(); |
| 79 | throw e; |
| 80 | } catch ( Throwable e ) { |
| 81 | tx.markRollbackOnly(); |
| 82 | throw new StoreException("Unknown exception",e); |
| 83 | } finally { |
| 84 | tx.commit(); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | } |
| 89 | |
| 90 | |