1 24 25 package com.mckoi.database; 26 27 33 34 public final class TableName implements Comparable , java.io.Serializable { 35 36 static final long serialVersionUID = 6527135256976754916L; 37 38 41 private static final String UNKNOWN_SCHEMA_NAME = "##UNKNOWN_SCHEMA##"; 42 43 47 private final String schema_name; 48 49 52 private final String table_name; 53 54 57 public TableName(String schema_name, String table_name) { 58 if (table_name == null) { 59 throw new NullPointerException ("'name' can not be null."); 60 } 61 if (schema_name == null) { 62 schema_name = UNKNOWN_SCHEMA_NAME; 63 } 64 65 this.schema_name = schema_name; 66 this.table_name = table_name; 67 } 68 69 public TableName(String table_name) { 70 this(UNKNOWN_SCHEMA_NAME, table_name); 71 } 72 73 76 public String getSchema() { 77 if (schema_name.equals(UNKNOWN_SCHEMA_NAME)) { 78 return null; 79 } 80 else { 81 return schema_name; 82 } 83 } 84 85 88 public String getName() { 89 return table_name; 90 } 91 92 97 public TableName resolveSchema(String scheman) { 98 if (schema_name.equals(UNKNOWN_SCHEMA_NAME)) { 99 return new TableName(scheman, getName()); 100 } 101 return this; 102 } 103 104 109 public static TableName resolve(String schemav, String namev) { 110 int i = namev.indexOf('.'); 111 if (i == -1) { 112 return new TableName(schemav, namev); 113 } 114 else { 115 return new TableName(namev.substring(0, i), namev.substring(i + 1)); 116 } 117 } 118 119 123 public static TableName resolve(String namev) { 124 return resolve(UNKNOWN_SCHEMA_NAME, namev); 125 } 126 127 129 132 public String toString() { 133 if (getSchema() != null) { 134 return getSchema() + "." + getName(); 135 } 136 return getName(); 137 } 138 139 142 public boolean equals(Object ob) { 143 TableName tn = (TableName) ob; 144 return tn.schema_name.equals(schema_name) && 145 tn.table_name.equals(table_name); 146 } 147 148 151 public boolean equalsIgnoreCase(TableName tn) { 152 return tn.schema_name.equalsIgnoreCase(schema_name) && 153 tn.table_name.equalsIgnoreCase(table_name); 154 } 155 156 159 public int compareTo(Object ob) { 160 TableName tn = (TableName) ob; 161 int v = schema_name.compareTo(tn.schema_name); 162 if (v == 0) { 163 return table_name.compareTo(tn.table_name); 164 } 165 return v; 166 } 167 168 171 public int hashCode() { 172 return schema_name.hashCode() + table_name.hashCode(); 173 } 174 175 } 176 | Popular Tags |