Package freedb

Source Code of freedb.LoadFreeDB

package freedb;

import java.io.File;
import java.io.FileFilter;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;

import org.odbms.ObjectContainer;

import de.linwave.gtm.GTM;
import de.linwave.gtm.IndexUtils;

/**
*
* @author ljoeckel
*
*/
public class LoadFreeDB
{

  private static ObjectContainer db = GTM.getInstance();

  /**
   *
   * @param args
   */
  public static void main(String[] args)
  {
    final AtomicLong cnt = new AtomicLong();
    System.out.println("Removed " + db.deleteClass(Disc.class) + " Disc instances");
    IndexUtils.addIndex(Disc.class, "DTITLE");
    IndexUtils.addIndex(Disc.class, "DYEAR");
    IndexUtils.addIndex(Disc.class, "DGENRE");

    try {
      List<String> subdirs = Arrays.asList("blues", "data", "jazz", "newage", "reggae", "soundtrack", "classical", "country", "folk", "misc", "rock");
      for (String subdir : subdirs) {

        File root = new File("/freedb/" + subdir);
        if (!root.exists()) {
          System.err.println("Directory " + root + " doesn't exists");
          continue;
        }
        if (!root.isDirectory()) {
          System.err.println(root + " isn't a directory!");
          continue;
        }

        // Get the files from the directory
        File[] files = root.listFiles(new FileFilter() {
          public boolean accept(File file)
          {

            Disc disc = new Disc(file);
            try {
              long oid = db.store(disc);
              if (cnt.incrementAndGet() % 100 == 0) {
                System.out.println(cnt.longValue() + " " + file + " oid=" + oid);
              }
            } catch (Exception ex) {
              System.err.println("Could not store " + file + " Reason: " + ex.getMessage());
            }
            return false;
          }
        });
      }

    } catch (Exception ex) {
      ex.printStackTrace();
    }
    System.exit(0);
  }
}
TOP

Related Classes of freedb.LoadFreeDB

TOP
Copyright © 2018 www.massapi.com. 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.