Package org.sonews.storage.impl.jdbc
Class JDBCDatabase
java.lang.Object
org.sonews.storage.impl.jdbc.JDBCDatabase
- All Implemented Interfaces:
Storage
Storage backend facade class for a relational SQL database using JDBC. The
statements used should work for at least PostgreSQL and MySQL.
- Since:
- sonews/0.5.0
- Author:
- Christian Lins
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Connection
static final int
protected PreparedStatement
protected PreparedStatement
protected PreparedStatement
protected PreparedStatement
protected PreparedStatement
protected PreparedStatement
protected PreparedStatement
protected PreparedStatement
protected PreparedStatement
protected PreparedStatement
protected PreparedStatement
protected PreparedStatement
protected PreparedStatement
protected PreparedStatement
protected PreparedStatement
protected PreparedStatement
protected PreparedStatement
protected PreparedStatement
protected PreparedStatement
protected PreparedStatement
protected PreparedStatement
protected PreparedStatement
protected PreparedStatement
protected PreparedStatement
protected PreparedStatement
protected PreparedStatement
protected PreparedStatement
protected PreparedStatement
protected PreparedStatement
protected PreparedStatement
protected int
How many times the database connection was reinitialized -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addArticle
(Article article) Adds an article to the database.protected void
addArticle
(Article article, int newArticleID) Adds an article to the database.protected void
arise()
Rises the database: reconnect and recreate all prepared statements.boolean
authenticateUser
(String username, char[] password) TODO Move to separate Authentication Backendvoid
close()
Closes the JDBCDatabase connection.protected void
int
void
createOrUpdateGroup
(Group group) void
getArticle
(long articleIndex, long gid) Retrieves an article by its ID.getArticle
(String messageID) getArticleHeaders
(Group group, long start, long end, String headerKey, String patStr) Searches for fitting header values using the given regular expression.getArticleHeads
(Group group, long first, long last) Returns a list of Long/ArticleImpl Pairs.long
getArticleIndex
(Article article, Group group) getArticleNumbers
(long gid) int
getFirstArticleNumber
(Group group) int
getLastArticleNumber
(Group group) int
getPostingsCount
(String groupname) boolean
isArticleExisting
(String messageID) Checks if there is an article with the given messageid in the JDBCDatabase.protected void
void
purgeGroup
(Group group) Performes a purge operation in the storage backend, e.g. to delete old messages or release allocated resources.protected void
restartConnection
(SQLException cause) Restart the JDBC connection to the Database server.boolean
Updates headers and group references of the given article.protected void
updateWatermark
(Group group, long watermark)
-
Field Details
-
MAX_RESTARTS
public static final int MAX_RESTARTS- See Also:
-
conn
-
pstmtAddArticle1
-
pstmtAddArticle2
-
pstmtAddArticle3
-
pstmtAddArticle4
-
pstmtCountArticles
-
pstmtCreateOrUpdateGroup0
-
pstmtCreateOrUpdateGroup1
-
pstmtCreateOrUpdateGroup2
-
pstmtDeleteArticle0
-
pstmtDeleteArticle1
-
pstmtDeleteArticle2
-
pstmtDeleteArticle3
-
pstmtGetArticle0
-
pstmtGetArticle1
-
pstmtGetArticleHeaders0
-
pstmtGetArticleHeaders1
-
pstmtGetArticleHeads
-
pstmtGetArticleIDs
-
pstmtGetArticleIndex
-
pstmtGetFirstArticleNumber
-
pstmtGetGroups
-
pstmtGetLastArticleNumber
-
pstmtGetMaxArticleID
-
pstmtGetMaxArticleIndex
-
pstmtGetOldestArticle
-
pstmtGetPostingsCount
-
pstmtIsArticleExisting
-
pstmtPurgeGroup0
-
pstmtPurgeGroup1
-
pstmtUpdateWatermark
-
restarts
protected int restartsHow many times the database connection was reinitialized
-
-
Constructor Details
-
JDBCDatabase
public JDBCDatabase()
-
-
Method Details
-
prepareGetPostingsCountStatement
- Throws:
SQLException
-
arise
Rises the database: reconnect and recreate all prepared statements.- Throws:
SQLException
-
closeResultSet
-
addArticle
Adds an article to the database.- Specified by:
addArticle
in interfaceStorage
- Parameters:
article
-- Throws:
StorageBackendException
-
addArticle
protected void addArticle(Article article, int newArticleID) throws SQLException, StorageBackendException Adds an article to the database. Method is not synchronized as it is only called by an already synchronized method.- Parameters:
article
-newArticleID
-- Throws:
SQLException
StorageBackendException
-
countArticles
- Specified by:
countArticles
in interfaceStorage
- Throws:
StorageBackendException
-
createOrUpdateGroup
- Specified by:
createOrUpdateGroup
in interfaceStorage
- Throws:
StorageBackendException
-
delete
- Specified by:
delete
in interfaceStorage
- Throws:
StorageBackendException
-
getArticle
- Specified by:
getArticle
in interfaceStorage
- Throws:
StorageBackendException
-
getArticle
Retrieves an article by its ID.- Specified by:
getArticle
in interfaceStorage
- Parameters:
articleIndex
-gid
-- Returns:
- Throws:
StorageBackendException
-
getArticleHeaders
public List<Pair<Long,String>> getArticleHeaders(Group group, long start, long end, String headerKey, String patStr) throws StorageBackendException, PatternSyntaxException Searches for fitting header values using the given regular expression.- Specified by:
getArticleHeaders
in interfaceStorage
- Parameters:
group
-start
-end
-headerKey
-patStr
-- Returns:
- Throws:
StorageBackendException
PatternSyntaxException
-
getArticleIndex
- Specified by:
getArticleIndex
in interfaceStorage
- Throws:
StorageBackendException
-
getArticleHeads
public List<Pair<Long,Article>> getArticleHeads(Group group, long first, long last) throws StorageBackendException Returns a list of Long/ArticleImpl Pairs.- Specified by:
getArticleHeads
in interfaceStorage
- Parameters:
group
-first
-last
-- Returns:
- Throws:
StorageBackendException
-
getArticleNumbers
- Specified by:
getArticleNumbers
in interfaceStorage
- Throws:
StorageBackendException
-
getGroups
- Specified by:
getGroups
in interfaceStorage
- Throws:
StorageBackendException
-
getLastArticleNumber
- Specified by:
getLastArticleNumber
in interfaceStorage
- Throws:
StorageBackendException
-
getFirstArticleNumber
- Specified by:
getFirstArticleNumber
in interfaceStorage
- Throws:
StorageBackendException
-
getOldestArticle
- Specified by:
getOldestArticle
in interfaceStorage
- Throws:
StorageBackendException
-
getPostingsCount
- Specified by:
getPostingsCount
in interfaceStorage
- Throws:
StorageBackendException
-
isArticleExisting
Checks if there is an article with the given messageid in the JDBCDatabase.- Specified by:
isArticleExisting
in interfaceStorage
- Parameters:
messageID
-- Returns:
- Throws:
StorageBackendException
-
close
@PreDestroy public void close()Closes the JDBCDatabase connection. -
purgeGroup
Description copied from interface:Storage
Performes a purge operation in the storage backend, e.g. to delete old messages or release allocated resources.- Specified by:
purgeGroup
in interfaceStorage
- Parameters:
group
-- Throws:
StorageBackendException
-
restartConnection
Restart the JDBC connection to the Database server.- Parameters:
cause
-- Throws:
StorageBackendException
-
update
Description copied from interface:Storage
Updates headers and group references of the given article.- Specified by:
update
in interfaceStorage
- Parameters:
article
-- Returns:
- Throws:
StorageBackendException
-
updateWatermark
- Throws:
StorageBackendException
-
authenticateUser
Description copied from interface:Storage
TODO Move to separate Authentication Backend- Specified by:
authenticateUser
in interfaceStorage
- Parameters:
username
-password
-- Returns:
- Throws:
StorageBackendException
-