Skip to content

Commit

Permalink
TEIID-4231 better handling for a non-active vdb
Browse files Browse the repository at this point in the history
# Conflicts:
#	test-integration/common/src/test/java/org/teiid/arquillian/IntegrationTestOData4.java
  • Loading branch information
shawkins committed Mar 31, 2017
1 parent 3e76853 commit ab1bb24
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
3 changes: 2 additions & 1 deletion olingo/src/main/java/org/teiid/odata/api/Client.java
Expand Up @@ -26,6 +26,7 @@
import java.util.List;

import org.teiid.adminapi.impl.VDBMetaData;
import org.teiid.core.TeiidProcessingException;
import org.teiid.metadata.MetadataStore;
import org.teiid.query.sql.lang.Command;
import org.teiid.query.sql.lang.Query;
Expand Down Expand Up @@ -59,7 +60,7 @@ void executeSQL(Query query, List<SQLParameter> parameters,

String getProperty(String name);

Connection open() throws SQLException;
Connection open() throws SQLException, TeiidProcessingException;

void close() throws SQLException;
}
41 changes: 27 additions & 14 deletions olingo/src/main/java/org/teiid/olingo/service/LocalClient.java
Expand Up @@ -34,7 +34,9 @@
import java.util.Properties;
import java.util.StringTokenizer;

import org.teiid.adminapi.VDB.Status;
import org.teiid.adminapi.impl.VDBMetaData;
import org.teiid.core.TeiidProcessingException;
import org.teiid.core.TeiidRuntimeException;
import org.teiid.core.util.PropertiesUtils;
import org.teiid.jdbc.ConnectionImpl;
Expand All @@ -54,6 +56,7 @@
import org.teiid.odata.api.UpdateResponse;
import org.teiid.odbc.ODBCServerRemoteImpl;
import org.teiid.olingo.ODataPlugin;
import org.teiid.query.QueryPlugin;
import org.teiid.query.metadata.TransformationMetadata;
import org.teiid.query.sql.lang.CacheHint;
import org.teiid.query.sql.lang.Command;
Expand Down Expand Up @@ -85,10 +88,11 @@ private long getCacheTime() {
}

@Override
public Connection open() throws SQLException {
public Connection open() throws SQLException, TeiidProcessingException {
this.connection = buildConnection(TeiidDriver.getInstance(), this.vdbName, this.vdbVersion, this.properties);
ODBCServerRemoteImpl.setConnectionProperties(connection);
ODBCServerRemoteImpl.setConnectionProperties(connection, this.properties);
getVDBInternal();
return this.connection;
}

Expand Down Expand Up @@ -122,22 +126,31 @@ public static ConnectionImpl buildConnection(TeiidDriver driver, String vdbName,

@Override
public VDBMetaData getVDB() {
if (this.vdb == null) {
try {
LocalServerConnection lsc = (LocalServerConnection) getConnection().getServerConnection();
VDBMetaData vdb = lsc.getWorkContext().getVDB();
if (vdb == null) {
throw new TeiidRuntimeException(ODataPlugin.Util.gs(
ODataPlugin.Event.TEIID16001, this.vdbName,
this.vdbVersion));
}
this.vdb = vdb;
} catch (SQLException e) {
throw new TeiidRuntimeException(e);
try {
return getVDBInternal();
} catch (TeiidProcessingException e) {
throw new TeiidRuntimeException(e);
} catch (SQLException e) {
throw new TeiidRuntimeException(e);
}
}

private VDBMetaData getVDBInternal() throws SQLException, TeiidProcessingException {
if (this.vdb == null) {
LocalServerConnection lsc = (LocalServerConnection) getConnection().getServerConnection();
vdb = lsc.getWorkContext().getVDB();
if (vdb == null) {
throw new TeiidRuntimeException(ODataPlugin.Util.gs(
ODataPlugin.Event.TEIID16001, this.vdbName,
this.vdbVersion));
}
this.vdb = vdb;
}
if (vdb.getStatus() != Status.ACTIVE) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID31099, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31099, vdb, vdb.getStatus()));
}
return this.vdb;
}
}

@Override
public void executeCall(String sql, List<SQLParameter> parameters, ProcedureReturnType returnType,
Expand Down

0 comments on commit ab1bb24

Please sign in to comment.