<commit_before>package de.thinkbaer.aios.jdbc.struct;

import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;

import de.thinkbaer.aios.api.datasource.query.Query;
import de.thinkbaer.aios.api.exception.AiosException;
import de.thinkbaer.aios.jdbc.ConnectionImpl;
import de.thinkbaer.aios.jdbc.SqlDataType;
import de.thinkbaer.aios.jdbc.query.AbstractQueryImpl;

public class TableQueryImpl extends AbstractQueryImpl<TableResultsImpl, TableQueryImpl>
		implements Query<TableResultsImpl> {

	// private static final Logger L =
	// LogManager.getLogger(SchemaQueryImpl.class);

	private String schema = null;

	private String catalog = null;

	private String table = null;

	private String[] types = null;

	private String column = null;

	private boolean skipKeys = false;

	@Override
	public TableResultsImpl execute(ConnectionImpl conn) throws Exception {

		TableResultsImpl results = new TableResultsImpl();

		if (catalog == null) {
			throw new AiosException("Catalog is not set");
		} else {

		}

		try {
			DatabaseMetaData databaseMetaData = conn.getConnection().getMetaData();

			ResultSet rsTables = databaseMetaData.getTables(getCatalog(), getSchema(), getTable(), types);
			while (rsTables.next()) {
				String catalogName = rsTables.getString("TABLE_CAT");
				String schemaName = rsTables.getString("TABLE_SCHEM");
				String tableName = rsTables.getString("TABLE_NAME");
				
				String tableType = rsTables.getString("TABLE_TYPE");
				String remarks = rsTables.getString("REMARKS");
				String typeCat = rsTables.getString("TYPE_CAT");
				String typeSchem = rsTables.getString("TYPE_SCHEM");
				String typeName = rsTables.getString("TYPE_NAME");
				String selfRefColName = rsTables.getString("SELF_REFERENCING_COL_NAME");
				String refGeneration = rsTables.getString("REF_GENERATION");

				Table t = results.addTable(tableName);
				t.setCatalog(catalogName);
				t.setSchema(schemaName);
				t.setType(typeSchem);
			}

			if (!skipKeys && getTable() != null) {
				
				ResultSet rsColumns = databaseMetaData.getColumns(getCatalog(), getSchema(), getTable(), getColumn());
				while (rsColumns.next()) {
					String catalogName = rsColumns.getString("TABLE_CAT");
					String schemaName = rsColumns.getString("TABLE_SCHEM");
					String tableName = rsColumns.getString("TABLE_NAME");
					
										
					String columnName = rsColumns.getString("COLUMN_NAME");
															
					Table t = results.getTable(catalogName, schemaName, tableName);
					if(!t.hasColumn(columnName)){
						Column c = t.addColumn(columnName);
												
						int oDataType = rsColumns.getInt("DATA_TYPE");												
						String oTypeName = rsColumns.getString("TYPE_NAME");					
						int oColumnSize = rsColumns.getInt("COLUMN_SIZE");
						int oDecimalDigits = rsColumns.getInt("DECIMAL_DIGITS");
						int oNumPrecRadix = rsColumns.getInt("NUM_PREC_RADIX");
						int oNnullable = rsColumns.getInt("NULLABLE");
						String oRemarks = rsColumns.getString("REMARKS");
						String oColumnDef = rsColumns.getString("COLUMN_DEF");
						int oSqlDataType = rsColumns.getInt("SQL_DATA_TYPE"); // unused
						int oSqlDataTypeSub = rsColumns.getInt("SQL_DATETIME_SUB"); // unused
						int oCharOctetLength = rsColumns.getInt("CHAR_OCTET_LENGTH"); 
						int oOrdinalPosition = rsColumns.getInt("ORDINAL_POSITION"); 
						String oIsNullable = rsColumns.getString("IS_NULLABLE");
						String oScopeCatalog = rsColumns.getString("SCOPE_CATALOG");
						String oScopeSchema = rsColumns.getString("SCOPE_SCHEMA");
						String oScopeTable = rsColumns.getString("SCOPE_TABLE");
						short oSourceDataType = rsColumns.getShort("SOURCE_DATA_TYPE");
						String oIsAutoincrement = rsColumns.getString("IS_AUTOINCREMENT");
						String oIsGeneratedcolumn = rsColumns.getString("IS_GENERATEDCOLUMN");
						
						c.setTypeCode(oDataType);
						c.setType(SqlDataType.forCode(oDataType).name());						
					}
					
					// ResultSet rsColumns = databaseMetaData.getColumns(getCatalog(), getSchema(), getTable(), getColumn());
				}
				
				// getPrimary
				ResultSet rsPrimarys = databaseMetaData.getPrimaryKeys(getCatalog(), getSchema(), getTable());<commit_msg>save work on structure queries<commit_after>package de.thinkbaer.aios.jdbc.struct;

import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import de.thinkbaer.aios.api.datasource.query.Query;
import de.thinkbaer.aios.api.exception.AiosException;
import de.thinkbaer.aios.jdbc.ConnectionImpl;
import de.thinkbaer.aios.jdbc.SqlDataType;
import de.thinkbaer.aios.jdbc.query.AbstractQueryImpl;

public class TableQueryImpl extends AbstractQueryImpl<TableResultsImpl, TableQueryImpl>
		implements Query<TableResultsImpl> {

	private static final Logger L = LogManager.getLogger(TableQueryImpl.class);
	// private static final Logger L =
	// LogManager.getLogger(SchemaQueryImpl.class);

	private String schema = null;

	private String catalog = null;

	private String table = null;

	private String[] types = null;

	private String column = null;

	private boolean skipKeys = false;

	@Override
	public TableResultsImpl execute(ConnectionImpl conn) throws Exception {

		TableResultsImpl results = new TableResultsImpl();

		if (catalog == null) {
			throw new AiosException("Catalog is not set");
		} else {

		}
		boolean attachKeys = skipKeys;
		 if(!attachKeys && getTable() != null){
			 attachKeys = true;
		 }

		try {
			DatabaseMetaData databaseMetaData = conn.getConnection().getMetaData();

			ResultSet rsTables = databaseMetaData.getTables(getCatalog(), getSchema(), getTable(), types);
			while (rsTables.next()) {
				String catalogName = rsTables.getString("TABLE_CAT");
				String schemaName = rsTables.getString("TABLE_SCHEM");
				String tableName = rsTables.getString("TABLE_NAME");
				
				String tableType = rsTables.getString("TABLE_TYPE");
				String remarks = rsTables.getString("REMARKS");
				String typeCat = rsTables.getString("TYPE_CAT");
				String typeSchem = rsTables.getString("TYPE_SCHEM");
				String typeName = rsTables.getString("TYPE_NAME");
				String selfRefColName = rsTables.getString("SELF_REFERENCING_COL_NAME");
				String refGeneration = rsTables.getString("REF_GENERATION");

				Table t = results.addTable(tableName);
				t.setCatalog(catalogName);
				t.setSchema(schemaName);
				t.setType(typeSchem);
			}

			if (attachKeys) {
				
				ResultSet rsColumns = databaseMetaData.getColumns(getCatalog(), getSchema(), getTable(), getColumn());
				while (rsColumns.next()) {
					String catalogName = rsColumns.getString("TABLE_CAT");
					String schemaName = rsColumns.getString("TABLE_SCHEM");
					String tableName = rsColumns.getString("TABLE_NAME");
					
										
					String columnName = rsColumns.getString("COLUMN_NAME");
															
					Table t = results.getTable(catalogName, schemaName, tableName);
					if(!t.hasColumn(columnName)){
						Column c = t.addColumn(columnName);
												
						int oDataType = rsColumns.getInt("DATA_TYPE");												
						String oTypeName = rsColumns.getString("TYPE_NAME");					
						int oColumnSize = rsColumns.getInt("COLUMN_SIZE");
						int oDecimalDigits = rsColumns.getInt("DECIMAL_DIGITS");
						int oNumPrecRadix = rsColumns.getInt("NUM_PREC_RADIX");
						int oNnullable = rsColumns.getInt("NULLABLE");
						String oRemarks = rsColumns.getString("REMARKS");
						String oColumnDef = rsColumns.getString("COLUMN_DEF");
						int oSqlDataType = rsColumns.getInt("SQL_DATA_TYPE"); // unused
						int oSqlDataTypeSub = rsColumns.getInt("SQL_DATETIME_SUB"); // unused
						int oCharOctetLength = rsColumns.getInt("CHAR_OCTET_LENGTH"); 
						int oOrdinalPosition = rsColumns.getInt("ORDINAL_POSITION"); 
						String oIsNullable = rsColumns.getString("IS_NULLABLE");
						String oScopeCatalog = rsColumns.getString("SCOPE_CATALOG");
						String oScopeSchema = rsColumns.getString("SCOPE_SCHEMA");
						String oScopeTable = rsColumns.getString("SCOPE_TABLE");
						short oSourceDataType = rsColumns.getShort("SOURCE_DATA_TYPE");
						String oIsAutoincrement = rsColumns.getString("IS_AUTOINCREMENT");
						
						try{
							String oIsGeneratedcolumn = rsColumns.getString("IS_GENERATEDCOLUMN");	
						}catch(SQLException e){
							L.error("SQL Exception",e);
						}
						
						
						c.setTypeCode(oDataType);
						c.setType(SqlDataType.forCode(oDataType).name());						
					}
					
					// ResultSet rsColumns = databaseMetaData.getColumns(getCatalog(), getSchema(), getTable(), getColumn());
				}
				
				// getPrimary
				ResultSet rsPrimarys = databaseMetaData.getPrimaryKeys(getCatalog(), getSchema(), getTable());
{'fraction_non_alphanumeric': 0.11339031339031339, 'fraction_numerical': 0.0002279202279202279, 'mean_word_length': 4.135166764189584, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7486880', 'n_tokens_mistral': 3188, 'n_tokens_neox': 2565, 'n_words': 486}