
prerna.reactor.algorithms.xray.GetExternalSchemaReactor Maven / Gradle / Ivy
The newest version!
package prerna.reactor.algorithms.xray;
//package prerna.sablecc2.reactor.algorithms.xray;
//
//import java.io.IOException;
//import java.sql.Connection;
//import java.sql.DatabaseMetaData;
//import java.sql.ResultSet;
//import java.sql.SQLException;
//import java.util.ArrayList;
//import java.util.HashMap;
//
//import com.fasterxml.jackson.core.JsonGenerationException;
//import com.fasterxml.jackson.databind.JsonMappingException;
//import com.fasterxml.jackson.databind.ObjectMapper;
//import com.fasterxml.jackson.databind.ObjectWriter;
//
//import prerna.engine.impl.rdbms.RdbmsConnectionHelper;
//import prerna.sablecc2.om.PixelDataType;
//import prerna.sablecc2.om.PixelOperationType;
//import prerna.sablecc2.om.ReactorKeysEnum;
//import prerna.sablecc2.om.nounmeta.NounMetadata;
//import prerna.sablecc2.reactor.AbstractReactor;
//
//public class GetExternalSchemaReactor extends AbstractReactor {
//
// public GetExternalSchemaReactor() {
// this.keysToGet = new String[] { ReactorKeysEnum.DB_DRIVER_KEY.getKey(), ReactorKeysEnum.HOST.getKey(),
// ReactorKeysEnum.PORT.getKey(), ReactorKeysEnum.USERNAME.getKey(),
// ReactorKeysEnum.PASSWORD.getKey(), ReactorKeysEnum.SCHEMA.getKey() };
// }
//
// @Override
// public NounMetadata execute() {
// organizeKeys();
// String dbDriver = this.keyValue.get(this.keysToGet[0]);
// if(dbDriver == null) {
// throw new IllegalArgumentException("Need to define the " + ReactorKeysEnum.DB_DRIVER_KEY.getKey());
// }
// String host = this.keyValue.get(this.keysToGet[1]);
// if(host == null) {
// throw new IllegalArgumentException("Need to define the " + ReactorKeysEnum.HOST.getKey());
// }
// String port = this.keyValue.get(this.keysToGet[2]);
// if(port == null) {
// throw new IllegalArgumentException("Need to define the " + ReactorKeysEnum.PORT.getKey());
// }
// String username = this.keyValue.get(this.keysToGet[3]);
// if(username == null) {
// throw new IllegalArgumentException("Need to define the " + ReactorKeysEnum.USERNAME.getKey());
// }
// String password = this.keyValue.get(this.keysToGet[4]);
// if(password == null) {
// throw new IllegalArgumentException("Need to define the " + ReactorKeysEnum.PASSWORD.getKey());
// }
// String schema = this.keyValue.get(this.keysToGet[5]);
// if(schema == null) {
// throw new IllegalArgumentException("Need to define the " + ReactorKeysEnum.SCHEMA.getKey());
// }
//
// Connection con = null;
// String schemaJSON = "";
// NounMetadata noun = null;
// try {
// con = RdbmsConnectionHelper.buildConnection(dbDriver, host, port, username, password, schema, null);
// String url = "";
// HashMap> tableDetails = new HashMap>(); // tablename:
// // [colDetails]
// HashMap> relations = new HashMap>(); // sub_table:
// // [(obj_table, fromCol, toCol)]
//
// DatabaseMetaData meta = con.getMetaData();
// ResultSet tables = meta.getTables(null, null, null, new String[] { "TABLE" });
// while (tables.next()) {
// ArrayList primaryKeys = new ArrayList();
// HashMap colDetails = new HashMap(); // name:
//
// ArrayList allCols = new ArrayList();
// HashMap fkDetails = new HashMap();
// ArrayList allRels = new ArrayList();
//
// String table = tables.getString("table_name");
// ResultSet keys = meta.getPrimaryKeys(null, null, table);
// while (keys.next()) {
// primaryKeys.add(keys.getString("column_name"));
// }
// keys = meta.getColumns(null, null, table, null);
// while (keys.next()) {
// colDetails = new HashMap();
// colDetails.put("name", keys.getString("column_name"));
// colDetails.put("type", keys.getString("type_name"));
// if (primaryKeys.contains(keys.getString("column_name"))) {
// colDetails.put("isPK", true);
// } else {
// colDetails.put("isPK", false);
// }
// allCols.add(colDetails);
// }
// tableDetails.put(table, allCols);
// keys = meta.getExportedKeys(null, null, table);
// while (keys.next()) {
// fkDetails = new HashMap();
// fkDetails.put("fromCol", keys.getString("PKCOLUMN_NAME"));
// fkDetails.put("toTable", keys.getString("FKTABLE_NAME"));
// fkDetails.put("toCol", keys.getString("FKCOLUMN_NAME"));
// allRels.add(fkDetails);
// }
// relations.put(table, allRels);
// }
// HashMap ret = new HashMap();
// ret.put("databaseName", con.getCatalog());
// ret.put("tables", tableDetails);
// ret.put("relationships", relations);
// ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
// schemaJSON = ow.writeValueAsString(ret);
// noun = new NounMetadata(schemaJSON, PixelDataType.CUSTOM_DATA_STRUCTURE, PixelOperationType.CODE_EXECUTION);
//
// con.close();
//
// } catch (SQLException e) {
// classLogger.error(Constants.STACKTRACE, e);
// } catch (JsonGenerationException e) {
// classLogger.error(Constants.STACKTRACE, e);
// } catch (JsonMappingException e) {
// classLogger.error(Constants.STACKTRACE, e);
// } catch (IOException e) {
// classLogger.error(Constants.STACKTRACE, e);
// } finally {
// if (con != null) {
// try {
// con.close();
// } catch (SQLException e) {
// classLogger.error(Constants.STACKTRACE, e);
// }
// }
// }
//
// return noun;
// }
//
//}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy