0
votes

I'm trying to access my metadata in order to list the tables on my ignite database using this two approaches, but all I can get is my schema name and nothing from the getmetadata method, and for that I'm using the following code:

var JDBC = require('jdbc');
var metadata = require('jdbc-metadata');
var async = require("async");
var jinst = require('jdbc/lib/jinst');
var ResultSet = require('jdbc/lib/resultset');
var databasemetadata = require('jdbc/lib/databasemetadata');

if (!jinst.isJvmCreated()) {
  jinst.addOption("-Xrs");
  jinst.setupClasspath([appRoot2 + '/ignite-core-2.4.0.jar']);
}

var config = {
  // Ignite configuration to your server
  url: 'jdbc:ignite:thin://host:port',
  drivername: 'org.apache.ignite.IgniteJdbcThinDriver',
  minpoolsize: 1,
  maxpoolsize: 100,
  properties: {}
};

var igniteConn = new JDBC(config);
igniteConn.initialize(function(err) {
  if (err) {
    done(err);
    return console.error('Connection Error: ' + err);
    saveToLog(req, 'Error on connection: ' + err, 300, 'JO-002', '');
  } else {
    console.log("connection established");
  }
});

igniteConn.reserve(function(err, connObj) {
      if (connObj) {
        console.log("Using connection: " + connObj.uuid);
        var conn = connObj.conn;
        async.series([

          function(callback) {
            conn.getSchema(function(err, res) {
              if (err) {
                callback(err);
              } else {
                console.log(res);
                callback(res);
              }
            });
          },
          function(callback) {
            conn.getMetadata(function(err, res) {
              if (err) {
                callback(err);
              } else {
                console.log("///////");
                console.log(res);
                callback(res);
              }
            });
          }
        ], function(err, results) {
          // Check for errors if need be.
          // results is an array.
        });

The second approach using the driverManager:

var drivermanager = require('jdbc/lib/drivermanager');
drivermanager.getConnection(config.url, null, null, function(err, conn) {
  if (err) throw err;
  testconn = new Connection(conn);

  if (testconn) {
    async.series([
      function(callback) {
        testconn.getMetaData(function(err, result) {
          if (err) callback(err);
          console.log(result);
          /*
          else {
            result.getTables(null,null,null,null,function(err,res){
              if(err) callback(err);

              else {                      
                console.log(res);
              }

            });
          }*/
          //resultSet = result.getTables(null, null, null,"TABLE");
        });
      },
    ], function(err, results) {
      // Results can also be processed here.
      // Release the connection back to the pool.
    });
  }
});

I can run queries against my tables normally for the information. If anyone has any suggestions, how I can get to my metadata or if you know the query that I can run for getting that if there's any other alternatives (like SELECT information.tabels ... but this is not working on ignite) that would be really appreciated.

1
What is ignite version you are using? issues.apache.org/jira/browse/IGNITE-5233 Metadata should be available since 2.3 - antkr
I'm using 2.4, yeah i've checked that it is available but still can't access to it - ELWALI
The part that i don't get, is when using Java Program i can access to metadata and list my tables, but it is not the case when using nodejs as i posted - ELWALI

1 Answers

2
votes

The following snippet worked for me:

var config = {
  libpath: 'ignite-core-2.4.0.jar',
  // Ignite configuration to your server
  url: 'jdbc:ignite:thin://127.0.0.1',
  drivername: 'org.apache.ignite.IgniteJdbcThinDriver',
  minpoolsize: 1,
  maxpoolsize: 100,
  properties: {}
};

var jdbcMetadata = new metadata(config);

jdbcMetadata.metadata(function (err, metadata) {
    console.log('Getting tables...');

    jdbcMetadata.tables({schema: "PUBLIC", types: ['TABLE', 'VIEW']}, function (err, tables) {
        console.log(tables);

        jdbcMetadata.close(function(err) {
          console.log('Connection closed');
        });
    });
});

I could see:

[ { tableCat: null,
    tableSchem: 'PUBLIC',
    tableName: 'A',
    tableType: 'TABLE',
    remarks: null,
    typeCat: null,
    typeSchem: null,
    typeName: null,
    selfReferencingColName: null,
    refGeneration: null } ]