Package org.apache.metamodel

Examples of org.apache.metamodel.UpdateableDataContext


  public void testConvertedInsert() throws Exception {
    MockUpdateableDataContext source = new MockUpdateableDataContext();
    Column fooColumn = source.getColumnByQualifiedLabel("schema.table.foo");
    assertNotNull(fooColumn);

    UpdateableDataContext intercepted = Converters.addTypeConverter(source,
        fooColumn, new StringToIntegerConverter());

    final List<Object[]> values = source.getValues();

    assertEquals(3, values.size());

    intercepted.executeUpdate(new UpdateScript() {
      @Override
      public void run(UpdateCallback callback) {
        callback.insertInto("schema.table").value(0, 1).value(1, "2")
            .execute();
        callback.insertInto("schema.table").value(0, 3).value(1, "4")
View Full Code Here


        assertEquals(
                "[Column[name=foo,columnNumber=0,type=VARCHAR,nullable=null,nativeType=null,columnSize=null]]",
                converters.keySet().toString());
        assertEquals(StringToIntegerConverter.class, converters.values().iterator().next().getClass());

        final UpdateableDataContext dc = Converters.addTypeConverters(decoratedDataContext, converters);

        DataSet ds = dc.query().from(table).select(table.getColumns()).execute();
        assertEquals(ConvertedDataSet.class, ds.getClass());
        assertTrue(ds.next());
        assertEquals("Row[values=[1, hello]]", ds.getRow().toString());
        assertEquals(Integer.class, ds.getRow().getValue(0).getClass());
        assertEquals(1, ds.getRow().getValue(0));
        assertTrue(ds.next());
        assertEquals(Integer.class, ds.getRow().getValue(0).getClass());
        assertEquals(2, ds.getRow().getValue(0));
        assertTrue(ds.next());
        assertEquals(Integer.class, ds.getRow().getValue(0).getClass());
        assertEquals(3, ds.getRow().getValue(0));
        assertFalse(ds.next());
        ds.close();

        dc.executeUpdate(new UpdateScript() {
            @Override
            public void run(UpdateCallback callback) {
                callback.insertInto(table).value("foo", 4).value("bar", "mrrrrh").execute();
            }
        });

        // query the decorator
        ds = dc.query().from(table).select(table.getColumns()).where("foo").eq(4).execute();
        assertTrue(ds.next());
        assertEquals("Row[values=[4, mrrrrh]]", ds.getRow().toString());
        assertEquals(Integer.class, ds.getRow().getValue(0).getClass());
        assertEquals(4, ds.getRow().getValue(0));
        assertFalse(ds.next());
View Full Code Here

        assertEquals("[4, mrrrrh]", Arrays.toString(physicalRow));
        assertEquals(String.class, physicalRow[0].getClass());
    }

    public void testScenario() throws Exception {
        UpdateableDataContext dc = new MockUpdateableDataContext();
        List<Object[]> physicalValuesList = ((MockUpdateableDataContext) dc).getValues();
        assertEquals(3, physicalValuesList.size());
        for (Object[] physicalValues : physicalValuesList) {
            assertEquals("foo is expected to be string", String.class, physicalValues[0].getClass());
        }

        final Table table = dc.getDefaultSchema().getTables()[0];
        Map<Column, TypeConverter<?, ?>> converters = Converters.autoDetectConverters(dc, table, 1000);
        assertEquals(1, converters.size());
        dc = Converters.addTypeConverters(dc, converters);

        final Query q = dc.query().from(table).select("foo").toQuery();
        assertEquals("SELECT table.foo FROM schema.table", q.toSql());
        DataSet ds = dc.executeQuery(q);
        assertTrue(ds.next());
        assertEquals(1, ds.getRow().getValue(0));
        assertTrue(ds.next());
        assertEquals(2, ds.getRow().getValue(0));
        assertTrue(ds.next());
        assertEquals(3, ds.getRow().getValue(0));
        assertFalse(ds.next());

        dc.executeUpdate(new UpdateScript() {
            @Override
            public void run(UpdateCallback callback) {
                callback.insertInto(table).value("foo", 4).value("bar", "heidiho!").execute();
            }
        });

        ds = dc.executeQuery(q);
        assertTrue(ds.next());
        assertEquals(1, ds.getRow().getValue(0));
        assertTrue(ds.next());
        assertEquals(2, ds.getRow().getValue(0));
        assertTrue(ds.next());
        assertEquals(3, ds.getRow().getValue(0));
        assertTrue(ds.next());
        assertEquals(4, ds.getRow().getValue(0));
        assertFalse(ds.next());
       
        assertEquals(4, physicalValuesList.size());
        for (Object[] physicalValues : physicalValuesList) {
            assertEquals("foo is expected to be string", String.class, physicalValues[0].getClass());
        }
       
        dc.executeUpdate(new UpdateScript() {
            @Override
            public void run(UpdateCallback callback) {
                callback.insertInto(table).value("foo", 5).value("bar", "hejsa...").execute();
                callback.update(table).where("foo").lessThan(3).value("foo", 100).execute();
            }
        });
       
        ds = dc.executeQuery(q);
        assertTrue(ds.next());
        assertEquals(3, ds.getRow().getValue(0));
        assertTrue(ds.next());
        assertEquals(4, ds.getRow().getValue(0));
        assertTrue(ds.next());
View Full Code Here

import org.apache.metamodel.schema.Table;

public class ConvertedDataSetInterceptorTest extends TestCase {

  public void testConvertedQuery() throws Exception {
    UpdateableDataContext dc = new MockUpdateableDataContext();
    Column fooColumn = dc.getColumnByQualifiedLabel("schema.table.foo");
    assertNotNull(fooColumn);

    dc = Converters.addTypeConverter(dc, fooColumn,
        new StringToIntegerConverter());

    Table table = dc.getDefaultSchema().getTableByName("table");
    Query query = dc.query().from(table).select(table.getColumns())
        .toQuery();
    assertEquals("SELECT table.foo, table.bar FROM schema.table",
        query.toSql());

    DataSet ds = dc.executeQuery(query);
    assertEquals(ConvertedDataSet.class, ds.getClass());

    assertTrue(ds.next());
    assertEquals("Row[values=[1, hello]]", ds.getRow().toString());
    assertEquals(Integer.class, ds.getRow().getValue(0).getClass());
View Full Code Here

    @Override
    public void executeUpdate(UpdateScript update) {
        if (!(_delegate instanceof UpdateableDataContext)) {
            throw new UnsupportedOperationException("Delegate is not an UpdateableDataContext");
        }
        final UpdateableDataContext delegate = (UpdateableDataContext) _delegate;

        if (_tableCreationInterceptors.isEmpty() && _tableDropInterceptors.isEmpty()
                && _rowInsertionInterceptors.isEmpty() && _rowUpdationInterceptors.isEmpty()
                && _rowDeletionInterceptors.isEmpty()) {
            delegate.executeUpdate(update);
            return;
        }

        UpdateScript interceptableUpdateScript = new InterceptableUpdateScript(this, update,
                _tableCreationInterceptors, _tableDropInterceptors, _rowInsertionInterceptors,
                _rowUpdationInterceptors, _rowDeletionInterceptors);
        delegate.executeUpdate(interceptableUpdateScript);
    }
View Full Code Here

import org.apache.metamodel.schema.Table;

public class InterceptionCsvIntegrationTest extends TestCase {

  public void testScenario() throws Exception {
    final UpdateableDataContext source = new CsvDataContext(new File(
        "target/test_interception_scenario.txt"));
    final InterceptableDataContext dc = Interceptors.intercept(source);

    dc.addTableCreationInterceptor(new TableCreationInterceptor() {
      @Override
View Full Code Here

TOP

Related Classes of org.apache.metamodel.UpdateableDataContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.