Examples of UpdateScript


Examples of org.apache.metamodel.UpdateScript

        final Schema schema = dc.getDefaultSchema();
        assertEquals(0, schema.getTableCount());

        final MutableRef<Table> tableRef = new MutableRef<Table>();

        dc.executeUpdate(new UpdateScript() {
            @Override
            public void run(UpdateCallback cb) {
                Table table = cb.createTable(schema, "foobar").withColumn("foo").withColumn("bar").execute();
                tableRef.set(table);
                assertEquals(schema, table.getSchema());
                assertEquals(schema.getTables()[0], table);
                assertTrue(file.exists());

                assertEquals("[foo, bar]", Arrays.toString(table.getColumnNames()));

                cb.insertInto(table).value(0, "f").value(1, "b").execute();
                cb.insertInto(table).value(0, "o").value(table.getColumnByName("bar"), "a").execute();
                cb.insertInto(table).value(0, "o").value("bar", "r").execute();
            }
        });

        // query the file to check results
        final Table readTable = schema.getTables()[0];
        assertEquals(tableRef.get(), readTable);
        assertEquals("[foo, bar]", Arrays.toString(readTable.getColumnNames()));

        final Query query = dc.query().from(readTable).select("bar").and("foo").toQuery();
        DataSet ds = dc.executeQuery(query);

        assertTrue(ds.next());
        assertEquals("Row[values=[b, f]]", ds.getRow().toString());
        assertTrue(ds.next());
        assertEquals("Row[values=[a, o]]", ds.getRow().toString());
        assertTrue(ds.next());
        assertEquals("Row[values=[r, o]]", ds.getRow().toString());
        assertFalse(ds.next());

        // do the same trick on an existing file
        dc = new CsvDataContext(file);
        dc.executeUpdate(new UpdateScript() {
            @Override
            public void run(UpdateCallback cb) {
                cb.insertInto(tableRef.get()).value("foo", "hello").value("bar", "world").execute();
            }
        });

        ds = dc.executeQuery(query);

        assertTrue(ds.next());
        assertEquals("Row[values=[b, f]]", ds.getRow().toString());
        assertTrue(ds.next());
        assertEquals("Row[values=[a, o]]", ds.getRow().toString());
        assertTrue(ds.next());
        assertEquals("Row[values=[r, o]]", ds.getRow().toString());
        assertTrue(ds.next());
        assertEquals("Row[values=[world, hello]]", ds.getRow().toString());
        assertFalse(ds.next());
        ds.close();

        dc.executeUpdate(new UpdateScript() {
            @Override
            public void run(UpdateCallback callback) {
                callback.deleteFrom(readTable).where("bar").eq("a").execute();
                callback.deleteFrom(readTable).where("bar").eq("r").execute();
            }
        });

        ds = dc.executeQuery(query);
        assertTrue(ds.next());
        assertEquals("Row[values=[b, f]]", ds.getRow().toString());
        assertTrue(ds.next());
        assertEquals("Row[values=[world, hello]]", ds.getRow().toString());
        assertFalse(ds.next());
        ds.close();

        dc.executeUpdate(new UpdateScript() {
            @Override
            public void run(UpdateCallback callback) {
                callback.update(readTable).value("foo", "universe").execute();
                callback.update(readTable).value("bar", "c").where("bar").isEquals("b").execute();
            }
        });

        ds = dc.executeQuery(query);
        assertTrue(ds.next());
        assertEquals("Row[values=[world, universe]]", ds.getRow().toString());
        assertTrue(ds.next());
        assertEquals("Row[values=[c, universe]]", ds.getRow().toString());
        assertFalse(ds.next());
        ds.close();

        // drop table
        dc.executeUpdate(new UpdateScript() {
            @Override
            public void run(UpdateCallback callback) {
                callback.dropTable(readTable).execute();
            }
        });
View Full Code Here

Examples of org.apache.metamodel.UpdateScript

        file.delete();
        assertFalse(file.exists());

        final CsvDataContext dc = new CsvDataContext(file, new CsvConfiguration(
                CsvConfiguration.DEFAULT_COLUMN_NAME_LINE, "UTF8", '|', '?', '!'));
        dc.executeUpdate(new UpdateScript() {
            @Override
            public void run(UpdateCallback cb) {
                Table table = cb.createTable(dc.getDefaultSchema(), "table").withColumn("id").withColumn("name")
                        .execute();
                cb.insertInto(table).value("id", 1).value("name", "Kasper").execute();
View Full Code Here

Examples of org.apache.metamodel.UpdateScript

    public void testCannotWriteToReadOnly() throws Exception {
        final CsvDataContext dc = new CsvDataContext(new FileInputStream("src/test/resources/empty_file.csv"),
                new CsvConfiguration());
        try {
            dc.executeUpdate(new UpdateScript() {
                @Override
                public void run(UpdateCallback cb) {
                    cb.createTable(dc.getDefaultSchema(), "foo");
                }
            });
View Full Code Here

Examples of org.apache.metamodel.UpdateScript

        _sourceTableName = sourceTableName;
    }

    public void copy() {
        final MongoDbDataContext targetDataContext = new MongoDbDataContext(_mongoDb);
        targetDataContext.executeUpdate(new UpdateScript() {

            @Override
            public void run(UpdateCallback callback) {
                final Table sourceTable = getSourceTable();
                final Table targetTable = callback.createTable(targetDataContext.getDefaultSchema(), _collectionName)
View Full Code Here

Examples of org.apache.metamodel.UpdateScript

        final File tempFile = FileHelper.createTempFile("metamodel_deletion", "csv");

        final CsvConfiguration configuration = _updateCallback.getConfiguration();

        final CsvDataContext copyDataContext = new CsvDataContext(tempFile, configuration);
        copyDataContext.executeUpdate(new UpdateScript() {

            @Override
            public void run(UpdateCallback callback) {
                final Table originalTable = getTable();
                final Table copyTable = callback.createTable(copyDataContext.getDefaultSchema(), originalTable.getName())
View Full Code Here

Examples of org.apache.metamodel.UpdateScript

                && _rowDeletionInterceptors.isEmpty()) {
            delegate.executeUpdate(update);
            return;
        }

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

Examples of org.apache.metamodel.UpdateScript

                + "Column[name=baz,columnNumber=3,type=INTEGER,nullable=null,nativeType=null,columnSize=null], "
                + "Column[name=foo,columnNumber=4,type=VARCHAR,nullable=null,nativeType=null,columnSize=null]]",
                Arrays.toString(table.getColumns()));

        // first delete the manually created database!
        dc.executeUpdate(new UpdateScript() {
            @Override
            public void run(UpdateCallback callback) {
                callback.dropTable(databaseName).execute();
            }
        });

        table = dc.getDefaultSchema().getTableByName(databaseName);
        assertNull(table);

        dc.executeUpdate(new UpdateScript() {
            @Override
            public void run(UpdateCallback callback) {
                Table table = callback.createTable(dc.getDefaultSchema(), databaseName).withColumn("foo")
                        .ofType(ColumnType.VARCHAR).withColumn("greeting").ofType(ColumnType.VARCHAR).execute();
                assertEquals("[_id, _rev, foo, greeting]", Arrays.toString(table.getColumnNames()));
            }
        });

        dc.executeUpdate(new UpdateScript() {
            @Override
            public void run(UpdateCallback callback) {
                callback.insertInto(databaseName).value("foo", "bar").value("greeting", "hello").execute();
                callback.insertInto(databaseName).value("foo", "baz").value("greeting", "hi").execute();
            }
        });

        DataSet ds = dc.query().from(databaseName).select("_id", "foo", "greeting").execute();
        assertTrue(ds.next());
        assertNotNull(ds.getRow().getValue(0));
        assertEquals("bar", ds.getRow().getValue(1));
        assertEquals("hello", ds.getRow().getValue(2));
        assertTrue(ds.next());
        assertNotNull(ds.getRow().getValue(0));
        assertEquals("baz", ds.getRow().getValue(1));
        assertEquals("hi", ds.getRow().getValue(2));
        assertFalse(ds.next());
        ds.close();

        dc.executeUpdate(new UpdateScript() {
            @Override
            public void run(UpdateCallback callback) {
                callback.update(databaseName).value("greeting", "howdy").where("foo").isEquals("baz").execute();

                callback.update(databaseName).value("foo", "foo").where("foo").isEquals("bar").execute();
View Full Code Here

Examples of org.apache.metamodel.UpdateScript

        assertTrue(ds.next());
        assertEquals(0, ((Number) ds.getRow().getValue(0)).intValue());
        assertFalse(ds.next());
        ds.close();

        dc.executeUpdate(new UpdateScript() {
            @Override
            public void run(UpdateCallback callback) {
                callback.insertInto(getDatabaseName()).value("name", "foo").value("gender", 'M').execute();
                callback.insertInto(getDatabaseName()).value("name", "bar").value("age", 32).execute();
            }
View Full Code Here

Examples of org.apache.metamodel.UpdateScript

    public void testCreateLikeExistingStructure() throws Exception {
        dc.createTable(schema, "foo").like(table).withColumn("bar").like(col).nullable(false).execute();
    }

    public void testCreateTableClass() throws Exception {
        UpdateScript ct = new CreateTable(schema, "table").withColumn("foo").ofType(ColumnType.VARCHAR)
                .withColumn("bar").withColumn("baz");
        assertNotNull(ct);
    }
View Full Code Here

Examples of org.apache.metamodel.UpdateScript

      public RowInsertionBuilder intercept(RowInsertionBuilder input) {
        return input.value("foobar", "elite!");
      }
    });

    dc.executeUpdate(new UpdateScript() {
      @Override
      public void run(UpdateCallback callback) {
        Table table = callback
            .createTable(dc.getDefaultSchema(), "table")
            .withColumn("col1").withColumn("col2").execute();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.