JavaDoc


001    /**
002     * Copyright (c) 2008 Regiscope Digital Imaging Co, LLC, All rights reserved.
003     * This program is free software; you can redistribute it and/or modify
004     * it under the terms of version 2 of the GNU General Public License as
005     * published by the Free Software Foundation.
006     * There are special exceptions to the terms and conditions of the GPL
007     * as it is applied to this software. See the GNU General Public License for more details.
008     *
009     * This program is distributed in the hope that it will be useful,
010     * but WITHOUT ANY WARRANTY; without even the implied warranty of
011     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012     * GNU General Public License for more details.
013     *
014     * You should have received a copy of the GNU General Public License
015     * along with this program; if not, write to the Free Software
016     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017     */
018    
019    package org.dbreplicator.replication.column;
020    
021    import java.io.*;
022    import java.sql.*;
023    import java.util.*;
024    
025    import org.dbreplicator.replication.xml.*;
026    import org.dbreplicator.replication.EncoderDecoder;
027    import org.dbreplicator.replication.DBHandler.AbstractDataBaseHandler;
028    
029    /**
030     * The Integer Class
031     */
032    public class IntegerObject extends AbstractColumnObject
033    {
034    
035        int sqlType;
036        AbstractDataBaseHandler abstractDBHandler;
037    
038        /**
039         * sets the SQL type fro Integer datatype
040         * @param sqlType0
041         */
042        public IntegerObject(int sqlType0,AbstractDataBaseHandler abstractDBHandler0)
043        {
044            sqlType = sqlType0;
045            abstractDBHandler=abstractDBHandler0;
046        }
047    
048        /**
049         * set the value for the corresponding datatype i.e Integer
050         * @param pst
051         * @param element
052         * @param index
053         * @throws SQLException
054         */
055        public void setColumnObject(PreparedStatement pst, XMLElement element,
056                                    int index) throws SQLException
057        {
058            String value = element.elementValue;
059            setColumnObject(pst, value, index);
060        }
061    
062        public void setColumnObject(PreparedStatement pst, String value,
063                                    int index) throws SQLException
064        {
065            if (value.equalsIgnoreCase("NULL"))
066            {
067                pst.setNull(index, sqlType);
068            }
069            else
070            {
071                pst.setInt(index, Integer.parseInt(value));
072            }
073        }
074    
075        /**
076         * writes a Integer values in XML file
077         * @param os
078         * @param rs
079         * @param index
080         * @throws IOException
081         * @throws SQLException
082         */
083        public void write(Writer os, ResultSet rs, int index,ArrayList encodedCols,String col) throws
084            SQLException, IOException
085        {
086            try
087            {
088                if(!encodedCols.contains(col.toUpperCase())) {
089                  os.write(getObject(rs, index).toString());
090    //            os.write("<![CDATA[" + getObject(rs, index).toString() + "]]>");
091                } else {
092                  os.write(EncoderDecoder.escapeUnicodeString1(getObject(rs, index).
093                      toString(), true));
094    //              os.write("<![CDATA[" +
095    //                       EncoderDecoder.escapeUnicodeString1(getObject(rs, index).
096    //                  toString(), true) +
097    //                       "]]>");
098                }
099    
100    
101            }
102            catch (NullPointerException ex)
103            {
104                os.write("NULL");
105            }
106        }
107    
108        private void write(Writer os, Object rowValue,ArrayList encodedCols,String col) throws
109            SQLException, IOException
110        {
111            try
112            {
113                if(!encodedCols.contains(col.toUpperCase())) {
114                os.write("<![CDATA[" + rowValue.toString() + "]]>");
115                } else {
116                  os.write("<![CDATA[" +
117                           EncoderDecoder.escapeUnicodeString1(rowValue.toString(), true) +
118                           "]]>");
119                }
120            }
121            catch (NullPointerException ex)
122            {
123                os.write("NULL");
124            }
125        }
126    
127        /**
128         * puts the value for the column aginst the column Name
129         * @param os
130         * @param rows
131         * @param oldResultSet
132         * @param index
133         * @param modifiedColumns
134         * @param columnName
135         * @throws SQLException
136         * @throws IOException
137         */
138        public void writeUpdate(Writer os, ResultSet rows,
139                                ResultSet oldResultSet
140                                , int index, HashMap modifiedColumns,
141                                String columnName,ArrayList encodedCols) throws SQLException, IOException
142        {
143            Object newObject = rows.getObject(index);
144            Object oldObject = oldResultSet.getObject(index);
145    
146            if (newObject == null)
147            {
148                write(os, "NULL",encodedCols,columnName);
149                if (oldObject != null)
150                {
151                    modifiedColumns.put(columnName, "NULL");
152                }
153            }
154            else
155            {
156                write(os, newObject,encodedCols,columnName);
157                if (oldObject != null)
158                {
159                    if (! (newObject.equals(oldObject)))
160                    {
161                        modifiedColumns.put(columnName, newObject);
162                    }
163                }
164                else
165                {
166                    modifiedColumns.put(columnName, newObject);
167                }
168    
169            }
170        }
171    
172        /**
173         * returns the parsed value of String in Integer
174         * @param value String
175         * @return Object
176         */
177        public Object getObject(String value) throws SQLException
178        {
179            if (value.equalsIgnoreCase("NULL"))
180            {
181                return null;
182            }
183            return Integer.valueOf(value);
184        }
185    
186        /**
187         * returns the Object corresponding to the index passed from the resultSet
188         * @param row
189         * @param index
190         * @return
191         * @throws SQLException
192         */
193    
194        private Object getObject(ResultSet row, int index) throws SQLException
195        {
196            return row.getObject(index);
197        }
198    
199    
200    
201    }





























































Powered by Drupal - Theme by Danger4k