TcaplusDB TDR Table Java SDK Get Started

The preparations for using the Java SDK mainly include:

  1. Prepare the environment;
  2. Create an app;
  3. Create a game zone;
  4. Create a table;
  5. Collect environmental information;
  6. Download SDK;
  7. Configure the development environment.

If the above preparations have been completed, they can be skipped.

1. Prepare the Environment

Refer to Create a Cluster to deploy the TcaplusDB cluster, or apply for the TcaplusDB service.

2. Create an App

Refer to Create an App to create an App.

3. Create A Game Zone

Refer to Create a Game Zone to create a game zone (Zone).

4. Create A Table

Refer to Add a Table to add a table.

TDR tables are divided into Generic tables and List tables.

4.1. Generic Table Definition Descriptions

Sample of the Generic table description file: Download.

Content example of the Generic table description file:

<?xml version="1.0" encoding="GBK" standalone="yes" ?>               
<metalib name="table_test" tagsetversion="1" version="1">               
    <struct name="test" version="1" splittablekey="gameid"  primarykey="gameid,itemid,name">               
        <entry name="gameid" type="uint" />                
        <entry name="itemid" type="uint" />               
        <entry name="name" type="string" size="5" />               
        <entry name="typeid" type="uint8"/>               
        <entry name="Data" type="tinyuint" defaultvalue="9"/>               
        <entry name="uname" type="string" size="5" defaultvalue="ab"/>               
        <index name="index_id" column="gameid" />               
    </struct>
</metalib>

Refer to TDR Table for the format description of the TDR table description file.

4.2. List Table Definition Descriptions

Sample of the List table description file: Download.

Content example of the List table description file:

<?xml version="1.0" encoding="GBK" standalone="yes" ?>               
<metalib name="table_test" tagsetversion="1" version="1">               
    <struct name="test" version="1" splittablekey="gameid"  primarykey="gameid,itemid,name" customattr2="TableType=LIST;ListNum=3">               
        <entry name="gameid" type="uint" />                
        <entry name="itemid" type="uint" />               
        <entry name="name" type="string" size="5" />               
        <entry name="typeid" type="uint8"/>               
        <entry name="Data" type="tinyuint" defaultvalue="9"/>               
        <entry name="uname" type="string" size="5" defaultvalue="ab"/>               
        <index name="index_id" column="gameid" />               
    </struct>
</metalib>

Refer to TDR Table for the format description of the TDR table description file.

The TableType = LIST in customattr2 defined by the table is used to identify the list table. Similarly, the ListNum attribute in customattr2 is used to specify how many elements can be stored in a single List at most.

Note: Since the List table has a built-in primarykey field to store the element serial numbers in the List, users can only define up to 7 primarykey fields for the List table.

5. Collect Environmental Information

When using the Java SDK, it requires some environment related parameters. See the following table for specific parameters and collection methods.

Parameter Value Getting method
Directory server address list Get directory service address list
App ID Get App ID
App access password Get app access password
Game zone ID Get game zone ID
Table name test

6. Download Java SDK

For details about the Java SDK release and download link, see TDR Table SDK Download.

7. Configure the Development Environment

7.1. Maven Project

Maven specifies dependency packages in two common ways: relative path dependency and maven repository dependency.

Note: The x.x.x below needs to be replaced with a specific version number, such as 3.40.0.

  • Relative path dependency

    Unzip the Java SDK package and place the service-api-x.x.x.jar file in the lib directory of the current Maven project.

    Modify the pom.xml file of the project and add package dependencies.

    <dependency>
          <groupId>com.tencent.tcaplus</groupId>
          <artifactId>service-api</artifactId>
          <version>x.x.x</version>
          <scope>system</scope>
          <systemPath>${project.basedir}/lib/service-api-x.x.x.jar</systemPath>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.5</version>
    </dependency>
    
  • Maven repository dependency.

    Unzip the Java SDK package and place the service-api-x.x.x.jar file in a temporary directory (such as /tmp/).

    Install the service-api-x.x.x.jar package to the local Maven repository or deploy it to the remote repository.

    # Install to local jar
    mvn install:install-file -Dfile="/tmp/service-api-x.x.x.jar" -DgroupId=com.tencent.tcaplus -DartifactId=service-api -Dversion=x.x.x -Dpackaging=jar
    
    # Deploy to remote jar
    # Note: replace "<remote jar address>" with the actual remote jar URL address
    mvn deploy:deploy-file -Dfile="/tmp/service-api-x.x.x.jar" -DgroupId=com.tencent.tcaplus -DartifactId=service-api -Dversion=x.x.x -Dpackaging=jar -Durl=<remote jar address>
    

7.2. Other Types of Projects

You can import the corresponding package directly at compile time with the cp parameter, or add it to the classpath environment variables, as shown below:

# Compile with the corresponding dependency package
javac -cp ./tcaplus-service-api-x.x.x.jar:./slf4j-api-1.7.5.jar Example.java

# Run with the corresponding dependency package
java -cp ./tcaplus-service-api-x.x.x.jar:./slf4j-api-1.7.5.jar Example

8. Use Java SDK

Please refer to the Java SDK Interfaces Descriptions for details

9. FAQ

In the process of using the Java SDK, if you have questions (such as viewing the SDK version, configuring SDK log printing, upgrading the SDK, etc.), or errors, please refer to "FAQ" and "Meaning and Handling of Error Codes".

  1. FAQ document;

  2. Meaning and Handling of Error Codes document;

results matching ""

    No results matching ""