Package jtrackbase

Source Code of jtrackbase.Trackbase

/* License see bottom */
package jtrackbase;

import java.io.IOException;
import java.util.Collection;
import java.util.logging.LogManager;
import java.util.logging.Logger;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import jtrackbase.db.DatabaseCreator;
import jtrackbase.db.Genre;
import jtrackbase.db.GenreFacade;
import jtrackbase.db.Medium;
import jtrackbase.db.MediumType;
import jtrackbase.db.MediumTypeFacade;
import jtrackbase.db.Tag;
import jtrackbase.db.TagFacade;
import jtrackbase.gui.TrackbaseFrame;

public class Trackbase {
  private static final Logger log=Logger.getLogger(Trackbase.class.getName());
 
  private Trackbase() {
   
  }
 
  public static void main(String[] args) {
    LogManager lm=LogManager.getLogManager();
    try {
      lm.readConfiguration(Thread.currentThread().getContextClassLoader().getResourceAsStream("log.properties"));
    } catch (IOException ex) {
      System.err.println("failed to configure logging");
    }
    log.info("Starting...");
    Trackbase tb=new Trackbase();
    if (!tb.checkIfDBExists()) {
      DatabaseCreator.initDatabase();
    }
    tb.startUp();
  }

  private boolean checkIfDBExists() {
    try {
      EntityManagerFactory factory = Persistence.createEntityManagerFactory("trackbase");
      EntityManager em = factory.createEntityManager();
      em.find(Medium.class, 10L);
    } catch (Exception ex) {
      return false;
    }
    return true;
  }
 
  private void startUp() {
    Collection<MediumType> mts=MediumTypeFacade.findAll();
    if (mts==null || mts.size()==0) {
      MediumTypeFacade.initBasicTypes();
    }
    Collection<Genre> genres=GenreFacade.findAll();
    if (genres==null || genres.size()==0) {
      GenreFacade.initBasicTypes();
    }
    Collection<Tag> tags=TagFacade.findAll();
    if (tags==null || tags.size()==0) {
      TagFacade.initBasicTypes();
    }
    TrackbaseFrame tf=new TrackbaseFrame();
    tf.setVisible(true);
  }
}
/*
Copyright (C) 2008  Onkobu Tanaake

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program (gplv3.txt).
*/
TOP

Related Classes of jtrackbase.Trackbase

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.