Esempio n. 1
0
  /**
   * Checks that system generated columns with name starting with SYS_ in the Oracle engine do not
   * appear in the table metadata.
   *
   * @throws Exception propagates any Exception thrown by the test
   */
  @Test
  public void testSystemGeneratedColumns() throws Exception {
    DatabaseEngine engine = DatabaseFactory.getConnection(properties);

    try {
      DbEntity entity =
          dbEntity()
              .name("TEST_SYS_COL")
              // Simulates a system generated column
              .addColumn("SYS_COL1", INT)
              .addColumn("COL1", INT)
              .pkFields("COL1")
              .build();
      engine.addEntity(entity);

      assertFalse(
          "The simulated system generated column should not appear in the table metadata",
          engine.getMetadata("TEST_SYS_COL").containsKey("SYS_COL1"));
      assertTrue(
          "The regular column should appear in the table metadata",
          engine.getMetadata("TEST_SYS_COL").containsKey("COL1"));
    } finally {
      engine.close();
    }
  }
Esempio n. 2
0
  /**
   * Initializes the database connection.
   *
   * @param dbFile The database file.
   * @throws DatabaseFactoryException If an error occurs getting the database connection.
   * @throws DatabaseEngineException If an error occurs creating the call result entity.
   */
  public static DatabaseEngine initializeDbConnection(String dbFile)
      throws DatabaseFactoryException, DatabaseEngineException {
    Properties properties =
        new Properties() {
          {
            setProperty("pdb.jdbc", "jdbc:h2:" + dbFile + ";LOCK_TIMEOUT=60000;AUTO_SERVER=TRUE");
            setProperty("pdb.engine", "com.feedzai.commons.sql.abstraction.engine.impl.H2Engine");
            setProperty("pdb.schema_policy", "create");
          }
        };

    DatabaseEngine engine = DatabaseFactory.getConnection(properties);

    if (!engine.containsEntity(SurveyEntities.CALL_RESULT_TABLE)) {
      engine.addEntity(SurveyEntities.CALL_RESULT_ENTITY);
    }

    return engine;
  }