[Libreoffice-commits] core.git: Branch 'aoo/trunk' - connectivity/java

Damjan Jovanovic damjan at apache.org
Wed Sep 20 06:09:53 UTC 2017


 connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/PostgresqlCatalog.java      |    5 -
 connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/PostgresqlTables.java       |    5 -
 connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/OCatalog.java         |   20 ++++++
 connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/OColumnContainer.java |    1 
 connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/OContainer.java       |   32 +++++-----
 connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/OTable.java           |    4 -
 connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/SqlTableHelper.java   |   17 ++---
 connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/util/DbTools.java           |   15 ++--
 8 files changed, 64 insertions(+), 35 deletions(-)

New commits:
commit 91af6fa89dd7eee302c59fcf110c3c19e157ab35
Author: Damjan Jovanovic <damjan at apache.org>
Date:   Wed Sep 20 05:10:08 2017 +0000

    Revert r1808599; apparently we really do need Any.VOID instead of Java's
    
    null. Also fix one more place where this is the problem.
    (I wonder why. Seems like something that could be improved.)
    
    Fix "Refresh Tables", which was making all tables disappear. Apparently
    we needed to actually re-read our tables, and deal with the fact that the
    OCatalog is disposed after the return. Further development is ongoing.
    
    Also make other null strings into empty strings like UNO requires.
    
    Patch by: me

diff --git a/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/PostgresqlCatalog.java b/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/PostgresqlCatalog.java
index 80039c7255c9..ad66cf6de697 100644
--- a/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/PostgresqlCatalog.java
+++ b/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/PostgresqlCatalog.java
@@ -31,6 +31,7 @@ import com.sun.star.sdbc.XRow;
 import com.sun.star.sdbcx.comp.postgresql.comphelper.CompHelper;
 import com.sun.star.sdbcx.comp.postgresql.sdbcx.OCatalog;
 import com.sun.star.sdbcx.comp.postgresql.sdbcx.OContainer;
+import com.sun.star.uno.Any;
 import com.sun.star.uno.UnoRuntime;
 
 public class PostgresqlCatalog extends OCatalog {
@@ -43,7 +44,7 @@ public class PostgresqlCatalog extends OCatalog {
         XResultSet results = null;
         try {
             // Using { "VIEW", "TABLE", "%" } shows INFORMATION_SCHEMA and others, but it also shows indexes :-(
-            results = metadata.getTables(null, "%", "%", new String[] { "VIEW", "TABLE" });
+            results = metadata.getTables(Any.VOID, "%", "%", new String[] { "VIEW", "TABLE" });
             XRow row = UnoRuntime.queryInterface(XRow.class, results);
             List<String> names = new ArrayList<>();
             while (results.next()) {
@@ -63,7 +64,7 @@ public class PostgresqlCatalog extends OCatalog {
     public OContainer refreshViews() {
         XResultSet results = null;
         try {
-            results = metadata.getTables(null, "%", "%", new String[] { "VIEW" });
+            results = metadata.getTables(Any.VOID, "%", "%", new String[] { "VIEW" });
             XRow row = UnoRuntime.queryInterface(XRow.class, results);
             List<String> names = new ArrayList<>();
             while (results.next()) {
diff --git a/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/PostgresqlTables.java b/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/PostgresqlTables.java
index ed0f97d3cdf6..885cca5cdc3b 100644
--- a/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/PostgresqlTables.java
+++ b/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/PostgresqlTables.java
@@ -41,6 +41,7 @@ import com.sun.star.sdbcx.comp.postgresql.util.DbTools;
 import com.sun.star.sdbcx.comp.postgresql.util.DbTools.NameComponents;
 import com.sun.star.sdbcx.comp.postgresql.util.PropertyIds;
 import com.sun.star.sdbcx.comp.postgresql.util.StandardSQLState;
+import com.sun.star.uno.Any;
 import com.sun.star.uno.AnyConverter;
 import com.sun.star.uno.UnoRuntime;
 
@@ -57,7 +58,7 @@ public class PostgresqlTables extends OContainer {
     @Override
     public XPropertySet createObject(String name) throws SQLException {
         NameComponents nameComponents = DbTools.qualifiedNameComponents(metadata, name, ComposeRule.InDataManipulation);
-        Object queryCatalog = nameComponents.getCatalog().isEmpty() ? null : nameComponents.getCatalog();
+        Object queryCatalog = nameComponents.getCatalog().isEmpty() ? Any.VOID : nameComponents.getCatalog();
         XPropertySet ret = null;
         XResultSet results = null;
         try {
@@ -111,7 +112,7 @@ public class PostgresqlTables extends OContainer {
 
     @Override
     public void impl_refresh() {
-        catalog.refreshTables();
+        catalog.refreshObjects();
     }
 
     @Override
diff --git a/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/OCatalog.java b/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/OCatalog.java
index b2ab379e685c..f6c4026bdbb2 100644
--- a/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/OCatalog.java
+++ b/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/OCatalog.java
@@ -128,6 +128,26 @@ public abstract class OCatalog extends ComponentBase
         return users;
     }
 
+    public synchronized void refreshObjects() {
+        checkDisposed();
+        if (tables != null) {
+            tables.dispose();
+            tables = null;
+        }
+        if (views != null) {
+            views.dispose();
+            views = null;
+        }
+        if (groups != null) {
+            groups.dispose();
+            groups = null;
+        }
+        if (users != null) {
+            users.dispose();
+            users = null;
+        }
+    }
+
     /**
      * Builds the name which should be used to access the object later on in the collection.
      * Will only be called in fillNames.
diff --git a/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/OColumnContainer.java b/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/OColumnContainer.java
index 67f0162f2755..1f66c6517222 100644
--- a/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/OColumnContainer.java
+++ b/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/OColumnContainer.java
@@ -127,6 +127,7 @@ public class OColumnContainer extends OContainer {
     @Override
     protected void impl_refresh() {
         extraColumnInfo.clear();
+        // FIXME: won't help
         table.refreshColumns();
     }
 
diff --git a/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/OContainer.java b/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/OContainer.java
index 9f9fab85a897..69c18bf885c3 100644
--- a/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/OContainer.java
+++ b/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/OContainer.java
@@ -210,6 +210,10 @@ public abstract class OContainer extends WeakBase implements
 
             iterator = refreshListeners.iterator();
         }
+        if (iterator == null) {
+            // early disposal
+            return;
+        }
         EventObject event = new EventObject(this);
         while (iterator.hasNext()) {
             XRefreshListener listener = (XRefreshListener) iterator.next();
@@ -217,6 +221,20 @@ public abstract class OContainer extends WeakBase implements
         }
     }
 
+    @Override
+    public void addRefreshListener(XRefreshListener listener) {
+        synchronized (lock) {
+            refreshListeners.add(listener);
+        }
+    }
+
+    @Override
+    public void removeRefreshListener(XRefreshListener listener) {
+        synchronized (lock) {
+            refreshListeners.remove(listener);
+        }
+    }
+
     // XDataDescriptorFactory
 
     @Override
@@ -347,20 +365,6 @@ public abstract class OContainer extends WeakBase implements
         }
     }
 
-    @Override
-    public void addRefreshListener(XRefreshListener listener) {
-        synchronized (lock) {
-            refreshListeners.add(listener);
-        }
-    }
-
-    @Override
-    public void removeRefreshListener(XRefreshListener listener) {
-        synchronized (lock) {
-            refreshListeners.remove(listener);
-        }
-    }
-
     protected int indexOf(String name) {
         for (int i = 0; i < namesByIndex.size(); i++) {
             if (namesByIndex.get(i).equals(name)) {
diff --git a/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/OTable.java b/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/OTable.java
index 036924cd7425..82caf1dbcd9c 100644
--- a/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/OTable.java
+++ b/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/OTable.java
@@ -48,8 +48,8 @@ public abstract class OTable extends ODescriptor
     private XConnection connection;
     protected String catalogName;
     protected String schemaName;
-    protected String description;
-    protected String type;
+    protected String description = "";
+    protected String type = "";
 
     protected OContainer keys;
     protected OContainer columns;
diff --git a/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/SqlTableHelper.java b/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/SqlTableHelper.java
index 03e1459599aa..e7da37bf40c0 100644
--- a/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/SqlTableHelper.java
+++ b/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/SqlTableHelper.java
@@ -39,6 +39,7 @@ import com.sun.star.sdbcx.comp.postgresql.util.ComposeRule;
 import com.sun.star.sdbcx.comp.postgresql.util.DbTools;
 import com.sun.star.sdbcx.comp.postgresql.util.Osl;
 import com.sun.star.sdbcx.comp.postgresql.util.StandardSQLState;
+import com.sun.star.uno.Any;
 import com.sun.star.uno.UnoRuntime;
 
 public class SqlTableHelper {
@@ -69,13 +70,13 @@ public class SqlTableHelper {
         }
     }
 
-    public List<ColumnDescription> readColumns(XDatabaseMetaData metadata, String catalog, String schema, String table) throws SQLException {
-        String catalogName = catalog;
-        if (catalog.isEmpty()) {
-            catalogName = null;
+    public List<ColumnDescription> readColumns(XDatabaseMetaData metadata, String catalogName, String schema, String table) throws SQLException {
+        Object catalog = Any.VOID;
+        if (!catalogName.isEmpty()) {
+            catalog = catalogName;
         }
 
-        XResultSet results = metadata.getColumns(catalogName, schema, table, "%");
+        XResultSet results = metadata.getColumns(catalog, schema, table, "%");
         List<ColumnDescription> columnDescriptions = collectColumnDescriptions(results);
         sanitizeColumnDescriptions(columnDescriptions);
 
@@ -142,7 +143,7 @@ public class SqlTableHelper {
 
     private OKey readPrimaryKey(XDatabaseMetaData metadata,
             String catalogName, String schemaName, String tableName, boolean isCaseSensitive, OTable table) throws SQLException {
-        Object catalog = null;
+        Object catalog = Any.VOID;
         if (!catalogName.isEmpty()) {
             catalog = catalogName;
         }
@@ -175,7 +176,7 @@ public class SqlTableHelper {
 
     private void readForeignKeys(XDatabaseMetaData metadata,
             String catalogName, String schemaName, String tableName, boolean isCaseSensitive, Map<String, OKey> keys, OTable table) throws SQLException {
-        Object catalog = null;
+        Object catalog = Any.VOID;
         if (!catalogName.isEmpty()) {
             catalog = catalogName;
         }
@@ -232,7 +233,7 @@ public class SqlTableHelper {
     }
 
     public ArrayList<String> readIndexes(XDatabaseMetaData metadata, String catalogName, String schemaName, String tableName, OTable table) throws SQLException {
-        Object catalog = null;
+        Object catalog = Any.VOID;
         if (!catalogName.isEmpty()) {
             catalog = catalogName;
         }
diff --git a/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/util/DbTools.java b/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/util/DbTools.java
index 36dc672752ae..f4ebf8a7d74f 100644
--- a/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/util/DbTools.java
+++ b/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/util/DbTools.java
@@ -55,6 +55,7 @@ import com.sun.star.sdbcx.XColumnsSupplier;
 import com.sun.star.sdbcx.XKeysSupplier;
 import com.sun.star.sdbcx.comp.postgresql.comphelper.CompHelper;
 import com.sun.star.sdbcx.comp.postgresql.sdbcx.OColumnContainer.ExtraColumnInfo;
+import com.sun.star.uno.Any;
 import com.sun.star.uno.AnyConverter;
 import com.sun.star.uno.UnoRuntime;
 
@@ -301,7 +302,7 @@ public class DbTools {
             }
             return nameComponents;
         } catch (IllegalArgumentException | WrappedTargetException | UnknownPropertyException exception) {
-            throw new SQLException("Error", null, StandardSQLState.SQL_GENERAL_ERROR.text(), 0, exception);
+            throw new SQLException("Error", Any.VOID, StandardSQLState.SQL_GENERAL_ERROR.text(), 0, exception);
         }
     }
 
@@ -443,7 +444,7 @@ public class DbTools {
 
             return String.format("CREATE TABLE %s (%s", composedName, columnText.toString());
         } catch (IllegalArgumentException | WrappedTargetException | UnknownPropertyException | IndexOutOfBoundsException exception) {
-            throw new SQLException("Error", null, StandardSQLState.SQL_GENERAL_ERROR.text(), 0, exception);
+            throw new SQLException("Error", Any.VOID, StandardSQLState.SQL_GENERAL_ERROR.text(), 0, exception);
         }
     }
 
@@ -566,7 +567,7 @@ public class DbTools {
 
             return sql.toString();
         } catch (IllegalArgumentException | WrappedTargetException | UnknownPropertyException exception) {
-            throw new SQLException("Error", null, StandardSQLState.SQL_GENERAL_ERROR.text(), 0, exception);
+            throw new SQLException("Error", Any.VOID, StandardSQLState.SQL_GENERAL_ERROR.text(), 0, exception);
         }
     }
 
@@ -645,7 +646,7 @@ public class DbTools {
             }
             return sql.toString();
         } catch (IllegalArgumentException | WrappedTargetException | UnknownPropertyException | IndexOutOfBoundsException exception) {
-            throw new SQLException("Error", null, StandardSQLState.SQL_GENERAL_ERROR.text(), 0, exception);
+            throw new SQLException("Error", Any.VOID, StandardSQLState.SQL_GENERAL_ERROR.text(), 0, exception);
         }
     }
 
@@ -705,7 +706,7 @@ public class DbTools {
             }
             return columns;
         } catch (IllegalArgumentException | WrappedTargetException | UnknownPropertyException | PropertyVetoException exception) {
-            throw new SQLException("Error", null, StandardSQLState.SQL_GENERAL_ERROR.text(), 0, exception);
+            throw new SQLException("Error", Any.VOID, StandardSQLState.SQL_GENERAL_ERROR.text(), 0, exception);
         } finally {
             CompHelper.disposeComponent(statement);
         }
@@ -737,7 +738,7 @@ public class DbTools {
             }
             return keyColumns;
         } catch (IndexOutOfBoundsException | IllegalArgumentException | WrappedTargetException | UnknownPropertyException exception) {
-            throw new SQLException("Error", null, StandardSQLState.SQL_GENERAL_ERROR.text(), 0, exception);
+            throw new SQLException("Error", Any.VOID, StandardSQLState.SQL_GENERAL_ERROR.text(), 0, exception);
         }
     }
 
@@ -754,7 +755,7 @@ public class DbTools {
                 XPropertySet columnProperties = AnyConverter.toObject(XPropertySet.class, sourceColumns.getByIndex(i));
                 destinationAppend.appendByDescriptor(columnProperties);
             } catch (WrappedTargetException | IndexOutOfBoundsException | IllegalArgumentException | ElementExistException exception) {
-                throw new SQLException("Error", null, StandardSQLState.SQL_GENERAL_ERROR.text(), 0, exception);
+                throw new SQLException("Error", Any.VOID, StandardSQLState.SQL_GENERAL_ERROR.text(), 0, exception);
             }
         }
     }


More information about the Libreoffice-commits mailing list