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 import org.apache.log4j.Logger; 023 024 /** 025 * This class is helpful for the multiple datatype handling in the multidatabse 026 * environment. For each column this typeinfo object stores it's sqlType which 027 * can be obtained from the JVM. Now by using the database handlers this typeInfo 028 * is set to it's corresponding database datatype , this inforamtion is saved in 029 * typeName. It also maintains information for the optional size supported datatypes. 030 * 031 */ 032 public class TypeInfo 033 { 034 035 protected static Logger log = Logger.getLogger(TypeInfo.class. 036 getName()); 037 038 private String typeName; 039 private int sqlType; 040 private boolean optsize; 041 private int columnSize0 = -1; 042 private int columnScale=-1; 043 044 045 public TypeInfo(String typeName0, int sqlType0) 046 { 047 typeName = typeName0; 048 sqlType = sqlType0; 049 } 050 051 public void setColumnSize(int columnSize) 052 { 053 columnSize0 = columnSize; 054 } 055 056 public int getcolumnSize() 057 { 058 return columnSize0; 059 } 060 061 public int getSqlType() 062 { 063 return sqlType; 064 } 065 066 public String getTypeName() 067 { 068 return typeName; 069 } 070 071 public void setSqlType(int sqlType0) { 072 sqlType = sqlType0; 073 } 074 075 public void setTypeName(String typeName0) { 076 typeName = typeName0; 077 } 078 079 public void setOptionalSizeProperty(boolean optsize0) { 080 optsize = optsize0; 081 } 082 083 public String getTypeDeclaration(int size) { 084 if (size == -1 || size == 0 || !optsize) { 085 return typeName; 086 } 087 StringBuffer temp = new StringBuffer(); 088 if (columnScale != 0) { 089 temp.append(typeName).append("( ").append(size).append(" , ").append( 090 columnScale).append(" )"); 091 } 092 else { 093 temp.append(typeName).append("( ").append(size).append(" )"); 094 } 095 return temp.toString(); 096 } 097 098 public int hashCode() { 099 return 17 * typeName.hashCode() + 47 * sqlType; 100 } 101 102 public String toString() 103 { 104 log.debug("[TYPEINFO[typename=" + typeName + "][sqlType=" + sqlType + "]]"); 105 return "[TYPEINFO[typename=" + typeName + "][sqlType=" + sqlType + "]]"; 106 } 107 108 public void setColumnScale(int columnScale0) 109 { 110 columnScale = columnScale0; 111 } 112 113 public int getColumnScale() 114 { 115 return columnScale; 116 } 117 118 }

