Java Code Examples for io.vertx.sqlclient.Row

The following examples show how to use io.vertx.sqlclient.Row. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: raml-module-builder   Source File: PostgresClientTest.java    License: Apache License 2.0 6 votes vote down vote up
private RowSet<Row> getMockTestPojoResultSet(int total) {
  List<String> columnNames = new ArrayList<String>(Arrays.asList(new String[] {
    "id", "foo", "bar", "biz", "baz"
  }));
  RowDesc rowDesc = new RowDesc(columnNames);
  List<Row> rows = new LinkedList<>();
  for (int i = 0; i < total; i++) {
    Row row = new RowImpl(rowDesc);
    row.addUUID(UUID.randomUUID());
    row.addString("foo " + i);
    row.addString("bar " + i);
    row.addDouble((double) i);
    row.addStringArray(new String[] { "This", "is", "a", "test" } );
    rows.add(row);
  }
  return new LocalRowSet(total).withColumns(columnNames).withRows(rows);
}
 
Example 2
@Test
public void testDate(TestContext ctx) {
  Async async = ctx.async();
  PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
    conn
      .query("SELECT '1981-05-30'::DATE \"LocalDate\"").execute(ctx.asyncAssertSuccess(result -> {
        LocalDate ld = LocalDate.parse("1981-05-30");
        ctx.assertEquals(1, result.size());
        Row row = result.iterator().next();
        ColumnChecker.checkColumn(0, "LocalDate")
          .returns(Tuple::getValue, Row::getValue, ld)
          .returns(Tuple::getLocalDate, Row::getLocalDate, ld)
          .returns(Tuple::getTemporal, Row::getTemporal, ld)
          .forRow(row);
        async.complete();
      }));
  }));
}
 
Example 3
@Test
public void testEncodeOffsetDateTimeArray(TestContext ctx) {
  Async async = ctx.async();
  PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
    conn.prepare("UPDATE \"ArrayDataType\" SET \"OffsetDateTime\" = $1  WHERE \"id\" = $2 RETURNING \"OffsetDateTime\"",
      ctx.asyncAssertSuccess(p -> {
        final OffsetDateTime dt = OffsetDateTime.parse("2017-05-14T19:35:58.237666Z");
        p.query().execute(Tuple.tuple()
            .addOffsetDateTimeArray(new OffsetDateTime[]{dt})
            .addInteger(2)
          , ctx.asyncAssertSuccess(result -> {
            ColumnChecker.checkColumn(0, "OffsetDateTime")
              .returns(Tuple::getValue, Row::getValue, new OffsetDateTime[]{dt})
              .returns(Tuple::getOffsetTimeArray, Row::getOffsetTimeArray, new OffsetTime[]{dt.toOffsetTime()})
              .returns(Tuple::getOffsetDateTimeArray, Row::getOffsetDateTimeArray, new OffsetDateTime[]{dt})
              .forRow(result.iterator().next());
            async.complete();
          }));
      }));
  }));
}
 
Example 4
@Test
public void testCustomType(TestContext ctx) {
  Async async = ctx.async();
  String expected = "Anytown";
  PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
    conn
      .query("SELECT (address).city FROM \"CustomDataType\"").execute(ctx.asyncAssertSuccess(result -> {
        ctx.assertEquals(2, result.size());
        Row row = result.iterator().next();
        ColumnChecker.checkColumn(0, "city")
          .returns(Tuple::getValue, Row::getValue, expected)
          .returns(Tuple::getString, Row::getString, expected)
          .forRow(row);
        async.complete();
      }));
  }));
}
 
Example 5
Source Project: vertx-sql-client   Source File: MySQLUtilityCommandTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testChangeUser(TestContext ctx) {
  MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
    conn.query("SELECT current_user()").execute(ctx.asyncAssertSuccess(res1 -> {
      Row row1 = res1.iterator().next();
      String username = row1.getString(0);
      ctx.assertEquals("mysql", username.substring(0, username.lastIndexOf('@')));
      MySQLAuthOptions changeUserOptions = new MySQLAuthOptions()
        .setUser("superuser")
        .setPassword("password")
        .setDatabase("emptyschema");
      conn.changeUser(changeUserOptions, ctx.asyncAssertSuccess(v2 -> {
        conn.query("SELECT current_user();SELECT database();").execute(ctx.asyncAssertSuccess(res2 -> {
          ctx.assertEquals("[email protected]%", res2.iterator().next().getString(0));
          ctx.assertEquals("emptyschema", res2.next().iterator().next().getValue(0));
          conn.close();
        }));
      }));
    }));
  }));
}
 
Example 6
Source Project: vertx-jooq   Source File: RowMappers.java    License: MIT License 6 votes vote down vote up
public static Function<Row,generated.rx.reactive.regular.vertx.tables.pojos.Something> getSomethingMapper() {
    return row -> {
        generated.rx.reactive.regular.vertx.tables.pojos.Something pojo = new generated.rx.reactive.regular.vertx.tables.pojos.Something();
        pojo.setSomeid(row.getInteger("someId"));
        pojo.setSomestring(row.getString("someString"));
        pojo.setSomehugenumber(row.getLong("someHugeNumber"));
        pojo.setSomesmallnumber(row.getShort("someSmallNumber"));
        pojo.setSomeregularnumber(row.getInteger("someRegularNumber"));
        pojo.setSomedouble(row.getDouble("someDouble"));
        pojo.setSomeenum(java.util.Arrays.stream(generated.rx.reactive.regular.vertx.enums.Someenum.values()).filter(td -> td.getLiteral().equals(row.getString("someEnum"))).findFirst().orElse(null));
        pojo.setSomejsonobject(row.get(io.vertx.core.json.JsonObject.class,row.getColumnIndex("someJsonObject")));
        pojo.setSomecustomjsonobject(generated.rx.reactive.regular.vertx.tables.converters.Converters.IO_GITHUB_JKLINGSPORN_VERTX_JOOQ_GENERATE_CONVERTER_SOMEJSONPOJOCONVERTER_INSTANCE.pgConverter().from(row.get(io.vertx.core.json.JsonObject.class,row.getColumnIndex("someCustomJsonObject"))));
        pojo.setSomejsonarray(row.get(io.vertx.core.json.JsonArray.class,row.getColumnIndex("someJsonArray")));
        pojo.setSometimestamp(row.getLocalDateTime("someTimestamp"));
        return pojo;
    };
}
 
Example 7
Source Project: vertx-sql-client   Source File: SqlClientExamples.java    License: Apache License 2.0 6 votes vote down vote up
public void usingConnections03(SqlConnection connection) {
  connection.prepare("INSERT INTO USERS (id, name) VALUES ($1, $2)", ar1 -> {
    if (ar1.succeeded()) {
      PreparedStatement prepared = ar1.result();

      // Create a query : bind parameters
      List<Tuple> batch = new ArrayList();

      // Add commands to the createBatch
      batch.add(Tuple.of("julien", "Julien Viet"));
      batch.add(Tuple.of("emad", "Emad Alblueshi"));

      prepared.query().executeBatch(batch, res -> {
        if (res.succeeded()) {

          // Process rows
          RowSet<Row> rows = res.result();
        } else {
          System.out.println("Batch failed " + res.cause());
        }
      });
    }
  });
}
 
Example 8
Source Project: vertx-sql-client   Source File: MySQLStoredProgramsTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testOutParameters(TestContext ctx) {
  MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
    conn.query("DROP PROCEDURE IF EXISTS test_out_parameter;").execute(ctx.asyncAssertSuccess(cleanProcedure -> {
      conn.query("CREATE PROCEDURE test_out_parameter(OUT p1 VARCHAR(20))\n" +
        "BEGIN\n" +
        "    SELECT 'hello,world!' INTO p1;\n" +
        "end;").execute(ctx.asyncAssertSuccess(createProcedure -> {
        conn.query("CALL test_out_parameter(@OUT);").execute(ctx.asyncAssertSuccess(callProcedure -> {
          conn.query("SELECT @OUT;").execute(ctx.asyncAssertSuccess(result -> {
            ctx.assertEquals(1, result.size());
            Row row = result.iterator().next();
            ctx.assertEquals("hello,world!", row.getValue(0));
            ctx.assertEquals("hello,world!", row.getString(0));
            conn.close();
          }));
        }));
      }));
    }));
  }));
}
 
Example 9
Source Project: vertx-sql-client   Source File: SpatialBinaryCodecTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testEncodeMultiPoint(TestContext ctx) {
  List<Point> points = new ArrayList<>();
  points.add(new Point(0, 0, 0));
  points.add(new Point(0, 1, 1));
  points.add(new Point(0, 2, 2));
  MultiPoint multiPoint = new MultiPoint(0, points);

  testBinaryEncodeGeometry(ctx, multiPoint, result -> {
    Row row = result.iterator().next();
    String text = row.getString(0);
    // a workaround for MySQL 5.6
    boolean expected1 = "MULTIPOINT(0 0,1 1,2 2)".equals(text);
    boolean expected2 = "MULTIPOINT((0 0),(1 1),(2 2))".equals(text);
    ctx.assertTrue(expected1 || expected2);
  });
}
 
Example 10
@Test
public void testEnum(TestContext ctx) {
  Async async = ctx.async();
  PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
    conn
      .query("SELECT \"currentMood\" FROM \"EnumDataType\" WHERE \"id\" = 5").execute(ctx.asyncAssertSuccess(result -> {
        ctx.assertEquals(1, result.size());
        Row row = result.iterator().next();
        ColumnChecker.checkColumn(0, "currentMood")
          .returns(Tuple::getValue, Row::getValue, "ok")
          .returns(Tuple::getString, Row::getString, "ok")
          .forRow(row);
        async.complete();
      }));
  }));
}
 
Example 11
Source Project: vertx-sql-client   Source File: RowStreamImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public RowStream<Row> fetch(long amount) {
  if (amount < 0L) {
    throw new IllegalArgumentException("Invalid fetch amount " + amount);
  }
  synchronized (this) {
    demand += amount;
    if (demand < 0L) {
      demand = Long.MAX_VALUE;
    }
    if (cursor == null) {
      return this;
    }
  }
  checkPending();
  return this;
}
 
Example 12
Source Project: raml-module-builder   Source File: PostgresClient.java    License: Apache License 2.0 6 votes vote down vote up
void selectStream(AsyncResult<SQLConnection> conn, String sql, Tuple params, int chunkSize,
    Handler<AsyncResult<RowStream<Row>>> replyHandler) {
  try {
    if (conn.failed()) {
      replyHandler.handle(Future.failedFuture(conn.cause()));
      return;
    }
    final Transaction tx = conn.result().tx;
    tx.prepare(sql, res -> {
      if (res.failed()) {
        log.error(res.cause().getMessage(), res.cause());
        replyHandler.handle(Future.failedFuture(res.cause()));
        return;
      }
      PreparedStatement pq = res.result();
      RowStream<Row> rowStream = pq.createStream(chunkSize, params);
      replyHandler.handle(Future.succeededFuture(rowStream));
    });
  } catch (Exception e) {
    log.error("select stream sql: " + e.getMessage() + " - " + sql, e);
    replyHandler.handle(Future.failedFuture(e));
  }
}
 
Example 13
Source Project: vertx-sql-client   Source File: PgTemplateTestBase.java    License: Apache License 2.0 6 votes vote down vote up
protected <P, T, V> void testGet(TestContext ctx,
                                 String sqlType,
                                 Function<Row, T> rowMapper,
                                 Function<P, Map<String, Object>> paramsMapper,
                                 String paramName,
                                 P params,
                                 V expected,
                                 Function<T, V> extractor,
                                 String column) {
  Async async = ctx.async();
  SqlTemplate<P, RowSet<T>> template = SqlTemplate
    .forQuery(connection, "SELECT #{" + paramName + "} :: " + sqlType + " \"" + column + "\"")
    .mapFrom(paramsMapper)
    .mapTo(rowMapper);
  template.execute(params, ctx.asyncAssertSuccess(result -> {
    ctx.assertEquals(1, result.size());
    ctx.assertEquals(expected, extractor.apply(result.iterator().next()));
    async.complete();
  }));
  async.await(10000);
}
 
Example 14
@Test
public void testEncodeEnumArray(TestContext ctx) {
  Async async = ctx.async();
  PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
    conn.prepare("UPDATE \"ArrayDataType\" SET \"Enum\" = $1 WHERE \"id\" = $2 RETURNING \"Enum\"",
      ctx.asyncAssertSuccess(p -> {
        p.query().execute(Tuple.tuple()
            .addStringArray(new String[]{"unhappy"})
            .addInteger(2)
          , ctx.asyncAssertSuccess(result -> {
            ColumnChecker.checkColumn(0, "Enum")
              .returns(Tuple::getValue, Row::getValue, new String[]{"unhappy"})
              .returns(Tuple::getStringArray, Row::getStringArray, new String[]{"unhappy"})
              .forRow(result.iterator().next());
            async.complete();
          }));
      }));
  }));
}
 
Example 15
Source Project: vertx-jooq   Source File: RowMappers.java    License: MIT License 6 votes vote down vote up
public static Function<Row,generated.rx.reactive.guice.vertx.tables.pojos.Something> getSomethingMapper() {
    return row -> {
        generated.rx.reactive.guice.vertx.tables.pojos.Something pojo = new generated.rx.reactive.guice.vertx.tables.pojos.Something();
        pojo.setSomeid(row.getInteger("someId"));
        pojo.setSomestring(row.getString("someString"));
        pojo.setSomehugenumber(row.getLong("someHugeNumber"));
        pojo.setSomesmallnumber(row.getShort("someSmallNumber"));
        pojo.setSomeregularnumber(row.getInteger("someRegularNumber"));
        pojo.setSomedouble(row.getDouble("someDouble"));
        pojo.setSomeenum(java.util.Arrays.stream(generated.rx.reactive.guice.vertx.enums.Someenum.values()).filter(td -> td.getLiteral().equals(row.getString("someEnum"))).findFirst().orElse(null));
        pojo.setSomejsonobject(row.get(io.vertx.core.json.JsonObject.class,row.getColumnIndex("someJsonObject")));
        pojo.setSomecustomjsonobject(generated.rx.reactive.guice.vertx.tables.converters.Converters.IO_GITHUB_JKLINGSPORN_VERTX_JOOQ_GENERATE_CONVERTER_SOMEJSONPOJOCONVERTER_INSTANCE.pgConverter().from(row.get(io.vertx.core.json.JsonObject.class,row.getColumnIndex("someCustomJsonObject"))));
        pojo.setSomejsonarray(row.get(io.vertx.core.json.JsonArray.class,row.getColumnIndex("someJsonArray")));
        pojo.setSometimestamp(row.getLocalDateTime("someTimestamp"));
        return pojo;
    };
}
 
Example 16
@Test
public void testStreamQueryError(TestContext ctx) {
  Async async = ctx.async();
  PgConnection.connect(vertx, options(), ctx.asyncAssertSuccess(conn -> {
    conn.prepare("SELECT * FROM Fortune", ctx.asyncAssertSuccess(ps -> {
      RowStream<Row> stream = ps.createStream(4, Tuple.tuple());
      stream.endHandler(v -> ctx.fail());
      AtomicInteger rowCount = new AtomicInteger();
      stream.exceptionHandler(err -> {
        ctx.assertEquals(4, rowCount.getAndIncrement());
        async.complete();
      });
      stream.handler(tuple -> rowCount.incrementAndGet());
    }));
  }));
}
 
Example 17
@Test
public void testTimestamp(TestContext ctx) {
  Async async = ctx.async();
  PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
    conn
      .query("SELECT '2017-05-14 19:35:58.237666'::TIMESTAMP \"LocalDateTime\"").execute(ctx.asyncAssertSuccess(result -> {
        LocalDateTime ldt = LocalDateTime.parse("2017-05-14T19:35:58.237666");
        ctx.assertEquals(1, result.size());
        Row row = result.iterator().next();
        ColumnChecker.checkColumn(0, "LocalDateTime")
          .returns(Tuple::getValue, Row::getValue, ldt)
          .returns(Tuple::getLocalTime, Row::getLocalTime, ldt.toLocalTime())
          .returns(Tuple::getLocalDate, Row::getLocalDate, ldt.toLocalDate())
          .returns(Tuple::getLocalDateTime, Row::getLocalDateTime, ldt)
          .returns(Tuple::getTemporal, Row::getTemporal, ldt)
          .forRow(row);
        async.complete();
      }));
  }));
}
 
Example 18
@Test
public void testDecodeGeometryCollection(TestContext ctx) {
  testDecodeGeometry(ctx, "SELECT ST_GeometryFromText('GEOMETRYCOLLECTION(Point(1 1),LineString(2 2, 3 3))', 0) AS test_geometry;", result -> {
    Row row = result.iterator().next();
    GeometryCollection geometryCollection = row.get(GeometryCollection.class, 0);
    ctx.assertEquals(0L, geometryCollection.getSRID());
    List<Geometry> geometries = geometryCollection.getGeometries();
    ctx.assertEquals(2, geometries.size());

    ctx.assertTrue(geometries.get(0) instanceof Point);
    Point firstGeometry = (Point) geometries.get(0);
    ctx.assertEquals(1d, firstGeometry.getX());
    ctx.assertEquals(1d, firstGeometry.getY());

    ctx.assertTrue(geometries.get(1) instanceof LineString);
    LineString secondGeometry = (LineString) geometries.get(1);
    List<Point> pointsOfSecondGeometry = secondGeometry.getPoints();
    ctx.assertEquals(2, pointsOfSecondGeometry.size());
    ctx.assertEquals(2d, pointsOfSecondGeometry.get(0).getX());
    ctx.assertEquals(2d, pointsOfSecondGeometry.get(0).getY());
    ctx.assertEquals(3d, pointsOfSecondGeometry.get(1).getY());
    ctx.assertEquals(3d, pointsOfSecondGeometry.get(1).getY());
  });
}
 
Example 19
Source Project: vertx-sql-client   Source File: SqlClientExamples.java    License: Apache License 2.0 6 votes vote down vote up
public void usingCursors01(SqlConnection connection) {
  connection.prepare("SELECT * FROM users WHERE age > ?", ar1 -> {
    if (ar1.succeeded()) {
      PreparedStatement pq = ar1.result();

      // Create a cursor
      Cursor cursor = pq.cursor(Tuple.of(18));

      // Read 50 rows
      cursor.read(50, ar2 -> {
        if (ar2.succeeded()) {
          RowSet<Row> rows = ar2.result();

          // Check for more ?
          if (cursor.hasMore()) {
            // Repeat the process...
          } else {
            // No more rows - close the cursor
            cursor.close();
          }
        }
      });
    }
  });
}
 
Example 20
Source Project: vertx-sql-client   Source File: MSSQLDataTypeTestBase.java    License: Apache License 2.0 6 votes vote down vote up
protected <T> void testPreparedQueryDecodeGeneric(TestContext ctx,
                                                  String tableName,
                                                  String columnName,
                                                  String rowIdentifier,
                                                  Consumer<Row> checker) {
  MSSQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
    conn
      .preparedQuery(String.format("SELECT %s FROM %s WHERE id = %s", columnName, tableName, rowIdentifier))
      .execute(ctx.asyncAssertSuccess(result -> {
        ctx.assertEquals(1, result.size());
        Row row = result.iterator().next();
        checker.accept(row);
        conn.close();
      }));
  }));
}
 
Example 21
@Test
public void testEncodeDoubleArray(TestContext ctx) {
  Async async = ctx.async();
  PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
    conn.prepare("UPDATE \"ArrayDataType\" SET \"Double\" = $1  WHERE \"id\" = $2 RETURNING \"Double\"",
      ctx.asyncAssertSuccess(p -> {
        p.query().execute(Tuple.tuple()
            .addDoubleArray(new Double[]{6.3})
            .addInteger(2)
          , ctx.asyncAssertSuccess(result -> {
            ColumnChecker.checkColumn(0, "Double")
              .returns(Tuple::getValue, Row::getValue, ColumnChecker.toObjectArray(new double[]{6.3}))
              .returns(Tuple::getShortArray, Row::getShortArray, ColumnChecker.toObjectArray(new short[]{(short)6.3}))
              .returns(Tuple::getIntegerArray, Row::getIntegerArray, ColumnChecker.toObjectArray(new int[]{(int)6.3}))
              .returns(Tuple::getLongArray, Row::getLongArray, ColumnChecker.toObjectArray(new long[]{(long)6.3}))
              .returns(Tuple::getFloatArray, Row::getFloatArray, ColumnChecker.toObjectArray(new float[]{(float)6.3}))
              .returns(Tuple::getDoubleArray, Row::getDoubleArray, ColumnChecker.toObjectArray(new double[]{6.3}))
              .forRow(result.iterator().next());
            async.complete();
          }));
      }));
  }));
}
 
Example 22
Source Project: vertx-sql-client   Source File: SpatialBinaryCodecTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testEncodeMultiLineString(TestContext ctx) {
  List<Point> pointsOfFirstLineString = new ArrayList<>();
  pointsOfFirstLineString.add(new Point(0, 1, 1));
  pointsOfFirstLineString.add(new Point(0, 2, 2));
  pointsOfFirstLineString.add(new Point(0, 3, 3));
  LineString firstLineString = new LineString(0, pointsOfFirstLineString);

  List<Point> pointsOfSecondLineString = new ArrayList<>();
  pointsOfSecondLineString.add(new Point(0, 4, 4));
  pointsOfSecondLineString.add(new Point(0, 5, 5));
  LineString secondLineString = new LineString(0, pointsOfSecondLineString);

  List<LineString> lineStrings = new ArrayList<>();
  lineStrings.add(firstLineString);
  lineStrings.add(secondLineString);
  MultiLineString multiLineString = new MultiLineString(0, lineStrings);

  testBinaryEncodeGeometry(ctx, multiLineString, result -> {
    Row row = result.iterator().next();
    String text = row.getString(0);
    ctx.assertEquals("MULTILINESTRING((1 1,2 2,3 3),(4 4,5 5))", text);
  });
}
 
Example 23
@Test
public void testEncodeFixedChar(TestContext ctx) {
  Async async = ctx.async();
  PgConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
    conn.prepare("UPDATE \"CharacterDataType\" SET \"FixedChar\" = upper($1) WHERE \"id\" = $2 RETURNING \"FixedChar\"",
      ctx.asyncAssertSuccess(p -> {
        p.query().execute(Tuple.tuple()
          .addString("no")
          .addInteger(2), ctx.asyncAssertSuccess(result -> {
          ctx.assertEquals(1, result.size());
          ctx.assertEquals(1, result.rowCount());
          Row row = result.iterator().next();
          String name = "NO ";
          ColumnChecker.checkColumn(0, "FixedChar")
            .returns(Tuple::getValue, Row::getValue, name)
            .returns(Tuple::getString, Row::getString, name)
            .forRow(row);
          async.complete();
        }));
      }));
  }));
}
 
Example 24
Source Project: vertx-sql-client   Source File: MySQLStoredProgramsTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testInOutParameters(TestContext ctx) {
  MySQLConnection.connect(vertx, options, ctx.asyncAssertSuccess(conn -> {
    conn.query("DROP PROCEDURE IF EXISTS test_inout_parameter;").execute(ctx.asyncAssertSuccess(cleanProcedure -> {
      conn.query("CREATE PROCEDURE test_inout_parameter(INOUT p1 INT)\n" +
        "BEGIN\n" +
        "    SET p1 = p1 + 12345;\n" +
        "end;").execute(ctx.asyncAssertSuccess(createProcedure -> {
        conn.query("SET @INOUT = 98765;\n" +
          "CALL test_inout_parameter(@INOUT);").execute(ctx.asyncAssertSuccess(callProcedure -> {
          conn.query("SELECT @INOUT;").execute(ctx.asyncAssertSuccess(result -> {
            ctx.assertEquals(1, result.size());
            Row row = result.iterator().next();
            ctx.assertEquals(111110, row.getInteger(0));
            conn.close();
          }));
        }));
      }));
    }));
  }));
}
 
Example 25
Source Project: vertx-sql-client   Source File: DB2DataTypeTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testByteBufIntoVarchar(TestContext ctx) {
  byte[] expected = "hello world".getBytes();
  connect(ctx.asyncAssertSuccess(conn -> {
    conn.preparedQuery("INSERT INTO db2_types (id,test_bytes) VALUES (?, ?)")
        .execute(Tuple.of(4, Buffer.buffer(expected)), ctx.asyncAssertSuccess(insertResult -> {
          conn.preparedQuery("SELECT id,test_bytes FROM db2_types WHERE id = 4")
              .execute(ctx.asyncAssertSuccess(rows -> {
                ctx.assertEquals(1, rows.size());
                Row row = rows.iterator().next();
                ctx.assertEquals(4, row.getInteger(0));
                ctx.assertTrue(Arrays.equals(expected, row.getBuffer(1).getBytes()),
                    "Expecting " + Arrays.toString(expected) + " but got "
                        + Arrays.toString(row.getBuffer(1).getBytes()));
              }));
        }));
  }));
}
 
Example 26
@Test
public void testEncodeVarChar(TestContext ctx) {
  testPreparedQueryEncodeGeneric(ctx, "not_nullable_datatype", "test_varchar", "testedvarchar", row -> {
    ColumnChecker.checkColumn(0, "test_varchar")
      .returns(Tuple::getValue, Row::getValue, "testedvarchar")
      .returns(Tuple::getString, Row::getString, "testedvarchar")
      .returns(String.class, "testedvarchar")
      .forRow(row);
  });
}
 
Example 27
Source Project: vertx-sql-client   Source File: SpatialBinaryCodecTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testEncodeLineString(TestContext ctx) {
  List<Point> points = new ArrayList<>();
  points.add(new Point(0, 1.1, 1.1));
  points.add(new Point(0, 2.2, 2.2));
  LineString lineString = new LineString(0, points);

  testBinaryEncodeGeometry(ctx, lineString, result -> {
    Row row = result.iterator().next();
    String text = row.getString(0);
    ctx.assertEquals("LINESTRING(1.1 1.1,2.2 2.2)", text);
  });
}
 
Example 28
Source Project: vertx-jooq   Source File: RowMappers.java    License: MIT License 5 votes vote down vote up
public static Function<Row,generated.classic.reactive.guice.vertx.tables.pojos.Somethingcomposite> getSomethingcompositeMapper() {
    return row -> {
        generated.classic.reactive.guice.vertx.tables.pojos.Somethingcomposite pojo = new generated.classic.reactive.guice.vertx.tables.pojos.Somethingcomposite();
        pojo.setSomeid(row.getInteger("someId"));
        pojo.setSomesecondid(row.getInteger("someSecondId"));
        pojo.setSomejsonobject(row.get(io.vertx.core.json.JsonObject.class,row.getColumnIndex("someJsonObject")));
        return pojo;
    };
}
 
Example 29
@Test
public void testDecodeNullFloat4(TestContext ctx) {
  testDecodeNullValue(ctx, "test_float_4", row -> {
    ColumnChecker.checkColumn(0, "test_float_4")
      .returns(Tuple::getValue, Row::getValue, FLOAT_NULL_VALUE)
      .returns(Tuple::getFloat, Row::getFloat, FLOAT_NULL_VALUE)
      .returns(Float.class, FLOAT_NULL_VALUE)
      .forRow(row);
  });
}
 
Example 30
Source Project: vertx-sql-client   Source File: SqlClientExamples.java    License: Apache License 2.0 5 votes vote down vote up
public void queries04(SqlClient client) {
  client
    .preparedQuery("INSERT INTO users (first_name, last_name) VALUES ($1, $2)")
    .execute(Tuple.of("Andy", "Guibert"),  ar -> {
    if (ar.succeeded()) {
      RowSet<Row> rows = ar.result();
      System.out.println(rows.rowCount());
    } else {
      System.out.println("Failure: " + ar.cause().getMessage());
    }
  });
}