Skip to content

Commit 7925f5f

Browse files
Update Java APIs with marker throwing runtime TypeDBDriverExceptions, though this is not best practice
1 parent 1e0912f commit 7925f5f

File tree

13 files changed

+49
-73
lines changed

13 files changed

+49
-73
lines changed

java/TypeDB.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.Set;
2929

3030
import static com.typedb.driver.common.collection.Collections.set;
31+
import com.typedb.driver.common.exception.TypeDBDriverException;
3132

3233
public class TypeDB {
3334
public static final String DEFAULT_ADDRESS = "localhost:1729";
@@ -44,7 +45,7 @@ public class TypeDB {
4445
* @param credentials The credentials to connect with
4546
* @param driverOptions The connection settings to connect with
4647
*/
47-
public static Driver coreDriver(String address, Credentials credentials, DriverOptions driverOptions) {
48+
public static Driver coreDriver(String address, Credentials credentials, DriverOptions driverOptions) throws TypeDBDriverException {
4849
return new DriverImpl(address, credentials, driverOptions);
4950
}
5051

@@ -61,7 +62,7 @@ public static Driver coreDriver(String address, Credentials credentials, DriverO
6162
* @param credentials The credential to connect with
6263
* @param driverOptions The connection settings to connect with
6364
*/
64-
public static Driver cloudDriver(String address, Credentials credentials, DriverOptions driverOptions) {
65+
public static Driver cloudDriver(String address, Credentials credentials, DriverOptions driverOptions) throws TypeDBDriverException {
6566
return cloudDriver(set(address), credentials, driverOptions);
6667
}
6768

@@ -78,7 +79,7 @@ public static Driver cloudDriver(String address, Credentials credentials, Driver
7879
* @param credentials The credential to connect with
7980
* @param driverOptions The connection settings to connect with
8081
*/
81-
public static Driver cloudDriver(Set<String> addresses, Credentials credentials, DriverOptions driverOptions) {
82+
public static Driver cloudDriver(Set<String> addresses, Credentials credentials, DriverOptions driverOptions) throws TypeDBDriverException {
8283
return new DriverImpl(addresses, credentials, driverOptions);
8384
}
8485

@@ -96,7 +97,7 @@ public static Driver cloudDriver(Set<String> addresses, Credentials credentials,
9697
* @param credentials The credential to connect with
9798
* @param driverOptions The connection settings to connect with
9899
*/
99-
public static Driver cloudDriver(Map<String, String> addressTranslation, Credentials credentials, DriverOptions driverOptions) {
100+
public static Driver cloudDriver(Map<String, String> addressTranslation, Credentials credentials, DriverOptions driverOptions) throws TypeDBDriverException {
100101
return new DriverImpl(addressTranslation, credentials, driverOptions);
101102
}
102103
}

java/api/Driver.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import com.typedb.driver.api.database.DatabaseManager;
2323
import com.typedb.driver.api.user.UserManager;
2424

25+
import com.typedb.driver.common.exception.TypeDBDriverException;
26+
2527
import javax.annotation.CheckReturnValue;
2628

2729
public interface Driver extends AutoCloseable {
@@ -56,7 +58,7 @@ public interface Driver extends AutoCloseable {
5658
* @param type The type of transaction to be created (READ, WRITE, or SCHEMA)
5759
*/
5860
@CheckReturnValue
59-
Transaction transaction(String database, Transaction.Type type);
61+
Transaction transaction(String database, Transaction.Type type) throws TypeDBDriverException ;
6062

6163
// @CheckReturnValue
6264
// Transaction transaction(String database, Transaction.Type type, Options options);

java/api/Transaction.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public interface Transaction extends AutoCloseable {
6565
* @param query The query to execute.
6666
*/
6767
@CheckReturnValue
68-
Promise<? extends QueryAnswer> query(String query);
68+
Promise<? extends QueryAnswer> query(String query) throws com.typedb.driver.common.exception.TypeDBDriverException;
6969

7070
/**
7171
* Registers a callback function which will be executed when this transaction is closed.
@@ -87,7 +87,7 @@ public interface Transaction extends AutoCloseable {
8787
* transaction.commit()
8888
* </pre>
8989
*/
90-
void commit();
90+
void commit() throws com.typedb.driver.common.exception.TypeDBDriverException;
9191

9292
/**
9393
* Rolls back the uncommitted changes made via this transaction.
@@ -97,7 +97,7 @@ public interface Transaction extends AutoCloseable {
9797
* transaction.rollback()
9898
* </pre>
9999
*/
100-
void rollback();
100+
void rollback() throws com.typedb.driver.common.exception.TypeDBDriverException;
101101

102102
/**
103103
* Closes the transaction.
@@ -107,7 +107,7 @@ public interface Transaction extends AutoCloseable {
107107
* transaction.close()
108108
* </pre>
109109
*/
110-
void close();
110+
void close() throws com.typedb.driver.common.exception.TypeDBDriverException;
111111

112112
/**
113113
* Used to specify the type of transaction.

java/api/database/Database.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
package com.typedb.driver.api.database;
2121

22+
import com.typedb.driver.common.exception.TypeDBDriverException;
23+
2224
import javax.annotation.CheckReturnValue;
2325

2426
public interface Database {
@@ -38,7 +40,7 @@ public interface Database {
3840
* </pre>
3941
*/
4042
@CheckReturnValue
41-
String schema();
43+
String schema() throws TypeDBDriverException;
4244

4345
/**
4446
* The types in the schema as a valid TypeQL define query string.
@@ -49,7 +51,7 @@ public interface Database {
4951
* </pre>
5052
*/
5153
@CheckReturnValue
52-
String typeSchema();
54+
String typeSchema() throws TypeDBDriverException;
5355

5456
/**
5557
* Deletes this database.
@@ -59,7 +61,7 @@ public interface Database {
5961
* database.delete()
6062
* </pre>
6163
*/
62-
void delete();
64+
void delete() throws TypeDBDriverException;
6365

6466
// /**
6567
// * Set of <code>Replica</code> instances for this database.

java/api/database/DatabaseManager.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
package com.typedb.driver.api.database;
2121

22+
import com.typedb.driver.common.exception.TypeDBDriverException;
23+
2224
import javax.annotation.CheckReturnValue;
2325
import java.util.List;
2426

@@ -38,7 +40,7 @@ public interface DatabaseManager {
3840
* @param name The name of the database to retrieve
3941
*/
4042
@CheckReturnValue
41-
Database get(String name);
43+
Database get(String name) throws TypeDBDriverException;
4244

4345
/**
4446
* Checks if a database with the given name exists
@@ -51,7 +53,7 @@ public interface DatabaseManager {
5153
* @param name The database name to be checked
5254
*/
5355
@CheckReturnValue
54-
boolean contains(String name);
56+
boolean contains(String name) throws TypeDBDriverException;
5557

5658
/**
5759
* Create a database with the given name
@@ -64,7 +66,7 @@ public interface DatabaseManager {
6466
* @param name The name of the database to be created
6567
*/
6668
// TODO: Return type should be 'Database' but right now that would require 2 server calls in Cloud
67-
void create(String name);
69+
void create(String name) throws TypeDBDriverException;
6870

6971
/**
7072
* Retrieves all databases present on the TypeDB server
@@ -75,5 +77,5 @@ public interface DatabaseManager {
7577
* </pre>
7678
*/
7779
@CheckReturnValue
78-
List<Database> all();
80+
List<Database> all() throws TypeDBDriverException;
7981
}

java/api/user/UserManager.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import javax.annotation.CheckReturnValue;
2323
import java.util.Set;
24+
import com.typedb.driver.common.exception.TypeDBDriverException;
2425

2526
/**
2627
* Provides access to all user management methods.
@@ -37,7 +38,7 @@ public interface UserManager {
3738
* @param username The user name to be checked
3839
*/
3940
@CheckReturnValue
40-
boolean contains(String username);
41+
boolean contains(String username) throws TypeDBDriverException;
4142

4243
/**
4344
* Retrieves a user with the given name.
@@ -50,7 +51,7 @@ public interface UserManager {
5051
* @param username The name of the user to retrieve
5152
*/
5253
@CheckReturnValue
53-
User get(String username);
54+
User get(String username) throws TypeDBDriverException;
5455

5556
// TODO: I don't like this, leaving this way for now. Use driver.users().get(username)
5657

@@ -63,7 +64,7 @@ public interface UserManager {
6364
* </pre>
6465
*/
6566
@CheckReturnValue
66-
User getCurrentUser();
67+
User getCurrentUser() throws TypeDBDriverException;
6768

6869
/**
6970
* Retrieves all users which exist on the TypeDB server.
@@ -73,7 +74,7 @@ public interface UserManager {
7374
* driver.users().all();
7475
* </pre>
7576
*/
76-
Set<User> all();
77+
Set<User> all() throws TypeDBDriverException;
7778

7879
/**
7980
* Creates a user with the given name &amp; password.
@@ -86,5 +87,5 @@ public interface UserManager {
8687
* @param username The name of the user to be created
8788
* @param password The password of the user to be created
8889
*/
89-
void create(String username, String password);
90+
void create(String username, String password) throws TypeDBDriverException;
9091
}

java/common/exception/TypeDBException.java

Lines changed: 0 additions & 32 deletions
This file was deleted.

java/concept/answer/QueryAnswerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ protected QueryAnswerImpl(com.typedb.driver.jni.QueryAnswer answer) {
3636
queryType = QueryType.of(query_answer_get_query_type(answer));
3737
}
3838

39-
public static QueryAnswerImpl of(com.typedb.driver.jni.QueryAnswer concept) {
39+
public static QueryAnswerImpl of(com.typedb.driver.jni.QueryAnswer concept) throws TypeDBDriverException {
4040
if (query_answer_is_ok(concept)) return new OkQueryAnswerImpl(concept);
4141
else if (query_answer_is_concept_row_stream(concept)) return new ConceptRowIteratorImpl(concept);
4242
else if (query_answer_is_concept_document_stream(concept)) return new ConceptDocumentIteratorImpl(concept);

java/connection/DatabaseImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public String name() {
4141
}
4242

4343
@Override
44-
public String schema() {
44+
public String schema() throws TypeDBDriverException {
4545
if (!nativeObject.isOwned()) throw new TypeDBDriverException(DATABASE_DELETED);
4646
try {
4747
return database_schema(nativeObject);
@@ -51,7 +51,7 @@ public String schema() {
5151
}
5252

5353
@Override
54-
public String typeSchema() {
54+
public String typeSchema() throws TypeDBDriverException {
5555
if (!nativeObject.isOwned()) throw new TypeDBDriverException(DATABASE_DELETED);
5656
try {
5757
return database_type_schema(nativeObject);
@@ -61,7 +61,7 @@ public String typeSchema() {
6161
}
6262

6363
@Override
64-
public void delete() {
64+
public void delete() throws TypeDBDriverException {
6565
if (!nativeObject.isOwned()) throw new TypeDBDriverException(DATABASE_DELETED);
6666
try {
6767
// NOTE: .released() relinquishes ownership of the native object to the Rust side

java/connection/DatabaseManagerImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public DatabaseManagerImpl(com.typedb.driver.jni.TypeDBDriver driver) {
4040
}
4141

4242
@Override
43-
public Database get(String name) throws Error {
43+
public Database get(String name) throws TypeDBDriverException {
4444
try {
4545
return new DatabaseImpl(databases_get(nativeDriver, name));
4646
} catch (com.typedb.driver.jni.Error e) {
@@ -49,7 +49,7 @@ public Database get(String name) throws Error {
4949
}
5050

5151
@Override
52-
public boolean contains(String name) throws Error {
52+
public boolean contains(String name) throws TypeDBDriverException {
5353
try {
5454
return databases_contains(nativeDriver, name);
5555
} catch (com.typedb.driver.jni.Error e) {
@@ -58,7 +58,7 @@ public boolean contains(String name) throws Error {
5858
}
5959

6060
@Override
61-
public void create(String name) throws Error {
61+
public void create(String name) throws TypeDBDriverException {
6262
try {
6363
databases_create(nativeDriver, name);
6464
} catch (com.typedb.driver.jni.Error e) {
@@ -67,7 +67,7 @@ public void create(String name) throws Error {
6767
}
6868

6969
@Override
70-
public List<Database> all() {
70+
public List<Database> all() throws TypeDBDriverException {
7171
try {
7272
return new NativeIterator<>(databases_all(nativeDriver)).stream().map(DatabaseImpl::new).collect(toList());
7373
} catch (com.typedb.driver.jni.Error e) {

0 commit comments

Comments
 (0)