Package org.apache.derby.io

Examples of org.apache.derby.io.StorageFile


                        properties.getProperty(Property.LOG_DEVICE_AT_BACKUP);
        }
      }  
       
            getLogStorageFactory();
      StorageFile logDir;
      logDir = logStorageFactory.newStorageFile(
                             LogFactory.LOG_DIRECTORY_NAME);
       
      //remove the log directory in case of restoreFrom
      //if it exist, this happens if the log device is on seperate
      //location than the db home.
      if (isRestoreFrom && logDevice != null)
      {
        if(!privRemoveDirectory(logDir))
        {
          //it may be just a file, try deleting it
          if(!privDelete(logDir))
                    {
            throw StandardException.newException(
                            SQLState.UNABLE_TO_REMOVE_DATA_DIRECTORY,
                            getLogDirPath( logDir));
                    }
        }
      }

            // if it is a create/restore from backup,
            // create the log directory.
            if (isCreateFrom || isRestoreFrom) {
                createLogDirectory();
            }

      File backupLogDir = new File(backupPath, LogFactory.LOG_DIRECTORY_NAME);
      String[] logfilelist = privList(backupLogDir);
      if(logfilelist !=null)
      {
        for (int i = 0; i < logfilelist.length; i++)
        {
          File blogFile = new File(backupLogDir, logfilelist[i]);
          StorageFile clogFile = logStorageFactory.newStorageFile(logDir, logfilelist[i]);
          if(!privCopyFile(blogFile , clogFile))
          {
            throw
              StandardException.newException(SQLState.UNABLE_TO_COPY_LOG_FILE, blogFile, clogFile);
          }
View Full Code Here


                for (; index < contents.length; contents[index++] = null)
                {
                    try
                    {
                        String dirname = contents[index];
                        StorageFile dir = rootStorageFactory.newStorageFile(dirname);
                        if (!dir.isDirectory())
                            continue;
                       
                        // Look to see if service.properties is in this
                        // directory.
                        StorageFile properties =
                            rootStorageFactory.newStorageFile(dir,
                                    PersistentService.PROPERTIES_NAME);
                       
                        if (!properties.exists())
                            continue;
                       
                        // convert to a canonical name while we are here.
                        contents[index] = dir.getCanonicalPath();
                        validIndex = true;
View Full Code Here

    @exception IOException Any exception during accessing the file for read/write
   */
  private StorageRandomAccessFile privAccessFile(StorageFactory storageFactory,String fileName,String filePerms)
    throws java.io.IOException
  {
    StorageFile verifyKeyFile = storageFactory.newStorageFile("",fileName);
    activeFile  = verifyKeyFile;
    this.action = 2;
    activePerms = filePerms;
      try
        {
View Full Code Here

   @exception IOException Any exception during accessing the file for read
   */
  private InputStream privAccessGetInputStream(StorageFactory storageFactory,String fileName)
  throws StandardException
  {
      StorageFile verifyKeyFile = storageFactory.newStorageFile("",fileName);
      activeFile  = verifyKeyFile;
      this.action = 3;
      try
      {
          return (InputStream)java.security.AccessController.doPrivileged(this);
View Full Code Here

                            home = relativeRoot.getPath();
                            canonicalHome = relativeRoot.getCanonicalPath();
                            rootStorageFactory = getStorageFactoryInstance( true, null, null, null);
                            if( home != null)
                            {
                                StorageFile rootDir = rootStorageFactory.newStorageFile( null);
                                rootDir.mkdirs();
                            }
                            return null;
                        }
                    }
                    );
View Full Code Here

                            }
                        }
                        else
                        {
                            StorageFactory storageFactory = privGetStorageFactoryInstance( true, serviceName, null, null);
                            StorageFile file = storageFactory.newStorageFile( PersistentService.PROPERTIES_NAME);
                            try {
                                InputStream is = file.getInputStream();
                                try {
                                    // Need to load the properties before closing the
                                    // StorageFactory.
                                    serviceProperties.load(new BufferedInputStream(is));
                                } finally {
View Full Code Here

            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);
View Full Code Here

                                    {
                                        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(PrivilegedFileOps.exists(backupRoot))
      {
        //First make sure backup have service.properties
        File bserviceProp = new File(restoreFrom, PersistentService.PROPERTIES_NAME);
        if(PrivilegedFileOps.exists(bserviceProp))
        {
          //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();}
View Full Code Here

                        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);
                        }
View Full Code Here

                                        storageFactory.getCanonicalName()),
                                    "serviceName = " + serviceName +
                                    ";storageFactory.getCanonicalName() = " +
                                    storageFactory.getCanonicalName());
                            }
                            StorageFile serviceDirectory = storageFactory.newStorageFile( null);
                            return serviceDirectory.deleteAll() ? this : null;
                        }
                        finally { storageFactory.shutdown(); }
                    }
                }
                ) != null;
View Full Code Here

TOP

Related Classes of org.apache.derby.io.StorageFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.