Project Report: fawkez

Packagesummary org.jcoderz.phoenix.dbview

org.jcoderz.phoenix.dbview.DbView

LineHitsNoteSource
1  /*
2   * $Id: DbView.java 1066 2008-07-08 19:12:15Z amandel $
3   *
4   * Copyright 2006, The jCoderZ.org Project. All rights reserved.
5   *
6   * Redistribution and use in source and binary forms, with or without
7   * modification, are permitted provided that the following conditions are
8   * met:
9   *
10   *    * Redistributions of source code must retain the above copyright
11   *      notice, this list of conditions and the following disclaimer.
12   *    * Redistributions in binary form must reproduce the above
13   *      copyright notice, this list of conditions and the following
14   *      disclaimer in the documentation and/or other materials
15   *      provided with the distribution.
16   *    * Neither the name of the jCoderZ.org Project nor the names of
17   *      its contributors may be used to endorse or promote products
18   *      derived from this software without specific prior written
19   *      permission.
20   *
21   * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND
22   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24   * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS
25   * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28   * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29   * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30   * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31   * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32   */
33  package org.jcoderz.phoenix.dbview;
34  
35  
36  import java.io.File;
37  import java.io.FileOutputStream;
38  import java.io.IOException;
39  import java.io.OutputStreamWriter;
40  import java.io.PrintWriter;
41  import java.io.Reader;
42  import java.lang.reflect.InvocationTargetException;
43  import java.lang.reflect.Method;
44  import java.lang.reflect.Modifier;
45  import java.nio.charset.Charset;
46  import java.sql.Blob;
47  import java.sql.Connection;
48  import java.sql.DriverManager;
49  import java.sql.PreparedStatement;
50  import java.sql.ResultSet;
51  import java.sql.ResultSetMetaData;
52  import java.sql.SQLException;
53  import java.sql.Timestamp;
54  import java.sql.Types;
55  import java.text.DateFormat;
56  import java.text.SimpleDateFormat;
57  import java.util.Date;
58  import java.util.HashMap;
59  import java.util.Map;
60  import java.util.TimeZone;
61  import java.util.logging.Level;
62  import java.util.logging.Logger;
63  import javax.naming.Context;
64  import javax.naming.InitialContext;
65  import javax.naming.NamingException;
66  import javax.sql.DataSource;
67  
68  import org.jcoderz.commons.util.Constants;
69  import org.jcoderz.commons.util.DbUtil;
70  import org.jcoderz.commons.util.IoUtil;
71  import org.jcoderz.commons.util.LoggingUtils;
72  import org.jcoderz.commons.util.XmlUtil;
73  
74  
75  /**
76   * Converts the db content into xml.
77   *
78   * @author Andreas Mandel
79   */
800 public class DbView
81  {
82     /** Default database jndi name. */
83     public static final String DATASOURCE = "java:comp/env/jdbc/svs/db";
84  
85     /** Line separator to be used in output files. */
860    public static final String LINE_SEPARATOR = Constants.LINE_SEPARATOR;
87  
88     private static final int MILLIS_PER_SECOND
89             = org.jcoderz.commons.types.Date.MILLIS_PER_SECOND;
90     private static final String SELECT_ALL_TABLES = "select * from tab";
910    private static final String CLASSNAME = DbView.class.getName();
920    private static final Logger logger = Logger.getLogger(CLASSNAME);
93  
940    private final Map mTypeMapper = new HashMap();
950    private final DateFormat mDateFormater
96           = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss.SSS",
97                   Constants.SYSTEM_LOCALE);
98  
99 (1)   {
1000       mDateFormater.setTimeZone(TimeZone.getTimeZone("UTC"));
101     }
102  
1030    private String mDbDriver = Constants.ORACLE_DRIVER_CLASS_NAME;
104     private int mNumberOfColumns;
105     private String mSqlStatement;
106     private String mDbUrl;
107     private String mDbUser;
108     private String mDbPasswd;
109     private File mOutputDir;
110     private File mOutputFile;
111     private Level mLogLevel;
112  
113  
114 (2)   public static void main (String[] args)
115           throws SecurityException
116     {
1170       final DbView main = new DbView();
118        try
119        {
1200          main.parseArguments(args);
1210          if (main.mSqlStatement == null)
122           {
1230             main.dumpAllTables();
124           }
125           else
126           {
1270             main.performQuery();
128           }
129        }
1300       catch (IllegalArgumentException ex)
131        {
1320          System.err.println(ex.getMessage());
1330          System.err.println("Usage:");
1340          System.err.println(DbView.class.getName());
1350          System.err.println(" -dbUrl [-dbUser scott -dbPasswd tiger] "
136                 + "-sql \"select * from tab\" "
137                 + "-outFile foo.xml");
1380          System.err.println("DbView -dbUrl [-dbUser scott -dbPasswd tiger] "
139                 + "-outDir sql/");
1400          System.err.println();
1410          System.err.println("To add type converters use:");
1420          System.err.println("-type ROW_NAME JAVA_CLASS FROM_DB TO_DISPLAY");
1430          System.err.println("ex.: -type STATUS com.encous.foo.Status fromInt "
144                 + "toDisplayString");
1450          System.err.println();
1460          System.err.println("To use a db driver other than oracle add:");
1470          System.err.println("-dbDriver your.db.driver");
148        }
1490       catch (Exception ex)
150        {
1510          ex.printStackTrace();
1520       }
1530    }
154  
155 (3)   public void dumpAllTables ()
156           throws IOException, ClassNotFoundException, SQLException
157     {
1580       dumpAllTables(mOutputDir);
1590    }
160  
161 (4)   public void performQuery ()
162           throws IOException, ClassNotFoundException, SQLException
163     {
1640       performConvertion (mOutputFile, mSqlStatement);
1650    }
166  
167 (5)   public void dumpAllTables (File dir)
168           throws IOException, ClassNotFoundException, SQLException
169     {
1700       Connection dbConnection = null;
1710       PreparedStatement statement = null;
172        try
173        {
1740          dbConnection = getConnectionFromDbUrl();
175  
1760          performConvertion(new File(dir, "tables.xml").getCanonicalPath(),
177                 dbConnection, SELECT_ALL_TABLES);
178  
1790          statement = dbConnection.prepareStatement(SELECT_ALL_TABLES);
1800(6)         final ResultSet rs = statement.executeQuery();
1810          while (rs.next())
182           {
1830             final String tableName = rs.getString(1);
1840             performConvertion(
185                    new File(dir,
186                        escapeTableName(tableName) + ".xml").getCanonicalPath(),
187                        dbConnection, "select * from \"" + tableName + '"');
1880          }
189        }
190        finally
191        {
1920           DbUtil.close(statement);
1930           DbUtil.close(dbConnection);
1940       }
195  
1960    }
197  
198     private void parseArguments (String[] args)
199           throws IOException, NoSuchMethodException, ClassNotFoundException
200     {
201        try
202        {
2030          for (int i = 0; i < args.length; )
204           {
2050             if ("-sql".equals(args[i]))
206              {
2070                mSqlStatement = args[++i];
208              }
2090             else if ("-dbUrl".equals(args[i]))
210              {
2110                mDbUrl = args[++i];
212              }
2130             else if ("-dbUser".equals(args[i]))
214              {
2150                mDbUser = args[++i];
216              }
2170             else if ("-dbPasswd".equals(args[i]))
218              {
2190                mDbPasswd = args[++i];
220              }
2210(7)            else if (args[i].equals("-type"))
222              {
2230                final String rowname = args[++i];
2240                final String classname = args[++i];
2250                final String fromDbType = args[++i];
2260                final String toDisplay = args[++i];
2270                addTypeMapping(rowname, classname, fromDbType, toDisplay);
2280             }
2290             else if ("-outDir".equals(args[i]))
230              {
2310                mOutputDir = new File(args[++i]);
232              }
2330             else if ("-outFile".equals(args[i]))
234              {
2350                mOutputFile = new File(args[++i]);
236              }
2370             else if ("-dbDriver".equals(args[i]))
238              {
2390                mDbDriver = args[++i];
240              }
2410             else if ("-loglevel".equals(args[i]))
242              {
2430                mLogLevel = Level.parse(args[++i]);
2440                Logger.getLogger("").setLevel(mLogLevel);
2450                LoggingUtils.setGlobalHandlerLogLevel(mLogLevel);
246              }
247              else
248              {
2490                throw new IllegalArgumentException(
250                       "Invalid argument '" + args[i] + "'");
251              }
2520             ++i;
253           }
254  
2550          checkParameters();
256        }
2570       catch (IndexOutOfBoundsException e)
258        {
2590          final IllegalArgumentException ex = new IllegalArgumentException(
260              "Missing value for " + args[args.length - 1]);
2610          ex.initCause(e);
2620          throw ex;
2630       }
2640    }
265  
266     private void checkParameters ()
267          throws IllegalArgumentException
268     {
2690        if (mOutputDir == null && mOutputFile == null)
270         {
2710            throw new IllegalArgumentException(
272                 "Need either output dir or output file.");
273         }
2740        if (mSqlStatement != null && mOutputFile != null)
275         {
2760            throw new IllegalArgumentException(
277                "Need output file for sql statement.");
278         }
2790        if (mSqlStatement == null && mOutputDir == null)
280         {
2810            throw new IllegalArgumentException(
282                     "Need output dir for global dump.");
283         }
2840        if (!mOutputDir.isDirectory())
285         {
2860           throw new RuntimeException("out dir must be a directory.");
287         }
2880        if (mOutputFile.isDirectory())
289         {
2900           throw new RuntimeException(
291                  "out file must not be a directory.");
292         }
2930    }
294  
295 (8)   public void performConvertion (File file, String query)
296           throws IOException, ClassNotFoundException, SQLException
297     {
2980       PrintWriter out = null;
2990       Connection dbConnection = null;
3000       PreparedStatement statement = null;
301        try
302        {
3030          final FileOutputStream stream = new FileOutputStream(file);
3040          final OutputStreamWriter writer = new OutputStreamWriter(stream,
305                 Charset.forName("us-ascii"));
3060          out = new PrintWriter(writer);
3070          dbConnection = getConnectionFromDbUrl();
3080(9)         statement = dbConnection.prepareStatement(query);
3090(10)         final ResultSet rs = statement.executeQuery();
3100          xmlOpen(null, dbConnection.getMetaData().getURL(), query, out);
3110          metaData2Xml(rs.getMetaData(), out);
3120          resultSet2Xml(rs, out);
3130          xmlClose(out);
314  
315        }
316        finally
317        {
3180          IoUtil.close(out);
3190          DbUtil.close(statement);
3200          DbUtil.close(dbConnection);
3210       }
3220    }
323  
324 (11)   public void addTypeMapping (String typeName, String typeClass,
325           String fromDb, String toString)
326           throws SecurityException, NoSuchMethodException, ClassNotFoundException
327     {
3280       mTypeMapper.put(typeName,
329              new TypeMapper(typeName, typeClass, fromDb, toString));
3300    }
331  
332     private void performConvertion (String fileName,
333           final Connection dbConnection, String query)
334           throws IOException, SQLException
335     {
3360(12)      logger.fine("about to dump '" + query + "' into '" + fileName +"'.");
3370       PrintWriter out = null;
3380       PreparedStatement statement = null;
339        try
340        {
3410          final FileOutputStream stream = new FileOutputStream(fileName);
3420          final OutputStreamWriter writer = new OutputStreamWriter(stream,
343                 Charset.forName("us-ascii"));
3440          out = new PrintWriter(writer);
3450(13)         statement = dbConnection.prepareStatement(query);
3460(14)         final ResultSet rs = statement.executeQuery();
3470          xmlOpen(null, dbConnection.getMetaData().getURL(), query, out);
3480          metaData2Xml(rs.getMetaData(), out);
3490          resultSet2Xml(rs, out);
3500          xmlClose(out);
351  
352        }
353        finally
354        {
3550           IoUtil.close(out);
3560           DbUtil.close(statement);
3570       }
3580    }
359  
360 (15)   private Connection getConnectionFromDataSource ()
361         throws NamingException, SQLException
362     {
3630       final Context ctx = new InitialContext();
3640       final DataSource ds = (DataSource) ctx.lookup(DATASOURCE);
3650       return ds.getConnection();
366     }
367  
368     private Connection getConnectionFromDbUrl ()
369           throws ClassNotFoundException, SQLException
370     {
3710       Class.forName(mDbDriver);
372        final Connection con;
373  
3740       if (mDbUser == null)
375        {
3760          con = DriverManager.getConnection(mDbUrl);
377        }
378        else
379        {
3800          con = DriverManager.getConnection(mDbUrl, mDbUser, mDbPasswd);
381        }
382  
3830       return con;
384     }
385  
386     private void xmlOpen (String dataSource, String dataBaseUri,
387           String statement, PrintWriter out)
388           throws IOException, SQLException
389     {
3900       out.print("<result statement='");
3910       out.print(XmlUtil.attributeEscape(statement));
3920       out.println("'");
3930       if (dataSource != null)
394        {
3950          out.print(" data-source='");
3960          out.print(XmlUtil.attributeEscape(dataSource));
3970          out.println("'");
398        }
3990       if (dataBaseUri != null)
400        {
4010          out.print(" db-uri='");
4020          out.print(XmlUtil.attributeEscape(dataBaseUri));
4030          out.println("'");
404        }
4050       out.print(" creation-date='");
4060       out.print(display(new Date()));
4070       out.println("'>");
4080    }
409  
410     private void xmlClose (PrintWriter out)
411     {
4120       out.println("</result>");
4130    }
414  
415     private void metaData2Xml (ResultSetMetaData md, PrintWriter out)
416           throws IOException, SQLException
417     {
4180       mNumberOfColumns = md.getColumnCount();
4190       out.print(" <meta-data number-of-columns='");
4200       out.print(mNumberOfColumns);
4210       out.println("'>");
4220       for (int column = 1; column <= mNumberOfColumns; column++)
423        {
4240          out.println(" <column");
4250          metaDataAsString("name", md.getColumnName(column), out);
4260          metaDataAsString("type-name", md.getColumnTypeName(column), out);
4270          metaDataAsString("display-name", md.getColumnLabel(column), out);
4280          metaDataAsString("class-name", md.getColumnClassName(column), out);
429           try
430           {
4310             metaDataAsString("precision", md.getPrecision(column), out);
432           }
4330          catch (NumberFormatException ex)
434           {
435              // this happens for lobs in oracle seems to denote infinity.
4360          }
4370          metaDataAsString("scale", md.getScale(column), out);
4380          metaDataAsString("catalog-name", md.getCatalogName(column), out);
4390          metaDataAsString("schema-name", md.getSchemaName(column), out);
4400          metaDataAsString("table-name", md.getTableName(column), out);
4410          metaDataAsStringNullable("is-nullable", md.isNullable(column), out);
4420          metaDataAsString("type", md.getColumnType(column), out);
4430          metaDataAsString("display-size", md.getColumnDisplaySize(column), out);
4440          out.println(" />");
445        }
4460       out.println(" </meta-data>");
4470    }
448  
449  
450     private void metaDataAsStringNullable (
451           String attributeName, int nullable, PrintWriter out)
452     {
4530       switch (nullable)
454        {
455           case ResultSetMetaData.columnNoNulls:
4560             metaDataAsString(attributeName, "no-nulls", out);
4570             break;
458           case ResultSetMetaData.columnNullable:
4590             metaDataAsString(attributeName, "nullable", out);
4600             break;
461           case ResultSetMetaData.columnNullableUnknown:
4620             metaDataAsString(attributeName, "unknown", out);
4630             break;
464           default:
4650             metaDataAsString(attributeName, "illeagal", out);
466           break;
467        }
4680    }
469  
470     /**
471      * @param string
472    * @param i
473    * @param out
474    */
475     private void metaDataAsString (
476           String attributeName, int i, PrintWriter out)
477     {
4780       metaDataAsString(attributeName, String.valueOf(i), out);
4790    }
480  
481  
482     /**
483      * @param string
484    * @param string2
485    * @param out
486    */
487     private void metaDataAsString (String attributeName,
488           String attributeValue, PrintWriter out)
489     {
4900       out.print(" ");
4910       out.print(attributeName);
4920       out.print("='");
4930       out.print(XmlUtil.attributeEscape(attributeValue));
4940       out.println("'");
4950    }
496  
497  
498  
499     private void resultSet2Xml (ResultSet rs, PrintWriter out)
500           throws IOException, SQLException
501     {
5020       out.println(" <result-set>");
5030       while (rs.next())
504        {
5050          out.print(" <row row-number='");
5060          out.print(rs.getRow());
5070          out.println("'>");
5080          result2Xml(rs, out);
5090          out.println(" </row>");
510        }
5110       out.println(" </result-set>");
5120    }
513  
514     private void result2Xml (ResultSet rs, PrintWriter out)
515           throws SQLException, IOException
516     {
5170       for (int column = 1; column <= mNumberOfColumns; column++)
518        {
5190          final Object o = typedGetter(rs, column);
5200          out.print(" <column");
5210          if (o == null)
522           {
5230             out.println(" isNull='true'>");
524           }
525           else
526           {
5270             out.println(">");
528           }
5290          final String name = rs.getMetaData().getColumnName(column);
5300          final String typeName = rs.getMetaData().getColumnTypeName(column);
5310          object2Xml(o, name, typeName, out);
5320          out.println(" </column>");
533        }
534  
5350    }
536  
537     private Object typedGetter (ResultSet rs, int column)
538           throws SQLException, IOException
539     {
540        final Object result;
5410       final int type = rs.getMetaData().getColumnType(column);
5420       switch (type)
543        {
544           case Types.TIMESTAMP:
5450             result = convertTimestamp(rs.getTimestamp(column));
5460             break;
547           case Types.DATE:
548           case Types.TIME:
549 (16)            // FIXME: Take care for milisecond & timezone!?
5500             result = rs.getDate(column);
5510             break;
552           case Types.CLOB:
5530             result = readNclob(rs, column);
5540             break;
555           case Types.BLOB:
5560             result = readBlob(rs, column);
5570             break;
558           default:
5590             result = rs.getObject(column);
560        }
5610       return result;
562     }
563  
564     private Object readBlob (ResultSet rs, int column)
565           throws SQLException
566     {
5670       final Blob blob = rs.getBlob(column);
568        final byte [] data;
5690       if (blob != null)
570        {
5710          final long length = blob.length();
5720          if (length > Integer.MAX_VALUE)
573           {
5740             data = "Length of Blob exceeds maximum of MAX_INT".getBytes();
575           }
576           else
577           {
5780             data = blob.getBytes(1, (int) length);
579           }
5800       }
581        else
582        {
5830          data = null;
584        }
5850       return data;
586     }
587  
588     private String readNclob (ResultSet rs, int column)
589           throws SQLException, IOException
590     {
591        final String result;
5920       final Reader reader = rs.getCharacterStream(column);
5930       if (reader != null)
594        {
595            try
596            {
5970              result = IoUtil.readFully(reader);
598            }
599            finally
600            {
6010              IoUtil.close(reader);
6020           }
603        }
604        else
605        {
6060           result = null;
607        }
6080       return result;
609     }
610  
611  
612     private void object2Xml (Object object, String name, String typeName,
613           PrintWriter out)
614           throws SQLException
615     {
6160       if (object != null)
617        {
6180          out.print(" <raw>");
6190          out.print(XmlUtil.escape(String.valueOf(object)));
6200          out.println("</raw>");
6210          final String display = objectFormater(object, name, typeName);
6220          if (display != null)
623           {
6240             out.print(" <display>");
6250             out.print(XmlUtil.escape(display));
6260             out.println("</display>");
627           }
6280       }
629        else
630        {
6310          out.println(" <raw/>");
632        }
6330    }
634  
635     private String objectFormater (Object object, String name, String typeName)
636           throws SQLException
637     {
6380       String result = null;
639  
6400       if (mTypeMapper.containsKey(name))
641        {
642           try
643           {
6440             final TypeMapper mapper = (TypeMapper) mTypeMapper.get(name);
6450             result = mapper.toDisplay(object);
646           }
6470          catch (IllegalArgumentException e)
648           {
6490(17)            result = "Failed to convert type '" + e.toString() + "'.";
6500             logger.log(Level.WARNING, result, e);
651           }
6520          catch (IllegalAccessException e)
653           {
6540             result = "Failed to convert type '" + e.toString() + "'.";
6550             logger.log(Level.WARNING, result, e);
656  
657           }
6580          catch (InvocationTargetException e)
659           {
6600             result = "Failed to convert type '" + e.toString() + "'.";
6610             logger.log(Level.WARNING, result, e);
662           }
6630          catch (RuntimeException e)
664           {
6650             result = "Failed to convert type '" + e.toString() + "'.";
6660             logger.log(Level.WARNING, result, e);
6670          }
668        }
6690(18)      else if (object instanceof Date)
670        {
6710          result = display((Date) object);
672        }
6730       else if (object instanceof String)
674        {
6750          result = display((String) object);
676        }
677        else
678        {
6790          result = null;
680        }
6810       return result;
682     }
683  
684  
685     private String display (Date d)
686     {
687        final String result;
6880       if (d == null)
689        {
6900          result = null;
691        }
692        else
693        {
6940          result = mDateFormater.format(d);
695        }
6960       return result;
697     }
698  
699     private String display (String str)
700     {
701        final String result;
7020       if (str == null)
703        {
7040          result = null;
705        }
7060       else if (str.indexOf('<') != -1)
707        {
7080          final String detect = str.trim();
7090          if (detect.indexOf('<') == 0
710                 && detect.lastIndexOf('>') == (detect.length() - 1))
711           {
7120             result = XmlUtil.formatXml(str);
713           }
714           else
715           {
7160             result = null;
717           }
7180       }
719        else
720        {
7210          result = null;
722        }
723  
7240       return result;
725     }
726  
727     private static Date convertTimestamp (Timestamp ts)
728     {
729        final Date d;
7300       if (ts != null)
731        {
732           // ts.getTime does not return millis....
7330          d = new Date(((ts.getTime() / MILLIS_PER_SECOND) * MILLIS_PER_SECOND)
734                 + (ts.getNanos()
735                     / org.jcoderz.commons.types.Date.NANOS_PER_MILLI));
736        }
737        else
738        {
7390          d = null;
740        }
7410       return d;
742     }
743  
7440    private static class TypeMapper
745     {
746        private final Class mTypeClass;
747        private final Method mFromDb;
748        private final Method mToString;
749        private final String mTypeName;
750        private final Class mInputType;
751  
752        public TypeMapper (String typeName, String typeClass, String fromDb,
753              String toString)
754              throws SecurityException, NoSuchMethodException,
755                 ClassNotFoundException
756        {
7570          this(typeName, Class.forName(typeClass), fromDb, toString);
7580       }
759  
760        public TypeMapper (String typeName, Class typeClass, String fromDb,
761              String toString)
762              throws SecurityException, NoSuchMethodException
7630       {
7640(19)         mTypeClass = typeClass;
7650          mToString = typeClass.getMethod(toString, null);
766  //         mFromDb = typeClass.getMethod(fromDb, new Class[] {Object.class});
7670          final Method [] methods = typeClass.getMethods();
7680          Method method = null;
7690          for (int i = 0; i < methods.length; i++)
770           {
7710             if (methods[i].getReturnType() == mTypeClass
772                 && methods[i].getName().startsWith(fromDb)
773                 && ((methods[i].getModifiers() & Modifier.STATIC) != 0))
774              {
7750                method = methods[i];
7760                break;
777              }
778           }
779  
7800          mFromDb = method;
7810(20)         mInputType = method.getParameterTypes()[0];
7820(21)(22)         mTypeName = typeName;
7830       }
784  
785        public String toDisplay (Object in)
786              throws IllegalArgumentException, IllegalAccessException,
787                 InvocationTargetException
788        {
7890          Object type = null;
790           try
791           {
7920             type = mFromDb.invoke(null, new Object[] {in});
793           }
7940          catch (Exception ex)
795           {
7960             if (in instanceof Number)
797              {
7980                if (mInputType == Integer.TYPE)
799                 {
8000                   type = mFromDb.invoke(null,
801                          new Object[]
802                          {
803                             new Integer(((Number) in).intValue())
804                          });
805                 }
8060                else if (mInputType == Long.TYPE)
807                 {
8080                   type = mFromDb.invoke(null,
809                          new Object[]
810                          {
811                             new Long(((Number) in).longValue())
812                          });
813                 }
814              }
815              else
816              {
8170                final IllegalArgumentException axe
818                       = new IllegalArgumentException(
819                          "Could not map type for object '" + String.valueOf(in)
820                          + "' of class " + in.getClass().getName()
821                          + " into expected converter "
822                          + "type " + mInputType.getName() + ".");
8230                axe.initCause(ex);
8240                throw axe;
825              }
8260          }
8270          return (String) mToString.invoke(type, null);
828        }
829     }
830  
831 (23)   public static String escapeTableName (String in)
832     {
8330        return in.replaceAll("[/\\\\$]", "#");
834     }
835  }

Findings in this File

f (24) System.out.print is used main class
f (25) System.out.print is used main class
f (26) System.out.print is used main class
f (27) System.out.print is used main class
f (28) System.out.print is used main class
f (29) System.out.print is used main class
f (30) System.out.print is used main class
f (31) System.out.print is used main class
f (32) System.out.print is used main class
f (33) System.out.print is used main class
f (34) System.out.print is used main class
f (35) System.out.print is used main class
f (36) Avoid printStackTrace(); use a logger call instead. main class
c (1) 99 : 4 Non-static initializers are confusing
c (2) 114 : 4 Missing a Javadoc comment.
c (3) 155 : 4 Missing a Javadoc comment.
c (4) 161 : 4 Missing a Javadoc comment.
c (5) 167 : 4 Missing a Javadoc comment.
w (6) 180 : 0 Method org.jcoderz.phoenix.dbview.DbView.dumpAllTables(File) may fail to clean up stream or resource of type java.sql.ResultSet
i (7) 221 : 0 method org.jcoderz.phoenix.dbview.DbView.parseArguments(String[]) makes literal string comparisons passing the literal as an argument
c (8) 295 : 4 Missing a Javadoc comment.
i (9) 308 : 0 A prepared statement is generated from a nonconstant String at org.jcoderz.phoenix.dbview.DbView.performConvertion(File, String)
w (10) 309 : 0 Method org.jcoderz.phoenix.dbview.DbView.performConvertion(File, String) may fail to clean up stream or resource of type java.sql.ResultSet
c (11) 324 : 4 Missing a Javadoc comment.
c (12) 336 : 70 '+' is not followed by whitespace.
e (13) 345 : 0 A prepared statement is generated from a nonconstant String at org.jcoderz.phoenix.dbview.DbView.performConvertion(String, Connection, String)
w (14) 346 : 0 Method org.jcoderz.phoenix.dbview.DbView.performConvertion(String, Connection, String) may fail to clean up stream or resource of type java.sql.ResultSet
i (15) 360 : 23 Avoid unused private methods such as 'getConnectionFromDataSource()'.
i (16) 549 : 0 Comment matches to-do format '(TODO|FIXME|CHECKME)'.
i (17) 649 : 22 The String literal "Failed to convert type '" appears 4 times in this file; the first occurrence is on line 649
i (18) 669 : 0 Method org.jcoderz.phoenix.dbview.DbView.objectFormater(Object, String, String) uses instanceof on multiple types to arbitrate logic
w (19) 764 : 0 class org.jcoderz.phoenix.dbview.DbView$TypeMapper defines fields that are used only as locals
w (20) 781 : 0 Possible null pointer dereference of method in new org.jcoderz.phoenix.dbview.DbView$TypeMapper(String, Class, String, String)
w (21) 782 : 0 class org.jcoderz.phoenix.dbview.DbView$TypeMapper defines fields that are used only as locals
i (22) 782 : 0 Unread field: org.jcoderz.phoenix.dbview.DbView$TypeMapper.mTypeName
c (23) 831 : 4 Missing a Javadoc comment.