📄 cmsdbaccess.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src/com/opencms/file/genericSql/Attic/CmsDbAccess.java,v $
* Date : $Date: 2003/06/27 14:59:47 $
* Version: $Revision: 1.278.2.1 $
* 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 com.opencms.boot.I_CmsLogChannels;
import com.opencms.core.A_OpenCms;
import com.opencms.core.CmsException;
import com.opencms.core.I_CmsConstants;
import com.opencms.file.*;
import com.opencms.file.utils.CmsAccessFilesystem;
import com.opencms.linkmanagement.CmsPageLinks;
import com.opencms.report.I_CmsReport;
import com.opencms.util.SqlHelper;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.EOFException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
import java.util.Vector;
import source.org.apache.java.util.Configurations;
/**
* 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
* @author Mark Foley
* @version $Revision: 1.278.2.1 $ $Date: 2003/06/27 14:59:47 $ *
*/
public class CmsDbAccess implements I_CmsConstants, I_CmsLogChannels {
protected static int C_RESTYPE_LINK_ID = 2;
protected static boolean C_USE_TARGET_DATE = true;
/**
* 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;
/**
* TESTFIX (mfoley@iee.org) New Code:
* Performs an Oracle-safe setBytes() action.
* @param statement The PreparedStatement.
* @param posn The parameter placeholder in the prepared statement.
* @param content The byte array to be inserted into the prepared statement.
* @throws SQLException Throws SQLException if something goes wrong.
*/
protected void m_doSetBytes(PreparedStatement statement, int posn, byte[] content)
throws SQLException {
if(content.length < 2000) {
statement.setBytes(posn,content);
} else {
statement.setBinaryStream(posn, new ByteArrayInputStream(content), content.length);
}
}
/**
* Instanciates the access-module and sets up all required modules and connections.
* @param config The OpenCms configuration.
* @throws 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;
boolean fillDefaults = true;
if(I_CmsLogChannels.C_LOGGING && A_OpenCms.isLogging() ) {
A_OpenCms.log(I_CmsLogChannels.C_OPENCMS_INIT, ". Database access init : ok" );
}
// read the name of the rb from the properties
rbName = (String)config.getString(C_CONFIGURATION_RESOURCEBROKER);
// 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, ". Digest configured : " + digest);
}
m_digestFileEncoding = config.getString(C_CONFIGURATION_RESOURCEBROKER + "." + rbName + "." + C_CONFIGURATIONS_DIGEST_FILE_ENCODING, "ISO-8859-1");
if(I_CmsLogChannels.C_LOGGING && A_OpenCms.isLogging() ) {
A_OpenCms.log(I_CmsLogChannels.C_OPENCMS_INIT, ". Digest file encoding : " + m_digestFileEncoding);
}
// create the digest
try {
m_digest = MessageDigest.getInstance(digest);
if(I_CmsLogChannels.C_LOGGING && A_OpenCms.isLogging() ) {
A_OpenCms.log(I_CmsLogChannels.C_OPENCMS_INIT, ". Using digest encoding: " +
m_digest.getAlgorithm() +
" from " + m_digest.getProvider().getName() +
" version " + m_digest.getProvider().getVersion());
}
} catch (NoSuchAlgorithmException e){
if(I_CmsLogChannels.C_LOGGING && A_OpenCms.isLogging() ) {
A_OpenCms.log(I_CmsLogChannels.C_OPENCMS_INIT, ". Error setting digest : using clear passwords - " + 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, ". Database fill default: yes");
}
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, ". Database offline pool: " + 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, ". Database online pool : " + 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, ". Database backup pool : " + m_poolNameBackup);
}
}
/**
* Creates a serializable object in the systempropertys.
*
* @param name The name of the property.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -