Skip to content

Commit

Permalink
Fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
alex268 committed Jul 18, 2023
1 parent 9c6596b commit 7c8b445
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 29 deletions.
16 changes: 9 additions & 7 deletions basic_example/src/main/java/tech/ydb/example/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import tech.ydb.auth.iam.CloudAuthHelper;
import tech.ydb.core.Status;
import tech.ydb.core.grpc.GrpcReadStream;
import tech.ydb.core.grpc.GrpcTransport;
import tech.ydb.table.SessionRetryContext;
import tech.ydb.table.TableClient;
Expand Down Expand Up @@ -206,7 +207,7 @@ private void upsertSimple() {
+ "VALUES (2, 6, 1, \"TBD\");";

// Begin new transaction with SerializableRW mode
TxControl txControl = TxControl.serializableRw().setCommitTx(true);
TxControl<?> txControl = TxControl.serializableRw().setCommitTx(true);

// Executes data query with specified transaction control settings.
retryCtx.supplyResult(session -> session.executeDataQuery(query, txControl))
Expand All @@ -219,7 +220,7 @@ private void selectSimple() {
+ "FROM series WHERE series_id = 1;";

// Begin new transaction with SerializableRW mode
TxControl txControl = TxControl.serializableRw().setCommitTx(true);
TxControl<?> txControl = TxControl.serializableRw().setCommitTx(true);

// Executes data query with specified transaction control settings.
DataQueryResult result = retryCtx.supplyResult(session -> session.executeDataQuery(query, txControl))
Expand All @@ -246,7 +247,7 @@ private void selectWithParams(long seriesID, long seasonID) {
+ "WHERE sa.series_id = $seriesId AND sa.season_id = $seasonId";

// Begin new transaction with SerializableRW mode
TxControl txControl = TxControl.serializableRw().setCommitTx(true);
TxControl<?> txControl = TxControl.serializableRw().setCommitTx(true);

// Type of parameter values should be exactly the same as in DECLARE statements.
Params params = Params.of(
Expand Down Expand Up @@ -287,7 +288,8 @@ private void scanQueryWithParams(long seriesID, long seasonID) {
logger.info("--[ ExecuteScanQueryWithParams ]--");
retryCtx.supplyStatus(session -> {
ExecuteScanQuerySettings settings = ExecuteScanQuerySettings.newBuilder().build();
return session.executeScanQuery(query, params, settings, rs -> {
GrpcReadStream<ResultSetReader> scan = session.executeScanQuery(query, params, settings);
return scan.start(rs -> {
while (rs.next()) {
logger.info("read episode {} of {} for {}",
rs.getColumn("episode_title").getText(),
Expand All @@ -310,7 +312,7 @@ private void multiStepTransaction(long seriesID, long seasonID) {
// Execute first query to get the required values to the client.
// Transaction control settings don't set CommitTx flag to keep transaction active
// after query execution.
TxControl tx1 = TxControl.serializableRw().setCommitTx(false);
TxControl<?> tx1 = TxControl.serializableRw().setCommitTx(false);
DataQueryResult res1 = session.executeDataQuery(query1, tx1, Params.of(
"$seriesId", PrimitiveValue.newUint64(seriesID),
"$seasonId", PrimitiveValue.newUint64(seasonID)
Expand Down Expand Up @@ -338,7 +340,7 @@ private void multiStepTransaction(long seriesID, long seasonID) {
// Execute second query.
// Transaction control settings continues active transaction (tx) and
// commits it at the end of second query execution.
TxControl tx2 = TxControl.id(txId).setCommitTx(true);
TxControl<?> tx2 = TxControl.id(txId).setCommitTx(true);
DataQueryResult res2 = session.executeDataQuery(query2, tx2, Params.of(
"$seriesId", PrimitiveValue.newUint64(seriesID),
"$fromDate", PrimitiveValue.newDate(fromDate),
Expand Down Expand Up @@ -371,7 +373,7 @@ private void tclTransaction() {

// Execute data query.
// Transaction control settings continues active transaction (tx)
TxControl txControl = TxControl.id(transaction).setCommitTx(false);
TxControl<?> txControl = TxControl.id(transaction).setCommitTx(false);
DataQueryResult result = session.executeDataQuery(query, txControl, params)
.join().getValue();

Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
<version>${log4j.version}</version>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j2-impl</artifactId>
<version>${log4j.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package tech.ydb.examples.indexes;

import java.time.Duration;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
Expand Down Expand Up @@ -42,7 +41,6 @@ GrpcTransport grpcTransport(IndexesConfigurationProperties properties, ExecutorS
}
logger.info("Creating rpc transport for endpoint={} database={}", endpoint, database);
GrpcTransportBuilder builder = GrpcTransport.forEndpoint(endpoint, database)
.withReadTimeout(Duration.ofSeconds(10))
.withCallExecutor(grpcExecutor);
if (token != null && !token.isEmpty()) {
builder.withAuthProvider(new TokenAuthProvider(token));
Expand Down
2 changes: 1 addition & 1 deletion url-shortener-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<artifactId>log4j-slf4j2-impl</artifactId>
</dependency>

<dependency>
Expand Down
15 changes: 7 additions & 8 deletions url-shortener-demo/src/main/java/tech/ydb/demo/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.time.Duration;

import tech.ydb.core.grpc.GrpcTransport;
import tech.ydb.demo.rest.RedirectServlet;
import tech.ydb.demo.rest.URLServlet;
import tech.ydb.demo.ydb.YdbDriver;
import tech.ydb.demo.ydb.YdbRepository;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
Expand All @@ -22,7 +16,13 @@
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import tech.ydb.core.grpc.GrpcTransport;
import tech.ydb.core.grpc.GrpcTransportBuilder;
import tech.ydb.demo.rest.RedirectServlet;
import tech.ydb.demo.rest.URLServlet;
import tech.ydb.demo.ydb.YdbDriver;
import tech.ydb.demo.ydb.YdbRepository;

/**
*
Expand Down Expand Up @@ -90,8 +90,7 @@ private GrpcTransport createGrpcTransport(AppParams prms) throws IOException {
String database = prms.database();

log.info("Creating rpc transport for endpoint={} database={}", endpoint, database);
GrpcTransportBuilder builder = GrpcTransport.forEndpoint(endpoint, database)
.withReadTimeout(Duration.ofSeconds(10));
GrpcTransportBuilder builder = GrpcTransport.forEndpoint(endpoint, database);

if (prms.certPath() != null) {
builder.withSecureConnection(Files.readAllBytes(Paths.get(prms.certPath())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.eclipse.jetty.servlet.DefaultServlet;

import tech.ydb.demo.Application;
import tech.ydb.demo.ydb.HashTool;
import tech.ydb.demo.ydb.UrlRecord;
import tech.ydb.demo.ydb.YdbException;
import tech.ydb.demo.ydb.YdbRepository;
import org.eclipse.jetty.servlet.DefaultServlet;

/**
*
* @author Alexandr Gorshenin
*/
public class RedirectServlet extends DefaultServlet {
private static final long serialVersionUID = -3978776572966824296L;

private YdbRepository repository() {
return new YdbRepository(Application.ydp());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.google.gson.stream.JsonWriter;

import tech.ydb.demo.Application;
import tech.ydb.demo.ydb.UrlRecord;
import tech.ydb.demo.ydb.YdbException;
Expand All @@ -21,6 +22,7 @@
* @author Alexandr Gorshenin
*/
public class URLServlet extends HttpServlet {
private static final long serialVersionUID = -1410806003624620851L;

private YdbRepository repository() {
return new YdbRepository(Application.ydp());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* @author Alexandr Gorshenin
*/
public class YdbException extends Exception {
private static final long serialVersionUID = -720473130272982493L;

public YdbException(String message, Throwable reason) {
super(message, reason);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import java.util.Optional;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import tech.ydb.core.Status;
import tech.ydb.core.UnexpectedResultException;
import tech.ydb.table.description.TableDescription;
Expand All @@ -11,8 +14,6 @@
import tech.ydb.table.transaction.TxControl;
import tech.ydb.table.values.PrimitiveType;
import tech.ydb.table.values.PrimitiveValue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
*
Expand Down Expand Up @@ -67,7 +68,7 @@ public void insertRecord(UrlRecord record) throws YdbException {
"$hash", PrimitiveValue.newText(record.hash())
);

TxControl txControl = TxControl.serializableRw().setCommitTx(true);
TxControl<?> txControl = TxControl.serializableRw().setCommitTx(true);

driver.retryCtx()
.supplyResult(session -> session.executeDataQuery(query, txControl, params))
Expand All @@ -88,7 +89,7 @@ public Optional<UrlRecord> findByHash(String hash) throws YdbException {
"$hash", PrimitiveValue.newText(hash)
);

TxControl txControl = TxControl.serializableRw();
TxControl<?> txControl = TxControl.serializableRw();

DataQueryResult result = driver.retryCtx()
.supplyResult(session -> session.executeDataQuery(query, txControl, params))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private void executeBatch(String query, ArrayList<Value<?>> pack) {

Params params = Params.of("$items", ListValue.of(values));

TxControl txControl = TxControl.serializableRw().setCommitTx(true);
TxControl<?> txControl = TxControl.serializableRw().setCommitTx(true);
retryCtx
.supplyResult(session -> session.executeDataQuery(query, txControl, params))
.join().getStatus().expectSuccess("expected success result");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.List;

import tech.ydb.core.grpc.GrpcTransport;

import tech.ydb.examples.App;
import tech.ydb.examples.AppRunner;
import tech.ydb.examples.pagination.model.School;
Expand Down Expand Up @@ -131,7 +130,7 @@ private void fillTableDataTransaction() {
path);

Params params = Params.of("$schoolsData", PaginationData.SCHOOL_DATA);
TxControl txControl = TxControl.serializableRw().setCommitTx(true);
TxControl<?> txControl = TxControl.serializableRw().setCommitTx(true);

session.executeDataQuery(query, txControl, params)
.join()
Expand Down Expand Up @@ -173,7 +172,7 @@ private List<School> selectPaging(long limit, School.Key lastSchool) {
"$lastCity", PrimitiveValue.newText(lastSchool.getCity()),
"$lastNumber", PrimitiveValue.newUint32(lastSchool.getNumber()));

TxControl txControl = TxControl.serializableRw().setCommitTx(true);
TxControl<?> txControl = TxControl.serializableRw().setCommitTx(true);

DataQueryResult result = session.executeDataQuery(query, txControl, params)
.join()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private void readTable(Session session, String tablePath) {
.toKeyExclusive(PrimitiveValue.newUint32(25))
.build();

session.readTable(tablePath, settings, resultSet -> {
session.readTable(tablePath, settings).start(resultSet -> {
// we are going to read a lot of data, so map column names to indexes
// outside of the loop to avoid overhead on each loop iteration
int keyIdx = resultSet.getColumnIndex("key");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected void run(GrpcTransport transport, String pathPrefix) {
.build();

Result<DataQueryResult> result = ctx.supplyResult(session -> {
TxControl txControl = TxControl.serializableRw()
TxControl<?> txControl = TxControl.serializableRw()
.setCommitTx(true);
return session.executeDataQuery("SELECT 1 + 2;", txControl);
}).join();
Expand Down

0 comments on commit 7c8b445

Please sign in to comment.