public final Object run()

in java/org.apache.derby.engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java [2809:2992]


    public final Object run() throws IOException, StandardException
    {
        switch( actionCode)
        {
        case BOOT_ACTION:
            readOnly = storageFactory.isReadOnlyDatabase();
            supportsRandomAccess = storageFactory.supportsRandomAccess();
            return null;
            
        case REMOVE_TEMP_DIRECTORY_ACTION:
            StorageFile tempDir = storageFactory.getTempDir();
            if( tempDir != null)
                tempDir.deleteAll();
            return null;

        case GET_CONTAINER_PATH_ACTION:
        case GET_ALTERNATE_CONTAINER_PATH_ACTION:
        {
            StringBuffer sb = new StringBuffer("seg");
            sb.append(containerId.getSegmentId());
            sb.append(storageFactory.getSeparator());
            if( actionCode == GET_CONTAINER_PATH_ACTION)
            {
                sb.append(stub ? 'd' : 'c');
                sb.append(Long.toHexString(containerId.getContainerId()));
                sb.append(".dat");
            }
            else
            {
                sb.append(stub ? 'D' : 'C');
                sb.append(Long.toHexString(containerId.getContainerId()));
                sb.append(".DAT");
            }
            return storageFactory.newStorageFile( sb.toString());
        } // end of cases GET_CONTAINER_PATH_ACTION & GET_ALTERNATE_CONTAINER_PATH_ACTION

        case REMOVE_STUBS_ACTION:
        {
            char separator = storageFactory.getSeparator();
            StorageFile root = storageFactory.newStorageFile( null);

            // get all the non-temporary data segment, they start with "seg"
            String[] segs = root.list();
            for (int s = segs.length-1; s >= 0; s--)
            {
                if (segs[s].startsWith("seg"))
                {
                    StorageFile seg = 
                        storageFactory.newStorageFile(root, segs[s]);

                    if (seg.exists() && seg.isDirectory())
                    {
                        String[] files = seg.list();
                        for (int f = files.length-1; f >= 0 ; f--)
                        {
                            // stub
                            if (files[f].startsWith("D") ||
                                files[f].startsWith("d"))
                            {
                                StorageFile stub = 
                                    storageFactory.newStorageFile(
                                        root, segs[s] + separator + files[f]);

                                boolean delete_status = stub.delete();
                                
                                if (SanityManager.DEBUG)
                                {
                                    // delete should always work, code which
                                    // created the StorageFactory already 
                                    // checked for existence.
                                    if (!delete_status)
                                    {
                                        SanityManager.THROWASSERT(
                                            "delete of stub (" + 
                                            stub + ") failed.");
                                    }
                                }
                            }
                        }
                    }
                }
            }
            break;
        } // end of case REMOVE_STUBS_ACTION

        case FIND_MAX_CONTAINER_ID_ACTION:
        {
            long maxnum = 1;
            StorageFile seg = storageFactory.newStorageFile( "seg0");

            if (seg.exists() && seg.isDirectory())
            {
                // create an array with names of all files in seg0
                String[] files = seg.list();

                // loop through array looking for maximum containerid.
                for (int f = files.length-1; f >= 0 ; f--)
                {
                    try
                    {
                        long fileNumber = 
                          Long.parseLong(
                              files[f].substring(
                                  1, (files[f].length() -4)), 16);

                        if (fileNumber > maxnum)
                            maxnum = fileNumber;
                    }
                    catch (Throwable t)
                    {
                        // ignore errors from parse, it just means that someone 
                        // put a file in seg0 that we didn't expect.  Continue 
                        // with the next one.
                    }
                }
            }
            return maxnum;
		} // end of case FIND_MAX_CONTAINER_ID_ACTION

        case DELETE_IF_EXISTS_ACTION:
        {
            boolean ret = actionFile.exists() && actionFile.delete();
            actionFile = null;
            return ret ? this : null;
        } // end of case DELETE_IF_EXISTS_ACTION

        case GET_PATH_ACTION:
        {
            String path = actionFile.getPath();
            actionFile = null;
            return path;
        } // end of case GET_PATH_ACTION

        case POST_RECOVERY_REMOVE_ACTION:
        {
			for (Enumeration<StorageFile> e = postRecoveryRemovedFiles.elements(); 
                    e.hasMoreElements(); )
            {
				StorageFile f = e.nextElement();
				if (f.exists())
                {
					boolean delete_status = f.delete();

                    if (SanityManager.DEBUG)
                    {
                        // delete should always work, code which
                        // created the StorageFactory already 
                        // checked for existence.
                        if (!delete_status)
                        {
                            SanityManager.THROWASSERT(
                                "delete of stub (" + stub + ") failed.");
                        }
                    }
                }
			}
            return null;
        }

        case GET_LOCK_ON_DB_ACTION:
            privGetJBMSLockOnDB();
            return null;

        case RELEASE_LOCK_ON_DB_ACTION:
            privReleaseJBMSLockOnDB();
            return null;

        case RESTORE_DATA_DIRECTORY_ACTION:
            privRestoreDataDirectory();
            return null;
		case GET_CONTAINER_NAMES_ACTION:
        {
            StorageFile seg = storageFactory.newStorageFile( "seg0");
            if (seg.exists() && seg.isDirectory())
            {
                // return the  names of all files in seg0
				return seg.list();
            }
            return null;
        }  // end of case GET_CONTAINER_NAMES_ACTION
		
		}
        return null;
    } // end of run