1 pjaol 1.1
2 /**
3 * Title: <p>
4 * Description: <p>
5 * Copyright: Copyright (c) Troy Thompson, Bob Byron<p>
6 * Company: JavaUnderground<p>
7 * @author Troy Thompson, Bob Byron
8 * @version 1.1
9 */
10 package com.javaunderground.jdbc;
11
12 import java.sql.*;
13
14 /**
15 * Base class for all database Formatters such as OracleFormatter.
16 */
17 public abstract class SqlFormatter {
18
19
20 /**
21 * Formats a blob to the following String "'<Blob length = " + blob.length()+">'"
22 pjaol 1.1 * This method's output will not translate directly into the database. It is informational only.
23 * @param blob The blob to be translated
24 * @return The String representation of the blob
25 * @exception SQLException
26 */
27 protected String format(java.sql.Blob blob) throws SQLException{
28 return "'<Blob length = " + blob.length()+">'";
29 }
30
31 /**
32 * Formats a clob to the following String "'<Clob length = " + clob.length()+">'"
33 * This method's output will not translate directly into the database. It is informational only.
34 * @param clob The clob to be translated
35 * @return The String representation of the clob
36 * @exception SQLException
37 */
38 protected String format(java.sql.Clob clob)throws SQLException{
39 return "'<Clob length = " + clob.length()+">'";
40 }
41
42 /**
43 pjaol 1.1 * Formats an Array to the following String "array.getBaseTypeName()"
44 * This method's output will not translate directly into the database. It is informational only.
45 * @param array The array to be translated
46 * @return The base name of the array
47 * @exception SQLException
48 *
49 */
50 protected String format(java.sql.Array array)throws SQLException{
51 return array.getBaseTypeName();
52 }
53
54
55 /**
56 * Formats a Ref to the following String "ref.getBaseTypeName()"
57 * This method's output will not translate directly into the database. It is informational only.
58 * @param ref The ref to be translated
59 * @return The base name of the ref
60 * @exception SQLException
61 */
62 protected String format(java.sql.Ref ref)throws SQLException{
63 return ref.getBaseTypeName();
64 pjaol 1.1 }
65
66
67 /**
68 * Checks the String for null and returns "'" + string + "'".
69 * @param string String to be formatted
70 * @return formatted String (null returns "NULL")
71 */
72 protected String format(java.lang.String string)throws SQLException{
73 if(string.equals("NULL"))
74 return string;
75 else
76 return "'" + string + "'";
77 }
78
79 /**
80 * If object is null, Blob, Clob, Array, Ref, or String this returns the value from the protected methods
81 * in this class that take those Classes.
82 * @param o Object to be formatted
83 * @return formatted String
84 */
85 pjaol 1.1 public String format(Object o) throws SQLException{
86 if (o == null) return "NULL";
87 if (o instanceof Blob) return format((Blob)o);
88 if (o instanceof Clob) return format((Clob)o);
89 if (o instanceof Array) return format((Array)o);
90 if (o instanceof Ref) return format((Ref)o);
91 if (o instanceof String) return format((String)o);
92 return o.toString();
93 }
94 }
|