protected void processIndexes(DatabaseMetaData dbMetaData, String curTable, Element table) throws SQLException { for (Index idx : getIndexes(dbMetaData, curTable)) { String tagName = idx.isUnique() ? "unique" : "index"; Element index = doc.createElement(tagName); index.setAttribute("name", idx.getName()); for (String colName : idx.getColumns()) { Element col = doc.createElement(tagName + "-column"); col.setAttribute("name", colName); index.appendChild(col); } table.appendChild(index); } }
protected void processViews(Platform platform, DatabaseMetaData dbMetaData) throws SQLException { if (!processViews) { return; } List<String> viewNames = getViewNames(dbMetaData); for (String viewName : viewNames) { Element view = doc.createElement("view"); view.setAttribute("name", viewName); /** * <view name="" viewdefinition="" /> */ String definition = platform.getViewDefinition(dbMetaData.getConnection(), schema, viewName); definition = definition.replaceAll("\0", ""); view.setAttribute("viewdefinition", definition); databaseNode.appendChild(view); } }
protected Element getForeignKeyElement(String fkName, Map<String, ForeignKey> foreignKeys) { Element fk = doc.createElement("foreign-key"); fk.setAttribute("name", fkName); ForeignKey forKey = foreignKeys.get(fkName); String foreignKeyTable = forKey.getRefTableName(); List<Reference> refs = forKey.getReferences(); fk.setAttribute("foreignTable", foreignKeyTable); String onDelete = forKey.getOnDelete(); // gmcgrego - just adding onDelete if it's cascade so as not to affect kfs behavior if (onDelete == "cascade") { fk.setAttribute("onDelete", onDelete); } for (Reference refData : refs) { Element ref = doc.createElement("reference"); ref.setAttribute("local", refData.getLocalColumn()); ref.setAttribute("foreign", refData.getForeignColumn()); fk.appendChild(ref); } return fk; }
protected void processSequences(Platform platform, DatabaseMetaData dbMetaData) throws SQLException { if (!processSequences) { return; } List<String> sequenceNames = getSequenceNames(dbMetaData); for (String sequenceName : sequenceNames) { Element sequence = doc.createElement("sequence"); sequence.setAttribute("name", sequenceName); /* * <view name="" nextval="" /> */ Long nextVal = platform.getSequenceNextVal(dbMetaData.getConnection(), schema, sequenceName); sequence.setAttribute("nextval", nextVal.toString()); databaseNode.appendChild(sequence); } doc.appendChild(databaseNode); }
/** * Convert a row from the result set into an Element */ protected Element getRow(final DocumentImpl doc, final String tableName, final ResultSetMetaData md, final ResultSet rs, final Column[] columns, final int rowCount) throws SQLException { // Generate a row object Element row = doc.createElement(tableName); // Cycle through the columns for (int i = 1; i <= md.getColumnCount(); i++) { // Extract a column value Object columnValue = getColumnValue(rs, i, columns[i], rowCount, tableName); // Null values can be omitted from the XML if (columnValue == null) { continue; } // Otherwise, escape the String and add it to the row Element row.setAttribute(columns[i].getName(), xmlEscape(columnValue.toString())); } // Return an Element representing one row of data from the ResultSet return row; }
String defValue = col.getDefValue(); Element column = doc.createElement("column"); column.setAttribute("name", name);
protected void processTable(String curTable, Platform platform, DatabaseMetaData dbMetaData) throws SQLException { long start = System.currentTimeMillis(); Element table = doc.createElement("table"); table.setAttribute("name", curTable); // Setup the primary keys. primaryKeys = getPrimaryKeys(platform, dbMetaData, curTable); // Process columns processColumns(dbMetaData, curTable, table); // Process foreign keys processForeignKeys(dbMetaData, curTable, table); // Process indexes processIndexes(dbMetaData, curTable, table); // Add this table to the XML databaseNode.appendChild(table); log(utils.pad("Processed " + curTable, System.currentTimeMillis() - start)); }
/** * Generates an XML database schema from JDBC metadata. * * @throws Exception * a generic exception. */ protected void generateXML(Platform platform) throws Exception { Connection connection = null; try { // Attempt to connect to a database. connection = getConnection(); // Get the database Metadata. DatabaseMetaData dbMetaData = connection.getMetaData(); databaseNode = doc.createElement("database"); databaseNode.setAttribute("name", getName()); // JHK added naming method databaseNode.setAttribute("defaultJavaNamingMethod", "nochange"); processTables(platform, dbMetaData); processViews(platform, dbMetaData); processSequences(platform, dbMetaData); } finally { closeQuietly(connection); } }
Element datasetNode = document.createElement("dataset"); Statement stmt = null; ResultSet rs = null;