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

📄 persistentserviceimpl.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                                }                            }                            );                    }                    catch( PrivilegedActionException pae)                    { throw Monitor.exceptionStartingModule( (IOException)pae.getException());}				}                else					throw StandardException.newException(SQLState.PROPERTY_FILE_NOT_FOUND_IN_BACKUP, bserviceProp);			}            else				throw StandardException.newException(SQLState.SERVICE_DIRECTORY_NOT_IN_BACKUP, backupRoot);			properties.put(Property.IN_RESTORE_FROM_BACKUP,"True");			if(createRoot)				properties.put(Property.DELETE_ROOT_ON_ERROR, "True");		}		return restoreFrom;	} // end of recreateServiceRoot	/**		Properties cannot be saved	*/	public String createServiceRoot(final String name, final boolean deleteExisting)		throws StandardException    {        if( !( rootStorageFactory instanceof WritableStorageFactory))            throw StandardException.newException(SQLState.READ_ONLY_SERVICE);		// we need to create the directory before we can call		// getCanonicalPath() on it, because if intermediate directories		// need to be created the getCanonicalPath() will fail.		Throwable t = null;        try        {			String protocolLeadIn = "";			//prepend the subsub protocol name to the storage factoty canonical			//name to form the service name except in case of the the 			//default subsubprototcol(PersistentService.DIRECTORY)			if (!(getType().equals( PersistentService.DIRECTORY))) 				protocolLeadIn = getType() + ":";            return protocolLeadIn + (String) AccessController.doPrivileged(                new PrivilegedExceptionAction()                {                    public Object run()                        throws StandardException, IOException, InstantiationException, IllegalAccessException                    {                        StorageFactory storageFactory = privGetStorageFactoryInstance( true, name, null, null);                        try                        {                            StorageFile serviceDirectory = storageFactory.newStorageFile( null);                            if (serviceDirectory.exists())                            {                                if (deleteExisting)                                {                                    if (!serviceDirectory.deleteAll())                                        throw StandardException.newException(SQLState.SERVICE_DIRECTORY_REMOVE_ERROR,                                                                             getDirectoryPath( name));                                }                                else                                    throw StandardException.newException(SQLState.SERVICE_DIRECTORY_EXISTS_ERROR,                                                                         getDirectoryPath( name));                            }                            if (serviceDirectory.mkdirs())                            {                                try                                {                                    return storageFactory.getCanonicalName();                                }                                catch (IOException ioe)                                {                                    serviceDirectory.deleteAll();                                    throw ioe;                                }                            }                            throw StandardException.newException(SQLState.SERVICE_DIRECTORY_CREATE_ERROR,                                                                 serviceDirectory, null);                        }                        finally { storageFactory.shutdown(); }                    }                }                );		}        catch (SecurityException se) { t = se; }        catch (PrivilegedActionException pae)        {            t = pae.getException();            if( t instanceof StandardException)                throw (StandardException) t;        }        throw StandardException.newException(SQLState.SERVICE_DIRECTORY_CREATE_ERROR, name, t);    } // end of createServiceRoot    private String getDirectoryPath( String name)    {        StringBuffer sb = new StringBuffer();        if( home != null)        {            sb.append( home);            sb.append( separatorChar);        }        if( separatorChar != '/')            sb.append( name.replace( '/', separatorChar));        else            sb.append( name);        return sb.toString();    } // end of getDirectoryPath	public boolean removeServiceRoot(final String serviceName)    {        if( !( rootStorageFactory instanceof WritableStorageFactory))            return false;        try        {            return AccessController.doPrivileged(                new PrivilegedExceptionAction()                {                    public Object run()                        throws StandardException, IOException, InstantiationException, IllegalAccessException                    {                        StorageFactory storageFactory = privGetStorageFactoryInstance( true, serviceName, null, null);                        try                        {                            if (SanityManager.DEBUG)                                SanityManager.ASSERT(serviceName.equals( storageFactory.getCanonicalName()), serviceName);                            StorageFile serviceDirectory = storageFactory.newStorageFile( null);                            return serviceDirectory.deleteAll() ? this : null;                        }                        finally { storageFactory.shutdown(); }                    }                }                ) != null;        }        catch( PrivilegedActionException pae){ return false;}	} // end of removeServiceRoot	public String getCanonicalServiceName(String name)		throws StandardException    {		String protocolLeadIn = getType() + ":";        int colon = name.indexOf( ':');        if( colon > 1) // Subsubprotocols must be at least 2 characters long        {            if( ! name.startsWith( protocolLeadIn))                return null; // It is not our database            name = name.substring( colon + 1);        }        if( getType().equals( PersistentService.DIRECTORY)) // The default subsubprototcol            protocolLeadIn = "";        final String nm = name;        try        {            return protocolLeadIn + (String) AccessController.doPrivileged(                new PrivilegedExceptionAction()                {                    public Object run()                        throws StandardException, IOException, InstantiationException, IllegalAccessException                    {                        StorageFactory storageFactory = privGetStorageFactoryInstance( true, nm, null, null);                        try                        {                            return storageFactory.getCanonicalName();                        }                        finally { storageFactory.shutdown();}                    }                }                );        }		catch (PrivilegedActionException pae)        {			throw Monitor.exceptionStartingModule(pae.getException());		}	} // end of getCanonicalServiceName	public String getUserServiceName(String serviceName)    {		if (home != null)        {			// allow for file separatorChar by adding 1 to the length			if ((serviceName.length() > (canonicalHome.length() + 1)) && serviceName.startsWith(canonicalHome))            {				serviceName = serviceName.substring(canonicalHome.length());				if (serviceName.charAt(0) == separatorChar)					serviceName = serviceName.substring(1);			}		}		return serviceName.replace( separatorChar, '/');	}	public boolean isSameService(String serviceName1, String serviceName2)    {		if (SanityManager.DEBUG)        {			try {            SanityManager.ASSERT(serviceName1.equals(getCanonicalServiceName(serviceName1)), serviceName1);			SanityManager.ASSERT(serviceName2.equals(getCanonicalServiceName(serviceName2)), serviceName2);			} catch (StandardException se)			{				return false;			}		}		return serviceName1.equals(serviceName2);	} // end of isSameService    /**     * Get the StorageFactory implementation for this PersistentService     *     * @return the StorageFactory class.     */    public Class getStorageFactoryClass()    {        return storageFactoryClass;    }        final class DirectoryList implements Enumeration, PrivilegedAction    {        private String[] contents;        private StorageFile systemDirectory;	         private int      index;        private boolean  validIndex;        private int actionCode;        private static final int INIT_ACTION = 0;        private static final int HAS_MORE_ELEMENTS_ACTION = 1;        DirectoryList()        {            actionCode = INIT_ACTION;            AccessController.doPrivileged( this);        }        public boolean hasMoreElements()        {            if (validIndex)                return true;            actionCode = HAS_MORE_ELEMENTS_ACTION;            return AccessController.doPrivileged( this) != null;        } // end of hasMoreElements        public Object nextElement() throws NoSuchElementException        {            if (!hasMoreElements())                throw new NoSuchElementException();            validIndex = false;            return contents[index++];        } // end of nextElement        // PrivilegedAction method        public final Object run()        {            switch( actionCode)            {            case INIT_ACTION:                systemDirectory = rootStorageFactory.newStorageFile( null);                contents = systemDirectory.list();                return null;            case HAS_MORE_ELEMENTS_ACTION:                for (; index < contents.length; contents[index++] = null)                {                    try                    {                        StorageFactory storageFactory = privGetStorageFactoryInstance( true, contents[index], null, null);                        try                        {                            StorageFile properties = storageFactory.newStorageFile( PersistentService.PROPERTIES_NAME);                            if (!properties.exists())                                continue;                            // convert to a canonical name while we are here.                            contents[index] = storageFactory.getCanonicalName();                            validIndex = true;                            return this;                        }                        finally { storageFactory.shutdown(); }                    }                    catch (Exception se) { continue; }                }                return null;            }            return null;        } // end of run    } // end of class DirectoryList}

⌨️ 快捷键说明

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