Search in sources :

Example 16 with ValueMetaInteger

use of org.pentaho.di.core.row.value.ValueMetaInteger in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryConnectionDelegate method getStrings.

public String[] getStrings(String sql, ObjectId... objectId) throws KettleException {
    // Get the prepared statement
    // 
    PreparedStatement ps = getPreparedStatement(sql);
    // Assemble the parameters (if any)
    // 
    // Assemble the parameters (if any)
    // 
    RowMetaInterface parameterMeta = new RowMeta();
    Object[] parameterData = new Object[objectId.length];
    for (int i = 0; i < objectId.length; i++) {
        parameterMeta.addValueMeta(new ValueMetaInteger("id" + (i + 1)));
        parameterData[i] = ((LongObjectId) objectId[i]).longValue();
    }
    // 
    return callRead(new Callable<String[]>() {

        @Override
        public String[] call() throws Exception {
            ResultSet resultSet = database.openQuery(ps, parameterMeta, parameterData);
            List<Object[]> rows = database.getRows(resultSet, 0, null);
            if (Utils.isEmpty(rows)) {
                return new String[0];
            }
            // assemble the result
            // 
            RowMetaInterface rowMeta = database.getReturnRowMeta();
            String[] strings = new String[rows.size()];
            for (int i = 0; i < strings.length; i++) {
                Object[] row = rows.get(i);
                strings[i] = rowMeta.getString(row, 0);
            }
            return strings;
        }
    });
}
Also used : RowMeta(org.pentaho.di.core.row.RowMeta) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) SimpleLoggingObject(org.pentaho.di.core.logging.SimpleLoggingObject) RepositoryObject(org.pentaho.di.repository.RepositoryObject) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ArrayList(java.util.ArrayList) List(java.util.List) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) SQLException(java.sql.SQLException) KettleValueException(org.pentaho.di.core.exception.KettleValueException)

Example 17 with ValueMetaInteger

use of org.pentaho.di.core.row.value.ValueMetaInteger in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryConnectionDelegate method getOneRow.

/**
 * This method should be called WITH AN ALREADY QUOTED schema and table
 */
public RowMetaAndData getOneRow(String schemaAndTable, String keyfield, ObjectId id) throws KettleException {
    String sql = "SELECT * FROM " + schemaAndTable + " WHERE " + keyfield + " = ?";
    // Get the prepared statement
    // 
    PreparedStatement ps = getPreparedStatement(sql);
    // Assemble the parameter (if any)
    // 
    RowMetaInterface parameterMeta = new RowMeta();
    parameterMeta.addValueMeta(new ValueMetaInteger("id"));
    Object[] parameterData = new Object[] { id != null ? Long.parseLong(id.getId()) : null };
    try {
        return callRead(new Callable<RowMetaAndData>() {

            @Override
            public RowMetaAndData call() throws Exception {
                ResultSet resultSet = null;
                resultSet = database.openQuery(ps, parameterMeta, parameterData);
                Object[] result = database.getRow(resultSet);
                if (resultSet != null) {
                    database.closeQuery(resultSet);
                }
                if (result == null) {
                    return new RowMetaAndData(database.getReturnRowMeta(), RowDataUtil.allocateRowData(database.getReturnRowMeta().size()));
                }
                return new RowMetaAndData(database.getReturnRowMeta(), result);
            }
        });
    } catch (KettleException e) {
        throw e;
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) RowMeta(org.pentaho.di.core.row.RowMeta) PreparedStatement(java.sql.PreparedStatement) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) SQLException(java.sql.SQLException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) ResultSet(java.sql.ResultSet) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) SimpleLoggingObject(org.pentaho.di.core.logging.SimpleLoggingObject) RepositoryObject(org.pentaho.di.repository.RepositoryObject)

Example 18 with ValueMetaInteger

use of org.pentaho.di.core.row.value.ValueMetaInteger in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryConnectionDelegate method insertJobEntryAttribute.

public synchronized ObjectId insertJobEntryAttribute(ObjectId id_job, ObjectId id_jobentry, long nr, String code, double value_num, String value_str) throws KettleException {
    ObjectId id = getNextJobEntryAttributeID();
    RowMetaAndData table = new RowMetaAndData();
    // CHECKSTYLE:LineLength:OFF
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_ID_JOBENTRY_ATTRIBUTE), id);
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_ID_JOB), id_job);
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_ID_JOBENTRY), id_jobentry);
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_NR), new Long(nr));
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_CODE), code);
    table.addValue(new ValueMetaNumber(KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_VALUE_NUM), new Double(value_num));
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_VALUE_STR), value_str);
    database.prepareInsert(table.getRowMeta(), KettleDatabaseRepository.TABLE_R_JOBENTRY_ATTRIBUTE);
    database.setValuesInsert(table);
    database.insertRow();
    database.closeInsert();
    return id;
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) LongObjectId(org.pentaho.di.repository.LongObjectId) ObjectId(org.pentaho.di.repository.ObjectId) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger)

Example 19 with ValueMetaInteger

use of org.pentaho.di.core.row.value.ValueMetaInteger in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryConnectionDelegate method getIDWithValue.

public synchronized ObjectId getIDWithValue(String tablename, String idfield, String lookupfield, String value, String lookupkey, ObjectId key) throws KettleException {
    RowMetaAndData par = new RowMetaAndData();
    par.addValue(new ValueMetaString("value"), value);
    par.addValue(new ValueMetaInteger("key"), new LongObjectId(key));
    RowMetaAndData result = getOneRow("SELECT " + idfield + " FROM " + tablename + " WHERE " + lookupfield + " = ? AND " + lookupkey + " = ?", par.getRowMeta(), par.getData());
    if (result != null && result.getRowMeta() != null && result.getData() != null && result.isNumeric(0)) {
        return new LongObjectId(result.getInteger(0, 0));
    }
    return null;
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) LongObjectId(org.pentaho.di.repository.LongObjectId)

Example 20 with ValueMetaInteger

use of org.pentaho.di.core.row.value.ValueMetaInteger in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryConnectionDelegate method getJobEntryAttributeRow.

private RowMetaAndData getJobEntryAttributeRow(ObjectId id_jobentry, int nr, String code) throws KettleException {
    RowMetaAndData par = new RowMetaAndData();
    par.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_ID_JOBENTRY), id_jobentry);
    par.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_CODE), code);
    par.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_NR), new Long(nr));
    if (pstmt_entry_attributes == null) {
        setLookupJobEntryAttribute();
    }
    database.setValues(par.getRowMeta(), par.getData(), pstmt_entry_attributes);
    return callRead(new Callable<RowMetaAndData>() {

        @Override
        public RowMetaAndData call() throws Exception {
            Object[] lookup = database.getLookup(pstmt_entry_attributes);
            return new RowMetaAndData(database.getReturnRowMeta(), lookup);
        }
    });
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) SQLException(java.sql.SQLException) KettleValueException(org.pentaho.di.core.exception.KettleValueException)

Aggregations

ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)314 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)209 RowMeta (org.pentaho.di.core.row.RowMeta)146 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)137 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)113 Test (org.junit.Test)90 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)89 ValueMetaDate (org.pentaho.di.core.row.value.ValueMetaDate)64 ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)61 ValueMetaNumber (org.pentaho.di.core.row.value.ValueMetaNumber)57 KettleException (org.pentaho.di.core.exception.KettleException)41 LongObjectId (org.pentaho.di.repository.LongObjectId)38 ValueMetaBigNumber (org.pentaho.di.core.row.value.ValueMetaBigNumber)34 ObjectId (org.pentaho.di.repository.ObjectId)33 ArrayList (java.util.ArrayList)32 KettleStepException (org.pentaho.di.core.exception.KettleStepException)26 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)21 ValueMetaTimestamp (org.pentaho.di.core.row.value.ValueMetaTimestamp)20 ValueMetaBinary (org.pentaho.di.core.row.value.ValueMetaBinary)18 SQLException (java.sql.SQLException)17