Package org.tarantool.core

Examples of org.tarantool.core.Tuple


   * @param args
   * @return tuple created from given args
   */
  public Tuple create(Object... args) {

    Tuple tuple = new Tuple(args.length);
    for (int i = 0; i < args.length; i++) {
      Object object = args[i];
      if (object == null) {
        throw new NullPointerException("Null values are not suppored, but argument #" + i + " has null value");
      }
View Full Code Here


          Integer id = Integer.parseInt(values[0]);
          String username = values[1];
          String email = values[2];
          byte[] enabled = { Byte.valueOf(values[3]) };
          Long registered = Long.parseLong(outdf.format(indf.parse(values[4])));
          Tuple tuple = new Tuple(5).setInt(0, id).setString(1, username, "UTF-8").setString(2, email, "UTF-8").setBytes(3, enabled)
              .setLong(4, registered);

          writer.writeRow(0, tuple);
        } else {
          System.err.println("Line should be splited in 5 parts, but has " + values.length + " for " + line);
        }
      } catch (Exception e) {
        System.err.println("Can't parse line " + line);
        e.printStackTrace();
      }
    }
    writer.close();
    reader.close();
    SocketChannelTarantoolConnection con = new SocketChannelTarantoolConnection();
    Tuple t = con.findOne(0, 0, 0, new Tuple(1).setInt(0, 1));
    System.out.println(t.getLong(4));
    con.close();
  }
View Full Code Here

        return 0L;
      }
    };
    TupleSupport ts = new TupleSupport();
    for (int i = 0; i < 10; i++) {
      Tuple tuple = ts.create(i, Long.parseLong("98765432" + i), "Hello world " + i + "!");
      snapshot.writeRow(0, tuple);
    }

    snapshot.close();
    Assert.assertTrue(closed.get());
View Full Code Here

        return 72058143204835330L;
      }
    };
    TupleSupport ts = new TupleSupport();
    for (int i = 0; i < 10; i++) {
      Tuple tuple = ts.create(i, Long.parseLong("98765432" + i), "Hello world " + i + "!");
      xlog.writeXLog(new Insert(0, tuple).flags(2));
    }

    xlog.close();
    Assert.assertTrue(closed.get());
View Full Code Here

    byte[] ar = readFile("test.snap");
    ReadableByteChannel readableByteChannel = createReadableByteChannel(closed, ar);
    TupleSupport ts = new TupleSupport();
    SnapshotReader snapShotReader = new SnapshotReader(readableByteChannel);
    for (int i = 0; i < 10; i++) {
      Tuple tuple = ts.create(i, Long.parseLong("98765432" + i), "Hello world " + i + "!");
      Row row = snapShotReader.nextRow();
      Assert.assertTrue(Arrays.equals(tuple.pack(), row.data.pack()));
    }
    snapShotReader.close();
    Assert.assertTrue(closed.get());

  }
View Full Code Here

    byte[] ar = readFile("test.xlog");
    ReadableByteChannel readableByteChannel = createReadableByteChannel(closed, ar);
    TupleSupport ts = new TupleSupport();
    XLogReader xlogReader = new XLogReader(readableByteChannel);
    for (int i = 0; i < 10; i++) {
      Tuple tuple = ts.create(i, Long.parseLong("98765432" + i), "Hello world " + i + "!");
      XLogEntry entry = xlogReader.nextEntry();
      Assert.assertTrue(Arrays.equals(tuple.pack(), entry.tuple.pack()));
    }
    xlogReader.close();
    Assert.assertTrue(closed.get());

  }
View Full Code Here

      int fields = Leb128.readUnsigned(buffer);
      if (fields != update.args) {
        throw new IllegalStateException("op " + update.name() + " should has " + update.args + " arguments, but has " + fields);
      }
    }
    Tuple opArgs = Tuple.createFromPackedFields(buffer, ByteOrder.LITTLE_ENDIAN, update.args);
    return new OperationImpl(update, fieldNo, opArgs);
  }
View Full Code Here

    test.initSpace(StandardTest.CALL_SPACE, 0, 0);
    test.initProc("box.delete", new CallStub() {

      @Override
      public List<Tuple> call(InMemoryTarantoolImpl impl, String procName, int flags, Tuple args) {
        Tuple pk = impl.copyExcept(args, 0);
        int space = Integer.parseInt(args.getString(0, "UTF-8"));
        Tuple deleted = impl.delete(space, pk);
        return deleted == null ? new ArrayList<Tuple>() : Arrays.asList(deleted);
      }
    });
    test.initProc("box.insert", new CallStub() {

      @Override
      public List<Tuple> call(InMemoryTarantoolImpl impl, String procName, int flags, Tuple args) {
        Tuple tuple = impl.copyExcept(args, 0);
        int space = Integer.parseInt(args.getString(0, "UTF-8"));
        Tuple put = impl.put(space, tuple, true, false);
        return Arrays.asList(put);
      }
    });
    test.initProc("box.select_range", new CallStub() {

      @Override
      public List<Tuple> call(InMemoryTarantoolImpl impl, String procName, int flags, Tuple args) {
        int spaceNo = Integer.parseInt(args.getString(0, "UTF-8"));
        int indexNo = Integer.parseInt(args.getString(1, "UTF-8"));
        int limit = Integer.parseInt(args.getString(2, "UTF-8"));
        if (args.size() == 3) {
          return impl.shiftAndLimit(0, limit, impl.all(spaceNo, indexNo));
        } else {
          Tuple key = impl.copyExcept(args, 0, 1, 2);
          List<Tuple> head = impl.head(spaceNo, indexNo, key);
          List<Tuple> value = impl.get(spaceNo, indexNo, key);
          if (value != null && value.size() > 0) {
            head.addAll(0, value);
          }
View Full Code Here

          return super.deserUnknown(tuple, cls, i);
        }
      }
    }, "id", "phone", "point", "iq", "height", "lifeFormId", "salary", "birthday", "name", "sign", "male", "site");
    User user = new User();
    Tuple tuple = mapping.toTuple(user);
    User userCopy = mapping.fromTuple(tuple);
    assertArrayEquals(tuple.pack(), mapping.toTuple(userCopy).pack());
    assertEquals(user.getSite(), userCopy.getSite());
  }
View Full Code Here

  public void insertTestTuples() {
    SocketChannelPooledConnectionFactory factory = new SocketChannelPooledConnectionFactory();
    TarantoolConnection connection = factory.getConnection();
    TupleSupport ts = new TupleSupport();
    for (int i = 0; i < 10; i++) {
      Tuple tuple = ts.create(i, Long.parseLong("98765432" + i), "Hello world " + i + "!");
      connection.insert(0, tuple);
    }
    connection.close();
  }
View Full Code Here

TOP

Related Classes of org.tarantool.core.Tuple

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.