Example #1
0
 /////////////// private
 private DataSource getDataSource() throws Exception {
   FileSystem fs = getFileSystem();
   jdbcDataSource ds = new jdbcDataSource();
   ds.setDatabase("jdbc:hsqldb:.");
   ds.setUser("sa");
   ds.setPassword("");
   if (!DatabaseUtils.hasTable(ds, "ledge_id_table")) {
     DatabaseUtils.runScript(ds, fs.getReader("sql/database/IdGeneratorTables.sql", "UTF-8"));
   }
   if (!DatabaseUtils.hasTable(ds, "ledge_naming_context")) {
     DatabaseUtils.runScript(ds, fs.getReader("sql/naming/DBNamingTables.sql", "UTF-8"));
   }
   DatabaseUtils.runScript(ds, fs.getReader("sql/naming/DBNamingTest.sql", "UTF-8"));
   return ds;
 }
Example #2
0
 /**
  * Returns the model dependent object by its id.
  *
  * @param id the id of the object
  * @return model object
  */
 public FileObject getObject(String id) {
   if (fileSystem.exists(id)) {
     return new FileObject(fileSystem, id);
   } else {
     return null;
   }
 }
Example #3
0
  /**
   * Gets all children of the parent, may return empty array.
   *
   * @param parent the parent
   * @return table of children
   */
  public FileObject[] getChildren(FileObject parent) {
    if (parent == null) {
      return new FileObject[0];
    }

    FileObject parentObject = parent;
    if (!parentObject.isDirectory()) {
      return new FileObject[0];
    }

    String parentPath = normalizeDirPath(parentObject.getPath());
    String[] fileNames;
    try {
      fileNames = fileSystem.list(parentPath);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
    if (fileNames == null) {
      return new FileObject[0];
    }

    FileObject[] files = new FileObject[fileNames.length];
    for (int i = 0; i < fileNames.length; i++) {
      String filePath = parentPath + '/' + fileNames[i];
      files[i] = new FileObject(fileSystem, filePath);
    }
    return files;
  }
Example #4
0
 private void runScript(String path) throws Exception {
   logger.info("running " + adapt(path));
   Reader scriptReader = fileSystem.getReader(adapt(path), "UTF-8");
   if (scriptReader == null) {
     throw new IOException("script " + path + " missing from classpath");
   }
   DatabaseUtils.runScript(dataSource, scriptReader);
 }
Example #5
0
 private String adapt(String path) {
   String raw = path.substring(0, path.length() - 3); // strip sql suffix
   final String adapted = raw + dbType.getSuffix() + ".sql";
   if (fileSystem.exists(adapted)) {
     return adapted;
   } else {
     return path;
   }
 }
Example #6
0
  public void setUp() throws Exception {
    FileSystem fs = getFileSystem();
    InputSource source =
        new InputSource(
            fs.getInputStream("config/org.objectledge.logging.LoggingConfigurator.xml"));
    DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document logConfig = builder.parse(source);
    LedgeDOMConfigurator configurator = new LedgeDOMConfigurator(fs);
    configurator.doConfigure(logConfig.getDocumentElement(), LogManager.getLoggerRepository());

    Logger logger = new Log4JLogger(org.apache.log4j.Logger.getLogger(ContextFactory.class));
    DataSource ds = getDataSource();
    DefaultPicoContainer container = new DefaultPicoContainer();
    IdGenerator idGenerator = new IdGenerator(ds);
    JotmTransaction transaction = new JotmTransaction(0, 120, new Context(), logger, null);
    Database database = new DefaultDatabase(ds, idGenerator, transaction);
    Persistence persistence = new DefaultPersistence(database, logger);
    container.registerComponentInstance(Persistence.class, persistence);
    Configuration config = getConfig("naming/dbNaming.xml");
    contextFactory = new ContextFactory(container, config, logger);
  }
Example #7
0
  /** {@inheritDoc} */
  public void init(ServletConfig servletConfig) throws ServletException {
    BasicConfigurator.configure();
    Logger log = Logger.getLogger(LedgeServlet.class);

    FileSystem fs = fileSystem(servletConfig, getClass().getClassLoader());

    ServletContext context = servletConfig.getServletContext();
    String ctxConfigParam = servletConfig.getServletName() + ".config";
    String config = servletConfig.getInitParameter("config");
    if (config == null) {
      config = context.getInitParameter(ctxConfigParam);
    }
    if (config == null) {
      config = "/config";
    }
    String root = ((LocalFileSystemProvider) fs.getProvider("local")).getBasePath();

    log.info(
        "starting up "
            + servletConfig.getServletName()
            + " servlet: root="
            + root
            + " config="
            + config);
    try {
      container = new LedgeContainer(fs, config, getClass().getClassLoader());
    } catch (Exception e) {
      log.error("failed to initialize container", e);
      throw new ServletException("failed to initialize container", e);
    }

    dispatcher =
        (HttpDispatcher) container.getContainer().getComponentInstance(HttpDispatcher.class);
    if (dispatcher == null) {
      log.error("dispatcher component is missing");
      throw new ServletException("dispatcher component is missing");
    }
  }
Example #8
0
  public void setUp() throws Exception {
    super.setUp();
    FileSystem fs = FileSystem.getStandardFileSystem("src/test/resources");
    container = new LedgeContainer(fs, "/config", getClass().getClassLoader());
    coralSessionFactory =
        (CoralSessionFactory)
            container.getContainer().getComponentInstance(CoralSessionFactory.class);
    dataSource =
        (DataSource) container.getContainer().getComponentInstanceOfType(ThreadDataSource.class);
    log = Logger.getLogger(getClass());

    InitComponent init = new InitComponent(dataSource, fs, true, new Log4JLogger(log));
    init.run();

    databaseConnection = new DatabaseDataSourceConnection(dataSource);
  }
Example #9
0
  @Override
  public void execute() throws MojoExecutionException, MojoFailureException {
    try {
      initDataSource();
      IntegrityChecker checker =
          new IntegrityChecker(
              dataSource.getConnection(),
              FileSystem.getClasspathFileSystem(),
              new MavenDNALogger(getLog()));

      checker.run();
    } catch (SQLException e) {
      SQLException se = (SQLException) e;
      while (se.getNextException() != null) {
        getLog().error(se);
        se = se.getNextException();
      }
      throw new MojoExecutionException("SQL Exception", se);
    } catch (Exception e) {
      throw new MojoExecutionException("internal error", e);
    } finally {
      shutdownDataSource();
    }
  }