1 17 package org.apache.ws.jaxme.sqls.impl; 18 19 import java.util.ArrayList ; 20 import java.util.Iterator ; 21 import java.util.List ; 22 23 import org.apache.ws.jaxme.sqls.SQLFactory; 24 import org.apache.ws.jaxme.sqls.Schema; 25 import org.apache.ws.jaxme.sqls.Table; 26 27 28 31 public class SchemaImpl implements Schema { 32 public static class NameImpl extends SQLFactoryImpl.IdentImpl implements Schema.Name { 33 NameImpl(String pName) { 34 super(pName); 35 } 36 public boolean equals(Object o) { 37 if (o == null || !(o instanceof Schema.Name)) { 38 return false; 39 } 40 return super.equals(o); 41 } 42 } 43 44 private SQLFactory sqlFactory; 45 private Schema.Name name; 46 private List tables = new ArrayList (); 47 48 53 protected SchemaImpl(SQLFactory pFactory, Schema.Name pName) { 54 sqlFactory = pFactory; 55 name = pName; 56 } 57 58 public SQLFactory getSQLFactory() { 59 return sqlFactory; 60 } 61 62 public Schema.Name getName() { 63 return name; 64 } 65 66 public Table newTable(String pName) { 67 return newTable(new TableImpl.NameImpl(pName)); 68 } 69 70 public Table newTable(Table.Name pName) { 71 if (pName == null) { 72 throw new NullPointerException ("A table name must not be null."); 73 } 74 Integer maxLength = getSQLFactory().getMaxTableNameLength(); 75 if (maxLength != null && pName.getName().length() > maxLength.intValue()) { 76 throw new IllegalArgumentException ("The length of the table name " + pName + 77 " exceeds the maximum length of " + maxLength); 78 } 79 Table table = getTable(pName); 80 if (table != null) { 81 throw new IllegalStateException ("A table named " + table.getName() + 82 " already exists in the schema " + getName()); 83 } 84 table = ((SQLFactoryImpl) getSQLFactory()).newTableImpl(this, pName); 85 tables.add(table); 86 return table; 87 } 88 89 public Table getTable(Table.Name pName) { 90 if (pName == null) { 91 throw new NullPointerException ("A table name must not be null."); 92 } 93 for (Iterator iter = getTables(); iter.hasNext(); ) { 94 Table table = (Table) iter.next(); 95 if (getSQLFactory().isTableNameCaseSensitive()) { 96 if (pName.getName().equalsIgnoreCase(table.getName().getName())) { 97 return table; 98 } 99 } else { 100 if (pName.equals(table.getName())) { 101 return table; 102 } 103 } 104 } 105 return null; 106 } 107 108 public Table getTable(String pName) { 109 return getTable(new TableImpl.NameImpl(pName)); 110 } 111 112 public Iterator getTables() { 113 return tables.iterator(); 114 } 115 116 public boolean equals(Object o) { 117 if (o == null || !(o instanceof Schema)) { 118 return false; 119 } 120 Schema other = (Schema) o; 121 if (getName() == null) { 122 return other.getName() == null; 123 } else { 124 return getName().equals(other.getName()); 125 } 126 } 127 128 public int hashCode() { 129 return getName() == null ? 0 : getName().hashCode(); 130 } 131 } 132 | Popular Tags |