Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.opencms.defaults.master.genericsql
Class CmsDbAccess  view CmsDbAccess download CmsDbAccess.java

java.lang.Object
  extended bycom.opencms.defaults.master.genericsql.CmsDbAccess

public class CmsDbAccess
extends java.lang.Object

This class provides methods to access the database in a generic way.


Field Summary
static java.lang.String C_COS_PREFIX
           
protected  java.lang.String m_backupPoolName
          The pool to access the backup ressources
protected  java.lang.String m_onlinePoolName
          The pool to access the online ressources
protected  java.lang.String m_poolName
          The pool to access offline ressources
protected  java.util.Properties m_queries
          The query properties for this accessmodule
protected  java.lang.String m_rootChannel
          The root channel of the module
 
Constructor Summary
CmsDbAccess()
          Public empty constructor, call "init()" on this class afterwards.
CmsDbAccess(java.lang.String poolName, java.lang.String onlinePoolName, java.lang.String backupPoolName)
          Constructs a new DbAccessObject.
 
Method Summary
 void changePermissions(com.opencms.file.CmsObject cms, com.opencms.defaults.master.CmsMasterContent content, com.opencms.defaults.master.CmsMasterDataSet dataset)
          Changes the perrmissions of the Master
protected  boolean checkAccess(com.opencms.defaults.master.CmsMasterContent content, boolean viewonly)
          Checks if read (and visible) permissions are granted.
private  void combineQueries()
          Combines the queries in the properties to complete quereis.
protected  int computeProjectId(com.opencms.file.CmsObject cms, com.opencms.defaults.master.CmsMasterDataSet dataset)
          Computes the correct project id based on the channels.
 int copy(com.opencms.file.CmsObject cms, com.opencms.defaults.master.CmsMasterContent content, com.opencms.defaults.master.CmsMasterDataSet dataset, java.util.Vector mediaToAdd, java.util.Vector channelToAdd)
          Inserts a new row in the database with the copied dataset.
protected  java.util.Vector createVectorOfCd(java.sql.ResultSet res, java.lang.Class contentDefinitionClass, com.opencms.file.CmsObject cms)
          Returns a vector of contentdefinitions based on the sql resultset.
protected  java.util.Vector createVectorOfCd(java.sql.ResultSet res, java.lang.Class contentDefinitionClass, com.opencms.file.CmsObject cms, boolean viewonly)
          Returns a vector of contentdefinitions based on the sql resultset.
protected  java.util.Vector createVectorOfCd(java.util.Vector datasets, java.lang.Class contentDefinitionClass, com.opencms.file.CmsObject cms)
          Returns a vector of contentdefinitions based on the sql resultset.
 void delete(com.opencms.file.CmsObject cms, com.opencms.defaults.master.CmsMasterContent content, com.opencms.defaults.master.CmsMasterDataSet dataset)
           
protected  void deleteAllChannels(int masterId)
          Deletes all channel lines for one master.
protected  void deleteAllMedia(int masterId)
          Deletes all media lines for one master.
 java.sql.Connection getConnection(com.opencms.file.CmsObject cms)
          Returns the correct connection.
 java.util.Vector getHistory(com.opencms.file.CmsObject cms, java.lang.Class contentDefinitionClass, int masterId, int subId)
          Returns a vector with all version of a master in the backup
 java.lang.String getRootChannel()
          Get the root channel
 com.opencms.defaults.master.CmsMasterContent getVersionFromHistory(com.opencms.file.CmsObject cms, java.lang.Class contentDefinitionClass, int masterId, int subId, int versionId)
          Returns the version of a master in the backup
 com.opencms.defaults.master.CmsMasterDataSet getVersionFromHistory(com.opencms.file.CmsObject cms, int masterId, int subId, int versionId)
          Returns the version of a master in the backup
 void init(java.lang.String offline, java.lang.String online, java.lang.String backup)
          Initializes the DBAccessObject.
 void insert(com.opencms.file.CmsObject cms, com.opencms.defaults.master.CmsMasterContent content, com.opencms.defaults.master.CmsMasterDataSet dataset)
          Inserts a new row in the database with the dataset.
protected  boolean isOnlineProject(com.opencms.file.CmsObject cms)
          Returns true, if this is the onlineproject
private  void loadQueries(java.lang.Class currentClass)
          Loads recursively all query.properties from all packages of the superclasses.
protected  void publishBackupData(com.opencms.file.CmsObject cms, com.opencms.defaults.master.CmsMasterDataSet dataset, int subId, int versionId, long publishDate)
           
protected  void publishCopyData(com.opencms.defaults.master.CmsMasterDataSet dataset, int subId)
           
protected  void publishDeleteData(int masterId, int subId, java.lang.String table)
           
protected  void publishOneLine(com.opencms.file.CmsObject cms, com.opencms.defaults.master.CmsMasterDataSet dataset, int subId, java.lang.String contentDefinitionName, boolean enableHistory, int versionId, long publishingDate, java.util.Vector changedRessources, java.util.Vector changedModuleData)
           
 void publishProject(com.opencms.file.CmsObject cms, boolean enableHistory, int projectId, int versionId, long publishingDate, int subId, java.lang.String contentDefinitionName, java.util.Vector changedRessources, java.util.Vector changedModuleData)
          Publishes all ressources for this project Publishes all modified content definitions for this project.
 void publishResource(com.opencms.file.CmsObject cms, com.opencms.defaults.master.CmsMasterDataSet dataset, int subId, java.lang.String contentDefinitionName, boolean enableHistory, int versionId, long publishingDate, java.util.Vector changedResources, java.util.Vector changedModuleData)
          Publishes a single content definition
 void read(com.opencms.file.CmsObject cms, com.opencms.defaults.master.CmsMasterContent content, com.opencms.defaults.master.CmsMasterDataSet dataset, int masterId)
           
 java.util.Vector readAllByChannel(com.opencms.file.CmsObject cms, int channelId, int subId)
          Reads all content definitions of a given channel
 java.util.Vector readChannels(com.opencms.file.CmsObject cms, com.opencms.defaults.master.CmsMasterContent content)
          Reads all channels from the database.
protected  void readLockstate(com.opencms.defaults.master.CmsMasterDataSet dataset, int subId)
          Read the lockstate from the database.
 java.util.Vector readMedia(com.opencms.file.CmsObject cms, com.opencms.defaults.master.CmsMasterContent content)
          Reads all media from the database.
private  boolean replace(java.lang.String key)
          Computes one run of the replacement for one query.
 void restore(com.opencms.file.CmsObject cms, com.opencms.defaults.master.CmsMasterContent content, com.opencms.defaults.master.CmsMasterDataSet dataset, int versionId)
          Restores a version of the master and media from backup
 void setRootChannel(java.lang.String newRootChannel)
          Set the root channel
protected  void sqlClose(java.sql.Connection con, java.sql.Statement stmnt, java.sql.ResultSet res)
          Closes all sql ressources.
protected  int sqlFillValues(java.sql.PreparedStatement stmnt, com.opencms.defaults.master.CmsMasterMedia media)
          Fills a prepared statement with media values.
protected  int sqlFillValues(java.sql.PreparedStatement stmnt, int subId, com.opencms.defaults.master.CmsMasterDataSet dataset)
          Inserts all values to the statement for insert and update.
protected  int sqlFillValues(java.sql.ResultSet res, com.opencms.file.CmsObject cms, com.opencms.defaults.master.CmsMasterDataSet dataset)
          Inserts all values to the statement for insert and update.
protected  java.sql.PreparedStatement sqlPrepare(com.opencms.file.CmsObject cms, java.sql.Connection con, java.lang.String queryKey)
          Creates a new connection and prepares a stement.
protected  java.sql.PreparedStatement sqlPrepare(com.opencms.file.CmsObject cms, java.sql.Connection con, java.lang.String queryKey, java.util.HashMap optionalSqlTokens)
          Replaces in a SQL statement $XXX tokens by strings and returns a prepared statement.
protected  java.sql.PreparedStatement sqlPrepare(java.sql.Connection con, java.lang.String queryKey)
          Creates a new connection and prepares a stement.
protected  int sqlSetDateArray(java.sql.PreparedStatement stmnt, long[] array, int columnscounter)
          Sets an array of ints into the stmnt.
protected  int sqlSetDateArray(java.sql.ResultSet res, long[] array, int columnscounter)
          Sets an array of ints from the resultset.
protected  int sqlSetIntArray(java.sql.PreparedStatement stmnt, int[] array, int columnscounter)
          Sets an array of ints into the stmnt.
protected  int sqlSetIntArray(java.sql.ResultSet res, int[] array, int columnscounter)
          Sets an array of ints from the resultset.
protected  int sqlSetTextArray(java.sql.PreparedStatement stmnt, java.lang.String[] array, int columnscounter)
          Sets an array of strings into the stmnt.
protected  int sqlSetTextArray(java.sql.ResultSet res, java.lang.String[] array, int columnscounter)
          Sets an array of strings from the resultset.
 java.lang.String toString()
          Returns a string representation of this instance.
 void undelete(com.opencms.file.CmsObject cms, com.opencms.defaults.master.CmsMasterContent content, com.opencms.defaults.master.CmsMasterDataSet dataset)
           
protected  void updateChannels(com.opencms.file.CmsObject cms, int masterId, java.util.Vector channelToAdd, java.util.Vector channelToDelete)
          Updates the channels of a content definition.
protected  void updateMedia(int masterId, java.util.Vector mediaToAdd, java.util.Vector mediaToUpdate, java.util.Vector mediaToDelete)
          Updates the media object of a content definition.
 void write(com.opencms.file.CmsObject cms, com.opencms.defaults.master.CmsMasterContent content, com.opencms.defaults.master.CmsMasterDataSet dataset)
           
 void writeLockstate(com.opencms.file.CmsObject cms, com.opencms.defaults.master.CmsMasterContent content, com.opencms.defaults.master.CmsMasterDataSet dataset)
          Updates the lockstate in the database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

C_COS_PREFIX

public static final java.lang.String C_COS_PREFIX
See Also:
Constant Field Values

m_poolName

protected java.lang.String m_poolName
The pool to access offline ressources


m_onlinePoolName

protected java.lang.String m_onlinePoolName
The pool to access the online ressources


m_backupPoolName

protected java.lang.String m_backupPoolName
The pool to access the backup ressources


m_queries

protected java.util.Properties m_queries
The query properties for this accessmodule


m_rootChannel

protected java.lang.String m_rootChannel
The root channel of the module

Constructor Detail

CmsDbAccess

public CmsDbAccess()
Public empty constructor, call "init()" on this class afterwards. This allows more flexible custom module development. FLEX: Made the constructor public!


CmsDbAccess

public CmsDbAccess(java.lang.String poolName,
                   java.lang.String onlinePoolName,
                   java.lang.String backupPoolName)
Constructs a new DbAccessObject.

Method Detail

init

public void init(java.lang.String offline,
                 java.lang.String online,
                 java.lang.String backup)
Initializes the DBAccessObject.


setRootChannel

public void setRootChannel(java.lang.String newRootChannel)
Set the root channel


getRootChannel

public java.lang.String getRootChannel()
Get the root channel


insert

public void insert(com.opencms.file.CmsObject cms,
                   com.opencms.defaults.master.CmsMasterContent content,
                   com.opencms.defaults.master.CmsMasterDataSet dataset)
            throws com.opencms.core.CmsException
Inserts a new row in the database with the dataset.


copy

public int copy(com.opencms.file.CmsObject cms,
                com.opencms.defaults.master.CmsMasterContent content,
                com.opencms.defaults.master.CmsMasterDataSet dataset,
                java.util.Vector mediaToAdd,
                java.util.Vector channelToAdd)
         throws com.opencms.core.CmsException
Inserts a new row in the database with the copied dataset.


writeLockstate

public void writeLockstate(com.opencms.file.CmsObject cms,
                           com.opencms.defaults.master.CmsMasterContent content,
                           com.opencms.defaults.master.CmsMasterDataSet dataset)
                    throws com.opencms.core.CmsException
Updates the lockstate in the database.


write

public void write(com.opencms.file.CmsObject cms,
                  com.opencms.defaults.master.CmsMasterContent content,
                  com.opencms.defaults.master.CmsMasterDataSet dataset)
           throws com.opencms.core.CmsException

read

public void read(com.opencms.file.CmsObject cms,
                 com.opencms.defaults.master.CmsMasterContent content,
                 com.opencms.defaults.master.CmsMasterDataSet dataset,
                 int masterId)
          throws com.opencms.core.CmsException

readLockstate

protected void readLockstate(com.opencms.defaults.master.CmsMasterDataSet dataset,
                             int subId)
                      throws com.opencms.core.CmsException
Read the lockstate from the database. We nned this, because of someone has maybe stolen the lock.


readMedia

public java.util.Vector readMedia(com.opencms.file.CmsObject cms,
                                  com.opencms.defaults.master.CmsMasterContent content)
                           throws com.opencms.core.CmsException
Reads all media from the database.


readChannels

public java.util.Vector readChannels(com.opencms.file.CmsObject cms,
                                     com.opencms.defaults.master.CmsMasterContent content)
                              throws com.opencms.core.CmsException
Reads all channels from the database.


readAllByChannel

public java.util.Vector readAllByChannel(com.opencms.file.CmsObject cms,
                                         int channelId,
                                         int subId)
                                  throws com.opencms.core.CmsException
Reads all content definitions of a given channel


delete

public void delete(com.opencms.file.CmsObject cms,
                   com.opencms.defaults.master.CmsMasterContent content,
                   com.opencms.defaults.master.CmsMasterDataSet dataset)
            throws com.opencms.core.CmsException

undelete

public void undelete(com.opencms.file.CmsObject cms,
                     com.opencms.defaults.master.CmsMasterContent content,
                     com.opencms.defaults.master.CmsMasterDataSet dataset)
              throws com.opencms.core.CmsException

changePermissions

public void changePermissions(com.opencms.file.CmsObject cms,
                              com.opencms.defaults.master.CmsMasterContent content,
                              com.opencms.defaults.master.CmsMasterDataSet dataset)
                       throws com.opencms.core.CmsException
Changes the perrmissions of the Master


toString

public java.lang.String toString()
Returns a string representation of this instance. This can be used for debugging.


loadQueries

private void loadQueries(java.lang.Class currentClass)
Loads recursively all query.properties from all packages of the superclasses. This method calls recuresively itself with the superclass (if exists) as parameter.


combineQueries

private void combineQueries()
Combines the queries in the properties to complete quereis. Therefor a replacement is needed: The follwing Strings will be replaces automatically by the corresponding property-entrys: ${property_key}


replace

private boolean replace(java.lang.String key)
Computes one run of the replacement for one query. Stores the new value into m_queries.


sqlPrepare

protected java.sql.PreparedStatement sqlPrepare(java.sql.Connection con,
                                                java.lang.String queryKey)
                                         throws java.sql.SQLException
Creates a new connection and prepares a stement.


sqlPrepare

protected java.sql.PreparedStatement sqlPrepare(com.opencms.file.CmsObject cms,
                                                java.sql.Connection con,
                                                java.lang.String queryKey)
                                         throws java.sql.SQLException
Creates a new connection and prepares a stement.


sqlPrepare

protected java.sql.PreparedStatement sqlPrepare(com.opencms.file.CmsObject cms,
                                                java.sql.Connection con,
                                                java.lang.String queryKey,
                                                java.util.HashMap optionalSqlTokens)
                                         throws java.sql.SQLException
Replaces in a SQL statement $XXX tokens by strings and returns a prepared statement.


sqlClose

protected void sqlClose(java.sql.Connection con,
                        java.sql.Statement stmnt,
                        java.sql.ResultSet res)
Closes all sql ressources.


sqlFillValues

protected int sqlFillValues(java.sql.PreparedStatement stmnt,
                            int subId,
                            com.opencms.defaults.master.CmsMasterDataSet dataset)
                     throws java.sql.SQLException
Inserts all values to the statement for insert and update.


sqlFillValues

protected int sqlFillValues(java.sql.ResultSet res,
                            com.opencms.file.CmsObject cms,
                            com.opencms.defaults.master.CmsMasterDataSet dataset)
                     throws java.sql.SQLException
Inserts all values to the statement for insert and update.


computeProjectId

protected int computeProjectId(com.opencms.file.CmsObject cms,
                               com.opencms.defaults.master.CmsMasterDataSet dataset)
                        throws java.sql.SQLException
Computes the correct project id based on the channels.


sqlSetTextArray

protected int sqlSetTextArray(java.sql.PreparedStatement stmnt,
                              java.lang.String[] array,
                              int columnscounter)
                       throws java.sql.SQLException
Sets an array of strings into the stmnt.


sqlSetTextArray

protected int sqlSetTextArray(java.sql.ResultSet res,
                              java.lang.String[] array,
                              int columnscounter)
                       throws java.sql.SQLException
Sets an array of strings from the resultset.


sqlSetIntArray

protected int sqlSetIntArray(java.sql.PreparedStatement stmnt,
                             int[] array,
                             int columnscounter)
                      throws java.sql.SQLException
Sets an array of ints into the stmnt.


sqlSetIntArray

protected int sqlSetIntArray(java.sql.ResultSet res,
                             int[] array,
                             int columnscounter)
                      throws java.sql.SQLException
Sets an array of ints from the resultset.


sqlSetDateArray

protected int sqlSetDateArray(java.sql.PreparedStatement stmnt,
                              long[] array,
                              int columnscounter)
                       throws java.sql.SQLException
Sets an array of ints into the stmnt.


sqlSetDateArray

protected int sqlSetDateArray(java.sql.ResultSet res,
                              long[] array,
                              int columnscounter)
                       throws java.sql.SQLException
Sets an array of ints from the resultset.


createVectorOfCd

protected java.util.Vector createVectorOfCd(java.sql.ResultSet res,
                                            java.lang.Class contentDefinitionClass,
                                            com.opencms.file.CmsObject cms)
                                     throws java.sql.SQLException
Returns a vector of contentdefinitions based on the sql resultset. Never mind about the visible flag.


createVectorOfCd

protected java.util.Vector createVectorOfCd(java.sql.ResultSet res,
                                            java.lang.Class contentDefinitionClass,
                                            com.opencms.file.CmsObject cms,
                                            boolean viewonly)
                                     throws java.sql.SQLException
Returns a vector of contentdefinitions based on the sql resultset.


createVectorOfCd

protected java.util.Vector createVectorOfCd(java.util.Vector datasets,
                                            java.lang.Class contentDefinitionClass,
                                            com.opencms.file.CmsObject cms)
                                     throws java.sql.SQLException
Returns a vector of contentdefinitions based on the sql resultset.


checkAccess

protected boolean checkAccess(com.opencms.defaults.master.CmsMasterContent content,
                              boolean viewonly)
Checks if read (and visible) permissions are granted. the visible-permissens will be checked, if viewonly is set to true viewonly=true is needed for the backoffice


isOnlineProject

protected boolean isOnlineProject(com.opencms.file.CmsObject cms)
Returns true, if this is the onlineproject


deleteAllMedia

protected void deleteAllMedia(int masterId)
                       throws java.sql.SQLException
Deletes all media lines for one master.


deleteAllChannels

protected void deleteAllChannels(int masterId)
                          throws java.sql.SQLException
Deletes all channel lines for one master.


updateMedia

protected void updateMedia(int masterId,
                           java.util.Vector mediaToAdd,
                           java.util.Vector mediaToUpdate,
                           java.util.Vector mediaToDelete)
                    throws java.sql.SQLException,
                           com.opencms.core.CmsException
Updates the media object of a content definition.


updateChannels

protected void updateChannels(com.opencms.file.CmsObject cms,
                              int masterId,
                              java.util.Vector channelToAdd,
                              java.util.Vector channelToDelete)
                       throws java.sql.SQLException
Updates the channels of a content definition.


sqlFillValues

protected int sqlFillValues(java.sql.PreparedStatement stmnt,
                            com.opencms.defaults.master.CmsMasterMedia media)
                     throws java.sql.SQLException
Fills a prepared statement with media values.


getHistory

public java.util.Vector getHistory(com.opencms.file.CmsObject cms,
                                   java.lang.Class contentDefinitionClass,
                                   int masterId,
                                   int subId)
                            throws com.opencms.core.CmsException
Returns a vector with all version of a master in the backup


getVersionFromHistory

public com.opencms.defaults.master.CmsMasterContent getVersionFromHistory(com.opencms.file.CmsObject cms,
                                                                          java.lang.Class contentDefinitionClass,
                                                                          int masterId,
                                                                          int subId,
                                                                          int versionId)
                                                                   throws com.opencms.core.CmsException
Returns the version of a master in the backup


getVersionFromHistory

public com.opencms.defaults.master.CmsMasterDataSet getVersionFromHistory(com.opencms.file.CmsObject cms,
                                                                          int masterId,
                                                                          int subId,
                                                                          int versionId)
                                                                   throws com.opencms.core.CmsException
Returns the version of a master in the backup


restore

public void restore(com.opencms.file.CmsObject cms,
                    com.opencms.defaults.master.CmsMasterContent content,
                    com.opencms.defaults.master.CmsMasterDataSet dataset,
                    int versionId)
             throws com.opencms.core.CmsException
Restores a version of the master and media from backup


publishResource

public void publishResource(com.opencms.file.CmsObject cms,
                            com.opencms.defaults.master.CmsMasterDataSet dataset,
                            int subId,
                            java.lang.String contentDefinitionName,
                            boolean enableHistory,
                            int versionId,
                            long publishingDate,
                            java.util.Vector changedResources,
                            java.util.Vector changedModuleData)
                     throws com.opencms.core.CmsException
Publishes a single content definition


publishProject

public void publishProject(com.opencms.file.CmsObject cms,
                           boolean enableHistory,
                           int projectId,
                           int versionId,
                           long publishingDate,
                           int subId,
                           java.lang.String contentDefinitionName,
                           java.util.Vector changedRessources,
                           java.util.Vector changedModuleData)
                    throws com.opencms.core.CmsException
Publishes all ressources for this project Publishes all modified content definitions for this project.


publishOneLine

protected void publishOneLine(com.opencms.file.CmsObject cms,
                              com.opencms.defaults.master.CmsMasterDataSet dataset,
                              int subId,
                              java.lang.String contentDefinitionName,
                              boolean enableHistory,
                              int versionId,
                              long publishingDate,
                              java.util.Vector changedRessources,
                              java.util.Vector changedModuleData)
                       throws com.opencms.core.CmsException

publishDeleteData

protected void publishDeleteData(int masterId,
                                 int subId,
                                 java.lang.String table)
                          throws com.opencms.core.CmsException

publishCopyData

protected void publishCopyData(com.opencms.defaults.master.CmsMasterDataSet dataset,
                               int subId)
                        throws com.opencms.core.CmsException

publishBackupData

protected void publishBackupData(com.opencms.file.CmsObject cms,
                                 com.opencms.defaults.master.CmsMasterDataSet dataset,
                                 int subId,
                                 int versionId,
                                 long publishDate)
                          throws com.opencms.core.CmsException

getConnection

public java.sql.Connection getConnection(com.opencms.file.CmsObject cms)
                                  throws java.sql.SQLException
Returns the correct connection. If this is the onlineproject it returns the online connection, else it returns the offline connection.