use of java.sql.DatabaseMetaData in project adempiere by adempiere.
the class TableCreateColumns method doIt.
// prepare
/**
* Process
* @return info
* @throws Exception
*/
protected String doIt() throws Exception {
if (p_AD_Table_ID == 0)
throw new AdempiereSystemError("@NotFound@ @AD_Table_ID@ " + p_AD_Table_ID);
log.info("EntityType=" + p_EntityType + ", AllTables=" + p_AllTables + ", AD_Table_ID=" + p_AD_Table_ID);
//
Connection conn = null;
try {
conn = DB.getConnectionRO();
AdempiereDatabase db = DB.getDatabase();
DatabaseMetaData md = conn.getMetaData();
String catalog = db.getCatalog();
String schema = db.getSchema();
if (p_AllTables)
addTable(md, catalog, schema);
else {
MTable table = new MTable(getCtx(), p_AD_Table_ID, get_TrxName());
if (table == null || table.get_ID() == 0)
throw new AdempiereSystemError("@NotFound@ @AD_Table_ID@ " + p_AD_Table_ID);
log.info(table.getTableName() + ", EntityType=" + p_EntityType);
String tableName = table.getTableName();
if (DB.isOracle())
tableName = tableName.toUpperCase();
// globalqss 2005-10-24
if (DB.isPostgreSQL())
tableName = tableName.toLowerCase();
// end globalqss 2005-10-24
ResultSet rs = md.getColumns(catalog, schema, tableName, null);
addTableColumn(rs, table);
}
return "#" + m_count;
} finally {
if (conn != null) {
try {
conn.close();
} catch (Exception e) {
}
}
}
}
use of java.sql.DatabaseMetaData in project adempiere by adempiere.
the class CreateAdempiere method copy.
// dropDatabase
/**
* Create Tables and copy data
* @param whereClause optional where clause
* @param dropFirst drop first
* @return true if executed
*/
public boolean copy(String whereClause, boolean dropFirst) {
log.info(whereClause);
if (getConnection(false, true) == null)
return false;
//
boolean success = true;
int count = 0;
ArrayList<String> list = new ArrayList<String>();
String sql = "SELECT * FROM AD_Table";
if (whereClause != null && whereClause.length() > 0)
sql += " WHERE " + whereClause;
sql += " ORDER BY TableName";
//
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, null);
//jz: pstmt.getConnection() could be null
Connection conn = pstmt.getConnection();
DatabaseMetaData md = null;
if (conn != null)
md = conn.getMetaData();
else {
//jz: globalization issue??
throw new DBException("No Connection");
}
rs = pstmt.executeQuery();
while (rs.next() && success) {
MTable table = new MTable(m_ctx, rs, null);
if (table.isView())
continue;
if (dropFirst) {
executeCommands(new String[] { "DROP TABLE " + table.getTableName() }, m_conn, false, false);
}
//
if (createTable(table, md)) {
list.add(table.getTableName());
count++;
} else
success = false;
}
} catch (Exception e) {
log.log(Level.SEVERE, sql, e);
success = false;
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
if (!success)
return false;
/** Enable Contraints */
enableConstraints(list);
databaseBuild();
log.info("#" + count);
try {
if (m_conn != null)
m_conn.close();
} catch (SQLException e2) {
log.log(Level.SEVERE, "close connection", e2);
}
m_conn = null;
return success;
}
use of java.sql.DatabaseMetaData in project calcite-avatica by apache.
the class MetaResultSetTest method testGetProcedureColumns.
@Test
public void testGetProcedureColumns() throws SQLException {
DatabaseMetaData metadata = getDatabaseMetadata();
try (ResultSet rs = metadata.getProcedureColumns(null, null, null, null)) {
ResultSetMetaData rsMeta = rs.getMetaData();
assertEquals(20, rsMeta.getColumnCount());
assertColumn(rsMeta, 1, "PROCEDURE_CAT", Types.VARCHAR, DatabaseMetaData.columnNullable);
assertColumn(rsMeta, 2, "PROCEDURE_SCHEM", Types.VARCHAR, DatabaseMetaData.columnNullable);
assertColumn(rsMeta, 3, "PROCEDURE_NAME", Types.VARCHAR, DatabaseMetaData.columnNoNulls);
assertColumn(rsMeta, 4, "COLUMN_NAME", Types.VARCHAR, DatabaseMetaData.columnNoNulls);
assertColumn(rsMeta, 5, "COLUMN_TYPE", Types.SMALLINT, DatabaseMetaData.columnNoNulls);
assertColumn(rsMeta, 6, "DATA_TYPE", Types.INTEGER, DatabaseMetaData.columnNoNulls);
assertColumn(rsMeta, 7, "TYPE_NAME", Types.VARCHAR, DatabaseMetaData.columnNoNulls);
assertColumn(rsMeta, 8, "PRECISION", Types.INTEGER, DatabaseMetaData.columnNullable);
assertColumn(rsMeta, 9, "LENGTH", Types.INTEGER, DatabaseMetaData.columnNullable);
assertColumn(rsMeta, 10, "SCALE", Types.SMALLINT, DatabaseMetaData.columnNullable);
assertColumn(rsMeta, 11, "RADIX", Types.SMALLINT, DatabaseMetaData.columnNullable);
assertColumn(rsMeta, 12, "NULLABLE", Types.SMALLINT, DatabaseMetaData.columnNoNulls);
assertColumn(rsMeta, 13, "REMARKS", Types.VARCHAR, DatabaseMetaData.columnNullable);
assertColumn(rsMeta, 14, "COLUMN_DEF", Types.VARCHAR, DatabaseMetaData.columnNullable);
assertColumn(rsMeta, 15, "SQL_DATA_TYPE", Types.INTEGER, DatabaseMetaData.columnNullableUnknown);
assertColumn(rsMeta, 16, "SQL_DATETIME_SUB", Types.INTEGER, DatabaseMetaData.columnNullableUnknown);
assertColumn(rsMeta, 17, "CHAR_OCTET_LENGTH", Types.INTEGER, DatabaseMetaData.columnNullable);
assertColumn(rsMeta, 18, "ORDINAL_POSITION", Types.INTEGER, DatabaseMetaData.columnNoNulls);
assertColumn(rsMeta, 19, "IS_NULLABLE", Types.VARCHAR, DatabaseMetaData.columnNoNulls);
assertColumn(rsMeta, 20, "SPECIFIC_NAME", Types.VARCHAR, DatabaseMetaData.columnNullable);
}
}
use of java.sql.DatabaseMetaData in project calcite-avatica by apache.
the class MetaResultSetTest method testGetSuperTables.
@Test
public void testGetSuperTables() throws SQLException {
DatabaseMetaData metadata = getDatabaseMetadata();
try (ResultSet rs = metadata.getSuperTables(null, null, null)) {
ResultSetMetaData rsMeta = rs.getMetaData();
assertEquals(4, rsMeta.getColumnCount());
assertColumn(rsMeta, 1, "TABLE_CAT", Types.VARCHAR, DatabaseMetaData.columnNullable);
assertColumn(rsMeta, 2, "TABLE_SCHEM", Types.VARCHAR, DatabaseMetaData.columnNullable);
assertColumn(rsMeta, 3, "TABLE_NAME", Types.VARCHAR, DatabaseMetaData.columnNoNulls);
assertColumn(rsMeta, 4, "SUPERTABLE_NAME", Types.VARCHAR, DatabaseMetaData.columnNoNulls);
}
}
use of java.sql.DatabaseMetaData in project calcite-avatica by apache.
the class MetaResultSetTest method testGetTablePrivileges.
@Test
public void testGetTablePrivileges() throws SQLException {
DatabaseMetaData metadata = getDatabaseMetadata();
try (ResultSet rs = metadata.getTablePrivileges(null, null, null)) {
ResultSetMetaData rsMeta = rs.getMetaData();
assertEquals(7, rsMeta.getColumnCount());
assertColumn(rsMeta, 1, "TABLE_CAT", Types.VARCHAR, DatabaseMetaData.columnNullable);
assertColumn(rsMeta, 2, "TABLE_SCHEM", Types.VARCHAR, DatabaseMetaData.columnNullable);
assertColumn(rsMeta, 3, "TABLE_NAME", Types.VARCHAR, DatabaseMetaData.columnNoNulls);
assertColumn(rsMeta, 4, "GRANTOR", Types.VARCHAR, DatabaseMetaData.columnNullable);
assertColumn(rsMeta, 5, "GRANTEE", Types.VARCHAR, DatabaseMetaData.columnNoNulls);
assertColumn(rsMeta, 6, "PRIVILEGE", Types.VARCHAR, DatabaseMetaData.columnNoNulls);
assertColumn(rsMeta, 7, "IS_GRANTABLE", Types.VARCHAR, DatabaseMetaData.columnNullable);
}
}
Aggregations