summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Winkler2009-09-18 09:57:45 (EDT)
committerStefan Winkler2009-09-18 09:57:45 (EDT)
commitcac9338cbc1981e67637c452d5a7ac7441da9bd6 (patch)
tree337806fc6fc6728256866176730de5fc7f2fd162
parentc21c2288cc6e245cff53548e2068aa0858792e60 (diff)
downloadcdo-cac9338cbc1981e67637c452d5a7ac7441da9bd6.zip
cdo-cac9338cbc1981e67637c452d5a7ac7441da9bd6.tar.gz
cdo-cac9338cbc1981e67637c452d5a7ac7441da9bd6.tar.bz2
RESOLVED - bug 289051: [DB] PostgreSQL: "current transaction is aborted, commands ignored until end of transaction block"
https://bugs.eclipse.org/bugs/show_bug.cgi?id=289051
-rw-r--r--plugins/org.eclipse.net4j.db.postgresql/src/org/eclipse/net4j/db/postgresql/PostgreSQLAdapter.java66
1 files changed, 66 insertions, 0 deletions
diff --git a/plugins/org.eclipse.net4j.db.postgresql/src/org/eclipse/net4j/db/postgresql/PostgreSQLAdapter.java b/plugins/org.eclipse.net4j.db.postgresql/src/org/eclipse/net4j/db/postgresql/PostgreSQLAdapter.java
index 5b29bfd..e81da45 100644
--- a/plugins/org.eclipse.net4j.db.postgresql/src/org/eclipse/net4j/db/postgresql/PostgreSQLAdapter.java
+++ b/plugins/org.eclipse.net4j.db.postgresql/src/org/eclipse/net4j/db/postgresql/PostgreSQLAdapter.java
@@ -12,15 +12,23 @@
*/
package org.eclipse.net4j.db.postgresql;
+import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.DBType;
import org.eclipse.net4j.db.ddl.IDBField;
+import org.eclipse.net4j.db.ddl.IDBTable;
+import org.eclipse.net4j.db.internal.postgresql.bundle.OM;
import org.eclipse.net4j.spi.db.DBAdapter;
+import org.eclipse.net4j.util.om.trace.ContextTracer;
import org.postgresql.Driver;
import org.postgresql.ds.PGSimpleDataSource;
import javax.sql.DataSource;
+import java.sql.SQLException;
+import java.sql.Savepoint;
+import java.sql.Statement;
+
/**
* @author Victor Roldan Betancort
*/
@@ -30,6 +38,8 @@ public class PostgreSQLAdapter extends DBAdapter
public static final String VERSION = "8.3"; //$NON-NLS-1$
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SQL, DBAdapter.class);
+
private static final String[] RESERVED_WORDS = { "ALL", "ANALYSE", "ANALYZE", "AND", "ANY", "AS", "ASC", "ATOMIC", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
"AUTHORIZATION", "BETWEEN", "BIGINT", "BINARY", "BIT", "BOOLEAN", "BOTH", "C", "CASE", "CAST", "CHAR", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$
"CHARACTER", "CHECK", "COALESCE", "COLLATE", "COLUMN", "CONSTRAINT", "CONVERT", "CREATE", "CROSS", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$
@@ -61,6 +71,7 @@ public class PostgreSQLAdapter extends DBAdapter
/**
* @since 2.0
*/
+ @Override
public int getMaxTableNameLength()
{
// http://www.postgresql.org/docs/8.2/static/sql-syntax-lexical.html
@@ -70,6 +81,7 @@ public class PostgreSQLAdapter extends DBAdapter
/**
* @since 2.0
*/
+ @Override
public int getMaxFieldNameLength()
{
// http://www.postgresql.org/docs/8.2/static/sql-syntax-lexical.html
@@ -96,4 +108,58 @@ public class PostgreSQLAdapter extends DBAdapter
{
return RESERVED_WORDS;
}
+
+ /*
+ * TODO Remove this method override after fixing Bug 282791 - [DB] Check for existing tables instead of relying on
+ * SQLExceptions PostgreSQL uses transaction on DDL operations. If an error occurs, the SQL Connection goes to an
+ * error state, and can only be cleared by rolling back. Therefore, savepoints for table creation were added
+ */
+ @Override
+ public boolean createTable(IDBTable table, Statement statement) throws DBException
+ {
+ boolean created = true;
+
+ Savepoint savepoint = null;
+ try
+ {
+ savepoint = statement.getConnection().setSavepoint();
+ }
+ catch (SQLException ex2)
+ {
+ TRACER.trace("-- " + ex2.getMessage() + ". Trying to rollback operation"); //$NON-NLS-1$
+ }
+
+ try
+ {
+ doCreateTable(table, statement);
+ }
+ catch (SQLException ex)
+ {
+ created = false;
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace("-- " + ex.getMessage() + ". Trying to rollback operation"); //$NON-NLS-1$
+ }
+ if (savepoint != null)
+ {
+ try
+ {
+ statement.getConnection().rollback(savepoint);
+ }
+ catch (SQLException ex1)
+ {
+ TRACER.trace("-- " + ex1.getMessage()); //$NON-NLS-1$
+ }
+ }
+ else
+ {
+ TRACER.trace("-- ERROR: Could not rollback last operation. Savepoint was not created."); //$NON-NLS-1$
+ }
+
+ }
+
+ validateTable(table, statement);
+ return created;
+ }
+
}