⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 persistentserviceimpl.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*   Derby - Class org.apache.derby.impl.services.monitor.PersistentServiceImpl   Copyright 2004 The Apache Software Foundation or its licensors, as applicable.   Licensed 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.derby.impl.services.monitor;import org.apache.derby.iapi.reference.MessageId;import org.apache.derby.iapi.reference.SQLState;import org.apache.derby.iapi.services.i18n.MessageService;import org.apache.derby.iapi.services.monitor.Monitor;import org.apache.derby.iapi.services.monitor.PersistentService;import org.apache.derby.iapi.services.sanity.SanityManager;import org.apache.derby.iapi.error.StandardException;import org.apache.derby.iapi.store.raw.data.DataFactory;import org.apache.derby.io.StorageFile;import org.apache.derby.io.StorageFactory;import org.apache.derby.io.WritableStorageFactory;import org.apache.derby.iapi.reference.Attribute;import org.apache.derby.iapi.reference.Property;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.InputStream;import java.io.BufferedInputStream;import java.io.OutputStream;import java.io.IOException;import java.io.FileNotFoundException;import java.util.Enumeration;import java.util.NoSuchElementException;import java.util.Properties;import java.security.AccessController;import java.security.PrivilegedAction;import java.security.PrivilegedExceptionAction;import java.security.PrivilegedActionException;/** * This class implements the PersistentService interface using a StorageFactory class. * It handles all subSubProtocols except for cache. */final class PersistentServiceImpl implements PersistentService{    private String home; // the path of the database home directory. Can be null    private String canonicalHome; // will be null if home is null    private final String subSubProtocol;    private final Class storageFactoryClass;    private StorageFactory rootStorageFactory;    private char separatorChar;    PersistentServiceImpl( String subSubProtocol, Class storageFactoryClass)        throws StandardException    {        this.subSubProtocol = subSubProtocol;        this.storageFactoryClass = storageFactoryClass;        Object monitorEnv = Monitor.getMonitor().getEnvironment();		if (monitorEnv instanceof File)        {            final File relativeRoot = (File) monitorEnv;            try            {                AccessController.doPrivileged(                    new java.security.PrivilegedExceptionAction()                    {                        public Object run() throws IOException, StandardException                        {                            home = relativeRoot.getPath();                            canonicalHome = relativeRoot.getCanonicalPath();                            rootStorageFactory = getStorageFactoryInstance( true, null, null, null);                            if( home != null)                            {                                StorageFile rootDir = rootStorageFactory.newStorageFile( null);                                rootDir.mkdirs();                            }                            return null;                        }                    }                    );            }            catch( PrivilegedActionException pae)            {                home = null;                canonicalHome = null;            }        }        if( rootStorageFactory == null)        {            try            {                rootStorageFactory = getStorageFactoryInstance( true, null, null, null);            }            catch( IOException ioe){ throw Monitor.exceptionStartingModule(/*serviceName, */ ioe); }        }        AccessController.doPrivileged(            new java.security.PrivilegedAction()            {                public Object run()                {                    separatorChar = rootStorageFactory.getSeparator();                    return null;                }            }            );    } // end of constructor    	/*	** Methods of PersistentService	*/    /**     * @return true if the PersistentService has a StorageFactory, false if not.     */    public boolean hasStorageFactory()    {        return true;    }        /**     * Get an initialized StorageFactoryInstance     *     * @param useHome If true and the database name is not absolute then the database directory will be     *                relative to the home directory, if one is defined in the properties file.     * @param databaseName The name of the database (directory). The name does not include the subSubProtocol.     *                     If null then the storage factory will only be used to deal with the directory containing     *                     the databases.     * @param tempDirName The name of the temporary file directory set in properties. If null then a default     *                    directory should be used. Each database should get a separate temporary file     *                    directory within this one to avoid collisions.     * @param uniqueName A unique name that can be used to create the temporary file directory for this database.     *                   If null then temporary files will not be created in this StorageFactory instance.     *     * @return An initialized StorageFactory.     *     * @exception IOException if create, the database directory does not exist, and it cannot be created;     *                        if !create and the database does not exist as a directory.     */    public StorageFactory getStorageFactoryInstance(final boolean useHome,                                                    final String databaseName,                                                    final String tempDirName,                                                    final String uniqueName)        throws StandardException, IOException    {        try        {            return (StorageFactory) AccessController.doPrivileged(                new PrivilegedExceptionAction()                {                    public Object run() throws InstantiationException, IllegalAccessException, IOException                    {                        return privGetStorageFactoryInstance( useHome, databaseName, tempDirName, uniqueName);                    }                });        }        catch (PrivilegedActionException pae)        {            Exception e = pae.getException();            throw StandardException.newException( SQLState.REGISTERED_CLASS_INSTANCE_ERROR,                                                  e, subSubProtocol, storageFactoryClass);        }    } // end of getStorageFactoryInstance    private StorageFactory privGetStorageFactoryInstance( boolean useHome,                                                          String databaseName,                                                          String tempDirName,                                                          String uniqueName)         throws InstantiationException, IllegalAccessException, IOException    {        StorageFactory storageFactory = (StorageFactory) storageFactoryClass.newInstance();        String dbn;        if( databaseName != null            && subSubProtocol != null            && databaseName.startsWith( subSubProtocol + ":"))            dbn = databaseName.substring( subSubProtocol.length() + 1);        else            dbn = databaseName;        storageFactory.init( useHome ? home : null, dbn, tempDirName, uniqueName);        return storageFactory;    } // end of privGetStorageFactoryInstance        	/**			The type of the service is 'directory'		@see PersistentService#getType	*/	public String getType()    {        return subSubProtocol;    }	/**	    Return a list of all the directoies in the system directory.		@see PersistentService#getBootTimeServices	*/	public Enumeration getBootTimeServices()    {        if( home == null)            return null;        return new DirectoryList();    }    /**		Open the service properties in the directory identified by the service name.		The property SERVICE_ROOT (db2j.rt.serviceRoot) is added		by this method and set to the service directory.		@return A Properties object or null if serviceName does not represent a valid service.		@exception StandardException Service appears valid but the properties cannot be created.	*/	public Properties getServiceProperties( final String serviceName, Properties defaultProperties)		throws StandardException    {		if (SanityManager.DEBUG) {			if (! serviceName.equals(getCanonicalServiceName(serviceName)))			{				SanityManager.THROWASSERT("serviceName (" + serviceName + 										  ") expected to equal getCanonicalServiceName(serviceName) (" +										  getCanonicalServiceName(serviceName) + ")");			}		}		//recreate the service root  if requested by the user.		final String recreateFrom = recreateServiceRoot(serviceName, defaultProperties);        InputStream is = null;		try        {            is = (InputStream) AccessController.doPrivileged(                new PrivilegedExceptionAction()                {                    public Object run()                        throws FileNotFoundException, IOException, StandardException,                        InstantiationException, IllegalAccessException                    {                        if( recreateFrom != null) // restore from a file                        {                            File propFile = new File(recreateFrom, PersistentService.PROPERTIES_NAME);                            return new FileInputStream(propFile);                        }                        else                        {                            StorageFactory storageFactory = privGetStorageFactoryInstance( true, serviceName, null, null);                            StorageFile file = storageFactory.newStorageFile( PersistentService.PROPERTIES_NAME);                            InputStream is1 = file.getInputStream();                            storageFactory.shutdown();                            return is1;                        }                    }                }                );			Properties serviceProperties = new Properties(defaultProperties);			serviceProperties.load(new BufferedInputStream(is));			return serviceProperties;		}        catch (PrivilegedActionException pae)        {            if( pae.getException() instanceof FileNotFoundException)                return null;            throw Monitor.exceptionStartingModule( pae.getException());        }        catch (FileNotFoundException fnfe) {return null ;}		catch (SecurityException se) { throw Monitor.exceptionStartingModule(/*serviceName, */ se);	}        catch (IOException ioe) { throw Monitor.exceptionStartingModule(/*serviceName, */ ioe); }        finally        {			if (is != null)            {				try

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -