Class Defragment


  • public class Defragment
    extends java.lang.Object
    defragments database files.

    db4o structures storage inside database files as free and occupied slots, very much like a file system - and just like a file system it can be fragmented.

    The simplest way to defragment a database file:

    Defragment.defrag("sample.db4o");

    This will move the file to "sample.db4o.backup", then create a defragmented version of this file in the original position, using a temporary file "sample.db4o.mapping". If the backup file already exists, this will throw an exception and no action will be taken.

    For more detailed configuration of the defragmentation process, provide a DefragmentConfig instance:

    DefragmentConfig config=new DefragmentConfig("sample.db4o","sample.bap",new BTreeIDMapping("sample.map"));
    config.forceBackupDelete(true);
    config.storedClassFilter(new AvailableClassFilter());
    config.db4oConfig(db4oConfig);
    Defragment.defrag(config);


    This will move the file to "sample.bap", then create a defragmented version of this file in the original position, using a temporary file "sample.map" for BTree mapping. If the backup file already exists, it will be deleted. The defragmentation process will skip all classes that have instances stored within the db4o file, but that are not available on the class path (through the current classloader). Custom db4o configuration options are read from the Configuration passed as db4oConfig. Note: For some specific, non-default configuration settings like UUID generation, etc., you must pass an appropriate db4o configuration, just like you'd use it within your application for normal database operation.
    • Constructor Summary

      Constructors 
      Constructor Description
      Defragment()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void defrag​(DefragmentConfig config)
      Renames the file at the configured original path to the configured backup path and then builds a defragmented version of the file in the original place.
      static void defrag​(DefragmentConfig config, DefragmentListener listener)
      Renames the file at the configured original path to the configured backup path and then builds a defragmented version of the file in the original place.
      static void defrag​(java.lang.String origPath)
      Renames the file at the given original path to a backup file and then builds a defragmented version of the file in the original place.
      static void defrag​(java.lang.String origPath, java.lang.String backupPath)
      Renames the file at the given original path to the given backup file and then builds a defragmented version of the file in the original place.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Defragment

        public Defragment()
    • Method Detail

      • defrag

        public static void defrag​(java.lang.String origPath)
                           throws java.io.IOException
        Renames the file at the given original path to a backup file and then builds a defragmented version of the file in the original place.
        Parameters:
        origPath - The path to the file to be defragmented.
        Throws:
        java.io.IOException - if the original file cannot be moved to the backup location
      • defrag

        public static void defrag​(java.lang.String origPath,
                                  java.lang.String backupPath)
                           throws java.io.IOException
        Renames the file at the given original path to the given backup file and then builds a defragmented version of the file in the original place.
        Parameters:
        origPath - The path to the file to be defragmented.
        backupPath - The path to the backup file to be created.
        Throws:
        java.io.IOException - if the original file cannot be moved to the backup location
      • defrag

        public static void defrag​(DefragmentConfig config)
                           throws java.io.IOException
        Renames the file at the configured original path to the configured backup path and then builds a defragmented version of the file in the original place.
        Parameters:
        config - The configuration for this defragmentation run.
        Throws:
        java.io.IOException - if the original file cannot be moved to the backup location
      • defrag

        public static void defrag​(DefragmentConfig config,
                                  DefragmentListener listener)
                           throws java.io.IOException
        Renames the file at the configured original path to the configured backup path and then builds a defragmented version of the file in the original place.
        Parameters:
        config - The configuration for this defragmentation run.
        listener - A listener for status notifications during the defragmentation process.
        Throws:
        java.io.IOException - if the original file cannot be moved to the backup location