Util
Keywords: uk.ac.ic.doc.automed.Util,Util class

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## uk.ac.ic.doc.automed
Class Util

    java.lang.Object
      |
      +--uk.ac.ic.doc.automed.Util

public class Util
extends java.lang.Object

Constructor Summary
`Util()`

Method Summary
`static java.util.List` | `addArrayToList(java.lang.Object[] src, java.util.List dst)` Adds in order all elements in the source array to the destination List and returns the destination list so that the method can be used as an argument to a method call.
`static java.lang.String` | `addPrefix(java.lang.String prefix, java.lang.String msg)` Adds the prefix to the beginning of each line in message
`static java.lang.String` | `caseCommand(java.lang.String command)` converts the argument into lower case with the first letter in uppercase
`static java.lang.Object` | `executeStatement(java.lang.String sql, java.sql.Connection dbs, java.io.OutputStream feedback)`
`static java.lang.Object` | `executeStatement(java.lang.String sql, java.sql.Connection dbs, java.io.OutputStream feedback, java.util.Set nullifyZeros)`
`static java.lang.Object` | `executeStatement(java.lang.String sql, java.sql.Connection dbs, java.io.Writer feedback)` Executes the sql statement on the JDBC Concection and returns either a ResultSet, an Integer representing the update count or an SQLException if thrown when executing the command.
`static java.lang.Object` | `executeStatement(java.lang.String sql, java.sql.Connection dbs, java.io.Writer feedback, java.util.Set nullifyZeros)`
`static java.lang.Object[]` | `executeStatements(java.lang.String sql, java.lang.String del, java.sql.Connection dbs, java.io.OutputStream feedback)`
`static java.lang.Object[]` | `executeStatements(java.lang.String sql, java.lang.String del, java.sql.Connection dbs, java.io.OutputStream feedback, java.util.Set nullifyZeros)`
`static java.lang.Object[]` | `executeStatements(java.lang.String sql, java.lang.String del, java.sql.Connection dbs, java.io.Writer feedback)` Calls {link #executeStatement(String, Connection, Writer)} with each each statement in sql seperated by del.
`static java.lang.Object[]` | `executeStatements(java.lang.String sql, java.lang.String del, java.sql.Connection dbs, java.io.Writer feedback, java.util.Set nullifyZeros)`
`static java.net.URL` | `findAutoMedFile(java.lang.String filename)`
`static java.net.URL` | `findFile(java.lang.String name)` Returns a URL for the given name using several methods to make it useful for locating configuration files, resources etc.
`static java.io.InputStream` | `getAutoMedFile(java.lang.String filename)`
`static java.lang.String[]` | `getColumnNames(java.sql.ResultSet rst)`
`static int[]` | `getColumnTypes(java.sql.ResultSet rst)`
`static java.io.InputStream` | `getFile(java.lang.String name)`
`static java.lang.String` | `getInsertableSQLValue(java.lang.Object value, int sqlType)`
`static java.lang.String[]` | `getOpts(java.lang.String format, java.lang.String[] args)`
`static int` | `getSQLType(java.lang.String name)`
`static java.lang.String` | `getSQLTypeName(int t)`
`static void` | `printObject(java.lang.Object val, java.io.OutputStream out)`
`static void` | `printObject(java.lang.Object val, java.io.Writer out)`
`static void` | `printResultSet(java.sql.ResultSet rst, java.io.OutputStream out)`
`static void` | `printResultSet(java.sql.ResultSet rst, java.io.Writer out)`
`static void` | `printSQLFeedback(java.lang.Object obj, java.io.OutputStream out, java.lang.String sql)`
`static void` | `printSQLFeedback(java.lang.Object obj, java.io.Writer out, java.lang.String sql)`
`static java.lang.String` | `replace(java.lang.String s, java.lang.String substring)` Returns a new string resulting from replacing all occurences of `substring` in string `s` with `\` followed by `substring`.
`static java.lang.Object[][]` | `resultSetToArray(java.sql.ResultSet rst)`
`static java.lang.String` | `safeSQLString(java.lang.String unsafeSQLString)` Provide a version of a string that is safe to use in JDBC update statements.
`static java.lang.Object` | `stringToObject(java.lang.String value, java.lang.Class type)`
`static java.lang.String[]` | `tokenize(java.lang.String s)` Returns the tokens in s (as defined by default StringTokenizer) as an array

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### Util

    public Util()

Method Detail

### safeSQLString

    public static java.lang.String safeSQLString(java.lang.String unsafeSQLString)

  Provide a version of a string that is safe to use in JDBC update statements. In particular, all single quotes are changed to be escaped with an extra single quote

  Parameters:
    `unsafeSQLString` - String to make safe
  Returns:
    Version of string safe to insert into JDBC statements

### addPrefix

    public static java.lang.String addPrefix(java.lang.String prefix,
                                             java.lang.String msg)

  Adds the prefix to the beginning of each line in message

### caseCommand

    public static java.lang.String caseCommand(java.lang.String command)

  converts the argument into lower case with the first letter in uppercase

### findFile

    public static java.net.URL findFile(java.lang.String name)
                                 throws java.io.IOException

  Returns a URL for the given name using several methods to make it useful for locating configuration files, resources etc. If the name is a normal path then the URL is a file URL constructed in the normal way, either relative to the current working directory or from the root of the filesystem if absolute. If the name contains a double colon then the name is assumed to be relative to the fully qualified class name before the double colon (or the caller's class if no class name given). If the file name is absolute then the root is taken as the classpath element from which the given class was loaded otherwise the path is relative to the directory in which the given class was loaded from. This works for classes loaded normally and from jar files but hasn't yet been tested with http.

  Parameters:
    `name` - Either a local file path or a fully qualified class name (if none, calling classs used) followed by a double colon followed by a file path.
    `java.io.IOException`

### getFile

    public static java.io.InputStream getFile(java.lang.String name)
                                       throws java.io.IOException

    `java.io.IOException`

### findAutoMedFile

    public static java.net.URL findAutoMedFile(java.lang.String filename)
                                        throws java.io.IOException

    `java.io.IOException`

### getAutoMedFile

    public static java.io.InputStream getAutoMedFile(java.lang.String filename)
                                              throws java.io.IOException,
                                                     DataSourceRepositoryException

    `java.io.IOException`
    `DataSourceRepositoryException`

### tokenize

    public static java.lang.String[] tokenize(java.lang.String s)

  Returns the tokens in s (as defined by default StringTokenizer) as an array

### executeStatements

    public static java.lang.Object[] executeStatements(java.lang.String sql,
                                                       java.lang.String del,
                                                       java.sql.Connection dbs,
                                                       java.io.OutputStream feedback)

### executeStatements

    public static java.lang.Object[] executeStatements(java.lang.String sql,
                                                       java.lang.String del,
                                                       java.sql.Connection dbs,
                                                       java.io.OutputStream feedback,
                                                       java.util.Set nullifyZeros)

### executeStatements

    public static java.lang.Object[] executeStatements(java.lang.String sql,
                                                       java.lang.String del,
                                                       java.sql.Connection dbs,
                                                       java.io.Writer feedback)

  Calls {link #executeStatement(String, Connection, Writer)} with each each statement in sql seperated by del.

  Returns:
    An Object array with one element for each statement containing the return value from {link #executeStatement(String, Connection, Writer)}.

### executeStatements

    public static java.lang.Object[] executeStatements(java.lang.String sql,
                                                       java.lang.String del,
                                                       java.sql.Connection dbs,
                                                       java.io.Writer feedback,
                                                       java.util.Set nullifyZeros)

### executeStatement

    public static java.lang.Object executeStatement(java.lang.String sql,
                                                    java.sql.Connection dbs,
                                                    java.io.OutputStream feedback)

### executeStatement

    public static java.lang.Object executeStatement(java.lang.String sql,
                                                    java.sql.Connection dbs,
                                                    java.io.OutputStream feedback,
                                                    java.util.Set nullifyZeros)

### executeStatement

    public static java.lang.Object executeStatement(java.lang.String sql,
                                                    java.sql.Connection dbs,
                                                    java.io.Writer feedback)

  Executes the sql statement on the JDBC Concection and returns either a ResultSet, an Integer representing the update count or an SQLException if thrown when executing the command.

  Parameters:
    `sql` - The sql statement to execute.
    `dbs` - The connection on which to create and execute the statement.
    `feedback` - A Writer on which to output the ResultSet, update count or SQLException. If null, no feedback is generated. If not null and not a PrintWriter the Writer is wrapped in a printwriter.
  Returns:
    A ResultSet, Ineteger update count or SQLException

### executeStatement

    public static java.lang.Object executeStatement(java.lang.String sql,
                                                    java.sql.Connection dbs,
                                                    java.io.Writer feedback,
                                                    java.util.Set nullifyZeros)

### printSQLFeedback

    public static void printSQLFeedback(java.lang.Object obj,
                                        java.io.OutputStream out,
                                        java.lang.String sql)

### printSQLFeedback

    public static void printSQLFeedback(java.lang.Object obj,
                                        java.io.Writer out,
                                        java.lang.String sql)

### printResultSet

    public static void printResultSet(java.sql.ResultSet rst,
                                      java.io.OutputStream out)

### printResultSet

    public static void printResultSet(java.sql.ResultSet rst,
                                      java.io.Writer out)

### getColumnNames

    public static java.lang.String[] getColumnNames(java.sql.ResultSet rst)
                                             throws java.sql.SQLException

    `java.sql.SQLException`

### getColumnTypes

    public static int[] getColumnTypes(java.sql.ResultSet rst)
                                throws java.sql.SQLException

    `java.sql.SQLException`

### resultSetToArray

    public static java.lang.Object[][] resultSetToArray(java.sql.ResultSet rst)
                                                 throws java.sql.SQLException

    `java.sql.SQLException`

### getSQLTypeName

    public static java.lang.String getSQLTypeName(int t)
                                           throws java.sql.SQLException

    `java.sql.SQLException`

### getSQLType

    public static int getSQLType(java.lang.String name)
                          throws java.sql.SQLException

    `java.sql.SQLException`

### getInsertableSQLValue

    public static java.lang.String getInsertableSQLValue(java.lang.Object value,
                                                         int sqlType)
                                                  throws java.sql.SQLException

    `java.sql.SQLException`

### stringToObject

    public static java.lang.Object stringToObject(java.lang.String value,
                                                  java.lang.Class type)
                                           throws java.lang.Exception

    `java.lang.Exception`

### printObject

    public static void printObject(java.lang.Object val,
                                   java.io.OutputStream out)

### printObject

    public static void printObject(java.lang.Object val,
                                   java.io.Writer out)

### getOpts

    public static java.lang.String[] getOpts(java.lang.String format,
                                             java.lang.String[] args)
                                      throws java.lang.Exception

    `java.lang.Exception`

### addArrayToList

    public static java.util.List addArrayToList(java.lang.Object[] src,
                                                java.util.List dst)

  Adds in order all elements in the source array to the destination List and returns the destination list so that the method can be used as an argument to a method call. This is paricularly useful for the this() or super() call in a constructor where you need to convert an array to a list as the method call has to be the first line of code.

  Parameters:
    `src` - An array of Objects to add to the list.
    `dst` - The List to which the source array's elememts are to be added.

### replace

    public static java.lang.String replace(java.lang.String s,
                                           java.lang.String substring)

  Returns a new string resulting from replacing all occurences of `substring` in string `s` with `\` followed by `substring`.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD