📄 persistentserviceimpl.java
字号:
{ is.close(); } catch (IOException ioe2) {} } } } // end of getServiceProperties /** @exception StandardException Properties cannot be saved. */ public void saveServiceProperties( final String serviceName, StorageFactory sf, final Properties properties, final boolean replace) throws StandardException { if (SanityManager.DEBUG) { SanityManager.ASSERT(serviceName.equals(getCanonicalServiceName(serviceName)), serviceName); } if( ! (sf instanceof WritableStorageFactory)) throw StandardException.newException(SQLState.READ_ONLY_SERVICE); final WritableStorageFactory storageFactory = (WritableStorageFactory) sf; try { AccessController.doPrivileged( new PrivilegedExceptionAction() { public Object run() throws StandardException { StorageFile backupFile = null; StorageFile servicePropertiesFile = storageFactory.newStorageFile( PersistentService.PROPERTIES_NAME); if (replace) { backupFile = storageFactory.newStorageFile( PersistentService.PROPERTIES_NAME.concat("old")); try { if(!servicePropertiesFile.renameTo(backupFile)) throw StandardException.newException(SQLState.UNABLE_TO_RENAME_FILE, servicePropertiesFile, backupFile); } catch (SecurityException se) { throw Monitor.exceptionStartingModule(se); } } OutputStream os = null; try { os = servicePropertiesFile.getOutputStream(); properties.store( os, serviceName + MessageService.getTextMessage(MessageId.SERVICE_PROPERTIES_DONT_EDIT)); storageFactory.sync( os, false); os.close(); os = null; } catch (IOException ioe) { if (os != null) { try { os.close(); } catch (IOException ioe2) {} os = null; } if (backupFile != null) { // need to re-name the old properties file back again try { servicePropertiesFile.delete(); backupFile.renameTo(servicePropertiesFile); } catch (SecurityException se) {} } throw Monitor.exceptionStartingModule(ioe); } if (backupFile != null) { try { backupFile.delete(); backupFile = null; } catch (SecurityException se) {} } return null; } } ); } catch( PrivilegedActionException pae) { throw (StandardException) pae.getException();} } // end of saveServiceProperties /** Save to a backup file @exception StandardException Properties cannot be saved. */ public void saveServiceProperties(String serviceName, Properties properties, boolean replace) throws StandardException { File backupFile = null; File servicePropertiesFile = new File(serviceName, PersistentService.PROPERTIES_NAME); if (replace) { backupFile = new File(serviceName, PersistentService.PROPERTIES_NAME.concat("old")); try { if(!servicePropertiesFile.renameTo(backupFile)) { throw StandardException.newException(SQLState.UNABLE_TO_RENAME_FILE, servicePropertiesFile, backupFile); } } catch (SecurityException se) { throw Monitor.exceptionStartingModule(se); } } FileOutputStream fos = null; try { fos = new FileOutputStream(servicePropertiesFile); properties.store(fos, serviceName + MessageService.getTextMessage(MessageId.SERVICE_PROPERTIES_DONT_EDIT)); fos.getFD().sync(); fos.close(); fos = null; replace = false; } catch (IOException ioe) { if (fos != null) { try { fos.close(); } catch (IOException ioe2) { } fos = null; } if (backupFile != null) { // need to re-name the old properties file back again try { servicePropertiesFile.delete(); backupFile.renameTo(servicePropertiesFile); } catch (SecurityException se) { } } throw Monitor.exceptionStartingModule(ioe); } if (backupFile != null) { try { backupFile.delete(); backupFile = null; } catch (SecurityException se) { // do nothing } } } /* **Recreates service root if required depending on which of the following **attribute is specified on the conection URL: ** Attribute.CREATE_FROM (Create database from backup if it does not exist): ** When a database not exist, the service(database) root is created ** and the PersistentService.PROPERTIES_NAME (service.properties) file ** is restored from the backup. ** Attribute.RESTORE_FROM (Delete the whole database if it exists and then restore ** it from backup) ** Existing database root is deleted and the new the service(database) root is created. ** PersistentService.PROPERTIES_NAME (service.properties) file is restored from the backup. ** Attribute.ROLL_FORWARD_RECOVERY_FROM:(Perform Rollforward Recovery; ** except for the log directory everthing else is replced by the copy from ** backup. log files in the backup are copied to the existing online log ** directory.): ** When a database not exist, the service(database) root is created. ** PersistentService.PROPERTIES_NAME (service.properties) file is deleted ** from the service dir and recreated with the properties from backup. */ protected String recreateServiceRoot( final String serviceName, Properties properties) throws StandardException { //if there are no propertues then nothing to do in this routine if(properties == null) { return null; } String restoreFrom; //location where backup copy of service properties available boolean createRoot = false; boolean deleteExistingRoot = false; //check if user wants to create a database from a backup copy restoreFrom = properties.getProperty(Attribute.CREATE_FROM); if(restoreFrom !=null) { //create root dicretory if it does not exist. createRoot =true; deleteExistingRoot = false; } else { //check if user requested a complete restore(version recovery) from backup restoreFrom = properties.getProperty(Attribute.RESTORE_FROM); //create root dir if it does not exists and if there exists one already delete and recreate if(restoreFrom !=null) { createRoot =true; deleteExistingRoot = true; } else { //check if user has requested roll forward recovery using a backup restoreFrom = properties.getProperty(Attribute.ROLL_FORWARD_RECOVERY_FROM); if(restoreFrom !=null) { //if service root does not exist then only create one //This is useful when logDevice was on some other device //and the device on which data directorties existied has //failed and user is trying to restore it some other device. try { if( AccessController.doPrivileged( new PrivilegedExceptionAction() { public Object run() throws IOException, StandardException, InstantiationException, IllegalAccessException { StorageFactory storageFactory = privGetStorageFactoryInstance( true, serviceName, null, null); try { StorageFile serviceDirectory = storageFactory.newStorageFile( null); return serviceDirectory.exists() ? this : null; } finally {storageFactory.shutdown();} } } ) == null) { createRoot =true; deleteExistingRoot = false; } } catch( PrivilegedActionException pae) { throw Monitor.exceptionStartingModule( (IOException) pae.getException()); } } } } //restore the service properties from backup if(restoreFrom != null) { //First make sure backup service directory exists in the specified path File backupRoot = new File(restoreFrom); if(backupRoot.exists()) { //First make sure backup have service.properties File bserviceProp = new File(restoreFrom, PersistentService.PROPERTIES_NAME); if(bserviceProp.exists()) { //create service root if required if(createRoot) createServiceRoot(serviceName, deleteExistingRoot); try { AccessController.doPrivileged( new PrivilegedExceptionAction() { public Object run() throws IOException, StandardException, InstantiationException, IllegalAccessException { WritableStorageFactory storageFactory = (WritableStorageFactory) privGetStorageFactoryInstance( true, serviceName, null, null); try { StorageFile cserviceProp = storageFactory.newStorageFile( PersistentService.PROPERTIES_NAME); if(cserviceProp.exists()) if(!cserviceProp.delete()) throw StandardException.newException(SQLState.UNABLE_TO_DELETE_FILE, cserviceProp); return null; } finally { storageFactory.shutdown();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -