Search in sources :

Example 21 with ConnectorManager

use of org.teiid.dqp.internal.datamgr.ConnectorManager in project teiid by teiid.

the class TestLocalConnections method oneTimeSetup.

@SuppressWarnings("serial")
@BeforeClass
public static void oneTimeSetup() throws Exception {
    server.setUseCallingThread(true);
    server.setConnectorManagerRepository(new ConnectorManagerRepository() {

        @Override
        public ConnectorManager getConnectorManager(String connectorName) {
            return new ConnectorManager(connectorName, connectorName) {

                @Override
                public ExecutionFactory<Object, Object> getExecutionFactory() {
                    return new ExecutionFactory<Object, Object>() {

                        @Override
                        public boolean isSourceRequired() {
                            return false;
                        }

                        @Override
                        public Execution createExecution(Command command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
                            return new ResultSetExecution() {

                                boolean returnedRow = false;

                                @Override
                                public void execute() throws TranslatorException {
                                    lock.lock();
                                    try {
                                        sourceCounter.release();
                                        if (!wait.await(5, TimeUnit.SECONDS)) {
                                            throw new RuntimeException();
                                        }
                                    } catch (InterruptedException e) {
                                        throw new RuntimeException(e);
                                    } finally {
                                        lock.unlock();
                                    }
                                }

                                @Override
                                public void close() {
                                }

                                @Override
                                public void cancel() throws TranslatorException {
                                }

                                @Override
                                public List<?> next() throws TranslatorException, DataNotAvailableException {
                                    if (returnedRow) {
                                        return null;
                                    }
                                    returnedRow = true;
                                    return new ArrayList<Object>(Collections.singleton(null));
                                }
                            };
                        }
                    };
                }

                @Override
                public Object getConnectionFactory() throws TranslatorException {
                    return null;
                }
            };
        }
    });
    FunctionMethod function = new FunctionMethod("foo", null, FunctionCategoryConstants.MISCELLANEOUS, PushDown.CANNOT_PUSHDOWN, TestLocalConnections.class.getName(), "blocking", null, new FunctionParameter("result", DataTypeManager.DefaultDataTypes.INTEGER), false, FunctionMethod.Determinism.NONDETERMINISTIC);
    HashMap<String, Collection<FunctionMethod>> udfs = new HashMap<String, Collection<FunctionMethod>>();
    udfs.put("test", Arrays.asList(function));
    server.deployVDB("PartsSupplier", UnitTestUtil.getTestDataPath() + "/PartsSupplier.vdb", new DeployVDBParameter(udfs, null));
}
Also used : HashMap(java.util.HashMap) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) Execution(org.teiid.translator.Execution) ResultSetExecution(org.teiid.translator.ResultSetExecution) FunctionMethod(org.teiid.metadata.FunctionMethod) List(java.util.List) ArrayList(java.util.ArrayList) DataNotAvailableException(org.teiid.translator.DataNotAvailableException) FunctionParameter(org.teiid.metadata.FunctionParameter) ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) ExecutionFactory(org.teiid.translator.ExecutionFactory) ConnectorManager(org.teiid.dqp.internal.datamgr.ConnectorManager) DeployVDBParameter(org.teiid.jdbc.FakeServer.DeployVDBParameter) ResultSetExecution(org.teiid.translator.ResultSetExecution) ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) Collection(java.util.Collection) TranslatorException(org.teiid.translator.TranslatorException) BeforeClass(org.junit.BeforeClass)

Example 22 with ConnectorManager

use of org.teiid.dqp.internal.datamgr.ConnectorManager in project teiid by teiid.

the class TestExecutionReuse method oneTimeSetUp.

@BeforeClass
public static void oneTimeSetUp() throws Exception {
    EmbeddedConfiguration config = new EmbeddedConfiguration();
    config.setUserRequestSourceConcurrency(1);
    server = new FakeServer(false);
    server.setConnectorManagerRepository(new ConnectorManagerRepository() {

        private ConnectorManager cm = new ConnectorManager("x", "y") {

            private ExecutionFactory<Object, Object> ef = new ExecutionFactory<Object, Object>() {

                @Override
                public ResultSetExecution createResultSetExecution(QueryExpression command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
                    ec = executionContext;
                    return execution;
                }

                public boolean isSourceRequired() {
                    return false;
                }
            };

            @Override
            public ExecutionFactory<Object, Object> getExecutionFactory() {
                return ef;
            }

            @Override
            public Object getConnectionFactory() throws TranslatorException {
                return null;
            }
        };

        @Override
        public ConnectorManager getConnectorManager(String connectorName) {
            return cm;
        }
    });
    server.start(config, false);
    server.deployVDB("PartsSupplier", UnitTestUtil.getTestDataPath() + "/PartsSupplier.vdb");
}
Also used : FakeServer(org.teiid.jdbc.FakeServer) ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) EmbeddedConfiguration(org.teiid.runtime.EmbeddedConfiguration) ExecutionFactory(org.teiid.translator.ExecutionFactory) ConnectorManager(org.teiid.dqp.internal.datamgr.ConnectorManager) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) ResultSetExecution(org.teiid.translator.ResultSetExecution) ExecutionContext(org.teiid.translator.ExecutionContext) TranslatorException(org.teiid.translator.TranslatorException) QueryExpression(org.teiid.language.QueryExpression) BeforeClass(org.junit.BeforeClass)

Aggregations

ConnectorManager (org.teiid.dqp.internal.datamgr.ConnectorManager)22 ConnectorManagerRepository (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository)15 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)9 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)9 TranslatorException (org.teiid.translator.TranslatorException)7 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 ExecutionFactory (org.teiid.translator.ExecutionFactory)6 MetadataStore (org.teiid.metadata.MetadataStore)4 AdminProcessingException (org.teiid.adminapi.AdminProcessingException)3 SourceMappingMetadata (org.teiid.adminapi.impl.SourceMappingMetadata)3 TeiidException (org.teiid.core.TeiidException)3 VirtualDatabaseException (org.teiid.deployers.VirtualDatabaseException)3 ConnectorManagerException (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository.ConnectorManagerException)3 FunctionMethod (org.teiid.metadata.FunctionMethod)3 MetadataFactory (org.teiid.metadata.MetadataFactory)3 IOException (java.io.IOException)2 List (java.util.List)2 Map (java.util.Map)2 XMLStreamException (javax.xml.stream.XMLStreamException)2