KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > database > general > QualifiedIdentifier


1 package com.daffodilwoods.database.general;
2
3 import java.io.*;
4 import com.daffodilwoods.database.resource.*;
5 public class QualifiedIdentifier implements Externalizable{
6
7     public String JavaDoc catalog;
8
9     private static final long serialVersionUID = 6821180509771995439L;
10
11     public String JavaDoc schema;
12
13     public String JavaDoc name;
14     private String JavaDoc qualifiedName;
15
16     public QualifiedIdentifier() {
17     }
18
19     public QualifiedIdentifier(String JavaDoc catalog,String JavaDoc schema,String JavaDoc name) {
20       this.catalog = catalog;
21       this.schema = schema;
22       this.name = name;
23       initIdentifier();
24     }
25
26     public QualifiedIdentifier(String JavaDoc identifier) {
27       int table_name_index = identifier.lastIndexOf('.');
28       if(table_name_index == -1) {
29         name = identifier;
30       }
31       else {
32         name = identifier.substring(table_name_index+1);
33         int catalog_index = identifier.indexOf('.');
34         catalog = identifier.substring(0,catalog_index);
35         schema = identifier.substring(catalog_index+1, table_name_index);
36       }
37
38       initIdentifier();
39     }
40
41     public String JavaDoc getName() throws DException {
42       return name;
43     }
44
45     public String JavaDoc getIdentifier(){
46       return qualifiedName;
47     }
48
49       private void initIdentifier(){
50
51        StringBuffer JavaDoc identifier = new StringBuffer JavaDoc(25);
52        synchronized(identifier){
53          if(catalog != null && !(catalog.trim().equals("")))
54            identifier.append(catalog).append('.');
55          if(schema != null && !(schema.trim().equals("")))
56            identifier.append(schema).append('.');
57          if(name.indexOf("\"") == -1)
58            identifier.append(name);
59          else
60            identifier.append("\"").append(name).append("\"");
61
62          qualifiedName = identifier.toString();
63        }
64     }
65
66     public boolean equals1(Object JavaDoc value) {
67         if( ! (value instanceof String JavaDoc || value instanceof QualifiedIdentifier) )
68         return false;
69       String JavaDoc newIdentifier = value instanceof QualifiedIdentifier ? ((QualifiedIdentifier)value).getIdentifier() : (String JavaDoc)value;
70       return newIdentifier.equalsIgnoreCase(getIdentifier());
71     }
72
73     public boolean equals(Object JavaDoc value) {
74 if(value instanceof String JavaDoc){
75          ;//// Removed By Program ** System.out.println(value +" "+ this);
76
Thread.dumpStack();
77 }
78          QualifiedIdentifier q = (QualifiedIdentifier)value;
79          if( q.schema.equalsIgnoreCase("system") )
80            Thread.dumpStack();
81          return q.catalog.equalsIgnoreCase(catalog) && q.schema.equalsIgnoreCase(schema) && q.name.equalsIgnoreCase(name);
82     }
83     public int hashCode(){
84       return schema.toLowerCase().hashCode() + catalog.toLowerCase().hashCode() + name.toLowerCase().hashCode();
85     }
86
87     public String JavaDoc toString() {
88       return getIdentifier();// "Catalog : ["+catalog+"] Schema : ["+schema+"] TableName : ["+name+"]";
89
}
90
91     public void writeExternal(ObjectOutput objectOutput) {
92         try {
93         objectOutput.writeObject(catalog);
94         objectOutput.writeObject(schema);
95         objectOutput.writeObject(name);
96         }catch(IOException ioe ) {
97         }
98     }
99     public void readExternal(ObjectInput objectInput) {
100         try {
101         catalog = (String JavaDoc)objectInput.readObject();
102         schema = (String JavaDoc)objectInput.readObject();
103         name = (String JavaDoc)objectInput.readObject();
104         }catch(IOException ioe ) {
105         }catch(ClassNotFoundException JavaDoc cnfe) {
106         }
107         initIdentifier();
108     }
109     public String JavaDoc[] getTableName() throws DException{
110        return new String JavaDoc[]{catalog,schema,name};
111     }
112
113 }
114
Popular Tags