1 22 23 28 29 package org.xquark.mapper.dbms; 30 31 import java.util.Arrays ; 32 33 import org.xquark.mapper.metadata.RepositoryConstants; 34 35 39 public class TableSpec 40 { 41 private static final String RCSRevision = "$Revision: 1.1 $"; 42 private static final String RCSName = "$Name: $"; 43 44 45 public static final byte TYPE_REPOSITORY = 0; 46 public static final byte TYPE_COLLECTIONS = 1; 47 public static final byte TYPE_TABLES = 2; 48 public static final byte TYPE_TABLE_SEQ = 3; 49 public static final byte TYPE_PATHS = 4; 50 public static final byte TYPE_DUAL = 5; 51 public static final byte TYPE_PATH_SEQ = 6; 52 public static final byte TYPE_DOCS = 7; 53 public static final byte TYPE_DOC_SEQ = 8; 54 public static final byte TYPE_FREE_DOC = 9; 55 public static final byte TYPE_STRUCT = 10; 56 public static final byte TYPE_DATA = 11; 57 public static final byte TYPE_USER_DATA = 12; 58 public static final byte TYPE_EXTRA = 13; 59 public static final byte TYPE_QUERY_TMP = 14; 60 61 62 public static final byte CAT_QUERY_TMP = 0; 63 public static final byte CAT_REPOSITORY = 1; 64 public static final byte CAT_COLLECTION = 2; 65 public static final byte CAT_USER_TABLE = 3; 66 67 public static final int CAT_COUNT = 4; 68 69 70 public static final byte TABLE_DEFAULT = 0; 71 public static final byte TABLE_SEQUENCE = 1; 72 public static final byte TABLE_INDEX_ORGANIZED = 2; 73 public static final byte TABLE_TEMPORARY = 3; 74 75 private static final byte[] tableTypes = 76 {TABLE_DEFAULT, TABLE_INDEX_ORGANIZED, TABLE_SEQUENCE, TABLE_TEMPORARY}; 77 78 private static final String [] tableTypeStrings = 79 {"default", "index_organized", "sequence", "temporary"}; 80 81 82 public static final short ANY = 0; 83 85 private byte type; 86 private byte dbmsType; 87 private byte cat; 88 89 private boolean sequence = false; 90 private short dbms; 91 private String suffix; 92 private ColumnSpec[] columns; 93 private ConstraintSpec[] constraints; 94 private IndexSpec[] indexes; 95 96 public TableSpec() {} 100 101 public TableSpec(byte cat, byte type) 102 { 103 this.cat = cat; 104 this.type = type; 105 } 106 107 public TableSpec(byte cat, byte type, boolean sequence, 108 String suffix, short dbms, String dbmsType) 109 { 110 set(cat, type, sequence, suffix, dbms, dbmsType); 111 } 112 113 public String getTableName() 114 { 115 StringBuffer tableName = new StringBuffer (); 116 tableName.append(RepositoryConstants.TABLE_PREFIX); 117 tableName.append(suffix); 118 119 return tableName.toString(); 120 } 121 122 public String getTableName(short collectionID) 123 { 124 StringBuffer tableName = new StringBuffer (); 125 tableName.append(RepositoryConstants.TABLE_PREFIX); 126 tableName.append(collectionID); 127 tableName.append('_'); 128 tableName.append(suffix); 129 130 return tableName.toString(); 131 } 132 133 public String getAllCollectionsWildcardTableName() 134 { 135 StringBuffer tableName = new StringBuffer (); 136 tableName.append(RepositoryConstants.TABLE_PREFIX); 137 tableName.append("%_"); 138 tableName.append(suffix); 139 140 return tableName.toString(); 141 } 142 143 public String getTableName(short collectionID, short tableID) 144 { 145 StringBuffer tableName = new StringBuffer (); 146 tableName.append(RepositoryConstants.TABLE_PREFIX); 147 tableName.append(collectionID); 148 tableName.append('_'); 149 tableName.append(suffix); 150 tableName.append(tableID); 151 152 return tableName.toString(); 153 } 154 155 public void set(byte cat, byte type, boolean sequence, 159 String suffix, short dbms, String dbmsType) 160 { 161 this.cat = cat; 162 this.type = type; 163 this.sequence = sequence; 164 this.suffix = suffix; 165 this.dbms = dbms; 166 this.dbmsType = parseDBMSType(dbmsType); 167 } 168 169 public String getSuffix() 170 { 171 return suffix; 172 } 173 174 public byte getType() 175 { 176 return type; 177 } 178 179 public byte getDBMSType() 180 { 181 return dbmsType; 182 } 183 184 public short getDBMSVendor() 185 { 186 return dbms; 187 } 188 189 public boolean isSequence() 190 { 191 return sequence; 192 } 193 194 public ColumnSpec[] getColumns() 195 { 196 return columns; 197 } 198 199 public ConstraintSpec[] getConstraints() 200 { 201 return constraints; 202 } 203 204 public IndexSpec[] getIndexes() 205 { 206 return indexes; 207 } 208 209 public void setSuffix(String suffix) 210 { 211 this.suffix = suffix; 212 } 213 214 public void setColumns(ColumnSpec[] columns) 215 { 216 this.columns = columns; 217 } 218 219 public void setConstraints(ConstraintSpec[] constraints) 220 { 221 this.constraints = constraints; 222 } 223 224 public void setIndexes(IndexSpec[] indexes) 225 { 226 this.indexes = indexes; 227 } 228 229 private byte parseDBMSType(String type) 230 { 231 int index = Arrays.binarySearch(tableTypeStrings, type); 232 if (index < 0) 233 throw new RuntimeException ("The DBMS table type" + type + " used in tableSpec.xml is unknown."); 234 return tableTypes[index]; 235 } 236 } 237 | Popular Tags |