|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.jenkov.mrpersister.impl.mapping.Key
public class Key
Represents a key, either primary or foreign key, in a database table. The key consists of one or more columns. To create key values for a compound primary or foreign key, use the IKeyValue interface and the KeyValue implementation.
IKeyValue
,
KeyValue
Field Summary | |
---|---|
protected java.util.Collection |
columns
|
protected IObjectMapping |
objectMapping
|
protected java.lang.String |
table
|
Constructor Summary | |
---|---|
Key()
Creates an empty key instance. |
|
Key(java.util.Collection columns)
Creates a key consisting of the given columns. |
|
Key(java.lang.String column)
Creates a key consisting of a single column. |
|
Key(java.lang.String[] columns)
Creates a key consisting of the given columns. |
Method Summary | |
---|---|
void |
addColumn(java.lang.String column)
Adds a column to this key mapping. |
boolean |
equals(java.lang.Object obj)
|
java.lang.String |
getColumn()
If this key only consists of one column, this method will return that column. |
java.util.Collection |
getColumns()
Returns the collection of columns used in this key mapping. |
java.lang.String |
getTable()
Returns the table this key mapping points to. |
boolean |
isValid(IKeyValue keyValue)
Validates an IKeyValue instance against this key. |
void |
removeColumn(java.lang.String column)
Removes a column from this key mapping |
void |
setColumns(java.util.Collection columns)
Sets the collection of columns to use in this key mapping. |
void |
setTable(java.lang.String table)
Sets the table this key points to. |
int |
size()
Returns the number of columns in this key. |
IKeyValue |
toKeyValue(java.lang.Object keyValueObject)
Wraps the given key value object in a IKeyValue instance. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected IObjectMapping objectMapping
protected java.lang.String table
protected java.util.Collection columns
Constructor Detail |
---|
public Key()
public Key(java.util.Collection columns)
columns
- The names of the columns in the key.public Key(java.lang.String column)
column
- The name of the key column.public Key(java.lang.String[] columns)
columns
- The names of the columns in the key.Method Detail |
---|
public java.lang.String getTable()
IKey
getTable
in interface IKey
public void setTable(java.lang.String table)
IKey
setTable
in interface IKey
table
- The table this key mapping is to point to.public java.util.Collection getColumns()
IKey
getColumns
in interface IKey
public void setColumns(java.util.Collection columns)
IKey
setColumns
in interface IKey
columns
- The collection of columns to use in this key mapping.public int size()
IKey
size
in interface IKey
public void addColumn(java.lang.String column)
IKey
addColumn
in interface IKey
column
- The column to add to this key mapping.public void removeColumn(java.lang.String column)
IKey
removeColumn
in interface IKey
column
- The column to removepublic boolean isValid(IKeyValue keyValue)
IKey
IKeyValue
instance against this key.
If the key value contains values for all columns in this key,
this method returns true. False if not.
isValid
in interface IKey
keyValue
- The key value to validate.
public java.lang.String getColumn() throws PersistenceException
IKey
getColumn
in interface IKey
PersistenceException
- If this key contains zero, or more than one
column.public IKeyValue toKeyValue(java.lang.Object keyValueObject) throws PersistenceException
IKey
IKeyValue
instance.
If the object to be wrapped is already a IKeyValue
instance
it will be returned unchanged.
This will only work if this IKey
instance only consists of
a single column.
toKeyValue
in interface IKey
keyValueObject
- The object to wrap in a IKeyValue
instance.
IKeyValue
instance wrapping the given object.
PersistenceException
- if this IKey
instance is a
compound key (multi column key), or if empty.public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |