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.DBHandler.AbstractDataBaseHandler;
027    
028    /**
029     * Handles boolean (true/false) data types.
030     */
031    public class BooleanObject extends AbstractColumnObject
032    {
033    
034        int sqlType;
035        AbstractDataBaseHandler abstractDBHandler;
036        /**
037         * sets the SQL type fro boolean datatype
038         * @param sqlType0
039         */
040        public BooleanObject(int sqlType0,AbstractDataBaseHandler abstractDBHandler0)
041        {
042            sqlType = sqlType0;
043            abstractDBHandler= abstractDBHandler0;
044        }
045    
046        /**
047         * set the value for the corresponding datatype i.e boolean
048         * @param pst
049         * @param element
050         * @param index
051         * @throws SQLException
052         */
053        public void setColumnObject(PreparedStatement pst, XMLElement element,
054                                    int index) throws SQLException
055        {
056            String value = element.elementValue;
057            setColumnObject(pst, value, index);
058        }
059    
060        public void setColumnObject(PreparedStatement pst, String value,
061                                    int index) throws SQLException
062        {
063            if (value.equalsIgnoreCase("NULL"))
064            {
065                pst.setNull(index, sqlType);
066            }
067            else
068            {
069                pst.setBoolean(index, Boolean.valueOf(value.trim()).booleanValue());
070            }
071        }
072    
073        /**
074         * writes a bigdecimal values in XML file
075         * @param os
076         * @param rs
077         * @param index
078         * @throws SQLException
079         * @throws IOException
080         */
081        public void write(Writer os, ResultSet rs, int index,ArrayList encodedCols,String col) throws
082            SQLException, IOException
083        {
084            try
085            {
086                os.write("<![CDATA[" + getObject(rs, index).toString() + "]]>");
087            }
088            catch (NullPointerException ex)
089            {
090                os.write("NULL");
091            }
092        }
093    
094        private void write(Writer os, Object rowValue,ArrayList encodedCols,String col) throws
095            SQLException, IOException
096        {
097            try
098            {
099                os.write("<![CDATA[" + rowValue.toString() + "]]>");
100    
101            }
102            catch (NullPointerException ex)
103            {
104                os.write("NULL");
105            }
106        }
107    
108        /**
109         * puts the value for the column aginst the column Name
110         * @param os
111         * @param rows
112         * @param oldResultSet
113         * @param index
114         * @param modifiedColumns
115         * @param columnName
116         * @throws SQLException
117         * @throws IOException
118         */
119        public void writeUpdate(Writer os, ResultSet rows,
120                                ResultSet oldResultSet
121                                , int index, HashMap modifiedColumns,
122                                String columnName,ArrayList encodedCols) throws SQLException, IOException
123        {
124            Object newObject = rows.getObject(index);
125            Object oldObject = oldResultSet.getObject(index);
126    
127            if (newObject == null)
128            {
129                write(os, "NULL",encodedCols,columnName);
130                if (oldObject != null)
131                {
132                    modifiedColumns.put(columnName, "NULL");
133                }
134            }
135            else
136            {
137                write(os, newObject,encodedCols,columnName);
138                if (oldObject != null)
139                {
140                    if (! (newObject.equals(oldObject)))
141                    {
142                        modifiedColumns.put(columnName, newObject);
143                    }
144                }
145                else
146                {
147                    modifiedColumns.put(columnName, newObject);
148                }
149            }
150        }
151    
152        /**
153         * returns the parsed value of String in boolean
154         * @param value
155         * @return Object
156         */
157        public Object getObject(String value) throws SQLException
158        {
159            if (value.equalsIgnoreCase("NULL"))
160            {
161                return null;
162            }
163            return Boolean.valueOf(value);
164        }
165    
166        /**
167         * returns the Object corresponding to the index passed from the resultSet
168         * @param row
169         * @param index
170         * @return
171         * @throws SQLException
172         */
173        private Object getObject(ResultSet row, int index) throws SQLException
174        {
175            return row.getObject(index);
176        }
177    }





























































Powered by Drupal - Theme by Danger4k