use of org.teiid.resource.spi.WrappedConnection in project teiid by teiid.
the class ConnectorManager method buildCapabilities.
private BasicSourceCapabilities buildCapabilities(ExecutionFactory<Object, Object> translator) throws TranslatorException {
if (translator.isSourceRequiredForCapabilities()) {
Object connection = null;
Object connectionFactory = null;
try {
connectionFactory = getConnectionFactory();
if (connectionFactory != null) {
connection = translator.getConnection(connectionFactory, null);
}
if (connection == null) {
// $NON-NLS-1$);
throw new TranslatorException(QueryPlugin.Event.TEIID31108, QueryPlugin.Util.getString("datasource_not_found", getConnectionName()));
}
if (connection instanceof WrappedConnection) {
try {
connection = ((WrappedConnection) connection).unwrap();
} catch (ResourceException e) {
throw new TranslatorException(QueryPlugin.Event.TEIID30477, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30477, getConnectionName()));
}
}
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Initializing the capabilities for", translatorName);
synchronized (executionFactory) {
executionFactory.initCapabilities(connection);
}
} finally {
if (connection != null) {
translator.closeConnection(connection, connectionFactory);
}
}
}
BasicSourceCapabilities resultCaps = CapabilitiesConverter.convertCapabilities(translator, id);
return resultCaps;
}
use of org.teiid.resource.spi.WrappedConnection in project teiid by teiid.
the class ConnectorWorkItem method execute.
public synchronized void execute() throws TranslatorException {
if (isCancelled()) {
throw new TranslatorException(QueryPlugin.Event.TEIID30476, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30476));
}
timer.start();
try {
if (this.execution == null) {
if (this.connection == null) {
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_CONNECTOR, new Object[] { this.requestMsg.getAtomicRequestID(), "Processing NEW request:", this.requestMsg.getCommand() });
try {
this.connectionFactory = this.manager.getConnectionFactory();
} catch (TranslatorException e) {
if (this.connector.isSourceRequired()) {
throw e;
}
}
if (this.connectionFactory != null) {
this.connection = this.connector.getConnection(this.connectionFactory, securityContext);
}
if (this.connection == null && this.connector.isSourceRequired()) {
// $NON-NLS-1$);
throw new TranslatorException(QueryPlugin.Event.TEIID31108, QueryPlugin.Util.getString("datasource_not_found", this.manager.getConnectionName()));
}
}
Object unwrapped = null;
if (connection instanceof WrappedConnection) {
try {
unwrapped = ((WrappedConnection) connection).unwrap();
} catch (ResourceException e) {
throw new TranslatorException(QueryPlugin.Event.TEIID30477, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30477, this.manager.getConnectionName()));
}
}
// Translate the command
Command command = this.requestMsg.getCommand();
this.expectedColumns = command.getProjectedSymbols().size();
if (command instanceof StoredProcedure) {
this.expectedColumns = ((StoredProcedure) command).getResultSetColumns().size();
}
Execution exec = this.requestMsg.getCommandContext().getReusableExecution(this.manager.getId());
if (exec != null) {
((ReusableExecution) exec).reset(translatedCommand, this.securityContext, connection);
} else {
exec = connector.createExecution(translatedCommand, this.securityContext, queryMetadata, (unwrapped == null) ? this.connection : unwrapped);
}
setExecution(command, translatedCommand, exec);
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_CONNECTOR, new Object[] { this.requestMsg.getAtomicRequestID(), "Obtained execution" });
// Log the Source Command (Must be after obtaining the execution context)
manager.logSRCCommand(this.requestMsg, this.securityContext, Event.NEW, null, null);
}
// Execute query
this.execution.execute();
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_CONNECTOR, new Object[] { this.id, "Executed command" });
} catch (Throwable t) {
throw handleError(t);
} finally {
timer.stop();
}
}
use of org.teiid.resource.spi.WrappedConnection in project teiid by teiid.
the class NativeMetadataRepository method getMetadata.
private void getMetadata(MetadataFactory factory, ExecutionFactory executionFactory, Object connectionFactory) throws TranslatorException {
Object connection = null;
try {
connection = executionFactory.getConnection(connectionFactory, null);
} catch (Throwable e) {
// if security pass through is enabled the connection creation may fail at the startup
if (executionFactory.isSourceRequiredForMetadata()) {
throw new TranslatorException(QueryPlugin.Event.TEIID31178, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31178, factory.getName()));
}
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_CONNECTOR, e, "Exception getting connection for metadata, but no connection is required");
}
Object unwrapped = null;
if (connection instanceof WrappedConnection) {
try {
unwrapped = ((WrappedConnection) connection).unwrap();
} catch (ResourceException e) {
if (executionFactory.isSourceRequiredForMetadata()) {
throw new TranslatorException(QueryPlugin.Event.TEIID30477, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30477, factory.getName()));
}
connection = null;
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_CONNECTOR, e, "Could not unwrap exception to get metadata, but no connection is required");
}
}
try {
executionFactory.getMetadata(factory, (unwrapped == null) ? connection : unwrapped);
} finally {
executionFactory.closeConnection(connection, connectionFactory);
}
if (PropertiesUtils.getBooleanProperty(factory.getModelProperties(), IMPORT_PUSHDOWN_FUNCTIONS, false)) {
// $NON-NLS-1$
List<FunctionMethod> functions = executionFactory.getPushDownFunctions();
// create a copy and add to the schema
if (!functions.isEmpty()) {
try {
AccessibleByteArrayOutputStream baos = new AccessibleByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(functions);
oos.close();
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.getBuffer(), 0, baos.getCount()));
functions = (List<FunctionMethod>) ois.readObject();
for (FunctionMethod functionMethod : functions) {
factory.addFunction(functionMethod);
functionMethod.setProperty(FunctionMethod.SYSTEM_NAME, functionMethod.getName());
}
} catch (IOException e) {
throw new TeiidRuntimeException(e);
} catch (ClassNotFoundException e) {
throw new TeiidRuntimeException(e);
}
}
}
}
Aggregations