Exemplo n.º 1
0
  private static String getDefaultDatabase() throws FileNotFoundException, IOException {
    File dir = new File(PropertyManager.getInstance().getPathProperty("path_database"));
    File files[] =
        dir.listFiles(
            new FileFilter() {

              public boolean accept(File pathname) {
                return pathname.getPath().endsWith(".properties");
              }
            });

    for (int i = 0; i < files.length; i++) {
      File file = files[i];
      Database db = Database.loadFromFile(file);
      if (db.isDefaultDB()) {
        return db.getName();
      }
    }
    return null;
  }
Exemplo n.º 2
0
 public static void createDatabase(DatabaseGuiObject dgo)
     throws FileNotFoundException, IOException {
   Database db = new Database();
   db.setName(dgo.getName());
   db.setDefaultDB(dgo.isDefaultDB());
   db.setDialect(dgo.getDialect());
   if (dgo.getDialect().equals(HSQLDB)) {
     db.setUrl(
         "jdbc:hsqldb:file:"
             + PropertyManager.getInstance().getPathProperty("path_resources")
             + PropertyManager.sep
             + dgo.getName());
     db.setPassword("");
     db.setUsername("sa");
   } else {
     db.setUrl(dgo.getUrl());
     db.setPassword(dgo.getPassword());
     db.setUsername(dgo.getUsername());
   }
   db.setDriver(HibernateUtil.getDriverClass(dgo.getDialect()));
   db.saveToFile(
       new File(
           PropertyManager.getInstance().getPathProperty("path_database")
               + PropertyManager.sep
               + dgo.getName()
               + ".properties"));
   if (db.isDefaultDB()) {
     HibernateUtil.setDatabaseToDefault(db, false);
   }
   File coverDir =
       new File(
           PropertyManager.getInstance().getPathProperty("path_cover")
               + PropertyManager.sep
               + dgo.getName());
   if (!coverDir.mkdir()) {
     MessagePaneManager.showCheckErrorPane(
         LocaleManager.getInstance().getString("error_cover_dir"));
   }
 }
Exemplo n.º 3
0
  public static List<String> getListForCombo(String[] selected)
      throws FileNotFoundException, IOException {
    List<String> res = new ArrayList<String>();
    File dir = new File(PropertyManager.getInstance().getPathProperty("path_database"));
    File files[] =
        dir.listFiles(
            new FileFilter() {

              public boolean accept(File pathname) {
                return pathname.getPath().endsWith(".properties");
              }
            });

    for (int i = 0; i < files.length; i++) {
      File file = files[i];
      Database db = Database.loadFromFile(file);
      if (db.isDefaultDB()) {
        selected[0] = db.getName();
      }
      res.add(db.getName());
    }
    return res;
  }