org.apache.derby.iapi.util
Class IdUtil

java.lang.Object
  extended byorg.apache.derby.iapi.util.IdUtil

public abstract class IdUtil
extends java.lang.Object

Utility class for parsing and producing string representations of ids. This class supports both delimited and un-delimited ids.

The syntax for an id follows.

      id := delim-id | unDelim-id

          delim-id := "[""|[any char but quote]]+"
          undelim-id := (a-z|A-Z|anyunicodeletter)[a-z|A-Z|_|0-9|anyunicodeletter|anyunicodedigit]*

          In the syntax braces show grouping. '*' means repeat 0 or more times.
          '|' means or. '+' means repeat 1 or more times. 
  

In addition this class provides support for qualified names. A qualified name is a dot (.) separated list of ids.

Limitations:

  1. Unicode escape sequences in ids are not supported.
  2. Escape sequences (\n...) are not supported.


Field Summary
static int DBCP_SCHEMA_NAME
          Index of the schema name in a jar name on a db classpath
static int DBCP_SQL_JAR_NAME
          Index of the sql jar name in a jar name on a db classpath
 
Constructor Summary
IdUtil()
           
 
Method Summary
static java.lang.String appendId(java.lang.String id, java.lang.String list)
          Append an id in external form.
static java.lang.String deleteId(java.lang.String id, java.lang.String list)
          Delete an id from a list of ids.
static java.lang.String delimitId(java.lang.String id)
          Delimit the identifier provided.
static java.lang.String dups(java.lang.String[] l)
          Return an IdList with all the ids that are repeated in l.
private static boolean idChar(boolean first, int c)
           
static boolean idOnList(java.lang.String id, java.lang.String list)
          Return true if the id provided is on the list provided.
static java.lang.String intersect(java.lang.String[] l1, java.lang.String[] l2)
          Return an IdList with all the ids that in l1 and l2 or null if not ids are on both lists.
static java.lang.String mkIdList(java.lang.String[] ids)
          Produce a string form of an idList from an array of normalized ids.
private static java.lang.String mkIdListAsEntered(java.lang.String[] externalIds)
          Produce an id list from an array of ids in external form
static java.lang.String mkQualifiedName(java.lang.String[] ids)
          Make a string form of a qualified name from the array of ids provided.
static java.lang.String mkQualifiedName(java.lang.String id1, java.lang.String id2)
          Produce a delimited two part qualified name from two un-delimited identifiers.
static java.lang.String[][] parseDbClassPath(java.lang.String input, boolean normalizeToUpper)
          Scan a database classpath from the string provided.
static java.lang.String parseId(java.lang.String s)
          Convert the String provided to an ID.
static java.lang.String parseId(java.io.StringReader r, boolean normalize, boolean normalizeToUpper)
          Read an id from the StringReader provided.
static java.lang.String[] parseIdList(java.lang.String p)
          Scan a list of ids from the string provided.
private static java.lang.String[] parseIdList(java.io.StringReader r, boolean normalize)
          Parse an idList.
private static java.lang.String parseQId(java.io.StringReader r, boolean normalize)
           
static java.lang.String[] parseQualifiedName(java.lang.String s, boolean normalizeToUpper)
          Scan a qualified name from the String provided.
static java.lang.String[] parseQualifiedName(java.io.StringReader r, boolean normalizeToUpper)
          Scan a qualified name from a StringReader.
private static java.lang.String parseUnQId(java.io.StringReader r, boolean normalize, boolean normalizeToUpper)
           
static java.lang.String pruneDups(java.lang.String l)
          Return an IdList with all the duplicate ids removed
private static java.lang.String vectorToIdList(java.util.Vector v, boolean normal)
          Return an idList in external form with one id for every element of v.
private static void verifyEmpty(java.io.Reader r)
           
private static void verifyListEmpty(java.io.StringReader r)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DBCP_SCHEMA_NAME

public static final int DBCP_SCHEMA_NAME
Index of the schema name in a jar name on a db classpath

See Also:
Constant Field Values

DBCP_SQL_JAR_NAME

public static final int DBCP_SQL_JAR_NAME
Index of the sql jar name in a jar name on a db classpath

See Also:
Constant Field Values
Constructor Detail

IdUtil

public IdUtil()
Method Detail

delimitId

public static java.lang.String delimitId(java.lang.String id)
Delimit the identifier provided.

Returns:
the delimited identifier.

mkQualifiedName

public static java.lang.String mkQualifiedName(java.lang.String id1,
                                               java.lang.String id2)
Produce a delimited two part qualified name from two un-delimited identifiers.

Returns:
the result.

mkQualifiedName

public static java.lang.String mkQualifiedName(java.lang.String[] ids)
Make a string form of a qualified name from the array of ids provided.


parseQualifiedName

public static java.lang.String[] parseQualifiedName(java.lang.String s,
                                                    boolean normalizeToUpper)
                                             throws StandardException
Scan a qualified name from the String provided. Raise an excepion if the string does not contain a qualified name.

Parameters:
s - The string to be parsed
normalizeToUpper - If true then undelimited names are converted to upper case (the ANSI standard). If false then undelimited names are converted to lower case (used when the source database is Informix Foundation).
Returns:
An array of strings made by breaking the input string at its dots, '.'.
Throws:
StandardException - Oops

parseQualifiedName

public static java.lang.String[] parseQualifiedName(java.io.StringReader r,
                                                    boolean normalizeToUpper)
                                             throws StandardException
Scan a qualified name from a StringReader. Return an array of Strings with 1 entry per name scanned. Raise an exception if the StringReader does not contain a valid qualified name.

Parameters:
r - A StringReader for the string to be parsed
normalizeToUpper - If true then undelimited names are converted to upper case (the ANSI standard). If false then undelimited names are converted to lower case (used when the source database is Informix Foundation).
Returns:
An array of strings made by breaking the input string at its dots, '.'.
Throws:
StandardException - Oops

parseId

public static java.lang.String parseId(java.lang.String s)
                                throws StandardException
Convert the String provided to an ID. Throw an exception iff the string does not contain only a valid external form for an id. This is a convenience routine that simply uses getId(StringReader) to do the work.

See the header for getId below for restrictions.

Throws:
StandardException - Oops

parseId

public static java.lang.String parseId(java.io.StringReader r,
                                       boolean normalize,
                                       boolean normalizeToUpper)
                                throws StandardException
Read an id from the StringReader provided.

Throws:
StandardException - Ooops.

parseUnQId

private static java.lang.String parseUnQId(java.io.StringReader r,
                                           boolean normalize,
                                           boolean normalizeToUpper)
                                    throws java.io.IOException,
                                           StandardException
Throws:
java.io.IOException
StandardException

idChar

private static boolean idChar(boolean first,
                              int c)

parseQId

private static java.lang.String parseQId(java.io.StringReader r,
                                         boolean normalize)
                                  throws java.io.IOException,
                                         StandardException
Throws:
java.io.IOException
StandardException

verifyEmpty

private static void verifyEmpty(java.io.Reader r)
                         throws StandardException
Throws:
StandardException

parseDbClassPath

public static java.lang.String[][] parseDbClassPath(java.lang.String input,
                                                    boolean normalizeToUpper)
                                             throws StandardException
Scan a database classpath from the string provided. This returns an array with one qualified name per entry on the classpath. The constants above describe the content of the returned names. This raises an an exception if the string does not contain a valid database class path.
      classpath := item[:item]*
          item := id.id

          In the syntax braces ([]) show grouping. '*' means repeat 0 or more times.
          The syntax for id is defined in IdUtil.
  

Classpath returned is a two part name.
If the class path is empty then this returns an array of zero length.

Throws:
StandardException - Oops

parseIdList

public static java.lang.String[] parseIdList(java.lang.String p)
                                      throws StandardException
Scan a list of ids from the string provided. This returns an array with id per entry. This raises an an exception if the string does not contain a valid list of names.

Throws:
StandardException - Oops

parseIdList

private static java.lang.String[] parseIdList(java.io.StringReader r,
                                              boolean normalize)
                                       throws StandardException
Parse an idList.

Throws:
StandardException - Oops

intersect

public static java.lang.String intersect(java.lang.String[] l1,
                                         java.lang.String[] l2)
Return an IdList with all the ids that in l1 and l2 or null if not ids are on both lists.

Parameters:
l1 - An array of ids in normal form
l2 - An array of ids in nomral form

vectorToIdList

private static java.lang.String vectorToIdList(java.util.Vector v,
                                               boolean normal)
Return an idList in external form with one id for every element of v. If v has no elements, return null.

Parameters:
normal - True means the ids in v are in normal form and false means they are in external form.

dups

public static java.lang.String dups(java.lang.String[] l)
Return an IdList with all the ids that are repeated in l.

Parameters:
l - a list of ids in normal form.

pruneDups

public static java.lang.String pruneDups(java.lang.String l)
                                  throws StandardException
Return an IdList with all the duplicate ids removed

Parameters:
l - a list of ids in external form.
Throws:
StandardException - Oops.

mkIdList

public static java.lang.String mkIdList(java.lang.String[] ids)
Produce a string form of an idList from an array of normalized ids.


mkIdListAsEntered

private static java.lang.String mkIdListAsEntered(java.lang.String[] externalIds)
Produce an id list from an array of ids in external form


verifyListEmpty

private static void verifyListEmpty(java.io.StringReader r)
                             throws StandardException
Throws:
StandardException

idOnList

public static boolean idOnList(java.lang.String id,
                               java.lang.String list)
                        throws StandardException
Return true if the id provided is on the list provided.

Parameters:
id - an id in normal form
Throws:
StandardException - oops.

deleteId

public static java.lang.String deleteId(java.lang.String id,
                                        java.lang.String list)
                                 throws StandardException
Delete an id from a list of ids.

Parameters:
id - an id in normal form (quotes removed, upshifted)
list - a comma separated list of ids in external form (possibly delmited or not upshifted).
Returns:
the list with the id deleted or null if the resulting list has no ids. If 'id' is not on 'list' this returns list unchanged.
Throws:
StandardException - oops.

appendId

public static java.lang.String appendId(java.lang.String id,
                                        java.lang.String list)
                                 throws StandardException
Append an id in external form.

Returns:
the list with the id appended.
Throws:
StandardException - oops

Built on Mon 2007-06-04 09:58:47+0400, from revision ???

Apache Derby V10.1 Engine Documentation - Copyright © 1997,2005 The Apache Software Foundation or its licensors, as applicable.