bundledbpersistencemanager.java
来自「jsr170接口的java实现。是个apache的开源项目。」· Java 代码 · 共 1,354 行 · 第 1/4 页
JAVA
1,354 行
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.jackrabbit.core.persistence.bundle;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.apache.jackrabbit.util.Text;import org.apache.jackrabbit.core.state.ChangeLog;import org.apache.jackrabbit.core.state.ItemStateException;import org.apache.jackrabbit.core.state.NoSuchItemStateException;import org.apache.jackrabbit.core.state.NodeReferencesId;import org.apache.jackrabbit.core.state.NodeReferences;import org.apache.jackrabbit.core.persistence.PMContext;import org.apache.jackrabbit.core.persistence.AbstractPersistenceManager;import org.apache.jackrabbit.core.persistence.bundle.util.DbNameIndex;import org.apache.jackrabbit.core.persistence.bundle.util.NodePropBundle;import org.apache.jackrabbit.core.persistence.bundle.util.BundleBinding;import org.apache.jackrabbit.core.persistence.bundle.util.ErrorHandling;import org.apache.jackrabbit.core.persistence.bundle.util.StringIndex;import org.apache.jackrabbit.core.persistence.util.Serializer;import org.apache.jackrabbit.core.persistence.util.BLOBStore;import org.apache.jackrabbit.core.persistence.util.FileSystemBLOBStore;import org.apache.jackrabbit.core.fs.FileSystemResource;import org.apache.jackrabbit.core.fs.FileSystem;import org.apache.jackrabbit.core.fs.local.LocalFileSystem;import org.apache.jackrabbit.core.NodeId;import org.apache.jackrabbit.core.PropertyId;import org.apache.jackrabbit.uuid.UUID;import java.io.BufferedReader;import java.io.ByteArrayInputStream;import java.io.ByteArrayOutputStream;import java.io.DataInputStream;import java.io.DataOutputStream;import java.io.File;import java.io.FilterInputStream;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.sql.Blob;import java.sql.Connection;import java.sql.DatabaseMetaData;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.sql.Driver;import java.util.Iterator;import java.util.Collection;import java.util.ArrayList;import javax.jcr.RepositoryException;/** * This is a generic persistence manager that stores the {@link NodePropBundle}s * in a database. * <p/> * Configuration:<br> * <ul> * <li><param name="{@link #setBundleCacheSize(String) bundleCacheSize}" value="8"/> * <li><param name="{@link #setConsistencyCheck(String) consistencyCheck}" value="false"/> * <li><param name="{@link #setConsistencyFix(String) consistencyFix}" value="false"/> * <li><param name="{@link #setMinBlobSize(String) minBlobSize}" value="4096"/> * <li><param name="{@link #setDriver(String) driver}" value=""/> * <li><param name="{@link #setUrl(String) url}" value=""/> * <li><param name="{@link #setUser(String) user}" value=""/> * <li><param name="{@link #setPassword(String) password}" value=""/> * <li><param name="{@link #setSchema(String) schema}" value=""/> * <li><param name="{@link #setSchemaObjectPrefix(String) schemaObjectPrefix}" value=""/> * <li><param name="{@link #setErrorHandling(String) errorHandling}" value=""/> * </ul> */public class BundleDbPersistenceManager extends AbstractBundlePersistenceManager { /** the cvs/svn id */ static final String CVS_ID = "$URL: http://svn.apache.org/repos/asf/jackrabbit/tags/1.3.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java $ $Rev: 577840 $ $Date: 2007-09-20 20:59:30 +0300 (Thu, 20 Sep 2007) $"; /** the default logger */ private static Logger log = LoggerFactory.getLogger(BundleDbPersistenceManager.class); /** the variable for the schema prefix */ public static final String SCHEMA_OBJECT_PREFIX_VARIABLE = "${schemaObjectPrefix}"; /** storage model modifier: binary keys */ public static final int SM_BINARY_KEYS = 1; /** storage model modifier: longlong keys */ public static final int SM_LONGLONG_KEYS = 2; /** flag indicating if this manager was initialized */ protected boolean initialized = false; /** the jdbc driver name */ protected String driver; /** the jdbc url string */ protected String url; /** the jdbc user */ protected String user; /** the jdbc password */ protected String password; /** the schema identifier */ protected String schema; /** the prefix for the database objects */ protected String schemaObjectPrefix; /** flag indicating if a consistency check should be issued during startup */ protected boolean consistencyCheck = false; /** flag indicating if the consistency check should attempt to fix issues */ protected boolean consistencyFix = false; /** initial size of buffer used to serialize objects */ protected static final int INITIAL_BUFFER_SIZE = 1024; /** inidicates if uses (filesystem) blob store */ protected boolean externalBLOBs; /** jdbc conection */ protected Connection con; // shared prepared statements for bundle management protected PreparedStatement bundleInsert; protected PreparedStatement bundleUpdate; protected PreparedStatement bundleSelect; protected PreparedStatement bundleDelete; // shared prepared statements for NodeReference management protected PreparedStatement nodeReferenceInsert; protected PreparedStatement nodeReferenceUpdate; protected PreparedStatement nodeReferenceSelect; protected PreparedStatement nodeReferenceDelete; /** file system where BLOB data is stored */ protected CloseableBLOBStore blobStore; /** the index for local names */ private StringIndex nameIndex; /** * the minimum size of a property until it gets written to the blob store * @see #setMinBlobSize(String) */ private int minBlobSize = 0x1000; /** * flag for error handling */ protected ErrorHandling errorHandling = new ErrorHandling(); /** * the bundle binding */ protected BundleBinding binding; /** * the name of this persistence manager */ private String name = super.toString(); /** * Returns the configured JDBC connection url. * @return the configured JDBC connection url. */ public String getUrl() { return url; } /** * Sets the JDBC connection url. * @param url the url to set. */ public void setUrl(String url) { this.url = url; } /** * Returns the configured user that is used to establish JDBC connections. * @return the JDBC user. */ public String getUser() { return user; } /** * Sets the user name that will be used to establish JDBC connections. * @param user the user name. */ public void setUser(String user) { this.user = user; } /** * Returns the configured password that is used to establish JDBC connections. * @return the password. */ public String getPassword() { return password; } /** * Sets the password that will be used to establish JDBC connections. * @param password the password for the connection */ public void setPassword(String password) { this.password = password; } /** * Returns the class name of the JDBC driver. * @return the class name of the JDBC driver. */ public String getDriver() { return driver; } /** * Sets the class name of the JDBC driver. The driver class will be loaded * during {@link #init(PMContext) init} in order to assure the existence. * * @param driver the class name of the driver */ public void setDriver(String driver) { this.driver = driver; } /** * Returns the configured schema object prefix. * @return the configured schema object prefix. */ public String getSchemaObjectPrefix() { return schemaObjectPrefix; } /** * Sets the schema object prefix. This string is used to prefix all schema * objects, like tables and indexes. this is usefull, if several persistence * managers use the same database. * * @param schemaObjectPrefix the prefix for schema objects. */ public void setSchemaObjectPrefix(String schemaObjectPrefix) { // make sure prefix is all uppercase this.schemaObjectPrefix = schemaObjectPrefix.toUpperCase(); } /** * Returns the configured schema identifier. * @return the schema identifier. */ public String getSchema() { return schema; } /** * Sets the schema identifier. This identifier is used to load and execute * the respective .ddl resource in order to create the required schema * objects. * * @param schema the schema identifier. */ public void setSchema(String schema) { this.schema = schema; } /** * Returns if uses external (filesystem) blob store. * @return if uses external (filesystem) blob store. */ public boolean isExternalBLOBs() { return externalBLOBs; } /** * Sets the flag for external (filesystem) blob store usage. * @param externalBLOBs a value of "true" indicates that an external blob * store is to be used. */ public void setExternalBLOBs(boolean externalBLOBs) { this.externalBLOBs = externalBLOBs; } /** * Checks if consistency check is enabled. * @return <code>true</code> if consistenct check is enabled. */ public String getConsistencyCheck() { return Boolean.toString(consistencyCheck); } /** * Defines if a consistency check is to be performed on initialization. * @param consistencyCheck the consistency check flag. */ public void setConsistencyCheck(String consistencyCheck) { this.consistencyCheck = Boolean.valueOf(consistencyCheck).booleanValue(); } /** * Checks if consistency fix is enabled. * @return <code>true</code> if consistency fix is enabled. */ public String getConsistencyFix() { return Boolean.toString(consistencyFix); } /** * Defines if the consistency check should attempt to fix issues that * it finds. * * @param consistencyFix the consistency fix flag. */ public void setConsistencyFix(String consistencyFix) { this.consistencyFix = Boolean.valueOf(consistencyFix).booleanValue(); } /**
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?