{
SanityManager.ASSERT(serviceName.equals(getCanonicalServiceName(serviceName)), serviceName);
}
if( ! (sf instanceof WritableStorageFactory))
throw StandardException.newException(SQLState.READ_ONLY_SERVICE);
final WritableStorageFactory storageFactory = (WritableStorageFactory) sf;
// Write the service properties to file.
try
{
AccessController.doPrivileged(
new PrivilegedExceptionAction<Object>()
{
public Object run() throws StandardException
{
StorageFile backupFile = replace
? storageFactory.newStorageFile(
PersistentService.PROPERTIES_NAME.concat("old"))
: null;
StorageFile servicePropertiesFile = storageFactory.newStorageFile( PersistentService.PROPERTIES_NAME);
FileOperationHelper foh = new FileOperationHelper();
if (replace)
{
foh.renameTo(
servicePropertiesFile, backupFile, true);
}
OutputStream os = null;
try
{
os = servicePropertiesFile.getOutputStream();
properties.store(os, serviceName +
MessageService.getTextMessage(
MessageId.SERVICE_PROPERTIES_DONT_EDIT));
// The eof token should match the ISO-8859-1 encoding
// of the rest of the properties file written with store.
BufferedWriter bOut = new BufferedWriter(
new OutputStreamWriter(os,"ISO-8859-1"));
bOut.write(SERVICE_PROPERTIES_EOF_TOKEN);
bOut.newLine();
storageFactory.sync( os, false);
bOut.close();
os.close();
os = null;
}
catch (IOException ioe)