Search in sources :

Example 1 with CsvTransformGeneratorException

use of org.pentaho.platform.dataaccess.datasource.wizard.models.CsvTransformGeneratorException in project data-access by pentaho.

the class CsvTransformGeneratorIT method testCreateTable.

public void testCreateTable() throws Exception {
    IPentahoSession session = new StandaloneSession("test");
    KettleSystemListener.environmentInit(session);
    DatabaseMeta dbMeta = getDatabaseMeta();
    ModelInfo info = createModel();
    CsvTransformGenerator gen = new CsvTransformGenerator(info, dbMeta);
    String tableName = info.getStageTableName();
    try {
        gen.execSqlStatement(getDropTableStatement(tableName), dbMeta, null);
    } catch (CsvTransformGeneratorException e) {
    // it is OK if the table doesn't exist previously
    }
    gen.createOrModifyTable(session);
    // check the results
    long rowCount = this.getRowCount(tableName);
    assertEquals((long) 0, rowCount);
}
Also used : ModelInfo(org.pentaho.platform.dataaccess.datasource.wizard.models.ModelInfo) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) CsvTransformGeneratorException(org.pentaho.platform.dataaccess.datasource.wizard.models.CsvTransformGeneratorException) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta)

Example 2 with CsvTransformGeneratorException

use of org.pentaho.platform.dataaccess.datasource.wizard.models.CsvTransformGeneratorException in project data-access by pentaho.

the class CsvTransformGeneratorIT method testLoadTable1.

public void testLoadTable1() throws Exception {
    IPentahoSession session = new StandaloneSession("test");
    KettleSystemListener.environmentInit(session);
    ModelInfo info = createModel();
    CsvTransformGenerator gen = new CsvTransformGenerator(info, getDatabaseMeta());
    // create the model
    String tableName = info.getStageTableName();
    try {
        gen.execSqlStatement(getDropTableStatement(tableName), getDatabaseMeta(), null);
    } catch (CsvTransformGeneratorException e) {
    // table might not be there yet, it is OK
    }
    // generate the database table
    gen.createOrModifyTable(session);
    // load the table
    loadTable(gen, info, true, session);
    // check the results
    long rowCount = this.getRowCount(tableName);
    assertEquals((long) 235, rowCount);
    DatabaseMeta databaseMeta = getDatabaseMeta();
    assertNotNull(databaseMeta);
    Database database = new Database(databaseMeta);
    assertNotNull(database);
    database.connect();
    Connection connection = null;
    Statement stmt = null;
    ResultSet sqlResult = null;
    try {
        connection = database.getConnection();
        assertNotNull(connection);
        stmt = database.getConnection().createStatement();
        // check the first row
        Date testDate = new Date();
        testDate.setDate(1);
        testDate.setHours(0);
        testDate.setMinutes(0);
        testDate.setMonth(0);
        testDate.setSeconds(0);
        testDate.setYear(110);
        boolean ok = stmt.execute("select * from " + tableName);
        assertTrue(ok);
        sqlResult = stmt.getResultSet();
        assertNotNull(sqlResult);
        ok = sqlResult.next();
        assertTrue(ok);
        // test the values
        assertEquals((long) 3, sqlResult.getLong(1));
        assertEquals(25677.96525, sqlResult.getDouble(2));
        assertEquals((long) 1231, sqlResult.getLong(3));
        assertEquals(testDate.getYear(), sqlResult.getDate(4).getYear());
        assertEquals(testDate.getMonth(), sqlResult.getDate(4).getMonth());
        assertEquals(testDate.getDate(), sqlResult.getDate(4).getDate());
        assertEquals(testDate.getHours(), sqlResult.getTime(4).getHours());
        // assertEquals( testDate.getMinutes(), ((Date)cells[3]).getMinutes() ); this fails, a bug in the PDI date
        // parsing?
        assertEquals(testDate.getSeconds(), sqlResult.getTime(4).getSeconds());
        // assertEquals( testDate, cells[3] );
        assertEquals("Afghanistan", sqlResult.getString(5));
        assertEquals((long) 11, sqlResult.getLong(6));
        assertEquals(111.9090909, sqlResult.getDouble(7));
        assertEquals(false, sqlResult.getBoolean(8));
    } finally {
        sqlResult.close();
        stmt.close();
        connection.close();
    }
}
Also used : ModelInfo(org.pentaho.platform.dataaccess.datasource.wizard.models.ModelInfo) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) CsvTransformGeneratorException(org.pentaho.platform.dataaccess.datasource.wizard.models.CsvTransformGeneratorException) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Statement(java.sql.Statement) Connection(java.sql.Connection) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) Date(java.util.Date) Database(org.pentaho.di.core.database.Database) ResultSet(java.sql.ResultSet)

Example 3 with CsvTransformGeneratorException

use of org.pentaho.platform.dataaccess.datasource.wizard.models.CsvTransformGeneratorException in project data-access by pentaho.

the class CsvTransformGeneratorIT method getCleanTransformGen.

private CsvTransformGenerator getCleanTransformGen() throws Exception {
    IPentahoSession session = new StandaloneSession("test");
    KettleSystemListener.environmentInit(session);
    // create the model
    ModelInfo info = createModel();
    CsvTransformGenerator gen = new CsvTransformGenerator(info, getDatabaseMeta());
    String tableName = info.getStageTableName();
    try {
        gen.execSqlStatement(getDropTableStatement(tableName), getDatabaseMeta(), null);
    } catch (CsvTransformGeneratorException e) {
    // table might not be there yet, it is OK
    }
    return gen;
}
Also used : ModelInfo(org.pentaho.platform.dataaccess.datasource.wizard.models.ModelInfo) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) CsvTransformGeneratorException(org.pentaho.platform.dataaccess.datasource.wizard.models.CsvTransformGeneratorException) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession)

Example 4 with CsvTransformGeneratorException

use of org.pentaho.platform.dataaccess.datasource.wizard.models.CsvTransformGeneratorException in project data-access by pentaho.

the class CsvTransformGeneratorIT method testDropExistingTable.

/**
 * Given a name of an existing table to drop.
 * <br/>
 * When StagingTransformGenerator is called to drop this table,
 * then it should execute drop statement.
 */
public void testDropExistingTable() throws Exception {
    IPentahoSession session = new StandaloneSession("test");
    KettleSystemListener.environmentInit(session);
    DatabaseMeta dbMeta = getDatabaseMeta();
    ModelInfo info = createModel();
    CsvTransformGenerator gen = new CsvTransformGenerator(info, dbMeta);
    String tableName = info.getStageTableName();
    try {
        gen.execSqlStatement(getDropTableStatement(tableName), dbMeta, null);
    } catch (CsvTransformGeneratorException e) {
    // it is OK if the table doesn't exist previously
    }
    gen.createOrModifyTable(session);
    // check the results
    long rowCount = this.getRowCount(tableName);
    assertEquals((long) 0, rowCount);
    // now make sure I can drop the table as well
    gen.dropTable(tableName);
    try {
        this.getRowCount(tableName);
        fail();
    } catch (Exception e) {
    // expect the table to not exist
    }
}
Also used : ModelInfo(org.pentaho.platform.dataaccess.datasource.wizard.models.ModelInfo) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) CsvTransformGeneratorException(org.pentaho.platform.dataaccess.datasource.wizard.models.CsvTransformGeneratorException) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) CsvTransformGeneratorException(org.pentaho.platform.dataaccess.datasource.wizard.models.CsvTransformGeneratorException)

Example 5 with CsvTransformGeneratorException

use of org.pentaho.platform.dataaccess.datasource.wizard.models.CsvTransformGeneratorException in project data-access by pentaho.

the class CsvTransformGeneratorIT method testCreateIndex.

public void testCreateIndex() throws Exception {
    IPentahoSession session = new StandaloneSession("test");
    KettleSystemListener.environmentInit(session);
    // create the model
    ModelInfo info = createModel();
    CsvTransformGenerator gen = new CsvTransformGenerator(info, getDatabaseMeta());
    String tableName = info.getStageTableName();
    try {
        gen.execSqlStatement(getDropTableStatement(tableName), getDatabaseMeta(), null);
    } catch (CsvTransformGeneratorException e) {
    // table might not be there yet, it is OK
    }
    // generate the database table
    gen.createOrModifyTable(session);
    // load the table
    loadTable(gen, info, true, session);
    // check the results
    long rowCount = this.getRowCount(tableName);
    assertEquals((long) 235, rowCount);
    int indexCount = gen.createIndices(session);
    assertEquals(5, indexCount);
}
Also used : ModelInfo(org.pentaho.platform.dataaccess.datasource.wizard.models.ModelInfo) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) CsvTransformGeneratorException(org.pentaho.platform.dataaccess.datasource.wizard.models.CsvTransformGeneratorException) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession)

Aggregations

CsvTransformGeneratorException (org.pentaho.platform.dataaccess.datasource.wizard.models.CsvTransformGeneratorException)17 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)9 ModelInfo (org.pentaho.platform.dataaccess.datasource.wizard.models.ModelInfo)9 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)8 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)4 KettleException (org.pentaho.di.core.exception.KettleException)4 Database (org.pentaho.di.core.database.Database)3 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)3 CsvTransformGenerator (org.pentaho.platform.dataaccess.datasource.wizard.service.agile.CsvTransformGenerator)3 XStream (com.thoughtworks.xstream.XStream)2 ArrayList (java.util.ArrayList)2 Trans (org.pentaho.di.trans.Trans)2 StepMeta (org.pentaho.di.trans.step.StepMeta)2 TableOutputMeta (org.pentaho.di.trans.steps.tableoutput.TableOutputMeta)2 Domain (org.pentaho.metadata.model.Domain)2 LogicalModel (org.pentaho.metadata.model.LogicalModel)2 DatasourceDTO (org.pentaho.platform.dataaccess.datasource.wizard.models.DatasourceDTO)2 DatasourceServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1