KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > storage > implementation > database > RelationalDatabaseStorageManager


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10 package org.mmbase.storage.implementation.database;
11
12 import org.mmbase.module.core.*;
13 import org.mmbase.storage.StorageException;
14
15 /**
16  * A JDBC implementation of a storage manager for relational databases.
17  * @javadoc
18  *
19  * @author Pierre van Rooden
20  * @since MMBase-1.7
21  * @version $Id: RelationalDatabaseStorageManager.java,v 1.9 2005/10/07 18:49:22 michiel Exp $
22  */

23 public class RelationalDatabaseStorageManager extends DatabaseStorageManager {
24
25     /**
26      * Constructor
27      */

28     public RelationalDatabaseStorageManager() {
29     }
30
31     // javadoc is inherited
32
public double getVersion() {
33         return 1.0;
34     }
35
36     protected boolean tablesInheritFields() {
37         return false;
38     }
39
40     /**
41      * Adds a node to the passed builder and all its parent builders.
42      * @param node The node to insert. The node already needs to have a (new) number assigned
43      * @param builder the builder to store the node
44      * @throws StorageException if an error occurred during creation
45      */

46     public void create(final MMObjectNode node, final MMObjectBuilder builder) throws StorageException {
47         boolean localTransaction = !inTransaction;
48         if (localTransaction) {
49             beginTransaction();
50         }
51         try {
52             // insert in parent tables (from parents to childs) (especially because foreign keys on object's number may exist)
53
java.util.Iterator JavaDoc i = builder.getAncestors().iterator();
54             while(i.hasNext()) {
55                 MMObjectBuilder b = (MMObjectBuilder) i.next();
56                 super.create(node, b);
57             }
58             super.create(node, builder);
59             if (localTransaction) commit();
60         } catch (StorageException se) {
61             if (localTransaction && inTransaction) rollback();
62             throw se;
63         }
64     }
65
66     /**
67      * Changes a node in the passed builder and all its parent builders
68      * @param node The node to change
69      * @param builder the builder to change the node in
70      * @throws StorageException if an error occurred during change
71      */

72     public void change(MMObjectNode node, MMObjectBuilder builder) throws StorageException {
73         boolean localTransaction = !inTransaction;
74         if (localTransaction) {
75             beginTransaction();
76         }
77         try {
78             do {
79                 super.change(node, builder);
80                 builder = builder.getParentBuilder();
81             } while (builder!=null);
82             if (localTransaction) commit();
83         } catch (StorageException se) {
84             if (localTransaction && inTransaction) rollback();
85             throw se;
86         }
87     }
88
89     /**
90      * Deletes a node in the passed builder and all its parent builders.
91      * @param node The node to delete
92      * @param builder the builder to delete the node in
93      * @throws StorageException if an error occurred during delete
94      */

95     public void delete(MMObjectNode node, MMObjectBuilder builder) throws StorageException {
96         boolean localTransaction = !inTransaction;
97         if (localTransaction) {
98             beginTransaction();
99         }
100         
101         try {
102             do {
103                 super.delete(node, builder);
104                 builder = builder.getParentBuilder();
105             } while (builder!=null);
106             if (localTransaction) commit();
107         } catch (StorageException se) {
108             if (localTransaction && inTransaction) rollback();
109             throw se;
110         }
111     }
112
113 }
114
115
Popular Tags