mirror of
https://github.com/Wisser/Jailer.git
synced 2026-05-24 11:39:31 -05:00
added support for views, synonyms, functions and procedures
git-svn-id: https://svn.code.sf.net/p/jailer/code/trunk@1559 3dd849cd-670e-4645-a7cd-dd197c8d0e81
This commit is contained in:
@@ -336,6 +336,8 @@ SELECT 'Body' as titel, line, text FROM all_source where owner='%1$s' and type='
|
||||
<explainPrepare></explainPrepare>
|
||||
<explainQuery>explain %1$s</explainQuery>
|
||||
<explainCleanup></explainCleanup>
|
||||
<functionSourceQuery>SHOW CREATE FUNCTION %1$s.%2$s</functionSourceQuery>
|
||||
<procedureSourceQuery>SHOW CREATE PROCEDURE %1$s.%2$s</procedureSourceQuery>
|
||||
</dbms>
|
||||
|
||||
<!-- for DB2 LUW -->
|
||||
@@ -594,6 +596,12 @@ SELECT 'Body' as titel, line, text FROM all_source where owner='%1$s' and type='
|
||||
<explainPrepare></explainPrepare>
|
||||
<explainQuery>explain %1$s</explainQuery>
|
||||
<explainCleanup></explainCleanup>
|
||||
<functionSourceQuery>
|
||||
SELECT 'Function', p.proname || '(' || pg_catalog.pg_get_function_arguments(p.oid) || ') RETURNS ' || pg_catalog.pg_get_function_result(p.oid)
|
||||
FROM pg_catalog.pg_proc p
|
||||
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
|
||||
WHERE p.proname = '%2$s' AND n.nspname = '%1$s'
|
||||
</functionSourceQuery>
|
||||
</dbms>
|
||||
|
||||
<!-- for Cloudscape -->
|
||||
|
||||
@@ -22,9 +22,11 @@ import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JComponent;
|
||||
@@ -36,6 +38,7 @@ import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
|
||||
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
|
||||
|
||||
import net.sf.jailer.ExecutionContext;
|
||||
import net.sf.jailer.configuration.DBMS;
|
||||
import net.sf.jailer.configuration.DatabaseObjectRenderingDescription;
|
||||
import net.sf.jailer.database.Session;
|
||||
import net.sf.jailer.datamodel.DataModel;
|
||||
@@ -113,8 +116,12 @@ public class MDDescriptionBasedGeneric extends MDGeneric {
|
||||
* @return render of the database object
|
||||
*/
|
||||
public JComponent createRender(Session session, ExecutionContext executionContext) throws Exception {
|
||||
ResultSetRenderer details = new ResultSetRenderer(retrieveList(session), getName(), dataModel, session, executionContext);
|
||||
ResultSetRenderer details = new ResultSetRenderer(distinct(retrieveList(session)), getName(), dataModel, session, executionContext);
|
||||
if (databaseObjectRenderingDescription.getTextQuery() != null) {
|
||||
int textIndex = 1;
|
||||
if (DBMS.MySQL.equals(session.dbms) && databaseObjectRenderingDescription.getTextQuery().matches("\\s*SHOW\\s+CREATE\\b.*")) {
|
||||
textIndex = 2;
|
||||
}
|
||||
CachedResultSet text = retrieveList(session, databaseObjectRenderingDescription.getTextQuery(), schema.getName(), getName());
|
||||
LinkedHashMap<String, StringBuilder> rows = new LinkedHashMap<String, StringBuilder>();
|
||||
String nl = System.getProperty("line.separator", "\n");
|
||||
@@ -124,7 +131,7 @@ public class MDDescriptionBasedGeneric extends MDGeneric {
|
||||
sb = new StringBuilder();
|
||||
rows.put((String) row[0], sb);
|
||||
}
|
||||
String line = (String) row[1];
|
||||
String line = (String) row[textIndex];
|
||||
sb.append(line);
|
||||
if (!line.endsWith("\n")) {
|
||||
sb.append(nl);
|
||||
@@ -159,11 +166,23 @@ public class MDDescriptionBasedGeneric extends MDGeneric {
|
||||
return details;
|
||||
}
|
||||
|
||||
private CachedResultSet distinct(CachedResultSet list) throws SQLException {
|
||||
List<Object[]> rowList = new ArrayList<Object[]>();
|
||||
Set<Object> seen = new HashSet<Object>();
|
||||
for (Object[] row: list.getRowList()) {
|
||||
if (row[0] == null || !seen.contains(row[0])) {
|
||||
rowList.add(row);
|
||||
seen.add(row[0]);
|
||||
}
|
||||
}
|
||||
return new CachedResultSet(rowList, list.getMetaData());
|
||||
}
|
||||
|
||||
private CachedResultSet list;
|
||||
|
||||
protected CachedResultSet retrieveList(Session session) throws SQLException {
|
||||
if (list == null) {
|
||||
list = retrieveList(session, databaseObjectRenderingDescription.getListQuery(), schema.getName(), null);
|
||||
list = distinct(retrieveList(session, databaseObjectRenderingDescription.getListQuery(), schema.getName(), null));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -242,7 +242,7 @@ public abstract class MetaDataPanel extends javax.swing.JPanel {
|
||||
return super.retrieveList(session, query, schema, parentName);
|
||||
}
|
||||
CachedResultSet procs = new MetaDataCache.CachedResultSet(getProcedures(session, session.getMetaData(), schema, "%"),
|
||||
null, session, schema, new int[] { 3, 4, 1, 8 }, new String[] { "Name", "Remarks", "Category", "Type" });
|
||||
null, session, schema, new int[] { 3, 4, 1, 8, 9 }, new String[] { "Name", "Remarks", "Category", "Type", "SpecificName" });
|
||||
List<Object[]> catList = new ArrayList<Object[]>();
|
||||
for (Object[] cat: procs.getRowList()) {
|
||||
if (select(cat)) {
|
||||
@@ -266,18 +266,81 @@ public abstract class MetaDataPanel extends javax.swing.JPanel {
|
||||
}
|
||||
}
|
||||
|
||||
private List<MDDescriptionBasedGeneric> getGenericDatabaseObjects(final MDSchema mdSchema) {
|
||||
// TODO
|
||||
// /**
|
||||
// * Indexes list view.
|
||||
// */
|
||||
// private class MDIndexes extends MDDescriptionBasedGeneric {
|
||||
// private final MDSchema mdSchema;
|
||||
//
|
||||
// public MDIndexes(String name, MetaDataSource metaDataSource, final MDSchema schema, DataModel dataModel) {
|
||||
// super(name, metaDataSource, schema, dataModel, new DatabaseObjectRenderingDescription() {
|
||||
// {
|
||||
// setIconURL("/net/sf/jailer/ui/resource/indexes.png");
|
||||
// DatabaseObjectRenderingDescription itemDescr = new DatabaseObjectRenderingDescription();
|
||||
// itemDescr.setIconURL("/net/sf/jailer/ui/resource/index.png");
|
||||
// itemDescr.setTextQuery(schema.getMetaDataSource().getSession().dbms.getProcedureSourceQuery());
|
||||
// setItemDescription(itemDescr);
|
||||
// }
|
||||
// });
|
||||
// this.mdSchema = schema;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public CachedResultSet retrieveList(Session session, String query, String schema, String parentName) throws SQLException {
|
||||
// if (query != null) {
|
||||
// return super.retrieveList(session, query, schema, parentName);
|
||||
// }
|
||||
// CachedResultSet procs = new MetaDataCache.CachedResultSet(getIndexes(session, session.getMetaData(), schema, "%"),
|
||||
// null, session, schema, new int[] { 1 }, new String[] { "Index" });
|
||||
// List<Object[]> catList = new ArrayList<Object[]>();
|
||||
// for (Object[] cat: procs.getRowList()) {
|
||||
// catList.add(cat);
|
||||
// }
|
||||
// procs.close();
|
||||
// return new CachedResultSet(catList, procs.getMetaData());
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected DatabaseObjectRenderingDescription itemDescription(CachedResultSet item) {
|
||||
// DatabaseObjectRenderingDescription desc = new DatabaseObjectRenderingDescription(databaseObjectRenderingDescription.getItemDescription());
|
||||
// if (!item.getRowList().isEmpty() && String.valueOf(DatabaseMetaData.procedureReturnsResult).equals(String.valueOf(item.getRowList().get(0)[3]))) {
|
||||
// desc.setIconURL("/net/sf/jailer/ui/resource/function.png");
|
||||
// desc.setTextQuery(mdSchema.getMetaDataSource().getSession().dbms.getFunctionSourceQuery());
|
||||
// }
|
||||
// return desc;
|
||||
// }
|
||||
//
|
||||
// private ResultSet getIndexes(Session session, DatabaseMetaData metaData, String schema, String context) throws SQLException {
|
||||
// ResultSet rs = JDBCMetaDataBasedModelElementFinder.getIndexes(session, metaData, Quoting.staticUnquote(schema), "%");
|
||||
//// 1.TABLE_CAT String => table catalog (may be null)
|
||||
//// 2.TABLE_SCHEM String => table schema (may be null)
|
||||
//// 3.TABLE_NAME String => table name
|
||||
//// 4.NON_UNIQUE boolean => Can index values be non-unique. false when TYPE is tableIndexStatistic
|
||||
//// 5.INDEX_QUALIFIER String => index catalog (may be null); null when TYPE is tableIndexStatistic
|
||||
//// 6.INDEX_NAME String => index name; null when TYPE is tableIndexStatistic
|
||||
// List<Object[]> rowList = new ArrayList<Object[]>();
|
||||
// while (rs.next()) {
|
||||
// rowList.add(new Object[] { rs.getString(3) });
|
||||
// }
|
||||
// rs.close();
|
||||
// return new CachedResultSet(rowList, 1, new String[] { "Index" }, new int[] { Types.VARCHAR });
|
||||
// }
|
||||
// }
|
||||
|
||||
private List<MDDescriptionBasedGeneric> getGenericDatabaseObjects(final MDSchema mdSchema) {
|
||||
List<MDDescriptionBasedGeneric> genericDatabaseObjects = new ArrayList<MDDescriptionBasedGeneric>();
|
||||
genericDatabaseObjects.add(
|
||||
new MDProcedures("Procedures", metaDataSource, mdSchema, dataModel) {
|
||||
@Override
|
||||
protected boolean select(Object[] proc) {
|
||||
return proc[2] == null || !DBMS.ORACLE.equals(mdSchema.getMetaDataSource().getSession().dbms);
|
||||
new MDProcedures("Procedures", metaDataSource, mdSchema, dataModel) {
|
||||
@Override
|
||||
protected boolean select(Object[] proc) {
|
||||
return proc[2] == null || !DBMS.ORACLE.equals(mdSchema.getMetaDataSource().getSession().dbms);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
);
|
||||
// genericDatabaseObjects.add( new MDIndexes("Indexes", metaDataSource, mdSchema, dataModel));
|
||||
if (DBMS.ORACLE.equals(mdSchema.getMetaDataSource().getSession().dbms)) {
|
||||
genericDatabaseObjects.add(new MDPackages("Packages", metaDataSource, mdSchema, dataModel));
|
||||
genericDatabaseObjects.add(new MDPackages("Packages", metaDataSource, mdSchema, dataModel));
|
||||
}
|
||||
for (DatabaseObjectRenderingDescription desc: mdSchema.getMetaDataSource().getSession().dbms.getObjectRenderers()) {
|
||||
MDDescriptionBasedGeneric mdObjectRenderer
|
||||
|
||||
Reference in New Issue
Block a user