public static void initEmbeddedDataSource(String dbUrl) {
   eds = new EmbeddedDataSource();
   eds.setDatabaseName(dbUrl);
   eds.setUser(Constants.DERBY_DATABASE.STRING_DB_USER);
   eds.setPassword(Constants.DERBY_DATABASE.STRING_DB_PASSWORD);
   eds.setConnectionAttributes("create=true");
   logger.log(Level.INFO, eds.getDatabaseName());
 }
Exemplo n.º 2
0
 private WrappedDataSource createLocal() {
   localDataSource = (DataSource) System.getProperties().get(LOCAL_DB_NAME);
   if (localDataSource == null) {
     localDataSource = new EmbeddedDataSource();
     ((EmbeddedDataSource) localDataSource).setDatabaseName(LOCAL_DB_NAME);
     ((EmbeddedDataSource) localDataSource).setCreateDatabase(LOCAL_DB_ACTION);
     System.getProperties().put(LOCAL_DB_NAME, localDataSource);
   }
   logger.warn(EMBEDDED_DATA_SOURCE_IS_USED);
   WrappedDataSource wrappedDataSource = new WrappedDataSource(localDataSource);
   return wrappedDataSource;
 }
  @Override
  protected void shutdownDb() throws SQLException {
    // annoyingly, shutting down a derby instance involves catching an exception
    // and checking error codes to make sure it shut down "normally"

    try {
      EmbeddedDataSource dataSource = new EmbeddedDataSource();
      dataSource.setDatabaseName(dbDir.getAbsolutePath());
      dataSource.setShutdownDatabase("shutdown");
      dataSource.getConnection();
    } catch (SQLException e) {
      // make sure we get the correct error codes
      if (e.getErrorCode() != 45000 || !"08006".equals(e.getSQLState())) {
        throw e;
      }
    }
  }
Exemplo n.º 4
0
  /** Starts the server. */
  @CommandArgument
  public void start() {
    System.out.println("Starting server");
    try {

      Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
      EmbeddedDataSource ds = new EmbeddedDataSource();
      ds.setConnectionAttributes("create=true");
      ds.setDatabaseName("classes");

      logger.info("Initializing jobProgressStates monitor");
      ProgressStateFactory factory = new ProgressStateFactory();
      jobProgressStates = factory.getProgressStates();

      logger.info("Initializing folders...");
      Preferences pref = Preferences.userNodeForPackage(JobServer.class);
      String path = pref.get("rootDirectory", "./server");
      File rootDirectory = new File(path);
      File jobsDirectory = new File(rootDirectory, "jobs");

      rootDirectory.mkdir();
      jobsDirectory.mkdir();

      logger.info("Initializing service");
      DbClassManager classManager = new DbClassManager(ds);
      classManager.prepareDataSource();

      TaskScheduler scheduler = new PrioritySerialTaskScheduler();
      Executor executor = Executors.newCachedThreadPool();
      jobServer = new JobServer(jobsDirectory, factory, scheduler, classManager, executor);
      AuthenticationServer authServer = new AuthenticationServer(jobServer, JdcpUtil.DEFAULT_PORT);

      logger.info("Binding service");
      Registry registry = getRegistry();
      registry.bind("AuthenticationService", authServer);

      logger.info("Server ready");
      System.out.println("Server started");

    } catch (Exception e) {
      System.err.println("Failed to start server");
      logger.error("Failed to start server", e);
    }
  }