Skip to content

Commit

Permalink
Support showDatabase method and etc (#209)
Browse files Browse the repository at this point in the history
* Support showDatabase method

* Minor Fix

* Support the id field in TDDatabase again
  • Loading branch information
yuokada authored Jan 19, 2023
1 parent 9049c14 commit ba7182d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/main/java/com/treasuredata/client/TDClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,13 @@ public List<TDDatabase> listDatabases()
return doGet("/v3/database/list", new TypeReference<List<TDDatabase>>() {});
}

@Override
public TDDatabase showDatabase(String databaseName)
throws TDClientException
{
return doGet(buildUrl("/v3/database/show", databaseName), TDDatabase.class);
}

private static Pattern acceptableNamePattern = Pattern.compile("^([a-z0-9_]+)$");

static String validateDatabaseName(String databaseName)
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/treasuredata/client/TDClientApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ public interface TDClientApi<ClientImpl>
*/
List<String> listDatabaseNames();

/**
* Get the detailed information of a database
*
* @return TDDatabase
* @throws TDClientException if failed to retrieve the detailed information of a database.
*/
TDDatabase showDatabase(String databaseName);

/**
* Get the detailed information of databases
*
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/treasuredata/client/model/TDDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
@JsonCollectionRootName(value = "databases")
public class TDDatabase
{
private final String id;
private final String name;
private final long count;
private final String createdAt;
Expand All @@ -35,6 +36,7 @@ public class TDDatabase

@JsonCreator
public TDDatabase(
@JsonProperty("id") String id,
@JsonProperty("name") String name,
@JsonProperty("count") long count,
@JsonProperty("created_at") String createdAt,
Expand All @@ -43,6 +45,7 @@ public TDDatabase(
@JsonProperty("permission") String permission
)
{
this.id = id;
this.name = name;
this.count = count;
this.createdAt = createdAt;
Expand All @@ -51,6 +54,12 @@ public TDDatabase(
this.permission = permission;
}

@JsonProperty
public String getId()
{
return id;
}

@JsonProperty
public String getName()
{
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/com/treasuredata/client/TestTDClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,18 @@ public void serverStatus()
assertEquals("ok", s.getString("status"));
}

@Test
public void showDatabase()
throws Exception
{
String databaseName = "sample_datasets";
TDDatabase dbDetail = client.showDatabase(databaseName);
assertEquals("should match in sample_datasets", databaseName, dbDetail.getName());
assertTrue("should be positive", Integer.parseInt(dbDetail.getId()) > 0);

logger.debug(dbDetail.toString());
}

@Test
public void listDatabases()
throws Exception
Expand Down

0 comments on commit ba7182d

Please # to comment.