File tree Expand file tree Collapse file tree 4 files changed +87
-0
lines changed
src/main/java/tech/ydb/app Expand file tree Collapse file tree 4 files changed +87
-0
lines changed Original file line number Diff line number Diff line change 2929 <module >ydb-cookbook</module >
3030 <module >url-shortener-demo</module >
3131 <module >jdbc</module >
32+ <module >project-course</module >
3233 </modules >
3334
3435 <dependencyManagement >
Original file line number Diff line number Diff line change 1+ <project xmlns =" http://maven.apache.org/POM/4.0.0" xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
2+ xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
3+ <modelVersion >4.0.0</modelVersion >
4+ <parent >
5+ <groupId >tech.ydb.examples</groupId >
6+ <artifactId >ydb-sdk-examples</artifactId >
7+ <version >1.1.0-SNAPSHOT</version >
8+ </parent >
9+
10+ <groupId >tech.ydb.app</groupId >
11+ <artifactId >project-course</artifactId >
12+ <packaging >jar</packaging >
13+
14+ <name >project-course</name >
15+ <url >http://maven.apache.org</url >
16+
17+ <properties >
18+ <project .build.sourceEncoding>UTF-8</project .build.sourceEncoding>
19+ </properties >
20+
21+ <dependencies >
22+ <dependency >
23+ <groupId >tech.ydb</groupId >
24+ <artifactId >ydb-sdk-query</artifactId >
25+ </dependency >
26+ </dependencies >
27+
28+ <build >
29+ <plugins >
30+ <plugin >
31+ <groupId >org.codehaus.mojo</groupId >
32+ <artifactId >exec-maven-plugin</artifactId >
33+ <version >3.5.0</version >
34+ <configuration >
35+ <mainClass >tech.ydb.app.App</mainClass >
36+ </configuration >
37+ </plugin >
38+ </plugins >
39+ </build >
40+ </project >
Original file line number Diff line number Diff line change 1+ package tech .ydb .app ;
2+
3+ import tech .ydb .app .repository .YdbRepository ;
4+
5+ public class App {
6+ public static void main (String [] args ) {
7+ if (args .length != 1 ) {
8+ throw new UnsupportedOperationException ("Expected 1 parameter connectionString" );
9+ }
10+
11+ new YdbRepository (args [0 ]).TestDatabase ();
12+ }
13+ }
Original file line number Diff line number Diff line change 1+ package tech .ydb .app .repository ;
2+
3+ import tech .ydb .common .transaction .TxMode ;
4+ import tech .ydb .core .grpc .GrpcTransport ;
5+ import tech .ydb .query .QueryClient ;
6+ import tech .ydb .query .tools .QueryReader ;
7+ import tech .ydb .query .tools .SessionRetryContext ;
8+ import tech .ydb .table .result .ResultSetReader ;
9+
10+ /**
11+ * @author Kirill Kurdyukov
12+ */
13+ public class YdbRepository {
14+ private final SessionRetryContext retryCtx ;
15+
16+ public YdbRepository (String connectionString ) {
17+ GrpcTransport transport = GrpcTransport .forConnectionString (connectionString ).build ();
18+ QueryClient queryClient = QueryClient .newClient (transport ).build ();
19+ this .retryCtx = SessionRetryContext .create (queryClient ).build ();
20+ }
21+
22+ public void TestDatabase () {
23+ QueryReader resultSet = retryCtx .supplyResult (session ->
24+ QueryReader .readFrom (session .createQuery ("SELECT 1;" , TxMode .NONE ))
25+ ).join ().getValue ();
26+
27+ ResultSetReader resultSetReader = resultSet .getResultSet (0 );
28+
29+ if (resultSetReader .next ()) {
30+ System .out .println ("Database is available!" );
31+ }
32+ }
33+ }
You can’t perform that action at this time.
0 commit comments