Пример #1
0
  @Override
  public List<SchemaBean> getAllSchemas() throws DataSourceConnectionException, QueryException {
    final List<SchemaBean> list = new LinkedList<SchemaBean>();

    final Connection con = factory.getConnection();
    PreparedStatement pst = null;
    ResultSet rs = null;
    SchemaBean schema = null;
    try {
      pst = con.prepareStatement(SQL_GET_ALL_SCHEMAS);

      rs = pst.executeQuery();
      while (rs.next()) {
        schema = new SchemaBean();
        schema.setSchemaid(rs.getInt(1));
        schema.setName(rs.getString(2));
        schema.setCreationDate(rs.getDate(3));
        list.add(schema);
      }
    } catch (final SQLException ex) {
      log.error("An error ocurred when trying to get all schemas", ex);
      throw new QueryException(ex);
    } finally {
      try {
        if (rs != null) {
          rs.close();
        }
        if (pst != null) {
          pst.close();
        }
      } catch (final SQLException ex) {
        log.error("Error trying to close a resultset or a prepared statement", ex);
      }

      rs = null;
      pst = null;
    }
    return list;
  }
Пример #2
0
  @Override
  public SchemaBean getSchema(final String schemaName)
      throws DataSourceConnectionException, QueryException {

    final Connection con = factory.getConnection();
    PreparedStatement pst = null;
    ResultSet rs = null;
    SchemaBean schema = null;
    try {
      pst = con.prepareStatement(SQL_GET_SCHEMA);
      pst.setString(1, schemaName);
      rs = pst.executeQuery();
      if (rs.next()) {
        schema = new SchemaBean();
        schema.setSchemaid(rs.getInt(1));
        schema.setName(rs.getString(2));
        schema.setCreationDate(rs.getDate(3));
      }
    } catch (final SQLException ex) {
      log.error("An error ocurred when trying to get a schema by its name", ex);
      throw new QueryException(ex);
    } finally {
      try {
        if (rs != null) {
          rs.close();
        }
        if (pst != null) {
          pst.close();
        }
      } catch (final SQLException ex) {
        log.error("Error trying to close a resultset or a prepared statement", ex);
      }
      rs = null;
      pst = null;
    }
    return schema;
  }
Пример #3
0
  @Override
  public SchemaBean newSchema(final String schemaName, final List<String> validNamespaces)
      throws SchemaNameAlreadyExistsException, DataSourceConnectionException, QueryException {

    log.debug(
        "Client asks for a new schema with the following values:" + "schemaName = " + schemaName);
    // verify if the schemaName already exists
    SchemaBean sbean = null;
    if (this.getSchema(schemaName) != null) {
      log.debug("The schema name already exists in the datasource");
      throw new SchemaNameAlreadyExistsException();
    }
    Connection con = factory.getConnection();
    PreparedStatement pst = null;
    PreparedStatement pstName = null;
    ResultSet rs = null;
    try {

      final long schemaId = this.getSchemaNextId();

      pst = con.prepareStatement(SQL_NEW_SCHEMA, Statement.RETURN_GENERATED_KEYS);
      pst.setLong(1, schemaId);
      pst.setString(2, schemaName);
      final Date schemadate = new Date();
      final java.sql.Date sqldate = new java.sql.Date(schemadate.getTime());
      pst.setDate(3, sqldate);
      pst.executeUpdate();

      con.commit();

      // rs = pst.getGeneratedKeys();
      // rs.next();
      // final int schemaid = rs.getLong(1);
      final int schemaid = (int) schemaId;

      // now save the valid namespaces
      if (validNamespaces != null && validNamespaces.size() > 0) {
        final Iterator<String> namespaces = validNamespaces.iterator();
        pstName = con.prepareStatement(SQL_NEW_VALID_NAMESPACE);
        pstName.setInt(1, schemaid);
        while (namespaces.hasNext()) {
          final String namespace = namespaces.next();
          pstName.setString(2, namespace);
          pstName.executeUpdate();
        }
      }

      // create the bean
      sbean = new SchemaBean();
      sbean.setName(schemaName);
      sbean.setSchemaid(schemaid);
      sbean.setCreationDate(schemadate);

    } catch (final SQLException ex) {
      log.error("Error trying to create a new Schema", ex);
      throw new QueryException(ex);
    } finally {
      try {
        if (rs != null) {
          rs.close();
        }
        if (pst != null) {
          pst.close();
        }
        if (pstName != null) {
          pstName.close();
        }

      } catch (final SQLException ex) {
        log.error("Error trying to close a resultset or a prepared statement", ex);
      }
      rs = null;
      pst = null;
      pstName = null;
      con = null;
    }
    return sbean;
  }