JIDE 3.5.15

com.jidesoft.rss
Class FeedDatabasePersistenceManager

java.lang.Object
  extended by com.jidesoft.rss.FeedDatabasePersistenceManager

public class FeedDatabasePersistenceManager
extends Object

An implementation of FeedPersistenceLayer using hsqldb (http://hsqldb.org/). By default, it will take a local folder and create two subfolders. The "icon" subfolder is for channel icons. The "db" subfolder for hsqldb file.


Constructor Summary
FeedDatabasePersistenceManager(FeedReader feedReader)
           
 
Method Summary
 void addChannelToGroup(ChannelIF channel, ChannelGroupIF group)
           
 void close()
          flush data, close the db.
 ChannelIF createChannel(String title, URL url)
           
 ChannelGroupIF createGroup(String title)
           
 ItemIF createItem(ChannelIF channel, ItemIF item)
           
 ItemIF createItem(ChannelIF channel, String itemTitle)
           
 void deleteChannel(ChannelIF channel)
           
 void deleteGroup(ChannelGroupIF group)
           
 void deleteItem(ItemIF item)
           
protected  Connection getConnection()
          Gets the database connection.
 ChannelGroupIF[] getGroups()
           
protected  URL getScriptURL()
          Gets the URL for rssdbscript.dll.
protected  String getTableName(String originalTableName)
          Gets the table name.
protected  String getTablePostfix()
          Gets the table name postfix.
protected  String getTablePrefix()
          Gets the table name prefix.
protected  boolean initializeDB()
          Initializes the database.
protected  void installDB(Connection connection)
          Installs the database.
 void mergeGroups(ChannelGroupIF dstGroup, ChannelGroupIF srcGroup)
           
protected  PreparedStatement prepareStatement(Connection connection, String sql)
          By default, this method will call connection.prepareStatement(sql) and return the returned value.
 void removeChannelFromGroup(ChannelIF channel, ChannelGroupIF group)
           
 void updateChannel(ChannelIF channel)
           
 void updateGroup(ChannelGroupIF group)
           
 void updateItem(ItemIF item)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FeedDatabasePersistenceManager

public FeedDatabasePersistenceManager(FeedReader feedReader)
Method Detail

createGroup

public ChannelGroupIF createGroup(String title)
                           throws PersistenceManagerException
Throws:
PersistenceManagerException

updateGroup

public void updateGroup(ChannelGroupIF group)
                 throws PersistenceManagerException
Throws:
PersistenceManagerException

deleteGroup

public void deleteGroup(ChannelGroupIF group)
                 throws PersistenceManagerException
Throws:
PersistenceManagerException

mergeGroups

public void mergeGroups(ChannelGroupIF dstGroup,
                        ChannelGroupIF srcGroup)
                 throws PersistenceManagerException
Throws:
PersistenceManagerException

getGroups

public ChannelGroupIF[] getGroups()
                           throws PersistenceManagerException
Throws:
PersistenceManagerException

createChannel

public ChannelIF createChannel(String title,
                               URL url)
                        throws PersistenceManagerException
Throws:
PersistenceManagerException

updateChannel

public void updateChannel(ChannelIF channel)
                   throws PersistenceManagerException
Throws:
PersistenceManagerException

addChannelToGroup

public void addChannelToGroup(ChannelIF channel,
                              ChannelGroupIF group)
                       throws PersistenceManagerException
Throws:
PersistenceManagerException

removeChannelFromGroup

public void removeChannelFromGroup(ChannelIF channel,
                                   ChannelGroupIF group)
                            throws PersistenceManagerException
Throws:
PersistenceManagerException

deleteChannel

public void deleteChannel(ChannelIF channel)
                   throws PersistenceManagerException
Throws:
PersistenceManagerException

createItem

public ItemIF createItem(ChannelIF channel,
                         String itemTitle)
                  throws PersistenceManagerException
Throws:
PersistenceManagerException

createItem

public ItemIF createItem(ChannelIF channel,
                         ItemIF item)
                  throws PersistenceManagerException
Throws:
PersistenceManagerException

updateItem

public void updateItem(ItemIF item)
                throws PersistenceManagerException
Throws:
PersistenceManagerException

deleteItem

public void deleteItem(ItemIF item)
                throws PersistenceManagerException
Throws:
PersistenceManagerException

close

public void close()
           throws Exception
flush data, close the db.

Throws:
Exception - if any database access errors.

initializeDB

protected boolean initializeDB()
                        throws Exception
Initializes the database. By default, we will hsqldb. If the database file is not found, we will create it using installDB(java.sql.Connection) method.

Returns:
true if the database is used the first time.
Throws:
Exception - if any errors happen during the initialization such as the driver class not found or database access problem.

installDB

protected void installDB(Connection connection)
Installs the database.

Parameters:
connection - the connection.

getScriptURL

protected URL getScriptURL()
Gets the URL for rssdbscript.dll. You can override it if you provide your own database script in installDb method. By default, we put rssdbscript.ddl at the same place as FeedReader.class so the code to get the URL for it is FeedUtils.class.getResource(("rssdbscript.ddl")).

Returns:
the resource

getConnection

protected Connection getConnection()
Gets the database connection. This connection is used by this class to update the database.

Returns:
the database connection.

getTableName

protected String getTableName(String originalTableName)
Gets the table name. The original table names can be CATEGORIES, CAT_CHANNEL_LINK, CAT_GROUP_CHANNEL, CAT_ITEM_LINK, CHANNELS, CHANNEL_GROUPS, CHANNEL_SUBSCRIPTIONS, CLOUDS, IMAGES, ITEMS, ITEM_ENCLOSURE, ITEM_GUID, ITEM_METADATA, ITEM_SOURCE, TEXTINPUTS, and CONFIG. You can return different names here or you can override getTablePrefix() or getTablePostfix() if you just want to add a prefix or postfix. However make sure you change them in the rssdbscript.ddl file to match what you changed here.

Parameters:
originalTableName - the original table name
Returns:
the new name after after adding the prefix and postfix if any.

getTablePrefix

protected String getTablePrefix()
Gets the table name prefix. It is used by getTableName(String) method.

Returns:
"" by default.

getTablePostfix

protected String getTablePostfix()
Gets the table name postfix. It is used by getTableName(String) method.

Returns:
"" by default.

prepareStatement

protected PreparedStatement prepareStatement(Connection connection,
                                             String sql)
                                      throws SQLException
By default, this method will call connection.prepareStatement(sql) and return the returned value. We expose this as a protected method is because some database systems might need to customize the sql string. In this case, subclass can override it to customize it before calling connection.prepareStatement.

Parameters:
connection - the connection
sql - an SQL statement that may contain one or more '?' IN parameter placeholders
Returns:
the PreparedStatement object for sending parametrized SQL statements to the database.
Throws:
SQLException - if a database access error occurs or this method is called on a closed connection

JIDE 3.5.15