001 /** 002 * Copyright (c) 2003 Daffodil Software Ltd all rights reserved, 003 * Modifications Copyright (c) 2008 Regiscope Digital Imaging Co, LLC, All rights reserved. 004 * This program is free software; you can redistribute it and/or modify 005 * it under the terms of version 2 of the GNU General Public License as 006 * published by the Free Software Foundation. 007 * There are special exceptions to the terms and conditions of the GPL 008 * as it is applied to this software. See the GNU General Public License for more details. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU General Public License for more details. 014 * 015 * You should have received a copy of the GNU General Public License 016 * along with this program; if not, write to the Free Software 017 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 018 */ 019 020 package org.dbreplicator.replication; 021 022 public class SchemaQualifiedName 023 { 024 025 private String catalog; 026 private String schema; 027 private String tableName; 028 029 /** 030 * This class is responsible for keeping catalog, schema and tablename sapearte. 031 * It is used to find out the schema name or catalog name or table name from the 032 * specified formate tablename. 033 * It performs all saperation and conjunction operations over above specified 034 * fields. 035 */ 036 037 public SchemaQualifiedName() { 038 } 039 040 public SchemaQualifiedName(MetaDataInfo mdi, String catalog0, String schema0,String tableName0) { 041 catalog = catalog0; 042 if (schema0 != null) { 043 if (mdi instanceof pgMetaDataInfo) { 044 schema = schema0; 045 } 046 else { 047 schema = schema0.toUpperCase(); 048 } 049 } 050 tableName = tableName0; 051 } 052 053 public SchemaQualifiedName(MetaDataInfo mdi, String identifier) { 054 catalog = mdi.getCatalogName(identifier); 055 schema = mdi.getSchemaName(identifier); 056 tableName = mdi.getTableName(identifier); 057 } 058 059 public String getCatalogName() { 060 return catalog; 061 } 062 063 public String getSchemaName() { 064 //return schema != null ? schema.toUpperCase() : null; 065 return schema; 066 } 067 068 public String getTableName() { 069 //return tableName != null ? tableName.toUpperCase() : null; 070 return tableName; 071 } 072 073 074 public void setSchemaName(MetaDataInfo mds,String schemaName0) 075 { 076 if(schemaName0!=null){ 077 if(mds instanceof pgMetaDataInfo) { 078 schema = schemaName0; 079 } 080 else { 081 schema = schemaName0.toUpperCase(); 082 } 083 } 084 } 085 086 public boolean equals(Object obj) { 087 SchemaQualifiedName sname = (SchemaQualifiedName) obj; 088 if(schema!=null) 089 return schema.equalsIgnoreCase(sname.getSchemaName()) && tableName.equalsIgnoreCase(sname.getTableName()); 090 else 091 return tableName.equalsIgnoreCase(sname.getTableName()); 092 } 093 094 public int hashCode() { 095 if(schema!=null) 096 return 13 * schema.toUpperCase().hashCode() + 17 * tableName.toUpperCase().hashCode(); 097 else 098 return 17 * tableName.toUpperCase().hashCode(); 099 } 100 101 public String toString() { 102 return getSchemaName() != null ? getSchemaName() + "." + getTableName() : getTableName(); 103 } 104 105 // public String toString1() { 106 // return getSchemaName()!=null ? 107 // getSchemaName()+".\""+getTableName()+"\"" 108 // : "\""+getTableName()+"\""; 109 // } 110 // public static void main(String[] args) { 111 // SchemaQualifiedName sname1 = new SchemaQualifiedName("sachin.agarwal.kumar"); 112 // SchemaQualifiedName sname2 = new SchemaQualifiedName("sachin.agarwal"); 113 // SchemaQualifiedName sname3 = new SchemaQualifiedName("sachin"); 114 // SchemaQualifiedName sname1 = new SchemaQualifiedName("a.b.c"); 115 // SchemaQualifiedName sname2 = new SchemaQualifiedName("a.b"); 116 // SchemaQualifiedName sname3 = new SchemaQualifiedName("a"); 117 // } 118 }

