1 17 package org.apache.ws.jaxme.sqls.db2; 18 19 import java.util.ArrayList ; 20 import java.util.Collections ; 21 import java.util.Iterator ; 22 import java.util.List ; 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 39 public class DB2SQLFactoryImpl extends SQLFactoryImpl 40 implements DB2SQLFactory { 41 43 public class PredefinedTableSpace implements TableSpace { 44 private TableSpace.Name name; 45 private TableSpace.Type type; 46 47 PredefinedTableSpace(String 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 getExtentSize() { return null; } 56 public Long getPrefetchSize() { return null; } 57 public Number getOverhead() { return null; } 58 public Number getTransferRate() { return null; } 59 public Boolean 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 ("This tablespace is immutable."); 64 } 65 public void setExtentSize(Long pSize) { 66 throw new IllegalStateException ("This tablespace is immutable."); 67 } 68 public void setPrefetchSize(Long pSize) { 69 throw new IllegalStateException ("This tablespace is immutable."); 70 } 71 public void setOverhead(Number pOverhead) { 72 throw new IllegalStateException ("This tablespace is immutable."); 73 } 74 public void setTransferRate(Number pNumber) { 75 throw new IllegalStateException ("This tablespace is immutable."); 76 } 77 public void setDroppedTableRecovery(Boolean pRecoverable) { 78 throw new IllegalStateException ("This tablespace is immutable."); 79 } 80 public Container newSystemManagedContainer(String pFile) { 81 throw new IllegalStateException ("This tablespace is immutable."); 82 } 83 public Container newDatabaseManagedContainerInFile(String pFile, long pNumPages) { 84 throw new IllegalStateException ("This tablespace is immutable."); 85 } 86 public Container newDatabaseManagedContainerInDevice(String pDevice, long pNumPages) { 87 throw new IllegalStateException ("This tablespace is immutable."); 88 } 89 public Iterator getContainers() { 90 return Collections.EMPTY_LIST.iterator(); 91 } 92 public void setBufferPool(BufferPool pBufferPool) { 93 throw new IllegalStateException ("This tablespace is immutable."); 94 } 95 } 96 97 99 public final TableSpace SYSCATSPACE = new PredefinedTableSpace("SYSCATSPACE", TableSpace.Type.REGULAR); 100 102 public final TableSpace TEMPSPACE1 = new PredefinedTableSpace("TEMPSPACE1", TableSpace.Type.SYSTEM_TEMPORARY); 103 105 public final TableSpace USERSPACE1 = new PredefinedTableSpace("USERSPACE1", TableSpace.Type.USER_TEMPORARY); 106 107 private List tableSpaces = new ArrayList (); 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 pName, TableSpace.Type pType) { 128 if (pName == null) { 129 throw new NullPointerException ("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 ("The tablespace name must not be null. Use getDefaultTableSpace() to access the default TableSpace."); 137 } 138 if (getTableSpace(pName) != null) { 139 throw new IllegalStateException ("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 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 pName) { 170 return getTableSpace(new TableSpaceImpl.NameImpl(pName)); 171 } 172 173 public Iterator getTableSpaces() { 174 return tableSpaces.iterator(); 175 } 176 } 177 | Popular Tags |