public final class EntityName
extends java.lang.Object
database.table.field database.table table.field database table fieldwhere each part of a fully qualified name represents an entity which has a one-to-many relationship with the entity to its right (if any), and a one-to-one relationship with the entity to its left (if any).
The primary purpose of this class is to normalize entity names which may be fully qualified, partially qualified, or unqualified into an object which contains all parts of the entity name (even if this requires that some remain null).
Modifier and Type | Field and Description |
---|---|
static int |
DATABASE
Constant indicating name represents a database
|
static int |
FIELD
Constant indicating name represents a field
|
private java.lang.String[] |
names
Array of database, table, and field parts of qualified entity name
|
static int |
TABLE
Constant indicating name represents a table
|
Constructor and Description |
---|
EntityName(int type,
java.lang.String name)
Constructor which parses a qualified entity name into its constituent
parts.
|
Modifier and Type | Method and Description |
---|---|
static int |
getChildType(int type)
Get the type (i.e.,
TABLE or FIELD ) of the
next part of the entity name (as read from left to right), given the
type of a qualifier. |
java.lang.String |
getDatabase()
Get the database qualifier part of the entity name.
|
java.lang.String |
getField()
Get the field part of the entity name.
|
java.lang.String |
getPart(int type)
Get the name for the specified part of the entity name.
|
java.lang.String |
getTable()
Get the table qualifier part of the entity name.
|
static java.lang.String |
getTypeName(int type)
Get the descriptive name of the specified entity type.
|
static boolean |
hasChildType(int type)
Establish whether
type (presumably the type of an entity
name qualifier) has an associated "child" type, as described by the
getChildType(int) method description. |
static void |
main(java.lang.String[] args)
Unit test driver for this class.
|
private void |
parseName(int type,
java.lang.String name)
Parse a qualified entity name into its constituent parts.
|
java.lang.String |
toString()
Creates a string representation of a normalized entity name.
|
private static void |
validateType(int type)
Validate that
type represents a valid entity name component
type (i.e., is one of the type constants defined by this class). |
public static final int DATABASE
public static final int TABLE
public static final int FIELD
private java.lang.String[] names
public EntityName(int type, java.lang.String name) throws java.lang.IllegalArgumentException
type
- Constant indicating whether this object represents a database,
table, or field.name
- Qualified or unqualified entity name to be parsed.java.lang.IllegalArgumentException
- if type
is not a valid type constant or if
name
does not conform to the accepted schema
entity naming conventions
.public static java.lang.String getTypeName(int type) throws java.lang.IllegalArgumentException
type
- Constant indicating type: database, table, or field.java.lang.IllegalArgumentException
public static boolean hasChildType(int type)
type
(presumably the type of an entity
name qualifier) has an associated "child" type, as described by the
getChildType(int)
method description.type
- Type of the qualifier using the type constants of this class.true
if type
is either
DATABASE
or TABLE
.java.lang.IllegalArgumentException
- if type
is neither DATABASE
nor
TABLE
.getChildType(int)
,
DATABASE
,
TABLE
,
FIELD
public static int getChildType(int type) throws java.lang.IllegalArgumentException
TABLE
or FIELD
) of the
next part of the entity name (as read from left to right), given the
type of a qualifier.type
- Type of the qualifier; must be DATABASE
or
TABLE
.type
argument. Will be TABLE
if
type
is DATABASE
; will be
FIELD
if type
is TABLE
.java.lang.IllegalArgumentException
- if type
is neither DATABASE
nor
TABLE
.hasChildType(int)
,
DATABASE
,
TABLE
,
FIELD
private static void validateType(int type) throws java.lang.IllegalArgumentException
type
represents a valid entity name component
type (i.e., is one of the type constants defined by this class).type
- Type constant to test for validity.java.lang.IllegalArgumentException
- if type
is not one of the defined type constants.getChildType(int)
,
DATABASE
,
TABLE
,
FIELD
public java.lang.String getPart(int type)
type
- Constant indicating whether to return the database, table, or
field portion of the name.type
. May be
null
if this object does not contain the specified
part.public java.lang.String getDatabase()
null
if this entity name has no database
qualifier.public java.lang.String getTable()
null
if this entity name has no table
qualifier, or if it does not represent a table.public java.lang.String getField()
null
if
this entity does not represent a field.public java.lang.String toString()
toString
in class java.lang.Object
private void parseName(int type, java.lang.String name) throws java.lang.IllegalArgumentException
type
- Constant indicating whether this object represents a database,
table, or field.name
- Qualified or unqualified entity name to be parsed.java.lang.IllegalArgumentException
- if type
is not a valid type constant or if
name
does not conform to the accepted schema
entity naming conventions
.public static void main(java.lang.String[] args)
args
- Command line arguments: