KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > sqls > db2 > DB2SQLFactoryImpl


1 /*
2  * Copyright 2003, 2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15
16  */

17 package org.apache.ws.jaxme.sqls.db2;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.Collections JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.List JavaDoc;
23
24 import org.apache.ws.jaxme.sqls.Column;
25 import org.apache.ws.jaxme.sqls.SQLGenerator;
26 import org.apache.ws.jaxme.sqls.Schema;
27 import org.apache.ws.jaxme.sqls.Table;
28 import org.apache.ws.jaxme.sqls.impl.SQLFactoryImpl;
29
30
31 /** <p>Default implementation of an SQL factory for DB2 databases.
32  * This factory ensures that the created implementations of
33  * {@link Schema}, {@link Table}, {@link Column}, and {@link SQLGenerator}
34  * may be casted to {@link DB2Schema}, {@link DB2Table}, {@link DB2Column},
35  * {@link DB2SQLGenerator}, respectively.</p>
36  *
37  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
38  */

39 public class DB2SQLFactoryImpl extends SQLFactoryImpl
40     implements DB2SQLFactory {
41   /** <p>An immutable, predefined TableSpace.</p>
42    */

43   public class PredefinedTableSpace implements TableSpace {
44     private TableSpace.Name name;
45     private TableSpace.Type type;
46
47     PredefinedTableSpace(String JavaDoc pName, TableSpace.Type pType) {
48       name = new TableSpaceImpl.NameImpl(pName);
49       type = pType;
50     }
51     public DB2SQLFactory getSQLFactory() { return DB2SQLFactoryImpl.this; }
52     public Name getName() { return name; }
53     public Type getType() { return type; }
54     public PageSize getPageSize() { return null; }
55     public Long JavaDoc getExtentSize() { return null; }
56     public Long JavaDoc getPrefetchSize() { return null; }
57     public Number JavaDoc getOverhead() { return null; }
58     public Number JavaDoc getTransferRate() { return null; }
59     public Boolean JavaDoc hasDroppedTableRecovery() { return null; }
60     public BufferPool getBufferPool() { return null; }
61     public boolean isPredefined() { return true; }
62     public void setPageSize(PageSize pSize) {
63       throw new IllegalStateException JavaDoc("This tablespace is immutable.");
64     }
65     public void setExtentSize(Long JavaDoc pSize) {
66       throw new IllegalStateException JavaDoc("This tablespace is immutable.");
67     }
68     public void setPrefetchSize(Long JavaDoc pSize) {
69       throw new IllegalStateException JavaDoc("This tablespace is immutable.");
70     }
71     public void setOverhead(Number JavaDoc pOverhead) {
72       throw new IllegalStateException JavaDoc("This tablespace is immutable.");
73     }
74     public void setTransferRate(Number JavaDoc pNumber) {
75       throw new IllegalStateException JavaDoc("This tablespace is immutable.");
76     }
77     public void setDroppedTableRecovery(Boolean JavaDoc pRecoverable) {
78       throw new IllegalStateException JavaDoc("This tablespace is immutable.");
79     }
80     public Container newSystemManagedContainer(String JavaDoc pFile) {
81       throw new IllegalStateException JavaDoc("This tablespace is immutable.");
82     }
83     public Container newDatabaseManagedContainerInFile(String JavaDoc pFile, long pNumPages) {
84       throw new IllegalStateException JavaDoc("This tablespace is immutable.");
85     }
86     public Container newDatabaseManagedContainerInDevice(String JavaDoc pDevice, long pNumPages) {
87       throw new IllegalStateException JavaDoc("This tablespace is immutable.");
88     }
89     public Iterator JavaDoc getContainers() {
90       return Collections.EMPTY_LIST.iterator();
91     }
92     public void setBufferPool(BufferPool pBufferPool) {
93       throw new IllegalStateException JavaDoc("This tablespace is immutable.");
94     }
95   }
96
97   /** <p>The predefined table space <code>SYSCATSPACE</code>.</p>
98    */

99   public final TableSpace SYSCATSPACE = new PredefinedTableSpace("SYSCATSPACE", TableSpace.Type.REGULAR);
100   /** <p>The predefined table space <code>TEMPSPACE1</code>.</p>
101    */

102   public final TableSpace TEMPSPACE1 = new PredefinedTableSpace("TEMPSPACE1", TableSpace.Type.SYSTEM_TEMPORARY);
103   /** <p>The predefined table space <code>USERSPACE1</code>.</p>
104    */

105   public final TableSpace USERSPACE1 = new PredefinedTableSpace("USERSPACE1", TableSpace.Type.USER_TEMPORARY);
106
107   private List JavaDoc tableSpaces = new ArrayList JavaDoc();
108
109   public DB2SQLFactoryImpl() {}
110
111   public Schema newSchemaImpl(Schema.Name pName) {
112     return new DB2SchemaImpl(this, pName);
113   }
114
115   public Table newTableImpl(Schema pSchema, Table.Name pName) {
116     return new DB2TableImpl(pSchema, pName);
117   }
118
119   public Column newColumn(Table pTable, Column.Name pName, Column.Type pType) {
120     return new DB2ColumnImpl(pTable, pName, pType);
121   }
122
123   public SQLGenerator newSQLGenerator() {
124     return new DB2SQLGeneratorImpl();
125   }
126
127   public TableSpace newTableSpace(String JavaDoc pName, TableSpace.Type pType) {
128     if (pName == null) {
129       throw new NullPointerException JavaDoc("The tablespace name must not be null. Use getDefaultTableSpace() to access the default TableSpace.");
130     }
131     return newTableSpace(new TableSpaceImpl.NameImpl(pName), pType);
132   }
133
134   public TableSpace newTableSpace(TableSpace.Name pName, TableSpace.Type pType) {
135     if (pName == null) {
136       throw new NullPointerException JavaDoc("The tablespace name must not be null. Use getDefaultTableSpace() to access the default TableSpace.");
137     }
138     if (getTableSpace(pName) != null) {
139       throw new IllegalStateException JavaDoc("A TableSpace named " + pName + " already exists.");
140     }
141     TableSpace result = newTableSpaceImpl(pName, pType);
142     tableSpaces.add(result);
143     return result;
144   }
145
146   protected TableSpace newTableSpaceImpl(TableSpace.Name pName, TableSpace.Type pType) {
147     return new TableSpaceImpl(this, pName, pType);
148   }
149
150   public TableSpace getTableSpace(TableSpace.Name pName) {
151     for (Iterator JavaDoc iter = tableSpaces.iterator(); iter.hasNext(); ) {
152       TableSpace tableSpace = (TableSpace) iter.next();
153       if (pName.equals(tableSpace.getName())) {
154         return tableSpace;
155       }
156     }
157     if (pName.equals(SYSCATSPACE.getName())) {
158        return SYSCATSPACE;
159     }
160     if (pName.equals(TEMPSPACE1.getName())) {
161        return TEMPSPACE1;
162     }
163     if (pName.equals(USERSPACE1.getName())) {
164        return USERSPACE1;
165     }
166     return null;
167   }
168
169   public TableSpace getTableSpace(String JavaDoc pName) {
170     return getTableSpace(new TableSpaceImpl.NameImpl(pName));
171   }
172
173   public Iterator JavaDoc getTableSpaces() {
174     return tableSpaces.iterator();
175   }
176 }
177
Popular Tags