Examples of JdbcDataContext


Examples of org.apache.metamodel.jdbc.JdbcDataContext

    public void testInsertFailureForStringValueForIntegerColumn() throws Exception {
        if (!isConfigured()) {
            return;
        }

        JdbcDataContext dc = new JdbcDataContext(getConnection());
        final Schema schema = dc.getDefaultSchema();
        try {
            dc.executeUpdate(new BatchUpdateScript() {
                @Override
                public void run(UpdateCallback cb) {
                    Table table = cb.createTable(schema, "my_table").withColumn("id").ofType(ColumnType.INTEGER)
                            .ofNativeType("SERIAL").nullable(false).withColumn("person name").ofSize(255)
                            .withColumn("age").ofType(ColumnType.INTEGER).execute();
                    assertEquals("[id, person name, age]", Arrays.toString(table.getColumnNames()));
                    assertEquals(
                            "Column[name=id,columnNumber=0,type=INTEGER,nullable=false,nativeType=serial,columnSize=10]",
                            table.getColumnByName("id").toString());
                    assertEquals(
                            "Column[name=person name,columnNumber=1,type=VARCHAR,nullable=true,nativeType=varchar,columnSize=255]",
                            table.getColumnByName("person name").toString());
                    assertEquals(
                            "Column[name=age,columnNumber=2,type=INTEGER,nullable=true,nativeType=int4,columnSize=10]",
                            table.getColumnByName("age").toString());

                    cb.insertInto(table).value("person name", "John Doe").value("age", "42").execute();
                }
            });

        } catch (Exception e) {
            String message = e.getMessage().replaceAll("\n", " ");
            assertEquals(
                    "Could not execute batch: INSERT INTO \"public\".\"my_table\" (\"person name\",age) VALUES ('John Doe','42'): Batch entry 0 INSERT INTO \"public\".\"my_table\" (\"person name\",age) VALUES ('John Doe','42') was aborted.  Call getNextException to see the cause.",
                    message);
        } finally {
            dc.refreshSchemas();
            if (dc.getTableByQualifiedLabel("my_table") != null) {
                dc.executeUpdate(new UpdateScript() {
                    @Override
                    public void run(UpdateCallback cb) {
                        cb.dropTable("my_table").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.