Author: shawkins
Date: 2011-11-15 13:10:51 -0500 (Tue, 15 Nov 2011)
New Revision: 3652
Added:
trunk/client/src/main/java/org/teiid/jdbc/TeiidSQLWarning.java
Modified:
trunk/api/src/main/java/org/teiid/translator/ExecutionContext.java
trunk/client/src/main/java/org/teiid/jdbc/WarningUtil.java
Log:
TEIID-1829 better handling of source warnings
Modified: trunk/api/src/main/java/org/teiid/translator/ExecutionContext.java
===================================================================
--- trunk/api/src/main/java/org/teiid/translator/ExecutionContext.java 2011-11-15 18:08:40
UTC (rev 3651)
+++ trunk/api/src/main/java/org/teiid/translator/ExecutionContext.java 2011-11-15 18:10:51
UTC (rev 3652)
@@ -28,6 +28,7 @@
import javax.security.auth.Subject;
import org.teiid.adminapi.Session;
+import org.teiid.jdbc.TeiidSQLWarning;
@@ -143,9 +144,8 @@
int getBatchSize();
/**
- * Add an exception as a warning to this Execution. If the exception is not an
instance of a SQLWarning
- * it will be wrapped by a SQLWarning for the client. The warnings can be consumed
through the
- * {@link Statement#getWarnings()} method.
+ * Add an exception as a warning to this Execution. The exception will be wrapped by
a {@link TeiidSQLWarning} for the client.
+ * The warnings can be consumed through the {@link Statement#getWarnings()} method.
* @param ex
*/
void addWarning(Exception ex);
Added: trunk/client/src/main/java/org/teiid/jdbc/TeiidSQLWarning.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/TeiidSQLWarning.java
(rev 0)
+++ trunk/client/src/main/java/org/teiid/jdbc/TeiidSQLWarning.java 2011-11-15 18:10:51 UTC
(rev 3652)
@@ -0,0 +1,71 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.jdbc;
+
+import java.sql.SQLWarning;
+
+
+/**
+ * Teiid specific SQLWarning
+ */
+
+public class TeiidSQLWarning extends SQLWarning {
+
+ private String modelName = "UNKNOWN"; // variable stores the name of the model
for the atomic query //$NON-NLS-1$
+ private String sourceName = "UNKNOWN"; // variable stores name of the
connector binding //$NON-NLS-1$
+
+ public TeiidSQLWarning() {
+ super();
+ }
+
+ public TeiidSQLWarning(String reason) {
+ super(reason);
+ }
+
+ public TeiidSQLWarning(String reason, String state) {
+ super(reason, state);
+ }
+
+ public TeiidSQLWarning(String reason, String sqlState, Throwable ex, String
sourceName, String modelName) {
+ super(reason, sqlState, ex);
+ this.sourceName = sourceName;
+ this.modelName = modelName;
+ }
+
+ /**
+ *
+ * @return the source name or null if the warning is not associated with a source
+ */
+ public String getSourceName() {
+ return sourceName;
+ }
+
+ /**
+ *
+ * @return the model name or null if the warning is not associated with a model
+ */
+ public String getModelName() {
+ return modelName;
+ }
+
+}
\ No newline at end of file
Property changes on: trunk/client/src/main/java/org/teiid/jdbc/TeiidSQLWarning.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/client/src/main/java/org/teiid/jdbc/WarningUtil.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/WarningUtil.java 2011-11-15 18:08:40 UTC
(rev 3651)
+++ trunk/client/src/main/java/org/teiid/jdbc/WarningUtil.java 2011-11-15 18:10:51 UTC
(rev 3652)
@@ -26,6 +26,7 @@
import java.util.List;
import org.teiid.client.SourceWarning;
+import org.teiid.core.TeiidException;
@@ -44,6 +45,8 @@
* @param ex Throwable object which needs to be wrapped.
*/
static SQLWarning createWarning(Throwable ex) {
+ String sourceName = null;
+ String modelName = null;
if(ex instanceof SourceWarning) {
SourceWarning exception = (SourceWarning)ex;
if (exception.isPartialResultsError()) {
@@ -51,8 +54,15 @@
warning.addConnectorFailure(exception.getConnectorBindingName(),
TeiidSQLException.create(exception));
return warning;
}
+ ex = exception.getCause();
+ sourceName = exception.getConnectorBindingName();
+ modelName = exception.getModelName();
}
- return new SQLWarning(ex);
+ String code = null;
+ if (ex instanceof TeiidException) {
+ code = ((TeiidException)ex).getCode();
+ }
+ return new TeiidSQLWarning(ex.getMessage(), code, ex, sourceName, modelName);
}
/**
Show replies by date