Search in sources :

Example 6 with Column

use of com.healthmarketscience.jackcess.Column in project pentaho-kettle by pentaho.

the class AccessOutputMeta method getLayout.

public static final RowMetaInterface getLayout(Table table) throws SQLException, KettleStepException {
    RowMetaInterface row = new RowMeta();
    List<Column> columns = table.getColumns();
    for (int i = 0; i < columns.size(); i++) {
        Column column = columns.get(i);
        int valtype = ValueMetaInterface.TYPE_STRING;
        int length = -1;
        int precision = -1;
        int type = column.getType().getSQLType();
        switch(type) {
            case java.sql.Types.CHAR:
            case java.sql.Types.VARCHAR:
            case // Character Large Object
            java.sql.Types.LONGVARCHAR:
                valtype = ValueMetaInterface.TYPE_STRING;
                length = column.getLength();
                break;
            case java.sql.Types.CLOB:
                valtype = ValueMetaInterface.TYPE_STRING;
                length = DatabaseMeta.CLOB_LENGTH;
                break;
            case java.sql.Types.BIGINT:
                valtype = ValueMetaInterface.TYPE_INTEGER;
                // Max 9.223.372.036.854.775.807
                precision = 0;
                length = 15;
                break;
            case java.sql.Types.INTEGER:
                valtype = ValueMetaInterface.TYPE_INTEGER;
                // Max 2.147.483.647
                precision = 0;
                length = 9;
                break;
            case java.sql.Types.SMALLINT:
                valtype = ValueMetaInterface.TYPE_INTEGER;
                // Max 32.767
                precision = 0;
                length = 4;
                break;
            case java.sql.Types.TINYINT:
                valtype = ValueMetaInterface.TYPE_INTEGER;
                // Max 127
                precision = 0;
                length = 2;
                break;
            case java.sql.Types.DECIMAL:
            case java.sql.Types.DOUBLE:
            case java.sql.Types.FLOAT:
            case java.sql.Types.REAL:
            case java.sql.Types.NUMERIC:
                valtype = ValueMetaInterface.TYPE_NUMBER;
                length = column.getLength();
                precision = column.getPrecision();
                if (length >= 126) {
                    length = -1;
                }
                if (precision >= 126) {
                    precision = -1;
                }
                if (type == java.sql.Types.DOUBLE || type == java.sql.Types.FLOAT || type == java.sql.Types.REAL) {
                    if (precision == 0) {
                        // precision is obviously incorrect if the type if Double/Float/Real
                        precision = -1;
                    }
                } else {
                    if (precision == 0 && length < 18 && length > 0) {
                        // Among others Oracle is affected here.
                        valtype = ValueMetaInterface.TYPE_INTEGER;
                    }
                }
                if (length > 18 || precision > 18) {
                    valtype = ValueMetaInterface.TYPE_BIGNUMBER;
                }
                break;
            case java.sql.Types.DATE:
            case java.sql.Types.TIME:
            case java.sql.Types.TIMESTAMP:
                valtype = ValueMetaInterface.TYPE_DATE;
                break;
            case java.sql.Types.BOOLEAN:
            case java.sql.Types.BIT:
                valtype = ValueMetaInterface.TYPE_BOOLEAN;
                break;
            case java.sql.Types.BINARY:
            case java.sql.Types.BLOB:
            case java.sql.Types.VARBINARY:
            case java.sql.Types.LONGVARBINARY:
                valtype = ValueMetaInterface.TYPE_BINARY;
                break;
            default:
                valtype = ValueMetaInterface.TYPE_STRING;
                length = column.getLength();
                break;
        }
        ValueMetaInterface v;
        try {
            v = ValueMetaFactory.createValueMeta(column.getName(), valtype);
        } catch (KettlePluginException e) {
            throw new KettleStepException(e);
        }
        v.setLength(length, precision);
        row.addValueMeta(v);
    }
    return row;
}
Also used : KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) RowMeta(org.pentaho.di.core.row.RowMeta) Column(com.healthmarketscience.jackcess.Column) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 7 with Column

use of com.healthmarketscience.jackcess.Column in project pentaho-kettle by pentaho.

the class AccessInputDialog method get.

private void get() {
    RowMetaInterface fields = new RowMeta();
    try {
        AccessInputMeta meta = new AccessInputMeta();
        getInfo(meta);
        // Check if a table name is specified
        if (!checkInputTableName(meta)) {
            return;
        }
        FileInputList inputList = meta.getFiles(transMeta);
        if (inputList.getFiles().size() > 0) {
            // Open the file (only first file)...
            Database d = Database.open(new File(AccessInputMeta.getFilename(inputList.getFile(0))), true);
            String realTableName = transMeta.environmentSubstitute(meta.getTableName());
            Table t = null;
            if (realTableName.startsWith(AccessInputMeta.PREFIX_SYSTEM)) {
                t = d.getSystemTable(realTableName);
            } else {
                t = d.getTable(realTableName);
            }
            // Get the list of columns
            List<Column> col = t.getColumns();
            int nr = col.size();
            for (int i = 0; i < nr; i++) {
                Column c = col.get(i);
                ValueMetaInterface field = AccessInputMeta.getValueMeta(c);
                if (field != null && fields.indexOfValue(field.getName()) < 0) {
                    fields.addValueMeta(field);
                }
            }
        }
    } catch (Exception e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "System.Dialog.Error.Title"), BaseMessages.getString(PKG, "AccessInputDialog.ErrorReadingFile.DialogMessage", e.toString()), e);
    }
    if (fields.size() > 0) {
        // Clear Fields Grid
        wFields.removeAll();
        for (int j = 0; j < fields.size(); j++) {
            ValueMetaInterface field = fields.getValueMeta(j);
            wFields.add(new String[] { field.getName(), field.getName(), field.getTypeDesc(), "", "-1", "", "", "", "", "none", "N" });
        }
        wFields.removeEmptyRows();
        wFields.setRowNums();
        wFields.optWidth(true);
    } else {
        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_WARNING);
        mb.setMessage(BaseMessages.getString(PKG, "AccessInputDialog.UnableToFindFields.DialogTitle"));
        mb.setText(BaseMessages.getString(PKG, "AccessInputDialog.UnableToFindFields.DialogMessage"));
        mb.open();
    }
}
Also used : Table(com.healthmarketscience.jackcess.Table) RowMeta(org.pentaho.di.core.row.RowMeta) AccessInputMeta(org.pentaho.di.trans.steps.accessinput.AccessInputMeta) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) KettleException(org.pentaho.di.core.exception.KettleException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) MessageBox(org.eclipse.swt.widgets.MessageBox) Column(com.healthmarketscience.jackcess.Column) Database(com.healthmarketscience.jackcess.Database) File(java.io.File) FileInputList(org.pentaho.di.core.fileinput.FileInputList)

Aggregations

Column (com.healthmarketscience.jackcess.Column)7 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)4 Table (com.healthmarketscience.jackcess.Table)3 ArrayList (java.util.ArrayList)2 RowMeta (org.pentaho.di.core.row.RowMeta)2 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)2 Database (com.healthmarketscience.jackcess.Database)1 PropertyMap (com.healthmarketscience.jackcess.PropertyMap)1 Row (com.healthmarketscience.jackcess.Row)1 Query (com.healthmarketscience.jackcess.query.Query)1 File (java.io.File)1 HashSet (java.util.HashSet)1 MessageBox (org.eclipse.swt.widgets.MessageBox)1 KettleException (org.pentaho.di.core.exception.KettleException)1 KettlePluginException (org.pentaho.di.core.exception.KettlePluginException)1 KettleStepException (org.pentaho.di.core.exception.KettleStepException)1 FileInputList (org.pentaho.di.core.fileinput.FileInputList)1 ValueMetaAndData (org.pentaho.di.core.row.ValueMetaAndData)1 AccessInputMeta (org.pentaho.di.trans.steps.accessinput.AccessInputMeta)1 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)1