You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by da...@apache.org on 2017/09/19 06:18:22 UTC

svn commit: r1808824 - in /openoffice/trunk/main/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx: OColumnContainer.java OTable.java

Author: damjan
Date: Tue Sep 19 06:18:22 2017
New Revision: 1808824

URL: http://svn.apache.org/viewvc?rev=1808824&view=rev
Log:
Add support for adding and deleting columns in Java's SDBCX tables,
currently used by the PostgreSQL driver.

Patch by: me


Modified:
    openoffice/trunk/main/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/OColumnContainer.java
    openoffice/trunk/main/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/OTable.java

Modified: openoffice/trunk/main/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/OColumnContainer.java
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/OColumnContainer.java?rev=1808824&r1=1808823&r2=1808824&view=diff
==============================================================================
--- openoffice/trunk/main/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/OColumnContainer.java (original)
+++ openoffice/trunk/main/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/OColumnContainer.java Tue Sep 19 06:18:22 2017
@@ -33,9 +33,13 @@ import com.sun.star.sdbc.ColumnValue;
 import com.sun.star.sdbc.DataType;
 import com.sun.star.sdbc.SQLException;
 import com.sun.star.sdbc.XDatabaseMetaData;
+import com.sun.star.sdbc.XStatement;
+import com.sun.star.sdbcx.comp.postgresql.comphelper.CompHelper;
 import com.sun.star.sdbcx.comp.postgresql.sdbcx.SqlTableHelper.ColumnDescription;
 import com.sun.star.sdbcx.comp.postgresql.sdbcx.descriptors.SdbcxColumnDescriptor;
+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.uno.UnoRuntime;
 
 public class OColumnContainer extends OContainer {
@@ -116,10 +120,38 @@ public class OColumnContainer extends OC
     
     @Override
     protected XPropertySet appendObject(String _rForName, XPropertySet descriptor) throws SQLException {
-        return null;
+        if (table == null) {
+            return cloneDescriptor(descriptor);
+        }
+        String sql = String.format("ALTER TABLE %s ADD %s",
+                DbTools.composeTableName(metadata, table, ComposeRule.InTableDefinitions, false, false, true),
+                DbTools.createStandardColumnPart(descriptor, table.getConnection(), null, table.getTypeCreatePattern()));
+        XStatement statement = null;
+        try {
+            statement = table.getConnection().createStatement();
+            statement.execute(sql);
+        } finally {
+            CompHelper.disposeComponent(statement);
+        }
+        return createObject(_rForName);
     }
     
     @Override
     protected void dropObject(int index, String name) throws SQLException {
+        Osl.ensure(table, "Table is null!");
+        if (table == null) {
+            return;
+        }
+        String quote = metadata.getIdentifierQuoteString();
+        String sql = String.format("ALTER TABLE %s DROP %s",
+                DbTools.composeTableName(metadata, table, ComposeRule.InTableDefinitions, false, false, true),
+                DbTools.quoteName(quote, name));
+        XStatement statement = null;
+        try {
+            statement = table.getConnection().createStatement();
+            statement.execute(sql);
+        } finally {
+            CompHelper.disposeComponent(statement);
+        }
     }
 }

Modified: openoffice/trunk/main/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/OTable.java
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/OTable.java?rev=1808824&r1=1808823&r2=1808824&view=diff
==============================================================================
--- openoffice/trunk/main/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/OTable.java (original)
+++ openoffice/trunk/main/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/OTable.java Tue Sep 19 06:18:22 2017
@@ -167,6 +167,10 @@ public abstract class OTable extends ODe
         return connection;
     }
     
+    public String getTypeCreatePattern() {
+        return "";
+    }
+    
     protected abstract OContainer refreshColumns();
     protected abstract OContainer refreshIndexes();
     protected abstract OContainer refreshKeys();