Search in sources :

Example 21 with ValueMetaInteger

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

the class KettleDatabaseRepositoryConnectionDelegate method getTransAttributesWithPrefix.

public synchronized List<Object[]> getTransAttributesWithPrefix(ObjectId id_transformation, String codePrefix) throws KettleException {
    String sql = "SELECT *" + " FROM " + databaseMeta.getQuotedSchemaTableCombination(null, KettleDatabaseRepository.TABLE_R_TRANS_ATTRIBUTE) + " WHERE " + quote(KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_ID_TRANSFORMATION) + " = ?" + " AND " + quote(KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_CODE) + " LIKE '" + codePrefix + "%'";
    RowMetaAndData table = new RowMetaAndData();
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_ID_TRANSFORMATION), new LongObjectId(id_transformation));
    return callRead(() -> database.getRows(sql, table.getRowMeta(), table.getData(), ResultSet.FETCH_FORWARD, false, 0, null));
}
Also used : RowMetaAndData(org.pentaho.di.core.RowMetaAndData) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) LongObjectId(org.pentaho.di.repository.LongObjectId)

Example 22 with ValueMetaInteger

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

the class KettleDatabaseRepositoryConnectionDelegate method getIDs.

public ObjectId[] getIDs(String sql, ObjectId... objectId) throws KettleException {
    // Get the prepared statement
    // 
    PreparedStatement ps = getPreparedStatement(sql);
    // 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<ObjectId[]>() {

        @Override
        public ObjectId[] call() throws Exception {
            ResultSet resultSet = database.openQuery(ps, parameterMeta, parameterData);
            List<Object[]> rows = database.getRows(resultSet, 0, null);
            if (Utils.isEmpty(rows)) {
                return new ObjectId[0];
            }
            RowMetaInterface rowMeta = database.getReturnRowMeta();
            ObjectId[] ids = new ObjectId[rows.size()];
            for (int i = 0; i < ids.length; i++) {
                Object[] row = rows.get(i);
                ids[i] = new LongObjectId(rowMeta.getInteger(row, 0));
            }
            return ids;
        }
    });
}
Also used : RowMeta(org.pentaho.di.core.row.RowMeta) PreparedStatement(java.sql.PreparedStatement) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) LongObjectId(org.pentaho.di.repository.LongObjectId) 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) ResultSet(java.sql.ResultSet) 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)

Example 23 with ValueMetaInteger

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

the class KettleDatabaseRepositoryConnectionDelegate method getTransAttributes.

public synchronized List<Object[]> getTransAttributes(ObjectId id_transformation, String code, long nr) throws KettleException {
    String sql = "SELECT *" + " FROM " + databaseMeta.getQuotedSchemaTableCombination(null, KettleDatabaseRepository.TABLE_R_TRANS_ATTRIBUTE) + " WHERE " + quote(KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_ID_TRANSFORMATION) + " = ? AND " + quote(KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_CODE) + " = ? AND " + quote(KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_NR) + " = ?" + " ORDER BY " + quote(KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_VALUE_NUM);
    RowMetaAndData table = new RowMetaAndData();
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_ID_TRANSFORMATION), new LongObjectId(id_transformation));
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_CODE), code);
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_NR), new Long(nr));
    return callRead(() -> database.getRows(sql, table.getRowMeta(), table.getData(), ResultSet.FETCH_FORWARD, false, 0, 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) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) LongObjectId(org.pentaho.di.repository.LongObjectId)

Example 24 with ValueMetaInteger

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

the class KettleDatabaseRepositoryCreationHelper method updateJobEntryTypes.

/**
 * Update the list in R_JOBENTRY_TYPE
 *
 * @param create
 *
 * @exception KettleException
 *              if something went wrong during the update.
 */
public void updateJobEntryTypes(List<String> statements, boolean dryrun, boolean create) throws KettleException {
    synchronized (repository) {
        // We should only do an update if something has changed...
        PluginRegistry registry = PluginRegistry.getInstance();
        List<PluginInterface> jobPlugins = registry.getPlugins(JobEntryPluginType.class);
        for (int i = 0; i < jobPlugins.size(); i++) {
            PluginInterface jobPlugin = jobPlugins.get(i);
            String type_desc = jobPlugin.getIds()[0];
            String type_desc_long = jobPlugin.getName();
            ObjectId id = null;
            if (!create) {
                id = repository.jobEntryDelegate.getJobEntryTypeID(type_desc);
            }
            if (id == null) {
                // Not found, we need to add this one...
                // We need to add this one ...
                id = new LongObjectId(i + 1);
                if (!create) {
                    id = repository.connectionDelegate.getNextJobEntryTypeID();
                }
                RowMetaAndData table = new RowMetaAndData();
                table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_JOBENTRY_TYPE_ID_JOBENTRY_TYPE), id);
                table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_JOBENTRY_TYPE_CODE), type_desc);
                table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_JOBENTRY_TYPE_DESCRIPTION), type_desc_long);
                if (dryrun) {
                    String sql = database.getSQLOutput(null, KettleDatabaseRepository.TABLE_R_JOBENTRY_TYPE, table.getRowMeta(), table.getData(), null);
                    statements.add(sql);
                } else {
                    database.prepareInsert(table.getRowMeta(), null, KettleDatabaseRepository.TABLE_R_JOBENTRY_TYPE);
                    database.setValuesInsert(table);
                    database.insertRow();
                    database.closeInsert();
                }
            }
        }
    }
}
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) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) PluginInterface(org.pentaho.di.core.plugins.PluginInterface) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) LongObjectId(org.pentaho.di.repository.LongObjectId)

Example 25 with ValueMetaInteger

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

the class KettleDatabaseRepositoryCreationHelper method updateDatabaseTypes.

/**
 * Update the list in R_DATABASE_TYPE using the database plugin entries
 *
 * @throws KettleException
 *           if the update didn't go as planned.
 */
public List<String> updateDatabaseTypes(List<String> statements, boolean dryrun, boolean create) throws KettleException {
    synchronized (repository) {
        // We should only do an update if something has changed...
        // 
        List<PluginInterface> plugins = pluginRegistry.getPlugins(DatabasePluginType.class);
        for (int i = 0; i < plugins.size(); i++) {
            PluginInterface plugin = plugins.get(i);
            ObjectId id = null;
            if (!create) {
                id = repository.databaseDelegate.getDatabaseTypeID(plugin.getIds()[0]);
            }
            if (id == null) {
                // Not found, we need to add this one...
                // We need to add this one ...
                id = new LongObjectId(i + 1);
                if (!create) {
                    id = repository.connectionDelegate.getNextDatabaseTypeID();
                }
                RowMetaAndData table = new RowMetaAndData();
                table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_DATABASE_TYPE_ID_DATABASE_TYPE), id);
                table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_DATABASE_TYPE_CODE), plugin.getIds()[0]);
                table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_DATABASE_TYPE_DESCRIPTION), plugin.getName());
                if (dryrun) {
                    String sql = database.getSQLOutput(null, KettleDatabaseRepository.TABLE_R_DATABASE_TYPE, table.getRowMeta(), table.getData(), null);
                    statements.add(sql);
                } else {
                    database.prepareInsert(table.getRowMeta(), null, KettleDatabaseRepository.TABLE_R_DATABASE_TYPE);
                    database.setValuesInsert(table);
                    database.insertRow();
                    database.closeInsert();
                }
            }
        }
    }
    return statements;
}
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) PluginInterface(org.pentaho.di.core.plugins.PluginInterface) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) LongObjectId(org.pentaho.di.repository.LongObjectId) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString)

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