Search in sources :

Example 41 with HardCodedExecutionFactory

use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.

the class TestSystemVirtualModel method testTriggers.

@Test
public void testTriggers() throws Exception {
    this.internalConnection.close();
    ModelMetaData mmd3 = new ModelMetaData();
    mmd3.setName("x");
    mmd3.setModelType(Type.PHYSICAL);
    mmd3.addSourceMapping("x", "x", null);
    mmd3.addSourceMetadata("DDL", "create foreign table t (intkey integer); " + " create trigger tr on t after insert as for each row begin select intkey from t where intkey = new.intkey; end; " + " create trigger tr1 on t after update as for each row begin select intkey from t where intkey = new.intkey + old.intkey; end;");
    HardCodedExecutionFactory ef = new HardCodedExecutionFactory() {

        @Override
        public boolean supportsCompareCriteriaEquals() {
            return true;
        }
    };
    ef.addData("SELECT t.intkey FROM t WHERE t.intkey = 1", new ArrayList<List<?>>());
    server.addTranslator("x", ef);
    server.deployVDB("test3", mmd3);
    this.internalConnection = server.createConnection("jdbc:teiid:test3");
    // $NON-NLS-1$ //$NON-NLS-2$
    checkResult("testTriggers", "select * from sysadmin.triggers");
    closeStatement();
    // insert event
    ResultsFuture<?> future = server.getEventDistributor().dataModification("test3", "1", "x", "t", null, new Object[] { 1 }, null);
    future.get(2, TimeUnit.SECONDS);
    assertEquals("SELECT t.intkey FROM t WHERE t.intkey = 1", ef.getCommands().get(0).toString());
    ef.addData("SELECT t.intkey FROM t WHERE t.intkey = 3", new ArrayList<List<?>>());
    // update event
    future = server.getEventDistributor().dataModification("test3", "1", "x", "t", new Object[] { 2 }, new Object[] { 1 }, null);
    future.get(2, TimeUnit.SECONDS);
    assertEquals("SELECT t.intkey FROM t WHERE t.intkey = 3", ef.getCommands().get(1).toString());
    // delete event
    future = server.getEventDistributor().dataModification("test3", "1", "x", "t", new Object[] { 2 }, null, null);
    future.get(2, TimeUnit.SECONDS);
    // no trigger
    assertEquals(2, ef.getCommands().size());
}
Also used : HardCodedExecutionFactory(org.teiid.runtime.HardCodedExecutionFactory) ArrayList(java.util.ArrayList) List(java.util.List) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 42 with HardCodedExecutionFactory

use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.

the class TestJDBCSocketTransport method testStreamingLob.

@Test
public void testStreamingLob() throws Exception {
    HardCodedExecutionFactory ef = new HardCodedExecutionFactory();
    ef.addData("SELECT helloworld.x FROM helloworld", Arrays.asList(Arrays.asList(new BlobType(new BinaryWSProcedureExecution.StreamingBlob(new ByteArrayInputStream(new byte[100]))))));
    server.addTranslator("custom", ef);
    server.deployVDB(new ByteArrayInputStream("<vdb name=\"test\" version=\"1\"><model name=\"test\"><source name=\"test\" translator-name=\"custom\"/><metadata type=\"DDL\"><![CDATA[CREATE foreign table helloworld (x blob);]]> </metadata></model></vdb>".getBytes("UTF-8")));
    conn = TeiidDriver.getInstance().connect("jdbc:teiid:test@mm://" + addr.getHostName() + ":" + jdbcTransport.getPort(), null);
    Statement s = conn.createStatement();
    ResultSet rs = s.executeQuery("select to_chars(x, 'UTF-8') from helloworld");
    rs.next();
    // TODO: if we use getString streaming will still fail because the string logic gets the length first
    assertEquals(100, ObjectConverterUtil.convertToCharArray(rs.getCharacterStream(1), -1).length);
}
Also used : BlobType(org.teiid.core.types.BlobType) ByteArrayInputStream(java.io.ByteArrayInputStream) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) HardCodedExecutionFactory(org.teiid.runtime.HardCodedExecutionFactory) Test(org.junit.Test)

Example 43 with HardCodedExecutionFactory

use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.

the class TestMaterializationPerformance method testIndexPerformance.

@Test
public void testIndexPerformance() throws Exception {
    ModelMetaData mmm = new ModelMetaData();
    mmm.setName("test");
    mmm.setSchemaSourceType("ddl");
    mmm.setSchemaText("create foreign table x (col1 integer, col2 string); " + "create view matx (col1 integer, col2 string, constraint idx index (col2)) options (materialized true) as select * from x;");
    mmm.addSourceMapping("x", "hc", null);
    HardCodedExecutionFactory hardCodedExecutionFactory = new HardCodedExecutionFactory();
    hardCodedExecutionFactory.addData("SELECT x.col1, x.col2 FROM x", Arrays.asList(TestEnginePerformance.sampleData(10000)));
    es.addTranslator("hc", hardCodedExecutionFactory);
    es.deployVDB("test", mmm);
    setConnection(es.getDriver().connect("jdbc:teiid:test", null));
    for (int i = 0; i < 10000; i++) {
        execute("SELECT * from matx where col2 = ?", new Object[] { String.valueOf(i) });
        assertEquals(String.valueOf(i), getRowCount(), 1);
    }
}
Also used : HardCodedExecutionFactory(org.teiid.runtime.HardCodedExecutionFactory) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) AbstractQueryTest(org.teiid.jdbc.AbstractQueryTest) Test(org.junit.Test)

Example 44 with HardCodedExecutionFactory

use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.

the class TestMaterializationPerformance method testFunctionBasedIndexPerformance.

@Test
public void testFunctionBasedIndexPerformance() throws Exception {
    ModelMetaData mmm = new ModelMetaData();
    mmm.setName("test");
    mmm.setSchemaSourceType("ddl");
    mmm.setSchemaText("create foreign table x (col1 integer, col2 string); " + "create view matx (col1 integer, col2 string, constraint idx index (upper(col2))) options (materialized true) as select * from x;");
    mmm.addSourceMapping("x", "hc", null);
    HardCodedExecutionFactory hardCodedExecutionFactory = new HardCodedExecutionFactory();
    hardCodedExecutionFactory.addData("SELECT x.col1, x.col2 FROM x", Arrays.asList(TestEnginePerformance.sampleData(10000)));
    es.addTranslator("hc", hardCodedExecutionFactory);
    es.deployVDB("test", mmm);
    setConnection(es.getDriver().connect("jdbc:teiid:test", null));
    for (int i = 0; i < 10000; i++) {
        execute("SELECT * from matx where upper(col2) = ?", new Object[] { String.valueOf(i) });
        assertEquals(String.valueOf(i), getRowCount(), 1);
    }
}
Also used : HardCodedExecutionFactory(org.teiid.runtime.HardCodedExecutionFactory) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) AbstractQueryTest(org.teiid.jdbc.AbstractQueryTest) Test(org.junit.Test)

Example 45 with HardCodedExecutionFactory

use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.

the class TestSystemPerformance method setup.

@Before
public void setup() throws VirtualDatabaseException, ConnectorManagerException, TranslatorException {
    es = new EmbeddedServer();
    es.start(new EmbeddedConfiguration());
    ModelMetaData mmm = new ModelMetaData();
    mmm.setName("test");
    mmm.setSchemaSourceType("native");
    mmm.addSourceMapping("x", "hc", null);
    HardCodedExecutionFactory hardCodedExecutionFactory = new HardCodedExecutionFactory() {

        @Override
        public void getMetadata(MetadataFactory metadataFactory, Object conn) throws TranslatorException {
            String[] colNames = new String[COLS];
            for (int i = 0; i < colNames.length; i++) {
                colNames[i] = "col" + i;
            }
            for (int i = 0; i < TABLES; i++) {
                Table t = metadataFactory.addTable("x" + i);
                for (int j = 0; j < COLS; j++) {
                    metadataFactory.addColumn(colNames[j], "string", t);
                }
            }
        }

        @Override
        public boolean isSourceRequiredForMetadata() {
            return false;
        }
    };
    es.addTranslator("hc", hardCodedExecutionFactory);
    es.deployVDB("test", mmm);
}
Also used : Table(org.teiid.metadata.Table) MetadataFactory(org.teiid.metadata.MetadataFactory) EmbeddedServer(org.teiid.runtime.EmbeddedServer) EmbeddedConfiguration(org.teiid.runtime.EmbeddedConfiguration) HardCodedExecutionFactory(org.teiid.runtime.HardCodedExecutionFactory) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Before(org.junit.Before)

Aggregations

HardCodedExecutionFactory (org.teiid.runtime.HardCodedExecutionFactory)46 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)43 Test (org.junit.Test)40 Properties (java.util.Properties)27 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)27 StringContentProvider (org.eclipse.jetty.client.util.StringContentProvider)10 Connection (java.sql.Connection)8 ResultSet (java.sql.ResultSet)8 Statement (java.sql.Statement)7 CallableStatement (java.sql.CallableStatement)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 FakeServer (org.teiid.jdbc.FakeServer)4 QueryExpression (org.teiid.language.QueryExpression)3 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)3 Table (org.teiid.metadata.Table)3 EmbeddedConfiguration (org.teiid.runtime.EmbeddedConfiguration)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 BeforeClass (org.junit.BeforeClass)2 AbstractQueryTest (org.teiid.jdbc.AbstractQueryTest)2