# HG changeset patch # Parent 541edccb31e74b09c13d070744402cb5924645cf # User Jaroslav Havlin #231030: Make usage of scrollable cursors configurable - UI diff --git a/db.dataview/nbproject/project.xml b/db.dataview/nbproject/project.xml --- a/db.dataview/nbproject/project.xml +++ b/db.dataview/nbproject/project.xml @@ -29,7 +29,7 @@ 1 - 1.25.0.5 + 1.56 diff --git a/db.dataview/src/org/netbeans/modules/db/dataview/output/SQLExecutionHelper.java b/db.dataview/src/org/netbeans/modules/db/dataview/output/SQLExecutionHelper.java --- a/db.dataview/src/org/netbeans/modules/db/dataview/output/SQLExecutionHelper.java +++ b/db.dataview/src/org/netbeans/modules/db/dataview/output/SQLExecutionHelper.java @@ -1084,7 +1084,7 @@ */ private void updateScrollableSupport(Connection conn, DatabaseConnection dc, String sql) { - useScrollableCursors = checkDriverSupportsScrollableCursors(dc); + useScrollableCursors = dc.isUseScrollableCursors(); if (!useScrollableCursors) { return; } @@ -1113,33 +1113,4 @@ + " database for scrollable resultset support"); //NOI18N } } - - /** - * Decide whether scrollable cursors should be used by the connection. - */ - private boolean checkDriverSupportsScrollableCursors(DatabaseConnection dc) { - String drv = dc == null ? null : dc.getDriverClass(); - if (drv == null) { - return false; - } else { - String customPattern = System.getProperty( - "db.scrollable.cursors.drivers"); //NOI18N - if (customPattern != null) { - LOGGER.log(Level.INFO, - "Using custom pattern for scrollable cursors: {0}", //NOI18N - customPattern); - try { - return drv.matches(customPattern); - } catch (Exception e) { - LOGGER.log(Level.INFO, "Invalid pattern", e); //NOI18N - } - } - LOGGER.log(Level.FINE, "Using built-in list of drivers " //NOI18N - + " with support for scrollable cursors."); //NOI18N - return drv.startsWith("org.apache.derby") //NOI18N - || drv.startsWith("com.mysql") //NOI18N - || drv.startsWith("oracle") //NOI18N - || drv.startsWith("org.postgresql"); //NOI18N - } - } } diff --git a/db/apichanges.xml b/db/apichanges.xml --- a/db/apichanges.xml +++ b/db/apichanges.xml @@ -109,6 +109,23 @@ + + + Configure usage of scrollable cursors. + + + + + + + Users can enable or disable using of scrollable cursors, which + can make queries faster, but also can cause problems for some + drivers. + + + + + Enable editting of connection properties for db connections diff --git a/db/nbproject/project.properties b/db/nbproject/project.properties --- a/db/nbproject/project.properties +++ b/db/nbproject/project.properties @@ -45,7 +45,7 @@ javadoc.arch=${basedir}/arch.xml javadoc.apichanges=${basedir}/apichanges.xml -spec.version.base=1.55.0 +spec.version.base=1.56 extra.module.files=modules/ext/ddl.jar diff --git a/db/src/org/netbeans/api/db/explorer/DatabaseConnection.java b/db/src/org/netbeans/api/db/explorer/DatabaseConnection.java --- a/db/src/org/netbeans/api/db/explorer/DatabaseConnection.java +++ b/db/src/org/netbeans/api/db/explorer/DatabaseConnection.java @@ -287,6 +287,32 @@ } /** + * Check whether usage of scrollable cursors is recommended for this + * connection. + * + * @return True if scrollable cursors can be used, false if scrollable + * cursors are not supported by driver or database of this connection. + * + * @since db/1.56 + */ + public boolean isUseScrollableCursors() { + return delegate.isUseScrollableCursors(); + } + + /** + * Set whether usage of scrollable cursors is recommended for this + * connection. + * + * @param useScrollableCursors True if this connection is allowed to use + * scrollable cursors, false otherwise (older JDBC methods will be used + * instead.). + * @since db/1.56 + */ + public void setUseScrollableCursors(boolean useScrollableCursors) { + delegate.setUseScrollableCursors(useScrollableCursors); + } + + /** * Returns the {@link java.sql.Connection} instance which encapsulates * the physical connection to the database if this database connection * is connected. Note that "connected" here means "connected using the diff --git a/db/src/org/netbeans/api/db/explorer/node/Bundle.properties b/db/src/org/netbeans/api/db/explorer/node/Bundle.properties --- a/db/src/org/netbeans/api/db/explorer/node/Bundle.properties +++ b/db/src/org/netbeans/api/db/explorer/node/Bundle.properties @@ -148,6 +148,8 @@ ConnectionPropertiesDescription=Connection properties SeparateSystemTables=Show system tables separately SeparateSystemTablesDescription=Use special node for system tables +UseScrollableCursors=Use scrollable cursors +UseScrollableCursorsDescription=Use JDBC support for scrollable cursors. This makes the execution faster, but some drivers can become unstable. # Booleans diff --git a/db/src/org/netbeans/modules/db/explorer/DatabaseConnection.java b/db/src/org/netbeans/modules/db/explorer/DatabaseConnection.java --- a/db/src/org/netbeans/modules/db/explorer/DatabaseConnection.java +++ b/db/src/org/netbeans/modules/db/explorer/DatabaseConnection.java @@ -166,6 +166,8 @@ private volatile boolean separateSystemTables = false; + private Boolean useScrollableCursors = null; // null = driver default + /** * The API DatabaseConnection (delegates to this instance) */ @@ -1347,4 +1349,27 @@ this.separateSystemTables = separateSystemTables; propertySupport.firePropertyChange("separateSystemTables", oldVal, separateSystemTables); //NOI18N } + + /** + * Decide whether scrollable cursors should be used by the connection. + */ + private boolean isUseScrollableCursorsByDefault() { + return drv != null + && (drv.startsWith("org.apache.derby") //NOI18N + || drv.startsWith("com.mysql") //NOI18N + || drv.startsWith("oracle") //NOI18N + || drv.startsWith("org.postgresql")); //NOI18N + } + + public boolean isUseScrollableCursors() { + return useScrollableCursors == null + ? isUseScrollableCursorsByDefault() + : useScrollableCursors; + } + + public void setUseScrollableCursors(boolean useScrollableCursors) { + boolean oldVal = isUseScrollableCursors(); + this.useScrollableCursors = useScrollableCursors; + propertySupport.firePropertyChange("useScrollableCursors", oldVal, useScrollableCursors); //NOI18N + } } diff --git a/db/src/org/netbeans/modules/db/explorer/DatabaseConnectionConvertor.java b/db/src/org/netbeans/modules/db/explorer/DatabaseConnectionConvertor.java --- a/db/src/org/netbeans/modules/db/explorer/DatabaseConnectionConvertor.java +++ b/db/src/org/netbeans/modules/db/explorer/DatabaseConnectionConvertor.java @@ -253,6 +253,9 @@ dbconn.addImportantCatalog(importantDatabase); } dbconn.setSeparateSystemTables(handler.separateSystemTables); + if (handler.useScrollableCursors != null) { + dbconn.setUseScrollableCursors(handler.useScrollableCursors); + } LOGGER.fine("Created DatabaseConnection[" + dbconn.toString() + "] from file: " + handler.connectionFileName); return dbconn; @@ -392,7 +395,7 @@ void write(PrintWriter pw, String name) throws IOException { pw.println(""); //NOI18N - pw.println(""); //NOI18N + pw.println(""); //NOI18N pw.println(""); //NOI18N pw.println(" "); //NOI18N pw.println(" "); // NOI18N @@ -435,6 +438,7 @@ if (instance.isSeparateSystemTables()) { pw.println(" "); //NOI18N } + pw.println(" "); //NOI18N pw.println(""); //NOI18N } } @@ -455,6 +459,7 @@ private static final String ELEMENT_IMPORTANT_CATALOG = "important-catalog"; //NOI18N private static final String ELEMENT_CONNECTION_PROPERTY = "connection-property"; // NOI18N private static final String ELEMENT_SEPARATE_SYS_TABLES = "separate-system-tables"; //NOI18N + private static final String ELEMENT_USE_SCROLLABLE_CURSORS = "use-scrollable-cursors"; //NOI18N private static final String ELEMENT_CONNECTION_PROPERTY_NAME = "name"; // NOI18N private static final String ELEMENT_CONNECTION_PROPERTY_VALUE = "value"; // NOI18N private static final String ATTR_PROPERTY_VALUE = "value"; // NOI18N @@ -473,6 +478,7 @@ String displayName; Properties connectionProperties; boolean separateSystemTables = false; + Boolean useScrollableCursors = null; List importantSchemas = new ArrayList(); List importantCatalogs = new ArrayList(); @@ -542,6 +548,8 @@ importantCatalogs.add(value); } else if (ELEMENT_SEPARATE_SYS_TABLES.equals(qName)) { separateSystemTables = Boolean.parseBoolean(value); + } else if (ELEMENT_USE_SCROLLABLE_CURSORS.equals(qName)) { + useScrollableCursors = Boolean.parseBoolean(value); } } diff --git a/db/src/org/netbeans/modules/db/explorer/node/ConnectionNode.java b/db/src/org/netbeans/modules/db/explorer/node/ConnectionNode.java --- a/db/src/org/netbeans/modules/db/explorer/node/ConnectionNode.java +++ b/db/src/org/netbeans/modules/db/explorer/node/ConnectionNode.java @@ -89,6 +89,8 @@ private static final String CONNECTIONPROPERTIESDESC = "ConnectionPropertiesDescription"; //NOI18N private static final String SEPARATESYSTEMTABLES = "SeparateSystemTables"; //NOI18N private static final String SEPARATESYSTEMTABLESDESC = "SeparateSystemTablesDescription"; //NOI18N + private static final String USESCROLLABLECURSORS = "UseScrollableCursors"; //NOI18N + private static final String USESCROLLABLECURSORSDESC = "UseScrollableCursorsDescription"; //NOI18N private static final String FOLDER = "Connection"; // NOI18N private static final RequestProcessor RP = new RequestProcessor(ConnectionNode.class.getName()); @@ -175,6 +177,10 @@ && val instanceof Boolean) { connection.setSeparateSystemTables((Boolean) val); refreshNode = false; + } else if (nps.getName().equals(USESCROLLABLECURSORS) + && val instanceof Boolean) { + connection.setUseScrollableCursors((Boolean) val); + refreshNode = false; } super.setPropertyValue(nps, val); @@ -197,6 +203,7 @@ addProperty(REMEMBERPW, REMEMBERPWDESC, Boolean.class, !connected, connection.rememberPassword()); addProperty(SEPARATESYSTEMTABLES, SEPARATESYSTEMTABLESDESC, Boolean.class, true, connection.isSeparateSystemTables()); + addProperty(USESCROLLABLECURSORS, USESCROLLABLECURSORSDESC, Boolean.class, true, connection.isUseScrollableCursors()); addProperty(CONNECTIONPROPERTIES, CONNECTIONPROPERTIESDESC, Properties.class, !connected, connection.getConnectionProperties()); Property ps = getSheet().get(Sheet.PROPERTIES).get(CONNECTIONPROPERTIES); ps.setValue("canEditAsText", Boolean.FALSE); //NOI18N diff --git a/db/src/org/netbeans/modules/db/resources/connection-1_2.dtd b/db/src/org/netbeans/modules/db/resources/connection-1_2.dtd new file mode 100644 --- /dev/null +++ b/db/src/org/netbeans/modules/db/resources/connection-1_2.dtd @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/db/src/org/netbeans/modules/db/resources/mf-layer.xml b/db/src/org/netbeans/modules/db/resources/mf-layer.xml --- a/db/src/org/netbeans/modules/db/resources/mf-layer.xml +++ b/db/src/org/netbeans/modules/db/resources/mf-layer.xml @@ -624,6 +624,9 @@ + + + @@ -649,6 +652,11 @@ + + + + + diff --git a/db/test/unit/src/org/netbeans/modules/db/explorer/bar-connection.xml b/db/test/unit/src/org/netbeans/modules/db/explorer/bar-connection.xml --- a/db/test/unit/src/org/netbeans/modules/db/explorer/bar-connection.xml +++ b/db/test/unit/src/org/netbeans/modules/db/explorer/bar-connection.xml @@ -1,9 +1,10 @@ - + + diff --git a/db/test/unit/src/org/netbeans/modules/db/explorer/null-pwd-connection.xml b/db/test/unit/src/org/netbeans/modules/db/explorer/null-pwd-connection.xml --- a/db/test/unit/src/org/netbeans/modules/db/explorer/null-pwd-connection.xml +++ b/db/test/unit/src/org/netbeans/modules/db/explorer/null-pwd-connection.xml @@ -1,9 +1,10 @@ - + +