public final class SimplePositionDatabaseSqlite4Java
extends java.lang.Object
implements net.sourceforge.chessshell.plugin.api.ISimplePositionDatabase
| Modifier and Type | Field and Description |
|---|---|
private com.almworks.sqlite4java.SQLiteConnection |
itsConnection |
private java.lang.String |
itsCurrentPosition |
private java.lang.String |
itsFileName |
private byte |
itsFromSquare |
private java.util.Stack<java.lang.String> |
itsHistory |
private int |
itsLastReadBookmarkIndex |
private java.util.Properties |
itsProperties |
private byte |
itsToSquare |
private long |
positionCount |
| Modifier | Constructor and Description |
|---|---|
protected |
SimplePositionDatabaseSqlite4Java(java.lang.String fileName)
Open a SQLite database connection to the given file.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addBookmark(java.lang.String description)
Precondition: Current position is NOT bookmark'ed, AND current position != null (position count > 0).
|
void |
addMove(byte fromSquare,
byte toSquare,
java.lang.String positionAfterMove)
Add move and position after it (unless null).
|
void |
addPosition(java.lang.String fen)
Add position from a FEN string.
|
void |
addPositionAnnotationSymbol(int nagCode)
Add NAG symbol for current position.
|
boolean |
canGoBack() |
void |
clearAll()
Empty all of the database.
|
void |
clearAllBookmarks()
Delete all bookmarks.
|
private void |
clearBookmarks() |
private void |
clearMovesAndRelations() |
private void |
clearPositions() |
void |
close()
Always call this when the database is not to be used anymore.
|
void |
compact()
SQLite VACUUM operation.
|
boolean |
containsMove(byte fromSquare,
byte toSquare) |
boolean |
containsPosition(java.lang.String fen) |
boolean |
containsPositionAnnotationSymbol(int nagCode) |
void |
deleteBookmark()
Precondition: Current position is bookmark'ed.
|
void |
deleteBookmark(int index)
Delete bookmark by index.
|
void |
deleteMove(int index)
Delete move.
|
int |
getBookmarkCount() |
java.lang.String |
getBookmarkDescription(int index) |
java.lang.String |
getCurrentPosition() |
private long |
getCurrentPositionId() |
int |
getDefaultMoveRating() |
java.lang.String |
getFileName() |
private byte[] |
getHistoryBytes() |
int |
getIndexOfMove(byte fromSquare,
byte toSquare) |
private long |
getMaxBookmarkId() |
int |
getMaxMoveRating() |
void |
getMove(int index)
Read move from database.
|
int |
getMoveCount() |
private int |
getMoveCount(long positionId) |
byte |
getMoveFrom() |
int |
getMoveRating(int moveIndex) |
private long |
getMoveRowid(int moveIndex) |
java.lang.String |
getMoveTextCommentAfter(int moveIndex) |
java.lang.String |
getMoveTextCommentBefore(int moveIndex) |
byte |
getMoveTo() |
net.sourceforge.chessshell.common.MoveValueAnnotation |
getMoveValueAnnotation(int moveIndex) |
int |
getPositionAnnotationSymbol(int nagCodeIndex) |
int |
getPositionAnnotationSymbolCount() |
private java.lang.String |
getPositionById(long positionId) |
long |
getPositionCount() |
java.lang.String |
getPositionTextComment() |
java.util.Properties |
getProperties() |
void |
goBackOneMove()
When we have previously selected (played) a move, or added a move,
it is possible to go back.
|
void |
goForwardByMove(int i)
Select the i'th move (0-based index).
|
boolean |
hasMoveRating(int moveIndex) |
private void |
insertMoveRating(int moveIndex,
int rating)
Insert move rating.
|
private void |
insertMoveValueAnnotation(int moveIndex,
net.sourceforge.chessshell.common.MoveValueAnnotation value) |
private void |
insertOnlyMoveAnnotation(int moveIndex) |
private void |
insertPositionAnnotationSymbol(int nagCode)
Insert position annotation symbol.
|
boolean |
isClosed() |
boolean |
isCurrentPositionBookmarked() |
boolean |
isOnlyMove(int moveIndex) |
private boolean |
isPositionBookmarked(long positionId) |
void |
promoteVariation(int fromMoveIndex,
int toMoveIndex)
Promote move.
|
private java.lang.Object |
readFromBytes(byte[] yourBytes) |
private long |
readPositionCount() |
private void |
removeOnlyMoveAnnotation(int moveIndex) |
void |
selectBookmark(int index)
Navigate to bookmark by index.
|
void |
selectNextBookmark()
Navigate to next bookmark.
|
void |
selectPreviousBookmark()
Navigate to previous bookmark.
|
void |
setBookmarkDescription(int index,
java.lang.String description)
Set description for i'th bookmark.
|
void |
setDefaultMoveRating(int rating)
Set default move rating value.
|
void |
setMaxMoveRating(int rating)
Set maximal move rating.
|
void |
setMoveRating(int moveIndex,
int rating)
Set move rating.
|
void |
setMoveTextCommentAfter(int moveIndex,
java.lang.String commentText)
Set move text comment 'after'.
|
void |
setMoveTextCommentBefore(int moveIndex,
java.lang.String commentText)
Set move text comment 'before'.
|
void |
setMoveValueAnnotation(int moveIndex,
net.sourceforge.chessshell.common.MoveValueAnnotation value)
Move value annotations (!,?,...) - only one per move.
|
void |
setOnlyMoveAnnotation(int moveIndex,
boolean isOnlyMove)
Update only-move annotation for move.
|
void |
setPositionTextComment(java.lang.String txt)
Set text comment on current position.
|
private void |
updateMoveRating(int moveIndex,
int rating)
Update move rating.
|
private void |
updateMoveValueAnnotation(int moveIndex,
net.sourceforge.chessshell.common.MoveValueAnnotation value) |
private com.almworks.sqlite4java.SQLiteConnection itsConnection
private long positionCount
private final java.lang.String itsFileName
private java.lang.String itsCurrentPosition
private final java.util.Stack<java.lang.String> itsHistory
private final java.util.Properties itsProperties
private int itsLastReadBookmarkIndex
private byte itsFromSquare
private byte itsToSquare
protected SimplePositionDatabaseSqlite4Java(java.lang.String fileName)
throws net.sourceforge.chessshell.common.DatabaseException
fileName - net.sourceforge.chessshell.common.DatabaseExceptionprivate java.lang.Object readFromBytes(byte[] yourBytes)
throws java.lang.ClassNotFoundException,
java.io.IOException
java.lang.ClassNotFoundExceptionjava.io.IOExceptionprivate long readPositionCount()
throws net.sourceforge.chessshell.common.DatabaseException
net.sourceforge.chessshell.common.DatabaseExceptionprivate long getMaxBookmarkId()
throws net.sourceforge.chessshell.common.DatabaseException
net.sourceforge.chessshell.common.DatabaseExceptionpublic long getPositionCount()
getPositionCount in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasepublic void close()
throws net.sourceforge.chessshell.common.DatabaseException
close in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasenet.sourceforge.chessshell.common.DatabaseExceptionprivate byte[] getHistoryBytes()
throws java.io.IOException
java.io.IOExceptionpublic java.lang.String getFileName()
getFileName in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasepublic void addPosition(java.lang.String fen)
throws net.sourceforge.chessshell.common.DatabaseException
getCurrentPosition() will return 'fen'.addPosition in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasefen - net.sourceforge.chessshell.common.DatabaseExceptionpublic java.lang.String getCurrentPosition()
getCurrentPosition in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasepublic boolean containsPosition(java.lang.String fen)
throws net.sourceforge.chessshell.common.DatabaseException
containsPosition in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasefen - net.sourceforge.chessshell.common.DatabaseExceptionprivate long getCurrentPositionId()
throws net.sourceforge.chessshell.common.DatabaseException
net.sourceforge.chessshell.common.DatabaseExceptionprivate int getMoveCount(long positionId)
throws net.sourceforge.chessshell.common.DatabaseException
net.sourceforge.chessshell.common.DatabaseExceptionpublic int getMoveCount()
throws net.sourceforge.chessshell.common.DatabaseException
getMoveCount in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasenet.sourceforge.chessshell.common.DatabaseExceptionpublic void goBackOneMove()
canGoBack().goBackOneMove in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasecanGoBack()public java.util.Properties getProperties()
getProperties in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasepublic boolean containsMove(byte fromSquare,
byte toSquare)
throws net.sourceforge.chessshell.common.DatabaseException
containsMove in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasefromSquare - toSquare - net.sourceforge.chessshell.common.DatabaseExceptionpublic int getIndexOfMove(byte fromSquare,
byte toSquare)
throws net.sourceforge.chessshell.common.DatabaseException
getIndexOfMove in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasenet.sourceforge.chessshell.common.DatabaseExceptionpublic boolean canGoBack()
canGoBack in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasegoBackOneMove()public boolean isClosed()
isClosed in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasepublic void addMove(byte fromSquare,
byte toSquare,
java.lang.String positionAfterMove)
throws net.sourceforge.chessshell.common.DatabaseException
addMove in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasefromSquare - toSquare - positionAfterMove - net.sourceforge.chessshell.common.DatabaseExceptionpublic void goForwardByMove(int i)
throws net.sourceforge.chessshell.common.DatabaseException
goForwardByMove in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasei - net.sourceforge.chessshell.common.DatabaseExceptionprivate java.lang.String getPositionById(long positionId)
throws net.sourceforge.chessshell.common.DatabaseException
net.sourceforge.chessshell.common.DatabaseExceptionpublic int getBookmarkCount()
throws net.sourceforge.chessshell.common.DatabaseException
getBookmarkCount in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasenet.sourceforge.chessshell.common.DatabaseExceptionpublic boolean isCurrentPositionBookmarked()
throws net.sourceforge.chessshell.common.DatabaseException
isCurrentPositionBookmarked in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasenet.sourceforge.chessshell.common.DatabaseExceptionprivate boolean isPositionBookmarked(long positionId)
throws net.sourceforge.chessshell.common.DatabaseException
net.sourceforge.chessshell.common.DatabaseExceptionpublic void selectBookmark(int index)
throws net.sourceforge.chessshell.common.DatabaseException
selectBookmark in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabaseindex - net.sourceforge.chessshell.common.DatabaseExceptionpublic void selectNextBookmark()
throws net.sourceforge.chessshell.common.DatabaseException
selectNextBookmark in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasenet.sourceforge.chessshell.common.DatabaseExceptionpublic void selectPreviousBookmark()
throws net.sourceforge.chessshell.common.DatabaseException
selectPreviousBookmark in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasenet.sourceforge.chessshell.common.DatabaseExceptionpublic void clearAllBookmarks()
throws net.sourceforge.chessshell.common.DatabaseException
clearAllBookmarks in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasenet.sourceforge.chessshell.common.DatabaseExceptionpublic void deleteBookmark(int index)
throws net.sourceforge.chessshell.common.DatabaseException
deleteBookmark in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabaseindex - net.sourceforge.chessshell.common.DatabaseExceptionpublic void compact()
throws net.sourceforge.chessshell.common.DatabaseException
compact in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasenet.sourceforge.chessshell.common.DatabaseExceptionpublic void deleteBookmark()
throws net.sourceforge.chessshell.common.DatabaseException
isCurrentPositionBookmarked() first, and ONLY call this if it returns TRUE.
The bookmark collection may be corrupted otherwise.deleteBookmark in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasenet.sourceforge.chessshell.common.DatabaseExceptionpublic void addBookmark(java.lang.String description)
throws net.sourceforge.chessshell.common.DatabaseException
isCurrentPositionBookmarked() first, and ONLY call this if it returns FALSE - AND if
getPositionCount() > 0.
The bookmark collection may be corrupted otherwise.addBookmark in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasenet.sourceforge.chessshell.common.DatabaseExceptionpublic void setBookmarkDescription(int index,
java.lang.String description)
throws net.sourceforge.chessshell.common.DatabaseException
setBookmarkDescription in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabaseindex - description - net.sourceforge.chessshell.common.DatabaseExceptionpublic java.lang.String getBookmarkDescription(int index)
throws net.sourceforge.chessshell.common.DatabaseException
getBookmarkDescription in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabaseindex - net.sourceforge.chessshell.common.DatabaseExceptionpublic void setPositionTextComment(java.lang.String txt)
throws net.sourceforge.chessshell.common.DatabaseException
setPositionTextComment in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasetxt - net.sourceforge.chessshell.common.DatabaseExceptionpublic java.lang.String getPositionTextComment()
throws net.sourceforge.chessshell.common.DatabaseException
getPositionTextComment in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasenet.sourceforge.chessshell.common.DatabaseExceptionpublic void setMoveTextCommentAfter(int moveIndex,
java.lang.String commentText)
throws net.sourceforge.chessshell.common.DatabaseException
setMoveTextCommentAfter in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasemoveIndex - - 0-basedcommentText - net.sourceforge.chessshell.common.DatabaseExceptionpublic void setMoveTextCommentBefore(int moveIndex,
java.lang.String commentText)
throws net.sourceforge.chessshell.common.DatabaseException
setMoveTextCommentBefore in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasemoveIndex - commentText - net.sourceforge.chessshell.common.DatabaseExceptionpublic java.lang.String getMoveTextCommentAfter(int moveIndex)
throws net.sourceforge.chessshell.common.DatabaseException
getMoveTextCommentAfter in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasemoveIndex - net.sourceforge.chessshell.common.DatabaseExceptionpublic java.lang.String getMoveTextCommentBefore(int moveIndex)
throws net.sourceforge.chessshell.common.DatabaseException
getMoveTextCommentBefore in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasemoveIndex - net.sourceforge.chessshell.common.DatabaseExceptionpublic void deleteMove(int index)
throws net.sourceforge.chessshell.common.DatabaseException
deleteMove in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabaseindex - net.sourceforge.chessshell.common.DatabaseExceptionpublic void getMove(int index)
throws net.sourceforge.chessshell.common.DatabaseException
getMoveFrom() and getMoveTo() to get from/to squares.getMove in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabaseindex - net.sourceforge.chessshell.common.DatabaseExceptionpublic byte getMoveFrom()
getMoveFrom in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasegetMove(int)public byte getMoveTo()
getMoveTo in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasegetMove(int)public void setMoveValueAnnotation(int moveIndex,
net.sourceforge.chessshell.common.MoveValueAnnotation value)
throws net.sourceforge.chessshell.common.DatabaseException
setMoveValueAnnotation in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasevalue - net.sourceforge.chessshell.common.DatabaseExceptiongetMoveValueAnnotation(int)private void updateMoveValueAnnotation(int moveIndex,
net.sourceforge.chessshell.common.MoveValueAnnotation value)
throws net.sourceforge.chessshell.common.DatabaseException
net.sourceforge.chessshell.common.DatabaseExceptionprivate void insertMoveValueAnnotation(int moveIndex,
net.sourceforge.chessshell.common.MoveValueAnnotation value)
throws net.sourceforge.chessshell.common.DatabaseException
net.sourceforge.chessshell.common.DatabaseExceptionpublic net.sourceforge.chessshell.common.MoveValueAnnotation getMoveValueAnnotation(int moveIndex)
throws net.sourceforge.chessshell.common.DatabaseException
getMoveValueAnnotation in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasemoveIndex - net.sourceforge.chessshell.common.DatabaseExceptionsetMoveValueAnnotation(int, MoveValueAnnotation)private long getMoveRowid(int moveIndex)
throws net.sourceforge.chessshell.common.DatabaseException
moveIndex - net.sourceforge.chessshell.common.DatabaseExceptionpublic void setOnlyMoveAnnotation(int moveIndex,
boolean isOnlyMove)
throws net.sourceforge.chessshell.common.DatabaseException
setOnlyMoveAnnotation in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasemoveIndex - isOnlyMove - net.sourceforge.chessshell.common.DatabaseExceptionisOnlyMove(int)private void removeOnlyMoveAnnotation(int moveIndex)
throws net.sourceforge.chessshell.common.DatabaseException
net.sourceforge.chessshell.common.DatabaseExceptionprivate void insertOnlyMoveAnnotation(int moveIndex)
throws net.sourceforge.chessshell.common.DatabaseException
net.sourceforge.chessshell.common.DatabaseExceptionpublic boolean isOnlyMove(int moveIndex)
throws net.sourceforge.chessshell.common.DatabaseException
isOnlyMove in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasemoveIndex - net.sourceforge.chessshell.common.DatabaseExceptionsetOnlyMoveAnnotation(int, boolean)public void setMaxMoveRating(int rating)
throws net.sourceforge.chessshell.common.DatabaseException
setMaxMoveRating in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabaserating - net.sourceforge.chessshell.common.DatabaseExceptionpublic int getMaxMoveRating()
throws net.sourceforge.chessshell.common.DatabaseException
getMaxMoveRating in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasenet.sourceforge.chessshell.common.DatabaseExceptionpublic void setDefaultMoveRating(int rating)
throws net.sourceforge.chessshell.common.DatabaseException
setDefaultMoveRating in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabaserating - net.sourceforge.chessshell.common.DatabaseExceptionpublic int getDefaultMoveRating()
throws net.sourceforge.chessshell.common.DatabaseException
getDefaultMoveRating in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasenet.sourceforge.chessshell.common.DatabaseExceptionpublic void setMoveRating(int moveIndex,
int rating)
throws net.sourceforge.chessshell.common.DatabaseException
setMoveRating in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasemoveIndex - rating - net.sourceforge.chessshell.common.DatabaseExceptionprivate void updateMoveRating(int moveIndex,
int rating)
throws net.sourceforge.chessshell.common.DatabaseException
moveIndex - rating - net.sourceforge.chessshell.common.DatabaseExceptionprivate void insertMoveRating(int moveIndex,
int rating)
throws net.sourceforge.chessshell.common.DatabaseException
moveIndex - rating - net.sourceforge.chessshell.common.DatabaseExceptionpublic boolean hasMoveRating(int moveIndex)
throws net.sourceforge.chessshell.common.DatabaseException
hasMoveRating in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasemoveIndex - net.sourceforge.chessshell.common.DatabaseExceptionpublic int getMoveRating(int moveIndex)
throws net.sourceforge.chessshell.common.DatabaseException
getMoveRating in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasemoveIndex - net.sourceforge.chessshell.common.DatabaseExceptionpublic void addPositionAnnotationSymbol(int nagCode)
throws net.sourceforge.chessshell.common.DatabaseException
addPositionAnnotationSymbol in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasenagCode - net.sourceforge.chessshell.common.DatabaseExceptionprivate void insertPositionAnnotationSymbol(int nagCode)
throws net.sourceforge.chessshell.common.DatabaseException
nagCode - net.sourceforge.chessshell.common.DatabaseExceptionpublic int getPositionAnnotationSymbol(int nagCodeIndex)
throws net.sourceforge.chessshell.common.DatabaseException
getPositionAnnotationSymbol in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasenagCodeIndex - net.sourceforge.chessshell.common.DatabaseExceptionjava.lang.ArrayIndexOutOfBoundsExceptiongetCurrentPosition()public boolean containsPositionAnnotationSymbol(int nagCode)
throws net.sourceforge.chessshell.common.DatabaseException
containsPositionAnnotationSymbol in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasenagCode - net.sourceforge.chessshell.common.DatabaseExceptionpublic int getPositionAnnotationSymbolCount()
throws net.sourceforge.chessshell.common.DatabaseException
getPositionAnnotationSymbolCount in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasenet.sourceforge.chessshell.common.DatabaseExceptionpublic void clearAll()
throws net.sourceforge.chessshell.common.DatabaseException
clearAll in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasenet.sourceforge.chessshell.common.DatabaseExceptionprivate void clearPositions()
throws net.sourceforge.chessshell.common.DatabaseException
net.sourceforge.chessshell.common.DatabaseExceptionprivate void clearBookmarks()
throws net.sourceforge.chessshell.common.DatabaseException
net.sourceforge.chessshell.common.DatabaseExceptionprivate void clearMovesAndRelations()
throws net.sourceforge.chessshell.common.DatabaseException
net.sourceforge.chessshell.common.DatabaseExceptionpublic void promoteVariation(int fromMoveIndex,
int toMoveIndex)
throws net.sourceforge.chessshell.common.DatabaseException
promoteVariation in interface net.sourceforge.chessshell.plugin.api.ISimplePositionDatabasefromMoveIndex - toMoveIndex - net.sourceforge.chessshell.common.DatabaseException