📄 cmsdbaccess.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src/com/opencms/file/genericSql/CmsDbAccess.java,v $
* Date : $Date: 2002/04/30 09:27:57 $
* Version: $Revision: 1.242 $
*
* This library is part of OpenCms -
* the Open Source Content Mananagement System
*
* Copyright (C) 2001 The OpenCms Group
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* For further information about OpenCms, please see the
* OpenCms Website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.opencms.file.genericSql;
import javax.servlet.http.*;
import java.util.*;
import java.sql.*;
import java.security.*;
import java.io.*;
import source.org.apache.java.io.*;
import source.org.apache.java.util.*;
import com.opencms.core.*;
import com.opencms.file.*;
import com.opencms.file.utils.*;
import com.opencms.util.*;
import com.opencms.launcher.*;
/**
* This is the generic access module to load and store resources from and into
* the database.
*
* @author Andreas Schouten
* @author Michael Emmerich
* @author Hanjo Riege
* @author Anders Fugmann
* @author Finn Nielsen
* @version $Revision: 1.242 $ $Date: 2002/04/30 09:27:57 $ *
*/
public class CmsDbAccess implements I_CmsConstants, I_CmsLogChannels {
/**
* The name of the pool to use
*/
protected String m_poolName;
/**
* The name of the online pool to use
*/
protected String m_poolNameOnline;
/**
* The name of the backup pool to use
*/
protected String m_poolNameBackup;
/**
* The session-timeout value:
* currently six hours. After that time the session can't be restored.
*/
public static long C_SESSION_TIMEOUT = 6 * 60 * 60 * 1000;
/**
* The maximum amount of tables.
*/
protected static int C_MAX_TABLES = 18;
/**
* Table-key for max-id
*/
protected static String C_TABLE_SYSTEMPROPERTIES = "CMS_SYSTEMPROPERTIES";
/**
* Table-key for max-id
*/
protected static String C_TABLE_GROUPS = "CMS_GROUPS";
/**
* Table-key for max-id
*/
protected static String C_TABLE_GROUPUSERS = "CMS_GROUPUSERS";
/**
* Table-key for max-id
*/
protected static String C_TABLE_USERS = "CMS_USERS";
/**
* Table-key for max-id
*/
protected static String C_TABLE_PROJECTS = "CMS_PROJECTS";
/**
* Table-key for max-id
*/
protected static String C_TABLE_RESOURCES = "CMS_RESOURCES";
/**
* Table-key for max-id
*/
protected static String C_TABLE_FILES = "CMS_FILES";
/**
* Table-key for max-id
*/
protected static String C_TABLE_PROPERTYDEF = "CMS_PROPERTYDEF";
/**
* Table-key for max-id
*/
protected static String C_TABLE_PROPERTIES = "CMS_PROPERTIES";
/**
* Table-key for max-id
*/
protected static String C_TABLE_TASK = "CMS_TASKS";
/**
* Table-key for max-id
*/
protected static String C_TABLE_TASKTYPE = "CMS_TASKTYPE";
/**
* Table-key for max-id
*/
protected static String C_TABLE_TASKPAR = "CMS_TASKPAR";
/**
* Table-key for max-id
*/
protected static String C_TABLE_TASKLOG = "CMS_TASKLOG";
/**
* Constant to get property from configurations.
*/
protected static String C_CONFIGURATIONS_DIGEST = "digest";
/**
* Constant to get property from configurations.
*/
protected static String C_CONFIGURATIONS_DIGEST_FILE_ENCODING = "digest.fileencoding";
/**
* Constant to get property from configurations.
*/
protected static String C_CONFIGURATIONS_POOL = "pool";
/**
* A array containing all max-ids for the tables.
*/
protected int[] m_maxIds;
/**
* A digest to encrypt the passwords.
*/
protected MessageDigest m_digest = null;
/**
* The file.encoding to code passwords after encryption with digest.
*/
protected String m_digestFileEncoding = null;
/**
* Storage for all exportpoints.
*/
protected Hashtable m_exportpointStorage=null;
/**
* 'Constants' file.
*/
protected com.opencms.file.genericSql.CmsQueries m_cq;
/**
* Instanciates the access-module and sets up all required modules and connections.
* @param config The OpenCms configuration.
* @exception CmsException Throws CmsException if something goes wrong.
*/
public CmsDbAccess(Configurations config)
throws CmsException {
// set configurations for the dbpool driver
com.opencms.dbpool.CmsDriver.setConfigurations(config);
m_cq = getQueries();
String rbName = null;
String digest = null;
String exportpoint = null;
String exportpath = null;
boolean fillDefaults = true;
if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
A_OpenCms.log(I_CmsLogChannels.C_OPENCMS_INIT, "[CmsDbAccess] init the dbaccess-module.");
}
// read the name of the rb from the properties
rbName = (String)config.getString(C_CONFIGURATION_RESOURCEBROKER);
// read the exportpoints
m_exportpointStorage = new Hashtable();
int i = 0;
while ((exportpoint = config.getString(C_EXPORTPOINT + Integer.toString(i))) != null){
exportpath = config.getString(C_EXPORTPOINT_PATH + Integer.toString(i));
if (exportpath != null){
m_exportpointStorage.put(exportpoint, com.opencms.boot.CmsBase.getAbsoluteWebPath(exportpath));
}
i++;
}
// read all needed parameters from the configuration
// all needed pools are read in the following method
getConnectionPools(config, rbName);
digest = config.getString(C_CONFIGURATION_RESOURCEBROKER + "." + rbName + "." + C_CONFIGURATIONS_DIGEST, "MD5");
if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
A_OpenCms.log(I_CmsLogChannels.C_OPENCMS_INIT, "[CmsDbAccess] read digest from configurations: " + digest);
}
m_digestFileEncoding = config.getString(C_CONFIGURATION_RESOURCEBROKER + "." + rbName + "." + C_CONFIGURATIONS_DIGEST_FILE_ENCODING, "ISO8859_1");
if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
A_OpenCms.log(I_CmsLogChannels.C_OPENCMS_INIT, "[CmsDbAccess] read digestFileEncoding from configurations: " + m_digestFileEncoding);
}
// create the digest
try {
m_digest = MessageDigest.getInstance(digest);
if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
A_OpenCms.log(I_CmsLogChannels.C_OPENCMS_INIT, "[CmsDbAccess] digest created, using: " + m_digest.toString() );
}
} catch (NoSuchAlgorithmException e){
if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
A_OpenCms.log(I_CmsLogChannels.C_OPENCMS_INIT, "[CmsDbAccess] error creating digest - using clear paswords: " + e.getMessage());
}
}
// have we to fill the default resource like root and guest?
try {
if (readProject(C_PROJECT_ONLINE_ID) != null) {
// online-project exists - no need of filling defaults
fillDefaults = false;
}
} catch(CmsException exc) {
// ignore the exception - the project was not readable so fill in the defaults
}
if(fillDefaults) {
// YES!
if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
A_OpenCms.log(I_CmsLogChannels.C_OPENCMS_INIT, "[CmsDbAccess] fill default resources");
}
fillDefaults();
}
}
/**
* Gets all necessary connection pools
* This method can be adjusted for each resourcebroker
* @param config The configuration
*/
protected void getConnectionPools(Configurations config, String rbName){
// get the standard pool
m_poolName = config.getString(C_CONFIGURATION_RESOURCEBROKER + "." + rbName + "." + C_CONFIGURATIONS_POOL);
// set the default pool for the id generator
com.opencms.dbpool.CmsIdGenerator.setDefaultPool(m_poolName);
if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging()) {
A_OpenCms.log(I_CmsLogChannels.C_OPENCMS_INIT, "[CmsDbAccess] read pool-name from configurations: " + m_poolName);
}
//get the pool for the online resources
m_poolNameOnline = config.getString(C_CONFIGURATION_RESOURCEBROKER + "." + rbName + ".online." + C_CONFIGURATIONS_POOL);
if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging()) {
A_OpenCms.log(I_CmsLogChannels.C_OPENCMS_INIT, "[CmsDbAccess] read online-pool-name from configurations: " + m_poolNameOnline);
}
//get the pool for the backup resources
m_poolNameBackup = config.getString(C_CONFIGURATION_RESOURCEBROKER + "." + rbName + ".backup." + C_CONFIGURATIONS_POOL);
if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging()) {
A_OpenCms.log(I_CmsLogChannels.C_OPENCMS_INIT, "[CmsDbAccess] read backup-pool-name from configurations: " + m_poolNameBackup);
}
}
/**
* Creates a serializable object in the systempropertys.
*
* @param name The name of the property.
* @param object The property-object.
*
* @return object The property-object.
*
* @exception CmsException Throws CmsException if something goes wrong.
*/
public Serializable addSystemProperty(String name, Serializable object)
throws CmsException {
byte[] value;
Connection con = null;
PreparedStatement statement = null;
try {
// serialize the object
ByteArrayOutputStream bout= new ByteArrayOutputStream();
ObjectOutputStream oout=new ObjectOutputStream(bout);
oout.writeObject(object);
oout.close();
value=bout.toByteArray();
// create the object
con = DriverManager.getConnection(m_poolName);
statement= con.prepareStatement(m_cq.get("C_SYSTEMPROPERTIES_WRITE"));
statement.setInt(1,nextId(C_TABLE_SYSTEMPROPERTIES));
statement.setString(2,name);
statement.setBytes(3,value);
statement.executeUpdate();
} catch (SQLException e){
throw new CmsException("["+this.getClass().getName()+"]"+e.getMessage(),CmsException.C_SQL_ERROR, e);
} catch (IOException e){
throw new CmsException("["+this.getClass().getName()+"]"+CmsException. C_SERIALIZATION, e);
}finally {
// close all db-resources
if(statement != null) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -