Exemplo n.º 1
0
 @Test
 public void testIteration() {
   k1.putLong(0, 18);
   v1.putLong(0, 19);
   k2.putLong(0, 20);
   v2.putLong(0, 21);
   db.put(k1, v1, 0);
   db.put(k2, v2, 0);
   List<Long> result = new ArrayList<>();
   try (Transaction tx = env.createWriteTransaction()) {
     try (Cursor cursor = db.openCursor(tx)) {
       DirectBuffer k = new DirectBuffer();
       DirectBuffer v = new DirectBuffer();
       for (int rc = cursor.position(k, v, FIRST);
           rc != NOTFOUND;
           rc = cursor.position(k, v, NEXT)) {
         result.add(k.getLong(0));
       }
     }
     tx.commit();
   }
   assertThat(result.size(), is(2));
   assertThat(result.get(0), is(18L));
   assertThat(result.get(1), is(20L));
 }
Exemplo n.º 2
0
  @Test
  public void testCursorPutAndGet() throws Exception {
    k1.putLong(0, 14);
    v1.putLong(0, 15);
    k2.putLong(0, 16);
    v2.putLong(0, 17);

    try (Transaction tx = env.createWriteTransaction()) {
      try (Cursor cursor = db.openCursor(tx)) {
        cursor.put(k1, v1, 0);
        cursor.put(k2, v2, 0);
      }
      tx.commit();
    }

    DirectBuffer k = new DirectBuffer();
    DirectBuffer v = new DirectBuffer();

    try (Transaction tx = env.createReadTransaction()) {
      try (Cursor cursor = db.openCursor(tx)) {
        cursor.position(k, v, GetOp.FIRST);
        assertThat(k.getLong(0), is(14L));
        assertThat(v.getLong(0), is(15L));

        cursor.position(k, v, GetOp.NEXT);
        assertThat(k.getLong(0), is(16L));
        assertThat(v.getLong(0), is(17L));
      }
    }
  }
Exemplo n.º 3
0
  /** deletes the chosen attributes */
  public void deleteAttributes() {
    ListSelectorDialog dialog;
    ArffSortedTableModel model;
    Object[] atts;
    int[] indices;
    int i;
    JList list;
    int result;

    list = new JList(getAttributes());
    dialog = new ListSelectorDialog(null, list);
    result = dialog.showDialog();

    if (result != ListSelectorDialog.APPROVE_OPTION) return;

    atts = list.getSelectedValues();

    // really?
    if (ComponentHelper.showMessageBox(
            getParent(),
            "Confirm...",
            "Do you really want to delete these " + atts.length + " attributes?",
            JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE)
        != JOptionPane.YES_OPTION) return;

    model = (ArffSortedTableModel) m_TableArff.getModel();
    indices = new int[atts.length];
    for (i = 0; i < atts.length; i++) indices[i] = model.getAttributeColumn(atts[i].toString());

    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    model.deleteAttributes(indices);
    setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  }
Exemplo n.º 4
0
  @Test
  public void testCursorSeekRange() throws Exception {
    ByteBuffer byteBuffer = ByteBuffer.allocateDirect(8);
    k1.putLong(0, 18);
    v1.putLong(0, 19);
    k2.putLong(0, 20);
    v2.putLong(0, 21);

    try (Transaction tx = env.createWriteTransaction()) {
      try (Cursor cursor = db.openCursor(tx)) {
        cursor.put(k1, v1, 0);
        cursor.put(k2, v2, 0);
      }
      tx.commit();
    }

    try (Transaction tx = env.createReadTransaction()) {
      try (Cursor cursor = db.openCursor(tx)) {
        DirectBuffer k = new DirectBuffer(byteBuffer);
        DirectBuffer v = new DirectBuffer();
        k.putLong(0, 10);

        cursor.seekPosition(k, v, SeekOp.RANGE);
        assertThat(k.getLong(0), is(18L));
        assertThat(v.getLong(0), is(19L));

        k.wrap(byteBuffer);
        k.putLong(0, 19);
        cursor.seekPosition(k, v, SeekOp.RANGE);
        assertThat(k.getLong(0), is(20L));
        assertThat(v.getLong(0), is(21L));
      }
    }
  }
Exemplo n.º 5
0
  private Cursor initServlet(HttpServletRequest request) {
    String element = request.getParameter("element");
    String offsetString = request.getParameter("offset");
    String reinit = request.getParameter("reinit");
    String backend = request.getParameter("backend");

    if (reinit != null) {
      log.info("Forcing reinitialization...");
      Parametro parametro = new Parametro(ParameterService.ID_STARTUP_DATE);
      parameterService.persistParametro(parametro);
    }

    Long offset = null;
    try {
      if (StringUtils.isNotEmpty(offsetString)) {
        offset = Long.valueOf(offsetString);
      }
    } catch (NumberFormatException e) {
      log.error("Error getting offset cursor " + request.getParameter("offset"));
    }

    Cursor cursor = new Cursor(element, offset, StringUtils.isNotEmpty(backend));
    log.info("Cursor: " + cursor.toString());
    return cursor;
  }
Exemplo n.º 6
0
  public List<DBObject> getSourceBrowsers() {

    DBObject groupFields = new BasicDBObject("_id", "$device");
    groupFields.put("sum", new BasicDBObject("$sum", "$sum"));
    DBObject group = new BasicDBObject("$group", groupFields);
    DBObject sort = new BasicDBObject("$sort", new BasicDBObject("sum", 1));

    List<DBObject> pipeline = Arrays.asList(group, sort);

    // allowDiskUse
    AggregationOptions options =
        AggregationOptions.builder().allowDiskUse(true).batchSize(10000).build();
    Cursor cursor = device.aggregate(pipeline, options);

    List<DBObject> list = new ArrayList<DBObject>();
    while (cursor.hasNext()) {
      DBObject object = cursor.next();
      DBObject newObj = new BasicDBObject();
      newObj.put("device", object.get("_id"));
      newObj.put("sum", object.get("sum"));
      list.add(newObj);
    }
    cursor.close();
    return list;
  }
Exemplo n.º 7
0
  public int dump(String filenameOrDirectory, PrintStream out, TimeZone timeZone)
      throws IOException {
    int logsFound = 0;
    for (String fileName : filenamesOf(filenameOrDirectory, getLogPrefix())) {
      logsFound++;
      out.println("=== " + fileName + " ===");
      StoreChannel fileChannel = fileSystem.open(new File(fileName), "r");
      ByteBuffer buffer = ByteBuffer.allocateDirect(9 + Xid.MAXGTRIDSIZE + Xid.MAXBQUALSIZE * 10);
      long logVersion, prevLastCommittedTx;
      try {
        long[] header = VersionAwareLogEntryReader.readLogHeader(buffer, fileChannel, false);
        logVersion = header[0];
        prevLastCommittedTx = header[1];
      } catch (IOException ex) {
        out.println("Unable to read timestamp information, no records in logical log.");
        out.println(ex.getMessage());
        fileChannel.close();
        throw ex;
      }
      out.println(
          "Logical log version: "
              + logVersion
              + " with prev committed tx["
              + prevLastCommittedTx
              + "]");

      LogDeserializer deserializer = new LogDeserializer(buffer, instantiateCommandReaderFactory());
      PrintingConsumer consumer = new PrintingConsumer(out, timeZone);

      try (Cursor<LogEntry, IOException> cursor = deserializer.cursor(fileChannel)) {
        while (cursor.next(consumer)) ;
      }
    }
    return logsFound;
  }
 /**
  * Reads a Double out of a column in a Cursor and writes it to a ContentValues. Adds nothing to
  * the ContentValues if the column isn't present or if its value is null.
  *
  * @param cursor The cursor to read from
  * @param column The column to read
  * @param values The {@link ContentValues} to put the value into
  */
 public static void cursorDoubleToContentValuesIfPresent(
     Cursor cursor, ContentValues values, String column) {
   final int index = cursor.getColumnIndexOrThrow(column);
   if (!cursor.isNull(index)) {
     values.put(column, cursor.getDouble(index));
   }
 }
Exemplo n.º 9
0
 @Test
 public void testGetInt() throws Exception {
   List<Query.Type> types =
       Arrays.asList(
           Query.Type.INT8,
           Query.Type.UINT8,
           Query.Type.INT16,
           Query.Type.UINT16,
           Query.Type.INT24,
           Query.Type.UINT24,
           Query.Type.INT32);
   for (Query.Type type : types) {
     try (Cursor cursor =
         new SimpleCursor(
             QueryResult.newBuilder()
                 .addFields(Field.newBuilder().setName("col1").setType(type).build())
                 .addFields(Field.newBuilder().setName("null").setType(type).build())
                 .addRows(
                     Query.Row.newBuilder()
                         .addLengths("12345".length())
                         .addLengths(-1) // SQL NULL
                         .setValues(ByteString.copyFromUtf8("12345")))
                 .build())) {
       Row row = cursor.next();
       Assert.assertNotNull(row);
       Assert.assertEquals(12345, row.getInt("col1"));
       Assert.assertFalse(row.wasNull());
       Assert.assertEquals(0, row.getInt("null"));
       Assert.assertTrue(row.wasNull());
       Assert.assertEquals(null, row.getObject("null", Integer.class));
       Assert.assertTrue(row.wasNull());
     }
   }
 }
    public void mouseMoved(MouseEvent e) {
      EditorImpl.MyScrollBar scrollBar = myEditor.getVerticalScrollBar();
      int buttonHeight = scrollBar.getDecScrollButtonHeight();
      int lineCount =
          getDocument().getLineCount() + myEditor.getSettings().getAdditionalLinesCount();
      if (lineCount == 0) {
        return;
      }

      if (e.getY() < buttonHeight && myErrorStripeRenderer != null) {
        showTrafficLightTooltip(e);
        return;
      }

      if (showToolTipByMouseMove(e, getWidth())) {
        scrollbar.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        return;
      }

      cancelMyToolTips(e, false);

      if (scrollbar.getCursor().equals(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR))) {
        scrollbar.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
      }
    }
Exemplo n.º 11
0
 @Test
 public void testGetBigDecimal() throws Exception {
   List<Query.Type> types = Arrays.asList(Query.Type.DECIMAL);
   for (Query.Type type : types) {
     try (Cursor cursor =
         new SimpleCursor(
             QueryResult.newBuilder()
                 .addFields(Field.newBuilder().setName("col1").setType(type).build())
                 .addFields(Field.newBuilder().setName("null").setType(type).build())
                 .addRows(
                     Query.Row.newBuilder()
                         .addLengths("1234.56789".length())
                         .addLengths(-1) // SQL NULL
                         .setValues(ByteString.copyFromUtf8("1234.56789")))
                 .build())) {
       Row row = cursor.next();
       Assert.assertNotNull(row);
       Assert.assertEquals(
           new BigDecimal(BigInteger.valueOf(123456789), 5), row.getBigDecimal("col1"));
       Assert.assertFalse(row.wasNull());
       Assert.assertEquals(null, row.getBigDecimal("null"));
       Assert.assertTrue(row.wasNull());
     }
   }
 }
Exemplo n.º 12
0
 @Test
 public void testGetBytes() throws Exception {
   List<Query.Type> types =
       Arrays.asList(
           Query.Type.TEXT,
           Query.Type.BLOB,
           Query.Type.VARCHAR,
           Query.Type.VARBINARY,
           Query.Type.CHAR,
           Query.Type.BINARY,
           Query.Type.BIT);
   for (Query.Type type : types) {
     try (Cursor cursor =
         new SimpleCursor(
             QueryResult.newBuilder()
                 .addFields(Field.newBuilder().setName("col1").setType(type).build())
                 .addFields(Field.newBuilder().setName("null").setType(type).build())
                 .addRows(
                     Query.Row.newBuilder()
                         .addLengths("hello world".length())
                         .addLengths(-1) // SQL NULL
                         .setValues(ByteString.copyFromUtf8("hello world")))
                 .build())) {
       Row row = cursor.next();
       Assert.assertNotNull(row);
       Assert.assertArrayEquals("hello world".getBytes("UTF-8"), row.getBytes("col1"));
       Assert.assertFalse(row.wasNull());
       Assert.assertEquals(null, row.getBytes("null"));
       Assert.assertTrue(row.wasNull());
     }
   }
 }
Exemplo n.º 13
0
 @Test
 public void testGetTimestamp() throws Exception {
   List<Query.Type> types = Arrays.asList(Query.Type.DATETIME, Query.Type.TIMESTAMP);
   for (Query.Type type : types) {
     try (Cursor cursor =
         new SimpleCursor(
             QueryResult.newBuilder()
                 .addFields(Field.newBuilder().setName("col1").setType(type).build())
                 .addFields(Field.newBuilder().setName("null").setType(type).build())
                 .addRows(
                     Query.Row.newBuilder()
                         .addLengths("2008-01-02 14:15:16.123456".length())
                         .addLengths(-1) // SQL NULL
                         .setValues(ByteString.copyFromUtf8("2008-01-02 14:15:16.123456")))
                 .build())) {
       Row row = cursor.next();
       Assert.assertNotNull(row);
       Assert.assertEquals(Timestamp.valueOf("2008-01-02 14:15:16.123456"), row.getObject("col1"));
       Assert.assertEquals(
           Timestamp.valueOf("2008-01-02 14:15:16.123456"), row.getTimestamp("col1"));
       Timestamp ts = new Timestamp(1199283316000L);
       ts.setNanos(123456000);
       Assert.assertEquals(ts, row.getTimestamp("col1", GMT));
       Assert.assertFalse(row.wasNull());
       Assert.assertEquals(null, row.getTimestamp("null"));
       Assert.assertTrue(row.wasNull());
     }
   }
 }
Exemplo n.º 14
0
 @Test
 public void testGetDate() throws Exception {
   List<Query.Type> types = Arrays.asList(Query.Type.DATE);
   for (Query.Type type : types) {
     try (Cursor cursor =
         new SimpleCursor(
             QueryResult.newBuilder()
                 .addFields(Field.newBuilder().setName("col1").setType(type).build())
                 .addFields(Field.newBuilder().setName("null").setType(type).build())
                 .addRows(
                     Query.Row.newBuilder()
                         .addLengths("2008-01-02".length())
                         .addLengths(-1) // SQL NULL
                         .setValues(ByteString.copyFromUtf8("2008-01-02")))
                 .build())) {
       Row row = cursor.next();
       Assert.assertNotNull(row);
       Assert.assertEquals(Date.valueOf("2008-01-02"), row.getObject("col1"));
       Assert.assertEquals(Date.valueOf("2008-01-02"), row.getDate("col1"));
       Assert.assertEquals(new Date(1199232000000L), row.getDate("col1", GMT));
       Assert.assertFalse(row.wasNull());
       Assert.assertEquals(null, row.getDate("null"));
       Assert.assertTrue(row.wasNull());
     }
   }
 }
Exemplo n.º 15
0
 public synchronized void close__wrappee__base() throws DatabaseException {
   StringBuffer errors = null;
   checkEnv();
   checkProhibitedDbState(CLOSED, "Can't close Database:");
   this.hook44();
   removeAllTriggers();
   envHandle.removeReferringHandle(this);
   if (cursors.size() > 0) {
     errors = new StringBuffer("There are open cursors against the database.\n");
     errors.append("They will be closed.\n");
     Iterator iter = cursors.copy().iterator();
     while (iter.hasNext()) {
       Cursor dbc = (Cursor) iter.next();
       try {
         dbc.close();
       } catch (DatabaseException DBE) {
         errors.append("Exception while closing cursors:\n");
         errors.append(DBE.toString());
       }
     }
   }
   if (databaseImpl != null) {
     databaseImpl.removeReferringHandle(this);
     databaseImpl = null;
     handleLocker.setHandleLockOwner(true, this, true);
     handleLocker.operationEnd(true);
     state = CLOSED;
   }
   if (errors != null) {
     throw new DatabaseException(errors.toString());
   }
 }
  private boolean findEntry() {
    Cursor waitCursor = new Cursor(shell.getDisplay(), SWT.CURSOR_WAIT);
    shell.setCursor(waitCursor);

    boolean matchCase = searchDialog.getMatchCase();
    boolean matchWord = searchDialog.getMatchWord();
    String searchString = searchDialog.getSearchString();
    int column = searchDialog.getSelectedSearchArea();

    searchString = matchCase ? searchString : searchString.toLowerCase();

    boolean found = false;
    if (searchDialog.getSearchDown()) {
      for (int i = table.getSelectionIndex() + 1; i < table.getItemCount(); i++) {
        if (found = findMatch(searchString, table.getItem(i), column, matchWord, matchCase)) {
          table.setSelection(i);
          break;
        }
      }
    } else {
      for (int i = table.getSelectionIndex() - 1; i > -1; i--) {
        if (found = findMatch(searchString, table.getItem(i), column, matchWord, matchCase)) {
          table.setSelection(i);
          break;
        }
      }
    }

    shell.setCursor(null);
    if (waitCursor != null) waitCursor.dispose();

    return found;
  }
Exemplo n.º 17
0
  public void runTest(DatabaseType type) throws DatabaseException, FileNotFoundException {
    int i;
    DatabaseConfig conf = new DatabaseConfig();
    conf.setErrorStream(TestUtils.getErrorStream());
    conf.setErrorPrefix("HashCompareTest");
    conf.setType(type);
    if (type == DatabaseType.HASH) {
      conf.setHashComparator(new HashComparator());
    } else conf.setBtreeComparator(new BtreeComparator());
    conf.setAllowCreate(true);

    Database db = new Database(HASHCOMPARETEST_DBNAME, null, conf);

    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry data = new DatabaseEntry("world".getBytes());
    for (i = 0; i < 100; i++) {
      key.setData((new String("key" + i)).getBytes());
      db.put(null, key, data);
    }
    i = 0;
    Cursor dbc;
    dbc = db.openCursor(null, CursorConfig.DEFAULT);
    while (dbc.getNext(key, data, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
      ++i;
    }
    //		System.out.println("retrieved " + i + " entries");
    dbc.close();
    db.close();
  }
Exemplo n.º 18
0
  /*
   * Atualiza a tabela a cada 5 minutos
   */
  public void atualizacaoAutomaticaTabela() {

    this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

    ActionListener acao =
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent ae) {

            final Progress p = new Progress();
            p.setVisible(true);
            SwingWorker worker =
                new SwingWorker() {

                  @Override
                  protected Object doInBackground() throws Exception {
                    atualizaTabela();
                    return null;
                  }

                  @Override
                  protected void done() {
                    p.setVisible(false);
                  }
                };
            worker.execute();
          }
        };

    timer = new Timer(5000 * 60, acao); // a cada 5 minutos executa o metodo
    timer.start();
    this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  }
Exemplo n.º 19
0
  /** deletes the currently selected attribute */
  public void deleteAttribute() {
    ArffSortedTableModel model;

    // no column selected?
    if (m_CurrentCol == -1) return;

    model = (ArffSortedTableModel) m_TableArff.getModel();

    // really an attribute column?
    if (model.getAttributeAt(m_CurrentCol) == null) return;

    // really?
    if (ComponentHelper.showMessageBox(
            getParent(),
            "Confirm...",
            "Do you really want to delete the attribute '"
                + model.getAttributeAt(m_CurrentCol).name()
                + "'?",
            JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE)
        != JOptionPane.YES_OPTION) return;

    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    model.deleteAttributeAt(m_CurrentCol);
    setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  }
  /**
   * Returns the comparison result of the next row from each cursor. If one cursor has no more rows
   * but the other does then subsequent calls to this will indicate that the remaining rows are
   * unique.
   *
   * <p>The caller must check that hasNext() returns true before calling this.
   *
   * <p>Once next() has been called the cursors specified in the result of the call to next() are
   * guaranteed to point to the row that was indicated. Reading values from the cursor that was not
   * indicated in the call to next() will result in undefined behavior.
   *
   * @return LEFT, if the row pointed to by the left cursor is unique, RIGHT if the row pointed to
   *     by the right cursor is unique, BOTH if the rows in both cursors are the same.
   */
  public Result next() {
    if (!hasNext()) {
      throw new IllegalStateException("you must only call next() when hasNext() is true");
    }
    incrementCursors();
    assert hasNext();

    boolean hasLeft = !mCursorLeft.isAfterLast();
    boolean hasRight = !mCursorRight.isAfterLast();

    if (hasLeft && hasRight) {
      populateValues(mValues, mCursorLeft, mColumnsLeft, 0 /* start filling at index 0 */);
      populateValues(mValues, mCursorRight, mColumnsRight, 1 /* start filling at index 1 */);
      switch (compareStrings(mValues)) {
        case -1:
          mCompareResult = Result.LEFT;
          break;
        case 0:
          mCompareResult = Result.BOTH;
          break;
        case 1:
          mCompareResult = Result.RIGHT;
          break;
      }
    } else if (hasLeft) {
      mCompareResult = Result.LEFT;
    } else {
      assert hasRight;
      mCompareResult = Result.RIGHT;
    }
    mCompareResultIsValid = true;
    return mCompareResult;
  }
Exemplo n.º 21
0
 /**
  * Checks the current row, updating state and releasing locators on the server as required.
  *
  * <p>This method should only be called once per valid row in the result set.
  *
  * @param cursor the cursor object to use for releasing the locators
  * @throws SqlException if releasing the locators on the server fails
  */
 void checkCurrentRow(Cursor cursor) throws SqlException {
   if (this.doRelease) {
     CallableLocatorProcedures procs = cursor.getLocatorProcedures();
     for (int i = 0; i < this.columns.length; i++) {
       // Note the conversion from 1-based to 0-based index when
       // checking if the column has a NULL value.
       if (!this.published[i] && !cursor.isNull_[this.columns[i] - 1]) {
         // Fetch the locator so we can free it.
         int locator = cursor.locator(this.columns[i]);
         if (locator == this.lastLocatorSeen[i]) {
           // We are being called on the same row twice...
           return;
         } else if (locator == Lob.INVALID_LOCATOR) {
           // The locator is invalid, probably because the
           // database is running in soft upgrade mode and
           // doesn't have the neccessary stored procedures.
           // Don't try to release an invalid locator.
           return;
         }
         this.lastLocatorSeen[i] = locator;
         if (this.isBlob[i]) {
           procs.blobReleaseLocator(locator);
         } else {
           procs.clobReleaseLocator(locator);
         }
       }
     }
     // Reset state for the next row.
     Arrays.fill(this.published, false);
   }
 }
Exemplo n.º 22
0
  // region Private Methods
  private void onOK() {
    this.connectionDetails =
        new ConnectionDetails() {
          {
            setZookeeper(
                new ServerDetails(
                    ConnectionDetailsDialog.this.zooKeeperServer.getText(),
                    ConnectionDetailsDialog.this.zooKeeperPort.getValue().toString()));
          }
        };

    this.contentPane.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

    boolean canConnect = false;

    try {
      canConnect = this.connectionDetails.canConnect();
    } finally {
      this.contentPane.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    }

    if (canConnect) {
      dispose();
    } else {
      JOptionPane.showMessageDialog(
          ConnectionDetailsDialog.this,
          "Failed to connect to hbase.\n\nMake sure you have access to all hadoop nodes\nIn case you don't, map the nodes in your hosts file.",
          "Connection failed...",
          JOptionPane.ERROR_MESSAGE);

      ConnectionManager.release(connectionDetails);
      connectionDetails = null;
    }
  }
Exemplo n.º 23
0
 @Test
 public void testGetBytes() throws Exception {
   List<Field.Type> types =
       Arrays.asList(
           Field.Type.TYPE_VARCHAR,
           Field.Type.TYPE_BIT,
           Field.Type.TYPE_TINY_BLOB,
           Field.Type.TYPE_MEDIUM_BLOB,
           Field.Type.TYPE_LONG_BLOB,
           Field.Type.TYPE_BLOB,
           Field.Type.TYPE_VAR_STRING,
           Field.Type.TYPE_STRING,
           Field.Type.TYPE_GEOMETRY);
   for (Field.Type type : types) {
     try (Cursor cursor =
         new SimpleCursor(
             QueryResult.newBuilder()
                 .addFields(Field.newBuilder().setName("col0").setType(type).build())
                 .addRows(Row.newBuilder().addValues(ByteString.copyFromUtf8("hello world")))
                 .build())) {
       cursor.next();
       Assert.assertArrayEquals("hello world".getBytes("UTF-8"), cursor.getBytes("col0"));
     }
   }
 }
Exemplo n.º 24
0
  protected boolean refreshFeatureSelection(String layerName, String id) {

    try {
      if (id == null || geopistaEditor == null) return false;
      this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
      geopistaEditor.getSelectionManager().clear();
      GeopistaLayer geopistaLayer =
          (GeopistaLayer) geopistaEditor.getLayerManager().getLayer(layerName);
      Collection collection = searchByAttribute(geopistaLayer, 0, id);
      Iterator it = collection.iterator();
      if (it.hasNext()) {
        Feature feature = (Feature) it.next();
        geopistaEditor.select(geopistaLayer, feature);
      }
      geopistaEditor.zoomToSelected();
      this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
      return true;
    } catch (Exception ex) {
      this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
      StringWriter sw = new StringWriter();
      PrintWriter pw = new PrintWriter(sw);
      ex.printStackTrace(pw);
      logger.error("Exception: " + sw.toString());
      return false;
    }
  }
Exemplo n.º 25
0
  public OperationStatus getSearchBoth(
      Transaction txn, DatabaseEntry key, DatabaseEntry data, LockMode lockMode)
      throws DatabaseException {

    checkEnv();
    DatabaseUtil.checkForNullDbt(key, "key", true);
    DatabaseUtil.checkForNullDbt(data, "data", true);
    checkRequiredDbState(OPEN, "Can't call Database.getSearchBoth:");
    trace(Level.FINEST, "Database.getSearchBoth", txn, key, data, lockMode);

    CursorConfig cursorConfig = CursorConfig.DEFAULT;
    if (lockMode == LockMode.READ_COMMITTED) {
      cursorConfig = CursorConfig.READ_COMMITTED;
      lockMode = null;
    }

    Cursor cursor = null;
    try {
      cursor = new Cursor(this, txn, cursorConfig);
      cursor.setNonCloning(true);
      return cursor.search(key, data, lockMode, SearchMode.BOTH);
    } finally {
      if (cursor != null) {
        cursor.close();
      }
    }
  }
 public static void dumpCurrentRow(Cursor paramCursor, StringBuilder paramStringBuilder)
 {
   String[] arrayOfString = paramCursor.getColumnNames();
   paramStringBuilder.append(paramCursor.getPosition() + " {\n");
   int j = arrayOfString.length;
   int i = 0;
   for (;;)
   {
     if (i < j) {
       try
       {
         String str1 = paramCursor.getString(i);
         paramStringBuilder.append("   " + arrayOfString[i] + '=' + str1 + "\n");
         i += 1;
       }
       catch (SQLiteException localSQLiteException)
       {
         for (;;)
         {
           String str2 = "<unprintable>";
         }
       }
     }
   }
   paramStringBuilder.append("}\n");
 }
 public static void dumpCurrentRow(Cursor paramCursor, PrintStream paramPrintStream)
 {
   String[] arrayOfString = paramCursor.getColumnNames();
   paramPrintStream.println(paramCursor.getPosition() + " {");
   int j = arrayOfString.length;
   int i = 0;
   for (;;)
   {
     if (i < j) {
       try
       {
         String str1 = paramCursor.getString(i);
         paramPrintStream.println("   " + arrayOfString[i] + '=' + str1);
         i += 1;
       }
       catch (SQLiteException localSQLiteException)
       {
         for (;;)
         {
           String str2 = "<unprintable>";
         }
       }
     }
   }
   paramPrintStream.println("}");
 }
 public static void cursorStringToContentValuesIfPresent(Cursor paramCursor, ContentValues paramContentValues, String paramString)
 {
   int i = paramCursor.getColumnIndex(paramString);
   if ((i != -1) && (!paramCursor.isNull(i))) {
     paramContentValues.put(paramString, paramCursor.getString(i));
   }
 }
 public static void cursorRowToContentValues(Cursor paramCursor, ContentValues paramContentValues)
 {
   AbstractWindowedCursor localAbstractWindowedCursor;
   String[] arrayOfString;
   int i;
   if ((paramCursor instanceof AbstractWindowedCursor))
   {
     localAbstractWindowedCursor = (AbstractWindowedCursor)paramCursor;
     arrayOfString = paramCursor.getColumnNames();
     int j = arrayOfString.length;
     i = 0;
     label27:
     if (i >= j) {
       return;
     }
     if ((localAbstractWindowedCursor == null) || (!localAbstractWindowedCursor.isBlob(i))) {
       break label74;
     }
     paramContentValues.put(arrayOfString[i], paramCursor.getBlob(i));
   }
   for (;;)
   {
     i += 1;
     break label27;
     localAbstractWindowedCursor = null;
     break;
     label74:
     paramContentValues.put(arrayOfString[i], paramCursor.getString(i));
   }
 }
Exemplo n.º 30
0
 /** Load the current row. */
 void loadCurrent() {
   synchronized (sync) {
     baseRow = baseCursor.getSearchRow();
     deltaRow = deltaCursor.get();
     needNewDelta = false;
     needNewBase = false;
   }
 }