1 22 23 package org.xquark.extractor.algebra; 24 25 import org.xquark.extractor.common.SqlWrapperException; 26 27 public final class CollectionName { 28 29 private static final String RCSRevision = "$Revision: 1.4 $"; 30 private static final String RCSName = "$Name: $"; 31 32 33 private String _dataSource = null; 34 private String _catalog = null; 35 private String _schema = null; 36 private String _table = null; 37 38 public CollectionName(String source, String collection) throws SqlWrapperException{ 39 _dataSource = source; 42 int index = -1; 43 String [] steps = new String [3]; 44 int newIndex = -1; 45 int stepCursor = 0; 46 while (true) { 47 newIndex = collection.indexOf(".", index + 1); 48 if (-1 != newIndex) { 49 steps [stepCursor] = collection.substring(index + 1, newIndex); 50 if (0 ==steps [stepCursor].length()) { 51 throw new SqlWrapperException("Collection name string is not valid."); 52 } 53 index = newIndex; 54 stepCursor ++; 55 } 56 else { 57 steps [stepCursor] = collection.substring(index + 1, collection.length()); 58 if (0 ==steps [stepCursor].length()) { 59 throw new SqlWrapperException("Collection name string is not valid."); 60 } 61 stepCursor ++; 62 break; 63 } 64 } 65 if (1 == stepCursor) { 66 _table = steps[0]; 67 } 68 else if (2 == stepCursor) { 69 _schema = steps[0]; 70 _table = steps[1]; 71 } 72 else if (3 == stepCursor) { 73 _catalog = steps[0]; 74 _schema = steps[1]; 75 _table = steps[2]; 76 } 77 else { 78 throw new SqlWrapperException("Collection name string is not valid."); 79 } 80 } 82 83 public String getDataSource() { return _dataSource;} 84 85 public String getCatalog() { return _catalog;} 86 87 public String getSchema() { return _schema; } 88 public void setSchema(String schema) { _schema = schema; } 89 90 public boolean dataSourceIsWildCard() 91 { 92 boolean retVal = false; 93 if (null != _dataSource){ 94 if (_dataSource.equals("*")) { 95 retVal = true; 96 } 97 } 98 return retVal; 99 } 100 101 public boolean catalogIsWildCard() 102 { 103 boolean retVal = false; 104 if (null != _catalog){ 105 if (_catalog.equals("*")) { 106 retVal = true; 107 } 108 } 109 return retVal; 110 } 111 112 public boolean schemaIsWildCard() 113 { 114 boolean retVal = false; 115 if (null != _schema){ 116 if (_schema.equals("*")) { 117 retVal = true; 118 } 119 } 120 return retVal; 121 } 122 123 public boolean tableIsWildCard() 124 { 125 boolean retVal = false; 126 if (null != _table){ 127 if (_table.equals("*")) { 128 retVal = true; 129 } 130 } 131 return retVal; 132 } 133 134 public String getTable() { return _table; } 135 136 public void setTable(String table) { _table = table; } 137 138 public String pprint() { 139 141 StringBuffer retVal = new StringBuffer (); 142 if (null != _dataSource) { 143 retVal.append(_dataSource); 144 retVal.append(":"); 145 } 146 147 if (null != _catalog) { 148 retVal.append(_catalog); 149 retVal.append("."); 150 } 151 152 if (null != _schema) { 153 retVal.append(_schema); 154 retVal.append("."); 155 } 156 157 if (null != _table) { 158 retVal.append(_table); 159 retVal.append("."); 160 } 161 162 return retVal.toString(); 164 } 165 166 171 public boolean equals(Object o) { 172 if (o instanceof CollectionName) { 173 CollectionName cast = (CollectionName) o; 174 return _dataSource.equalsIgnoreCase(cast.getDataSource()) 175 && _catalog.equalsIgnoreCase(cast.getDataSource()) 176 && _schema.equalsIgnoreCase(cast.getSchema()) 177 && _table.equalsIgnoreCase(cast.getTable()); 178 } 179 return false; 180 } 181 } 182 | Popular Tags |