Skip to content

Commit 37868b3

Browse files
feat: lesson 1
1 parent c49e92b commit 37868b3

File tree

5 files changed

+126
-0
lines changed

5 files changed

+126
-0
lines changed

pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
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>

project-course/pom.xml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
<dependency>
27+
<groupId>junit</groupId>
28+
<artifactId>junit</artifactId>
29+
<version>3.8.1</version>
30+
<scope>test</scope>
31+
</dependency>
32+
</dependencies>
33+
34+
<build>
35+
<plugins>
36+
<!-- Другие плагины -->
37+
<plugin>
38+
<groupId>org.codehaus.mojo</groupId>
39+
<artifactId>exec-maven-plugin</artifactId>
40+
<version>3.5.0</version> <!-- Вы можете указать актуальную версию -->
41+
<configuration>
42+
<mainClass>tech.ydb.app.App</mainClass> <!-- Укажите ваш класс с методом main -->
43+
</configuration>
44+
</plugin>
45+
</plugins>
46+
</build>
47+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package tech.ydb.app;
2+
3+
import junit.framework.Test;
4+
import junit.framework.TestCase;
5+
import junit.framework.TestSuite;
6+
7+
/**
8+
* Unit test for simple App.
9+
*/
10+
public class AppTest
11+
extends TestCase
12+
{
13+
/**
14+
* Create the test case
15+
*
16+
* @param testName name of the test case
17+
*/
18+
public AppTest( String testName )
19+
{
20+
super( testName );
21+
}
22+
23+
public static Test suite()
24+
{
25+
return new TestSuite( AppTest.class );
26+
}
27+
28+
public void testApp()
29+
{
30+
assertTrue( true );
31+
}
32+
}

0 commit comments

Comments
 (0)