| java.lang.Object com.uwyn.rife.cmf.dam.OrdinalManager
OrdinalManager | public class OrdinalManager implements Cloneable(Code) | | This class makes it possible to easily manage an integer ordinal column
that is typically used to determine the order of the rows in a specific
table.
The basic version manages the ordinals for the entire table, but it's
also possible to create an OrdinalManager that uses several
independent ranges of ordinals according to a restricting integer column.
For example, consider the following 'article ' table:
id INT
categoryId INT
ordinal INT
name VARCHAR(30)
with the following rows:
id | categoryId | ordinal | name
----+------------+---------+-----------------------
2 | 1 | 0 | some article
0 | 1 | 1 | another one
3 | 1 | 2 | boom boom
1 | 2 | 0 | this is yet an article
5 | 2 | 1 | an article for you
4 | 3 | 0 | our latest article
6 | 3 | 1 | important one
You can clearly see three independent ordinal ranges
according to the categoryId column.
The OrdinalManager allows you to easily change the order of
the articles by moving them up and down with the provided methods:
OrdinalManager.move(Direction,int) move ,
OrdinalManager.up(int) up and
OrdinalManager.down(int) down .
It's also possible to do more complex manipulations by using the lower
level methods:
OrdinalManager.free(int) free ,
OrdinalManager.update(int,int) update ,
OrdinalManager.tighten() tighten and
OrdinalManager.obtainInsertOrdinal()obtainInsertOrdinal .
author: Geert Bevin (gbevin[remove] at uwyn dot com) version: $Revision: 3634 $ since: 1.0 |
Inner Class :public static class Direction extends EnumClass | |
Constructor Summary | |
public | OrdinalManager(Datasource datasource, String table, String ordinalColumn) Creates a new OrdinalManager that manages ordinals
globally for the specified table. | public | OrdinalManager(Datasource datasource, String table, String ordinalColumn, String restrictColumn) Creates a new OrdinalManager that manages ordinals for the
specified table in independent ranges according to a restricting
integer column. |
Method Summary | |
public Object | clone() Simply clones the instance with the default clone method. | public boolean | down(int ordinal) Moves a row with a specific ordinal downwards within the entire table. | public boolean | down(long restrictId, int ordinal) Moves a row with a specific ordinal downwards within the range
restricted by the provided ID. | public boolean | free(int ordinal) Frees up a slot for the specified ordinal within the entire table.,
this is done by incrementing everything after it by 1 to make space. | public boolean | free(long restrictId, int ordinal) Frees up a slot for the specified ordinal within the range restricted
by the provided ID, this is done by incrementing everything after it by
1 to make space. | public String | getOrdinalColumn() Retrieves the name of the ordinal column. | public String | getRestrictColumn() Retrieves the name of the restricting column. | public String | getTable() Retrieves the name of the table of this OrdinalManager . | public boolean | move(Direction direction, int ordinal) Moves the position of a row with a specific ordinal within the entire
table. | public boolean | move(Direction direction, long restrictId, int ordinal) Moves the position of a row with a specific ordinal within the range
restricted by the provided ID. | public boolean | move(int fromOrdinal, int toOrdinal) Moves a row with a specific ordinal to the location of another ordinal
within the entire table. | public boolean | move(long restrictId, int fromOrdinal, int toOrdinal) Moves a row with a specific ordinal to the location of another ordinal
within the range restricted by the provided ID. | public int | obtainInsertOrdinal() Returns the next freely available ordinal that can be used to insert a
new row behind all the other rows in the entire table. | public int | obtainInsertOrdinal(long restrictId) Returns the next freely available ordinal that can be used to insert a
new row behind all the other rows in the range restricted by the
provided ID. | public boolean | tighten() Tightens the series of ordinal within the entire table so that no
spaces are present in between the ordinals. | public boolean | tighten(long restrictId) Tightens the series of ordinal within the range restricted by the
provided ID so that no spaces are present in between the ordinals. | public boolean | up(int ordinal) Moves a row with a specific ordinal upwards within the entire table. | public boolean | up(long restrictId, int ordinal) Moves a row with a specific ordinal upwards within the range restricted
by the provided ID. | public boolean | update(int currentOrdinal, int newOrdinal) Changes the ordinal of a certain row to a new value. | public boolean | update(long restrictId, int currentOrdinal, int newOrdinal) Changes the ordinal of a certain row with a specific restriction ID to
a new value. |
OrdinalManager | public OrdinalManager(Datasource datasource, String table, String ordinalColumn)(Code) | | Creates a new OrdinalManager that manages ordinals
globally for the specified table.
Parameters: datasource - the datasource where the table is accessible Parameters: table - the name of the table that will be managed Parameters: ordinalColumn - the name of the column that contains the integerordinals since: 1.0 |
OrdinalManager | public OrdinalManager(Datasource datasource, String table, String ordinalColumn, String restrictColumn)(Code) | | Creates a new OrdinalManager that manages ordinals for the
specified table in independent ranges according to a restricting
integer column.
Parameters: datasource - the datasource where the table is accessible Parameters: table - the name of the table that will be managed Parameters: ordinalColumn - the name of the column that contains the integerordinals Parameters: restrictColumn - the name of the column whose values willpartition the ordinals in independent ranges since: 1.0 |
clone | public Object clone()(Code) | | Simply clones the instance with the default clone method. This creates
a shallow copy of all fields and the clone will in fact just be another
reference to the same underlying data. The independence of each cloned
instance is consciously not respected since they rely on resources that
can't be cloned.
since: 1.0 |
down | public boolean down(int ordinal)(Code) | | Moves a row with a specific ordinal downwards within the entire table.
Parameters: ordinal - the ordinal of the row that has to be moved true if the move was executed successfully; orfalse if this wasn't the case See Also: OrdinalManager.down(long,int) since: 1.0
|
down | public boolean down(long restrictId, int ordinal)(Code) | | Moves a row with a specific ordinal downwards within the range
restricted by the provided ID.
Parameters: restrictId - the restriction ID value Parameters: ordinal - the ordinal of the row that has to be moved true if the move was executed successfully; orfalse if this wasn't the case See Also: OrdinalManager.down(int) since: 1.0
|
free | public boolean free(int ordinal)(Code) | | Frees up a slot for the specified ordinal within the entire table.,
this is done by incrementing everything after it by 1 to make space.
So for example issuing the method free(1) on the
following table:
id | ordinal | name
----+---------+-----------------------
2 | 0 | some article
0 | 1 | another one
1 | 2 | this is yet an article
will result in:
id | ordinal | name
----+---------+-----------------------
2 | 0 | some article
0 | 2 | another one
1 | 3 | this is yet an article
Parameters: ordinal - an integer representing the ordinal to free true if the slot was freed up correctly; orfalse if the operation wasn't possible See Also: OrdinalManager.free(long,int) since: 1.0
|
free | public boolean free(long restrictId, int ordinal)(Code) | | Frees up a slot for the specified ordinal within the range restricted
by the provided ID, this is done by incrementing everything after it by
1 to make space.
So for example issuing the method free(2, 0) on the
following table:
id | categoryId | ordinal | name
----+------------+---------+-----------------------
2 | 1 | 0 | some article
0 | 1 | 1 | another one
3 | 1 | 2 | boom boom
1 | 2 | 0 | this is yet an article
5 | 2 | 1 | an article for you
4 | 3 | 0 | our latest article
6 | 3 | 1 | important one
will result into:
id | categoryId | ordinal | name
----+------------+---------+-----------------------
2 | 1 | 0 | some article
0 | 1 | 1 | another one
3 | 1 | 2 | boom boom
1 | 2 | 1 | this is yet an article
5 | 2 | 2 | an article for you
4 | 3 | 0 | our latest article
6 | 3 | 1 | important one
Parameters: restrictId - the id by which to restrict with Parameters: ordinal - an int representation the ordinal to free true if the slot was freed up correctly; orfalse if the operation wasn't possible See Also: OrdinalManager.free(int) since: 1.0
|
getOrdinalColumn | public String getOrdinalColumn()(Code) | | Retrieves the name of the ordinal column.
the name of the ordinal column since: 1.0 |
getRestrictColumn | public String getRestrictColumn()(Code) | | Retrieves the name of the restricting column.
the name of the restricting column; or null if this OrdinalManager manages thetable globally since: 1.0
|
getTable | public String getTable()(Code) | | Retrieves the name of the table of this OrdinalManager .
the name of the table since: 1.0 |
move | public boolean move(Direction direction, int ordinal)(Code) | | Moves the position of a row with a specific ordinal within the entire
table.
Parameters: direction - the direction in which to move: OrdinalManager.UP OrdinalManager.UP or OrdinalManager.DOWNOrdinalManager.DOWN Parameters: ordinal - the ordinal of the row that has to be moved true if the move was executed successfully; orfalse if this wasn't the case See Also: OrdinalManager.move(Direction,long,int) since: 1.0
|
move | public boolean move(Direction direction, long restrictId, int ordinal)(Code) | | Moves the position of a row with a specific ordinal within the range
restricted by the provided ID.
Parameters: direction - the direction in which to move: OrdinalManager.UP OrdinalManager.UP or OrdinalManager.DOWNOrdinalManager.DOWN Parameters: restrictId - the restriction ID value Parameters: ordinal - the ordinal of the row that has to be moved true if the move was executed successfully; orfalse if this wasn't the case See Also: OrdinalManager.move(Direction,int) since: 1.0
|
move | public boolean move(int fromOrdinal, int toOrdinal)(Code) | | Moves a row with a specific ordinal to the location of another ordinal
within the entire table.
Parameters: fromOrdinal - the ordinal of the row that has to be moved Parameters: toOrdinal - the ordinal of the row where the from row has will beput above true if the move was executed successfully; orfalse if this wasn't the case See Also: OrdinalManager.down(int) since: 1.0
|
move | public boolean move(long restrictId, int fromOrdinal, int toOrdinal)(Code) | | Moves a row with a specific ordinal to the location of another ordinal
within the range restricted by the provided ID.
Parameters: restrictId - the restriction ID value Parameters: fromOrdinal - the ordinal of the row that has to be moved Parameters: toOrdinal - the ordinal of the row where the from row has will beput above true if the move was executed successfully; orfalse if this wasn't the case See Also: OrdinalManager.down(int) since: 1.0
|
obtainInsertOrdinal | public int obtainInsertOrdinal()(Code) | | Returns the next freely available ordinal that can be used to insert a
new row behind all the other rows in the entire table.
So for example issuing the method obtainInsertOrdinal()
on the following table:
id | ordinal | name
----+---------+-----------------------
2 | 0 | some article
0 | 1 | another one
1 | 2 | this is yet an article
Will return the value 3 .
the requested ordinal; or 0 if no ordinals are present within the table yet See Also: OrdinalManager.obtainInsertOrdinal(long) since: 1.0
|
obtainInsertOrdinal | public int obtainInsertOrdinal(long restrictId)(Code) | | Returns the next freely available ordinal that can be used to insert a
new row behind all the other rows in the range restricted by the
provided ID.
So for example issuing the method
obtainInsertOrdinal(3) on the following table:
id | categoryId | ordinal | name
----+------------+---------+-----------------------
2 | 1 | 0 | some article
0 | 1 | 1 | another one
3 | 1 | 2 | boom boom
1 | 2 | 0 | this is yet an article
5 | 2 | 1 | an article for you
4 | 3 | 0 | our latest article
6 | 3 | 1 | important one
Will return the value 2 .
Parameters: restrictId - the id by which to restrict with the requested ordinal; or 0 if no ordinals are present within the range yet See Also: OrdinalManager.obtainInsertOrdinal() since: 1.0
|
tighten | public boolean tighten()(Code) | | Tightens the series of ordinal within the entire table so that no
spaces are present in between the ordinals.
So for example issuing the method tighten() on the
following table:
id | ordinal | name
----+---------+-----------------------
2 | 0 | some article
0 | 2 | another one
1 | 5 | this is yet an article
will result in:
id | ordinal | name
----+---------+-----------------------
2 | 0 | some article
0 | 1 | another one
1 | 2 | this is yet an article
true if the tightening was executed correctly; orfalse if the operation wasn't possible See Also: OrdinalManager.tighten(long) since: 1.0
|
tighten | public boolean tighten(long restrictId)(Code) | | Tightens the series of ordinal within the range restricted by the
provided ID so that no spaces are present in between the ordinals.
So for example issuing the method tighten(2) on the
following table:
id | categoryId | ordinal | name
----+------------+---------+-----------------------
2 | 1 | 1 | some article
0 | 1 | 2 | another one
3 | 1 | 7 | boom boom
1 | 2 | 4 | this is yet an article
5 | 2 | 8 | an article for you
4 | 3 | 4 | our latest article
6 | 3 | 5 | important one
will result in:
id | categoryId | ordinal | name
----+------------+---------+-----------------------
2 | 1 | 1 | some article
0 | 1 | 2 | another one
3 | 1 | 7 | boom boom
1 | 2 | 0 | this is yet an article
5 | 2 | 1 | an article for you
4 | 3 | 4 | our latest article
6 | 3 | 5 | important one
Parameters: restrictId - the id by which to restrict with true if the tightening was executed correctly; orfalse if the operation wasn't possible See Also: OrdinalManager.tighten() since: 1.0
|
up | public boolean up(int ordinal)(Code) | | Moves a row with a specific ordinal upwards within the entire table.
Parameters: ordinal - the ordinal of the row that has to be moved true if the move was executed successfully; orfalse if this wasn't the case See Also: OrdinalManager.up(long,int) since: 1.0
|
up | public boolean up(long restrictId, int ordinal)(Code) | | Moves a row with a specific ordinal upwards within the range restricted
by the provided ID.
Parameters: restrictId - the restriction ID value Parameters: ordinal - the ordinal of the row that has to be moved true if the move was executed successfully; orfalse if this wasn't the case See Also: OrdinalManager.up(int) since: 1.0
|
update | public boolean update(int currentOrdinal, int newOrdinal)(Code) | | Changes the ordinal of a certain row to a new value.
This simply updates the value of the ordinal column and doesn't
execute any other logic.
Parameters: currentOrdinal - the ordinal of the row that has to be updated Parameters: newOrdinal - the new ordinal value true if the update was executed successfully; or false if this wasn't the case See Also: OrdinalManager.update(long,int,int) since: 1.0
|
update | public boolean update(long restrictId, int currentOrdinal, int newOrdinal)(Code) | | Changes the ordinal of a certain row with a specific restriction ID to
a new value.
This simply updates the value of the ordinal column and doesn't
execute any other logic.
Parameters: restrictId - the id by which to restrict with Parameters: currentOrdinal - the ordinal of the row that has to be updated Parameters: newOrdinal - the new ordinal value true if the update was executed successfully; or false if this wasn't the case See Also: OrdinalManager.update(int,int) since: 1.0
|
|
|