Search in sources :

Example 1 with Column

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

the class AccessInput method convert.

private Object convert(Object obj, AccessInputField field, int index) throws Exception {
    // Get column
    Column c = data.t.getColumn(field.getColumn());
    // Find out field type
    ValueMetaAndData sourceValueMetaAndData = AccessInputMeta.getValueMetaAndData(c, field.getName(), obj);
    // DO CONVERSIONS...
    // 
    ValueMetaInterface targetValueMeta = data.outputRowMeta.getValueMeta(data.totalpreviousfields + index);
    return targetValueMeta.convertData(sourceValueMetaAndData.getValueMeta(), sourceValueMetaAndData.getValueData());
}
Also used : Column(com.healthmarketscience.jackcess.Column) ValueMetaAndData(org.pentaho.di.core.row.ValueMetaAndData) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 2 with Column

use of com.healthmarketscience.jackcess.Column in project tika by apache.

the class JackcessExtractor method parse.

public void parse(Database db, XHTMLContentHandler xhtml) throws IOException, SAXException, TikaException {
    String pw = db.getDatabasePassword();
    if (pw != null) {
        parentMetadata.set(JackcessParser.MDB_PW, pw);
    }
    PropertyMap dbp = db.getDatabaseProperties();
    for (PropertyMap.Property p : dbp) {
        parentMetadata.add(JackcessParser.MDB_PROPERTY_PREFIX + p.getName(), toString(p.getValue(), p.getType()));
    }
    PropertyMap up = db.getUserDefinedProperties();
    for (PropertyMap.Property p : up) {
        parentMetadata.add(JackcessParser.USER_DEFINED_PROPERTY_PREFIX + p.getName(), toString(p.getValue(), p.getType()));
    }
    Set<String> found = new HashSet<>();
    PropertyMap summaryProperties = db.getSummaryProperties();
    if (summaryProperties != null) {
        //try to get core properties
        PropertyMap.Property title = summaryProperties.get(TITLE_PROP_KEY);
        if (title != null) {
            parentMetadata.set(TikaCoreProperties.TITLE, toString(title.getValue(), title.getType()));
            found.add(title.getName());
        }
        PropertyMap.Property author = summaryProperties.get(AUTHOR_PROP_KEY);
        if (author != null && author.getValue() != null) {
            String authorString = toString(author.getValue(), author.getType());
            SummaryExtractor.addMulti(parentMetadata, TikaCoreProperties.CREATOR, authorString);
            found.add(author.getName());
        }
        PropertyMap.Property company = summaryProperties.get(COMPANY_PROP_KEY);
        if (company != null) {
            parentMetadata.set(OfficeOpenXMLExtended.COMPANY, toString(company.getValue(), company.getType()));
            found.add(company.getName());
        }
        for (PropertyMap.Property p : db.getSummaryProperties()) {
            if (!found.contains(p.getName())) {
                parentMetadata.add(JackcessParser.SUMMARY_PROPERTY_PREFIX + p.getName(), toString(p.getValue(), p.getType()));
            }
        }
    }
    Iterator<Table> it = db.newIterable().setIncludeLinkedTables(false).setIncludeSystemTables(false).iterator();
    while (it.hasNext()) {
        Table table = it.next();
        String tableName = table.getName();
        List<? extends Column> columns = table.getColumns();
        xhtml.startElement("table", "name", tableName);
        addHeaders(columns, xhtml);
        xhtml.startElement("tbody");
        Row r = table.getNextRow();
        while (r != null) {
            xhtml.startElement("tr");
            for (Column c : columns) {
                handleCell(r, c, xhtml);
            }
            xhtml.endElement("tr");
            r = table.getNextRow();
        }
        xhtml.endElement("tbody");
        xhtml.endElement("table");
    }
    for (Query q : db.getQueries()) {
        xhtml.startElement("div", "type", "sqlQuery");
        xhtml.characters(q.toSQLString());
        xhtml.endElement("div");
    }
}
Also used : PropertyMap(com.healthmarketscience.jackcess.PropertyMap) Table(com.healthmarketscience.jackcess.Table) Query(com.healthmarketscience.jackcess.query.Query) Column(com.healthmarketscience.jackcess.Column) Row(com.healthmarketscience.jackcess.Row) HashSet(java.util.HashSet)

Example 3 with Column

use of com.healthmarketscience.jackcess.Column in project tika by apache.

the class JackcessExtractor method addHeaders.

private void addHeaders(List<? extends Column> columns, XHTMLContentHandler xhtml) throws SAXException {
    xhtml.startElement("thead");
    xhtml.startElement("tr");
    for (Column c : columns) {
        xhtml.startElement("th");
        xhtml.characters(c.getName());
        xhtml.endElement("th");
    }
    xhtml.endElement("tr");
    xhtml.endElement("thead");
}
Also used : Column(com.healthmarketscience.jackcess.Column)

Example 4 with Column

use of com.healthmarketscience.jackcess.Column in project eol-globi-data by jhpoelen.

the class StudyImporterForADWTest method assertColumnNames.

private void assertColumnNames(List<String> expectedColumnNames, Table table) throws IOException {
    Table links = table;
    List<String> actualColumnNames = new ArrayList<String>();
    List<? extends Column> columns = links.getColumns();
    for (Column column : columns) {
        actualColumnNames.add(column.getName());
    }
    assertThat(actualColumnNames, is(expectedColumnNames));
}
Also used : Table(com.healthmarketscience.jackcess.Table) Column(com.healthmarketscience.jackcess.Column) ArrayList(java.util.ArrayList)

Example 5 with Column

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

the class AccessOutputMeta method getColumns.

public static final List<Column> getColumns(RowMetaInterface row) {
    List<Column> list = new ArrayList<Column>();
    for (int i = 0; i < row.size(); i++) {
        ValueMetaInterface value = row.getValueMeta(i);
        Column column = new Column();
        column.setName(value.getName());
        int length = value.getLength();
        switch(value.getType()) {
            case ValueMetaInterface.TYPE_INTEGER:
                if (length < 3) {
                    column.setType(DataType.BYTE);
                    length = DataType.BYTE.getFixedSize();
                } else {
                    if (length < 5) {
                        column.setType(DataType.INT);
                        length = DataType.INT.getFixedSize();
                    } else {
                        column.setType(DataType.LONG);
                        length = DataType.LONG.getFixedSize();
                    }
                }
                break;
            case ValueMetaInterface.TYPE_NUMBER:
                column.setType(DataType.DOUBLE);
                length = DataType.DOUBLE.getFixedSize();
                break;
            case ValueMetaInterface.TYPE_DATE:
                column.setType(DataType.SHORT_DATE_TIME);
                length = DataType.SHORT_DATE_TIME.getFixedSize();
                break;
            case ValueMetaInterface.TYPE_STRING:
                if (length < 255) {
                    column.setType(DataType.TEXT);
                    length *= DataType.TEXT.getUnitSize();
                } else {
                    column.setType(DataType.MEMO);
                    length *= DataType.MEMO.getUnitSize();
                }
                break;
            case ValueMetaInterface.TYPE_BINARY:
                column.setType(DataType.BINARY);
                break;
            case ValueMetaInterface.TYPE_BOOLEAN:
                column.setType(DataType.BOOLEAN);
                length = DataType.BOOLEAN.getFixedSize();
                break;
            case ValueMetaInterface.TYPE_BIGNUMBER:
                column.setType(DataType.NUMERIC);
                length = DataType.NUMERIC.getFixedSize();
                break;
            default:
                break;
        }
        if (length >= 0) {
            column.setLength((short) length);
        }
        if (value.getPrecision() >= 1 && value.getPrecision() <= 28) {
            column.setPrecision((byte) value.getPrecision());
        }
        list.add(column);
    }
    return list;
}
Also used : Column(com.healthmarketscience.jackcess.Column) ArrayList(java.util.ArrayList) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

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