Exemplo n.º 1
0
  /** Start the standalone (in process) database. */
  private void startStandaloneDatabase() throws Exception {
    // Get the server data directory
    File dataDir = null;

    if (dbDataDir == null) dataDir = ServerConfigLocator.locate().getServerDataDir();
    else dataDir = new File(dbDataDir);

    // Get DB directory
    File hypersoniDir = new File(dataDir, HYPERSONIC_DATA_DIR);

    if (!hypersoniDir.exists()) {
      hypersoniDir.mkdirs();
    }

    if (!hypersoniDir.isDirectory()) {
      throw new IOException("Failed to create directory: " + hypersoniDir);
    }

    dbPath = new File(hypersoniDir, name);

    String dbURL = JDBC_URL_PREFIX + getDatabasePath();

    // hold a connection so hypersonic does not close the database
    connection = getConnection(dbURL);
  }
Exemplo n.º 2
0
  /** Start the remote database. */
  private void startRemoteDatabase() throws Exception {
    // Get the server data directory
    File dataDir = null;
    if (dbDataDir == null) dataDir = ServerConfigLocator.locate().getServerDataDir();
    else dataDir = new File(dbDataDir);

    // Get DB directory
    File hypersoniDir = new File(dataDir, HYPERSONIC_DATA_DIR);

    if (!hypersoniDir.exists()) {
      hypersoniDir.mkdirs();
    }

    if (!hypersoniDir.isDirectory()) {
      throw new IOException("Failed to create directory: " + hypersoniDir);
    }

    dbPath = new File(hypersoniDir, name);

    // Start DB in new thread, or else it will block us
    serverThread =
        new Thread("hypersonic-" + name) {
          public void run() {
            try {
              // Create startup arguments
              String[] args =
                  new String[] {
                    "-database", dbPath.toString(),
                    "-port", String.valueOf(port),
                    "-address", address,
                    "-silent", String.valueOf(silent),
                    "-trace", String.valueOf(trace),
                    "-no_system_exit", String.valueOf(no_system_exit),
                  };

              // Start server
              ClassLoader cl = Thread.currentThread().getContextClassLoader();
              Class clazz = Class.forName(serverClass, true, cl);
              Method main = clazz.getMethod("main", new Class[] {args.getClass()});
              main.invoke(null, new Object[] {args});
            } catch (Exception e) {
              log.error("Failed to start database", e);
            }
          }
        };
    serverThread.start();
  }
  public void destroy() {
    System.out.println("Destruyendo instancia");
    try {
      if (Prodandes.darInstancia() != null) {
        ServerConfig config = ServerConfigLocator.locate();
        File dataDir = config.getServerDataDir();
        File tmp = new File(dataDir + RUTA_ARCHIVO_SERIALIZADO);
        System.out.println("Nombre=" + tmp.getName());
        System.out.println("Path=" + tmp.getPath());
        System.out.println("Abs. Path=" + tmp.getAbsolutePath());

        FileOutputStream fos = new FileOutputStream(tmp);
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(Prodandes.darInstancia());
        oos.close();
        fos.close();
        System.out.println("Album Serializado");
      }
    } catch (Exception e) {
      System.out.println("Error de persistencia en Servidor");
    }
  }