Updating existing applications
The latest 1010data Java SDK is designed for developing applications in a style that is more closely compatible with Java development, specifically object-oriented programming.
Applications developed with the original 1010data Java SDK must be updated to use the
object-oriented 1010data Java SDK. When you're updating your existing application, keep
that applications developed for the original 1010data Java SDK:
- Required you to instantiate exactly one instance of the
JavaSDK1010
class. The object-oriented 1010data Java SDK does not require you to instantiate any instance of theJavaSDK1010
class. - Required you to synchronize multiple threads yourself. The object-oriented
1010data Java SDK, handles thread synchronization. As a best practice, each
thread should create its own
Session
object. For more information, see Best practices or Establishing a session. - Required you to check for error codes after each method invocation. The object-oriented Java SDK uses an exception-based model. For more information, see Exception handling.
- Required applications using a SAM pool to manually acquire a UID via calls to
GetUID1010
. In the object-oriented 1010data Java SDK, this is not required. For more information, see Shared Access Management (SAM).
This example contains code written for the original 1010data Java SDK:
import com.tentendata.javasdk1010.*; public class PrintTable { public static void main(String[] args) { JavaSDK1010 link; int login; String gateway; String queryXML; String tablePath; String username; String password; int queryID, block, windowSize, finRows, rowsPerBlock; long numRows; Object[][] colInfo, table; if (args.length < 2) { System.err.println("usage: PrintTable USERNAME PASSWORD"); System.exit(1); } username = args[0]; password = args[1]; System.err.println("Single-user login for user " + username); gateway = "https://www2.1010data.com/cgi-bin/gw"; queryXML = "<sel value=\"(year>1900)\"/>"; tablePath = "pub.demo.baseball.batting"; windowSize = 10000; block = 40000; finRows = 0; // Create exactly one JavaSDK1010 object. link = new JavaSDK1010(); login = link.login1010(gateway, username, password, 1); // We need to check the return code after every action to // make sure that it succeeded. if (login < 0) { System.err.println("Failed " + login + ": " + link.msg1010(login)); System.exit(1); } try { queryID = link.newquery1010(); if(queryID < 0) { System.err.println("Fail to create query: (" + link.rc1010(login) + ") " + link.msg1010(login)); System.exit(1); } // -2 is COMPRESSED_BINARY link.querymode1010(queryID, windowSize, -2); link.prepquery1010(queryID, tablePath, queryXML); // Run the query. if(link.runquery1010(login, queryID) < 0) { System.err.println("Failed to run query: (" + link.rc1010(login) + ") " + link.msg1010(login)); System.exit(1); } colInfo = link.querycols1010(queryID); if(colInfo == null) { System.err.println("Failed to get column info: (" + link.rc1010(login) + ") " + link.msg1010(login)); System.exit(1); } numRows = link.queryrows1010(queryID); // For testing, limit the number of rows to 5000. numRows = Math.min(5000, numRows); block = 1000; while (finRows < numRows) { // Pull down one block at a time. // Start at finRows and get all the columns. table = link.getdataRM1010(queryID, finRows + block, colInfo); if(table == null) { System.err.println("Failure at getting data: (" + link.rc1010(login) + ") " + link.msg1010(login)); System.exit(1); } finRows += block; // For each row in this block... for (int i = 0; i < table.length; i++) { // for each column in this row... for (int j = 0; j < table[i].length; j++) { System.out.print(table[i][j] + "\t"); } System.out.println(); } // It is important to set the table to null // when you are finished using it. table = null; } } finally { link.logout1010(login); } } }
This example contains code written for the object-oriented 1010data Java SDK:
import com.tentendata.javasdk1010v2.*; public class PrintTable { public static void main(String[] args) { String gateway; String queryXML; String tablePath; String username; String password; Session session = null; Query query; if (args.length < 2) { System.err.println("usage: PrintTable USERNAME PASSWORD"); System.exit(1); } username = args[0]; password = args[1]; System.err.println("Single-user login for user " + username); gateway = "https://www2.1010data.com/cgi-bin/gw"; queryXML = "<sel value=\"(year>1900)\"/>"; tablePath = "pub.demo.baseball.batting"; try { session = new Session(gateway, username, password, LoginType.POSSESS); query = new Query(session, tablePath, queryXML); query.setWindowSize(1000); ResultSet results = query.run(); // Limit rows to 5000 for testing purposes. for (long i = 0; i < Math.min(5000,results.numRows()); i++) { Row row = results.row(i); Datum[] data = row.asArray(); for (int j = 0; j < data.length; j++) { if (j > 0) { System.out.print('\t'); } System.out.print(data[j].toString()); } System.out.println(); } } catch (TentenException exc) { System.err.println("1010 Exception occurred: " + exc.toString()); } finally { if (session!=null) { session.close(); } } } }