Package org.eclipse.imp.pdb.facts

Examples of org.eclipse.imp.pdb.facts.ISetWriter


        ResultSet rs = dmd.getTables(null, null, null, new String[] { "TABLE" });
        HashSet<String> tables = new HashSet<String>();
        while (rs.next()) tables.add(rs.getString("TABLE_NAME"));
        rs.close();
       
        ISetWriter setRes = vf.setWriter(TF.stringType());
       
        for (String tableName : tables) {
          setRes.insert(vf.string(tableName));
        }
        return setRes.done();
      } else {
        throw RuntimeExceptionFactory.illegalArgument(connection, null, null, "Connection does not exist.");
      }
    } catch (SQLException sqle) {
      throw RuntimeExceptionFactory.illegalArgument(connection, null, null, addMessage("Could not close the given connection", sqle));
View Full Code Here


        ResultSet rs = dmd.getTables(null, null, null, new String[] { "VIEW" });
        HashSet<String> tables = new HashSet<String>();
        while (rs.next()) tables.add(rs.getString("TABLE_NAME"));
        rs.close();
       
        ISetWriter setRes = vf.setWriter(TF.stringType());
       
        for (String tableName : tables) {
          setRes.insert(vf.string(tableName));
        }
        return setRes.done();
      } else {
        throw RuntimeExceptionFactory.illegalArgument(connection, null, null, "Connection does not exist.");
      }
    } catch (SQLException sqle) {
      throw RuntimeExceptionFactory.illegalArgument(connection, null, null, addMessage("Could not close the given connection", null));
View Full Code Here

        ResultSet rs = dmd.getTables(null, null, null, tableTypes);
        HashSet<String> tables = new HashSet<String>();
        while (rs.next()) tables.add(rs.getString("TABLE_NAME"));
        rs.close();
       
        ISetWriter setRes = vf.setWriter(Table);
       
        for (String tableName : tables) {
          rs = dmd.getColumns(null, null, tableName, null);
          IListWriter listRes = vf.listWriter(Column);
          while (rs.next()) {
            String cn = rs.getString("COLUMN_NAME");
            int dt = rs.getInt("DATA_TYPE");
            String nullable = rs.getString("IS_NULLABLE");
            listRes.append(vf.constructor(column, vf.string(cn), vf.constructor(JDBC.jdbc2rascalType(dt)), nullable.equalsIgnoreCase("YES") ? vf.bool(true) : vf.bool(false)));
          }
          setRes.insert(vf.constructor(table, vf.string(tableName), listRes.done()));
          rs.close();
        }
        return setRes.done();
      } else {
        throw RuntimeExceptionFactory.illegalArgument(connection, null, null, "Connection does not exist.");
      }
    } catch (SQLException sqle) {
      throw RuntimeExceptionFactory.illegalArgument(connection, null, null, addMessage("Could not close the given connection", sqle));
View Full Code Here

        ResultSet rs = stmt.executeQuery();
       
        Type elementType = resultType.getType().getTypeParameters().getFieldType(0);
        int columns = elementType.getArity();

        ISetWriter sw = vf.setWriter(elementType);
        while (rs.next()) {
          IValue tupleValues[] = new IValue[columns];
          for (int idx = 0; idx < columns; ++idx) {
            tupleValues[idx] = JDBC.jdbc2pdbValue(rs, idx + 1, this.vf);
          }
          sw.insert(vf.tuple(tupleValues));
        }
       
        rs.close();
        stmt.close();
       
        return sw.done();
      } else {
        throw RuntimeExceptionFactory.illegalArgument(connection, null, null, "Connection does not exist.");
      }
    } catch (SQLException sqle) {
      throw RuntimeExceptionFactory.illegalArgument(connection, null, null, sqle.getMessage());
View Full Code Here

        PreparedStatement stmt = conn.prepareStatement("SELECT * FROM " + tableName.getValue());
        ResultSet rs = stmt.executeQuery();
       
        Type elementType = JDBC.TF.valueType();

        ISetWriter sw = vf.setWriter(elementType);
        int columns = rs.getMetaData().getColumnCount();
       
        while (rs.next()) {
          IValue tupleValues[] = new IValue[columns];
          for (int idx = 0; idx < columns; ++idx) {
            tupleValues[idx] = JDBC.jdbc2pdbValue(rs, idx + 1, this.vf);
          }
          sw.insert(vf.tuple(tupleValues));
        }
       
        rs.close();
        stmt.close();
       
        return sw.done();
      } else {
        throw RuntimeExceptionFactory.illegalArgument(connection, null, null, "Connection does not exist.");
      }
    } catch (SQLException sqle) {
      throw RuntimeExceptionFactory.illegalArgument(connection, null, null, sqle.getMessage());
View Full Code Here

  public IValue readAUT(IString nameAUTFile){
    Type strType = types.stringType();
    Type intType = types.integerType();
    Type tupleType = types.tupleType(intType, strType, intType);
    java.lang.String fileName = nameAUTFile.getValue();
    ISetWriter rw = values.relationWriter(tupleType);
    BufferedReader bufRead = null;
    try{
      FileReader input = new FileReader(fileName);
      bufRead = new BufferedReader(input);
      java.lang.String line = bufRead.readLine();
      line = bufRead.readLine();
      while(line != null){
        java.lang.String[] fields = line.split("\\\"");
        java.lang.String[] field0 = fields[0].split("[\\(\\s,]");
        java.lang.String[] field2 = fields[2].split("[\\)\\s,]");
        rw.insert(values.tuple(values.integer(field0[1]), values.string(fields[1]), values
            .integer(field2[1])));
        line = bufRead.readLine();
      }
    }catch(IOException ioex){
      throw RuntimeExceptionFactory.io(values.string(ioex.getMessage()), null, null);
    }finally{
      if(bufRead != null){
        try{
          bufRead.close();
        }catch(IOException ioex){/* Ignore. */
        }
      }
    }
    return rw.done();
  }
View Full Code Here

      return t.accept(this);
    }
  }

  private IValue genSet(Type type) {
    ISetWriter writer = vf.setWriter(); // type.writer(vf);

    if (maxDepth <= 0 || (stRandom.nextInt(2) == 0)) {
      return writer.done();
    } else {
      RandomValueTypeVisitor visitor = descend();
      ISet set = (ISet) visitor.generate(type);

      IValue element = null;
      int recursionGuard = 0; // Domain of set can be small.
      while ((element == null || set.contains(element))
          && recursionGuard < 1000) {
        recursionGuard += 1;
        element = visitor.generate(type.getElementType());
      }

      writer.insertAll(set);

      if (element != null) {
        writer.insert(element);
      }
      return writer.done();
    }
  }
View Full Code Here

          throw new ImplementationError("expected to find a holeType, but did not: " + tree);
        }

        @Override
        public IConstructor visitTreeAmb(IConstructor arg)  {
          ISetWriter w = vf.setWriter();
          for (IValue elem : TreeAdapter.getAlternatives(arg)) {
            w.insert(elem.accept(this));
          }
          return arg.set("alternatives", w.done());
        }
      });
  }
View Full Code Here

        }
        elementType = elementType.lub(resultElem.getType());
        results.add(results.size(), resultElem.getValue());
      }
      Type resultType = TF.setType(elementType);
      ISetWriter w = __eval.__getVf().setWriter();
      w.insertAll(results);
      // Was: return makeResult(resultType, applyRules(w.done()));
      return org.rascalmpl.interpreter.result.ResultFactory.makeResult(
          resultType, w.done(), __eval);

    }
View Full Code Here

  public IValue generate(Type t) {
    return t.accept(this);
  }

  private IValue genSet(Type type) {
    ISetWriter writer = vf.setWriter(); // type.writer(vf);

    if (maxDepth <= 0 || (stRandom.nextInt(2) == 0)) {
      return writer.done();
    } else {
      RandomValueTypeVisitor visitor = descend();
      ISet set = (ISet) visitor.generate(type);

      IValue element = null;
      int recursionGuard = 0; // Domain of set can be small.
      while ((element == null || set.contains(element))
          && recursionGuard < 1000) {
        recursionGuard += 1;
        element = visitor.generate(type.getElementType());
      }

      writer.insertAll(set);

      if (element != null) {
        writer.insert(element);
      }
      return writer.done();
    }
  }
View Full Code Here

TOP

Related Classes of org.eclipse.imp.pdb.facts.ISetWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.