List of usage examples for java.sql DatabaseMetaData versionColumnNotPseudo
int versionColumnNotPseudo
To view the source code for java.sql DatabaseMetaData versionColumnNotPseudo.
Click Source Link
From source file:io.vitess.jdbc.VitessMySQLDatabaseMetadata.java
public ResultSet getVersionColumns(String catalog, String schema, String table) throws SQLException { if (null == table) { throw new SQLException("Table cannot be null"); }/*w w w .j a v a2s .c om*/ ResultSet resultSet = null; VitessStatement vitessStatement = null; ArrayList<ArrayList<String>> data = new ArrayList<>(); StringBuilder getVersionColumnsQB = new StringBuilder(); getVersionColumnsQB.append("SHOW COLUMNS FROM "); getVersionColumnsQB.append(this.quotedId); getVersionColumnsQB.append(table); getVersionColumnsQB.append(this.quotedId); getVersionColumnsQB.append(" FROM "); getVersionColumnsQB.append(this.quotedId); getVersionColumnsQB.append(catalog); getVersionColumnsQB.append(this.quotedId); getVersionColumnsQB.append(" WHERE Extra LIKE '%on update CURRENT_TIMESTAMP%'"); try { vitessStatement = new VitessStatement(this.connection); resultSet = vitessStatement.executeQuery(getVersionColumnsQB.toString()); ArrayList<String> row; while (resultSet.next()) { row = new ArrayList<>(); TypeDescriptor typeDesc = new TypeDescriptor(resultSet.getString("Type"), resultSet.getString("Null")); row.add(0, null); row.add(1, resultSet.getString("Field")); row.add(2, Short.toString(typeDesc.dataType)); row.add(3, typeDesc.typeName); row.add(4, typeDesc.columnSize == null ? null : typeDesc.columnSize.toString()); row.add(5, Integer.toString(typeDesc.bufferLength)); row.add(6, typeDesc.decimalDigits == null ? null : typeDesc.decimalDigits.toString()); row.add(7, Integer.toString(java.sql.DatabaseMetaData.versionColumnNotPseudo)); data.add(row); } } finally { if (null != resultSet) { resultSet.close(); vitessStatement.close(); } } String[] columnNames = new String[] { "SCOPE", "COLUMN_NAME", "DATA_TYPE", "TYPE_NAME", "COLUMN_SIZE", "BUFFER_LENGTH", "DECIMAL_DIGITS", "PSEUDO_COLUMN" }; Query.Type[] columnType = new Query.Type[] { Query.Type.INT16, Query.Type.CHAR, Query.Type.INT32, Query.Type.CHAR, Query.Type.INT32, Query.Type.INT32, Query.Type.INT16, Query.Type.INT16 }; return new VitessResultSet(columnNames, columnType, data, this.connection); }
From source file:org.apache.ddlutils.task.DumpMetadataTask.java
/** * Dumps the versioned (auto-updating) columns of the indicated table. * //from ww w . jav a2s . co m * @param xmlWriter The xml writer to write to * @param metaData The database metadata * @param catalogName The catalog name * @param schemaName The schema name * @param tableName The table name */ private void dumpVersionColumns(PrettyPrintingXmlWriter xmlWriter, final DatabaseMetaData metaData, final String catalogName, final String schemaName, final String tableName) throws SQLException { performResultSetXmlOperation(xmlWriter, null, new ResultSetXmlOperation() { public ResultSet getResultSet() throws SQLException { return metaData.getVersionColumns(catalogName, schemaName, tableName); } public void handleRow(PrettyPrintingXmlWriter xmlWriter, ResultSet result) throws SQLException { Set columns = getColumnsInResultSet(result); String columnName = result.getString("COLUMN_NAME"); if ((columnName != null) && (columnName.length() > 0)) { xmlWriter.writeElementStart(null, "versionedColumn"); xmlWriter.writeAttribute(null, "column", columnName); addIntAttribute(xmlWriter, "typeCode", result, columns, "DATA_TYPE"); addStringAttribute(xmlWriter, "type", result, columns, "TYPE_NAME"); addIntAttribute(xmlWriter, "size", result, columns, "BUFFER_LENGTH"); addIntAttribute(xmlWriter, "precision", result, columns, "COLUMN_SIZE"); addShortAttribute(xmlWriter, "scale", result, columns, "DECIMAL_DIGITS"); if (columns.contains("PSEUDO_COLUMN")) { try { switch (result.getShort("PSEUDO_COLUMN")) { case DatabaseMetaData.versionColumnPseudo: xmlWriter.writeAttribute(null, "columnType", "pseudo column"); break; case DatabaseMetaData.versionColumnNotPseudo: xmlWriter.writeAttribute(null, "columnType", "real column"); break; default: xmlWriter.writeAttribute(null, "columnType", "unknown"); break; } } catch (SQLException ex) { log("Could not read the PSEUDO_COLUMN value for versioned colum '" + columnName + "' of table '" + tableName + "' from the result set: " + ex.getStackTrace(), Project.MSG_ERR); } } xmlWriter.writeElementEnd(); } } public void handleError(SQLException ex) { log("Could not read the versioned columns for table '" + tableName + "' from the result set: " + ex.getStackTrace(), Project.MSG_ERR); } }); }