Package org.eclipse.imp.pdb.facts

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


     Display.getDefault().syncExec(new Runnable(){

      @Override
      public void run() {
        FontData[] fd =  Display.getDefault().getFontList(null, true);
        IListWriter w = vf.listWriter(tf.stringType());
        for(int i = 0; i < fd.length; i++){
          System.err.println("adding " + fd[i].getName());
          w.append(vf.string(fd[i].getName()));
        }
        res= w.done();
       
      }
     
    });
     return res;
View Full Code Here


      IInteger connectionId = (IInteger) connection.get(0);
      if (connectionMap.containsKey(connectionId)) {
        Connection conn = connectionMap.get(connectionId);
        DatabaseMetaData dmd = conn.getMetaData();
        ResultSet rs = dmd.getTableTypes();
        IListWriter resultWriter = this.vf.listWriter(TF.stringType());
        while (rs.next()) resultWriter.append(this.vf.string(rs.getString(1)));
        rs.close();
        return resultWriter.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

       
        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.");
View Full Code Here

      IInteger connectionId = (IInteger) connection.get(0);
      if (connectionMap.containsKey(connectionId)) {
        Connection conn = connectionMap.get(connectionId);
        DatabaseMetaData dmd = conn.getMetaData();
        ResultSet rs = dmd.getColumns(null, null, tableName.getValue(), 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)));
        }
        rs.close();
        return vf.constructor(table, tableName, listRes.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

      if (idx == 0 && rs.getInt(0) == 1219)
        System.err.println(rs.getDate(6));

      int jdbcColumnType = rs.getMetaData().getColumnType(idx);
      Calendar c = Calendar.getInstance();
      IListWriter lw = null;
      InputStream isr = null;
      int isrRes = -1;
     
      switch(jdbcColumnType) {
        case Types.ARRAY:
          throw new UnsupportedOperation("JDBC Array types are currently not supported", null);
        case Types.BIGINT:
          if (rs.getBigDecimal(idx) != null)
            res = vf.integer(rs.getBigDecimal(idx).toString());
          else
            res = vf.integer(0);
          break;
        case Types.BINARY:
          isr = rs.getBinaryStream(idx);
          lw = vf.listWriter(TypeFactory.getInstance().integerType());
          if (isr != null) {
            isrRes = isr.read();
            while (isrRes != -1) {
              lw.append(vf.integer(isrRes));
              isrRes = isr.read();
            }
          }
          res = lw.done();
          break;
        case Types.BIT:
          res = vf.bool(rs.getBoolean(idx));
          break;
        case Types.BLOB:
          lw = vf.listWriter(TypeFactory.getInstance().integerType());
          if (rs.getBlob(idx) != null) {
            isr = rs.getBlob(idx).getBinaryStream();
            if (isr != null) {
              isrRes = isr.read();
              while (isrRes != -1) {
                lw.append(vf.integer(isrRes));
                isrRes = isr.read();
              }
            }
          }
          res = lw.done();
          break;
        case Types.BOOLEAN:
          res = vf.bool(rs.getBoolean(idx));
          break;
        case Types.CHAR:
          if (rs.getString(idx) != null)
            res = vf.string(rs.getString(idx));
          else
            res = vf.string("");
          break;
        case Types.CLOB:
          lw = vf.listWriter(TypeFactory.getInstance().integerType());
          if (rs.getClob(idx) != null) {
            isr = rs.getClob(idx).getAsciiStream();
            if (isr != null) {
              isrRes = isr.read();
              while (isrRes != -1) {
                lw.append(vf.integer(isrRes));
                isrRes = isr.read();
              }
            }
          }
          res = lw.done();
          break;
        case Types.DATALINK:
          throw new UnsupportedOperation("JDBC Datalink types are currently not supported", null);
        case Types.DATE:
          if (rs.getDate(idx) != null) {
            c = Calendar.getInstance();
            c.setTimeInMillis(rs.getDate(idx).getTime());
//            c.setTime(rs.getDate(idx));
          }
          res = vf.date(c.get(Calendar.YEAR), c.get(Calendar.MONTH)+1, c.get(Calendar.DAY_OF_MONTH));
          break;
        case Types.DECIMAL:
          if (rs.getBigDecimal(idx) != null)
            res = vf.real(rs.getBigDecimal(idx).toString());
          else
            res = vf.real(0.0);
          break;
        case Types.DISTINCT:
          throw new UnsupportedOperation("JDBC Distinct types are currently not supported", null);
        case Types.DOUBLE:
          res = vf.real(rs.getDouble(idx));
          break;
        case Types.FLOAT:
          res = vf.real(rs.getFloat(idx));
          break;
        case Types.INTEGER:
          res = vf.integer(rs.getInt(idx));
          break;
        case Types.JAVA_OBJECT:
          throw new UnsupportedOperation("JDBC JavaObject types are currently not supported", null);
        case Types.LONGNVARCHAR:
          if (rs.getString(idx) != null)
            res = vf.string(rs.getString(idx));
          else
            res = vf.string("");
          break;
        case Types.LONGVARBINARY:
          lw = vf.listWriter(TypeFactory.getInstance().integerType());
          isr = rs.getBinaryStream(idx);
          if (isr != null) {
            isrRes = isr.read();
            while (isrRes != -1) {
              lw.append(vf.integer(isrRes));
              isrRes = isr.read();
            }
          }
          res = lw.done();
          break;
        case Types.LONGVARCHAR:
          if (rs.getString(idx) != null)
            res = vf.string(rs.getString(idx));
          else
            res = vf.string("");
          break;
        case Types.NCHAR:
          if (rs.getString(idx) != null)
            res = vf.string(rs.getString(idx));
          else
            res = vf.string("");
          break;
        case Types.NCLOB:
          lw = vf.listWriter(TypeFactory.getInstance().integerType());
          if (rs.getNClob(idx) != null) {
            isr = rs.getNClob(idx).getAsciiStream();
            if (isr != null) {
              isrRes = isr.read();
              while (isrRes != -1) {
                lw.append(vf.integer(isrRes));
                isrRes = isr.read();
              }
            }
          }
          res = lw.done();
          break;
        case Types.NULL:
          throw new UnsupportedOperation("JDBC Null types are currently not supported", null);
        case Types.NUMERIC:
          if (rs.getBigDecimal(idx) != null) {
            res = vf.real(rs.getBigDecimal(idx).toString());
          } else {
            res = vf.real(0);
          }
          break;
        case Types.NVARCHAR:
          if (rs.getString(idx) != null)
            res = vf.string(rs.getString(idx));
          else
            res = vf.string("");
          break;
        case Types.OTHER:
          throw new UnsupportedOperation("JDBC Other types are currently not supported", null);
        case Types.REAL:
          res = vf.real(rs.getDouble(idx));
          break;
        case Types.REF:
          throw new UnsupportedOperation("JDBC Ref types are currently not supported", null);
        case Types.ROWID:
          throw new UnsupportedOperation("JDBC RowID types are currently not supported", null);
        case Types.SMALLINT:
          res = vf.integer(rs.getInt(idx));
          break;
        case Types.SQLXML:
          throw new UnsupportedOperation("JDBC SQLXML types are currently not supported", null);
        case Types.STRUCT:
          throw new UnsupportedOperation("JDBC Struct types are currently not supported", null);
        case Types.TIME:
          if (rs.getTime(idx) != null) {
            c = Calendar.getInstance();
            c.setTimeInMillis(rs.getDate(idx).getTime());
          }
          res = vf.time(c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), c.get(Calendar.SECOND), c.get(Calendar.MILLISECOND));
          break;
        case Types.TIMESTAMP:
          if (rs.getTimestamp(idx) != null) {
            c = Calendar.getInstance();
            c.setTimeInMillis(rs.getDate(idx).getTime());
          }
          res = vf.datetime(c.get(Calendar.YEAR), c.get(Calendar.MONTH)+1, c.get(Calendar.DAY_OF_MONTH), c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), c.get(Calendar.SECOND), c.get(Calendar.MILLISECOND));
          break;
        case Types.TINYINT:
          res = vf.integer(rs.getInt(idx));
          break;
        case Types.VARBINARY:
          lw = vf.listWriter(TypeFactory.getInstance().integerType());
          isr = rs.getBinaryStream(idx);
          if (isr != null) {
            isrRes = isr.read();
            while (isrRes != -1) {
              lw.append(vf.integer(isrRes));
              isrRes = isr.read();
            }
          }
          res = lw.done();
          break;
        case Types.VARCHAR:
          if (rs.getString(idx) != null)
            res = vf.string(rs.getString(idx));
          else
View Full Code Here

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

        IListWriter lw = vf.listWriter(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);
          }
          lw.append(vf.tuple(tupleValues));
        }
       
        rs.close();
        stmt.close();
       
        return lw.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

        ResultSet rs = stmt.executeQuery();
       
        Type elementType = JDBC.TF.valueType();
        int columns = rs.getMetaData().getColumnCount();

        IListWriter lw = vf.listWriter(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);
          }
          lw.append(vf.tuple(tupleValues));
        }
       
        rs.close();
        stmt.close();
       
        return lw.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

      }
      Type argTypes = ((FunctionType) function.ftype).getArgumentTypes();
      if(function.nformals == arity && ((IValue) stack[start + posArityMinusOne]).getType().isSubtypeOf(argTypes.getFieldType(posArityMinusOne))) {
        this.stack[this.sp++] = stack[start + posArityMinusOne];
      } else {
        IListWriter writer = ValueFactoryFactory.getValueFactory().listWriter();
        for(int i = posArityMinusOne; i < arity - 1; i++) {
          writer.append((IValue) stack[start + i]);
        }
        this.stack[this.sp++] = writer.done();
      }
      this.stack[this.sp++] = stack[start + arity - 1]; // The keyword arguments
    }   
    this.sp = function.nlocals;
    return start;
View Full Code Here

  public IValue visitInteger(Type type) {
    return vf.integer(stRandom.nextInt());
  }
 
  private IValue genList(Type type){
    IListWriter writer = vf.listWriter(); // type.writer(vf);

    if (maxDepth <= 0 || (stRandom.nextInt(2) == 0)) {
      return writer.done();
    } else {
      RandomValueTypeVisitor visitor = descend();
      IValue element = visitor.generate(type.getElementType());
      if (element != null) {
        writer.append(element);
      }
      writer.appendAll((IList) visitor.generate(type));
      return writer.done();
    }
  }
View Full Code Here

         if (pattern != null) {
           IConstructor parsedFragment = parseFragment(eval, env, (IConstructor) TreeAdapter.getArgs(tree).get(0), location);
           return TreeAdapter.setArgs(tree, vf.list(parsedFragment));
         }
         else {
           IListWriter w = vf.listWriter();
           IList args = TreeAdapter.getArgs(tree);
           for (IValue arg : args) {
             w.append(arg.accept(this));
           }
           args = w.done();
          
           return TreeAdapter.setArgs(tree, args);
         }
       }
View Full Code Here

TOP

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

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.