org.pentaho.di.core.database.Database.getOneRow()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(10.0k)|赞(0)|评价(0)|浏览(148)

本文整理了Java中org.pentaho.di.core.database.Database.getOneRow()方法的一些代码示例,展示了Database.getOneRow()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Database.getOneRow()方法的具体详情如下:
包路径:org.pentaho.di.core.database.Database
类名称:Database
方法名:getOneRow

Database.getOneRow介绍

[英]Execute a query and return at most one row from the resultset
[中]执行查询并从结果集中最多返回一行

代码示例

代码示例来源:origin: pentaho/pentaho-kettle

  1. public RowMetaAndData getOneRow( String sql, RowMetaInterface rowMeta, Object[] rowData )
  2. throws KettleDatabaseException {
  3. return callRead( () -> database.getOneRow( sql, rowMeta, rowData ) );
  4. }

代码示例来源:origin: pentaho/pentaho-kettle

  1. public RowMetaAndData getOneRow( String sql ) throws KettleDatabaseException {
  2. return callRead( () -> database.getOneRow( sql ) );
  3. }

代码示例来源:origin: pentaho/pentaho-kettle

  1. public void run( IProgressMonitor monitor ) throws InvocationTargetException, InterruptedException {
  2. db = new Database( Spoon.loggingObject, dbMeta );
  3. try {
  4. db.connect();
  5. String sql = dbMeta.getDatabaseInterface().getSelectCountStatement( tableName );
  6. RowMetaAndData row = db.getOneRow( sql );
  7. size = row.getRowMeta().getInteger( row.getData(), 0 );
  8. if ( monitor.isCanceled() ) {
  9. throw new InvocationTargetException( new Exception( "This operation was cancelled!" ) );
  10. }
  11. } catch ( KettleException e ) {
  12. throw new InvocationTargetException( e, "Couldn't get a result because of an error :" + e.toString() );
  13. } finally {
  14. db.disconnect();
  15. }
  16. }
  17. };

代码示例来源:origin: pentaho/pentaho-kettle

  1. getOneRow( "SELECT MAX(" + databaseMeta.quoteField( val_key ) + ") FROM " + schemaTable );
  2. if ( rmad != null ) {
  3. long previous;

代码示例来源:origin: pentaho/pentaho-kettle

  1. /**
  2. * See if the column specified exists by reading
  3. *
  4. * @param columnname The name of the column to check.
  5. * @param tablename The name of the table to check.<br> This is supposed to be the properly quoted name of the table
  6. * or the complete schema-table name combination.
  7. * @return true if the table exists, false if it doesn't.
  8. * @deprecated Deprecated in favor of the smarter {@link #checkColumnExists(String, String, String)}
  9. */
  10. public boolean checkColumnExists( String columnname, String tablename ) throws KettleDatabaseException {
  11. try {
  12. if ( log.isDebug() ) {
  13. log.logDebug( "Checking if column [" + columnname + "] exists in table [" + tablename + "] !" );
  14. }
  15. // Just try to read from the table.
  16. String sql = databaseMeta.getSQLColumnExists( columnname, tablename );
  17. try {
  18. getOneRow( sql );
  19. return true;
  20. } catch ( KettleDatabaseException e ) {
  21. return false;
  22. }
  23. } catch ( Exception e ) {
  24. throw new KettleDatabaseException( "Unable to check if column ["
  25. + columnname + "] exists in table [" + tablename + "] on connection [" + databaseMeta.getName() + "]", e );
  26. }
  27. }

代码示例来源:origin: pentaho/pentaho-kettle

  1. private synchronized LongObjectId getNextTableID( String tablename, String idfield ) throws KettleException {
  2. LongObjectId retval = null;
  3. RowMetaAndData r = callRead( () -> database.getOneRow( "SELECT MAX(" + idfield + ") FROM " + tablename ) );
  4. if ( r != null ) {
  5. Long id = r.getInteger( 0 );
  6. if ( id == null ) {
  7. if ( log.isDebug() ) {
  8. log.logDebug( "no max(" + idfield + ") found in table " + tablename );
  9. }
  10. retval = new LongObjectId( 1 );
  11. } else {
  12. if ( log.isDebug() ) {
  13. log.logDebug( "max(" + idfield + ") found in table " + tablename + " --> " + idfield + " number: " + id );
  14. }
  15. retval = new LongObjectId( id.longValue() + 1L );
  16. }
  17. }
  18. return retval;
  19. }

代码示例来源:origin: pentaho/pentaho-kettle

  1. /**
  2. * See if the table specified exists by reading
  3. *
  4. * @param tablename
  5. * The name of the table to check.<br>
  6. * This is supposed to be the properly quoted name of the table or the complete schema-table name
  7. * combination.
  8. * @return true if the table exists, false if it doesn't.
  9. * @deprecated Deprecated in favor of {@link #checkTableExists(String, String)}
  10. */
  11. public boolean checkTableExists( String tablename ) throws KettleDatabaseException {
  12. try {
  13. if ( log.isDebug() ) {
  14. log.logDebug( "Checking if table [" + tablename + "] exists!" );
  15. }
  16. // Just try to read from the table.
  17. String sql = databaseMeta.getSQLTableExists( tablename );
  18. try {
  19. getOneRow( sql );
  20. return true;
  21. } catch ( KettleDatabaseException e ) {
  22. return false;
  23. }
  24. } catch ( Exception e ) {
  25. throw new KettleDatabaseException( "Unable to check if table [" + tablename + "] exists on connection [" + databaseMeta.getName() + "]", e );
  26. }
  27. }

代码示例来源:origin: pentaho/pentaho-kettle

  1. RowMetaAndData row = db.getOneRow( countStatement );
  2. if ( row != null ) {
  3. rowsCount = row.getInteger( 0 );

代码示例来源:origin: pentaho/pentaho-kettle

  1. public synchronized int countNrJobAttributes( ObjectId id_job, String code ) throws KettleException {
  2. String sql =
  3. "SELECT COUNT(*) FROM "
  4. + databaseMeta.getQuotedSchemaTableCombination( null, KettleDatabaseRepository.TABLE_R_JOB_ATTRIBUTE )
  5. + " WHERE " + quote( KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_ID_JOB ) + " = ? AND "
  6. + quote( KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_CODE ) + " = ?";
  7. RowMetaAndData table = new RowMetaAndData();
  8. table.addValue( new ValueMetaInteger(
  9. KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_ID_JOB ), id_job );
  10. table.addValue( new ValueMetaString(
  11. KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_CODE ), code );
  12. RowMetaAndData r = callRead( () -> database.getOneRow( sql, table.getRowMeta(), table.getData() ) );
  13. if ( r == null || r.getData() == null ) {
  14. return 0;
  15. }
  16. return (int) r.getInteger( 0, 0L );
  17. }

代码示例来源:origin: pentaho/pentaho-kettle

  1. "SELECT count(*) FROM "
  2. + data.schemaTable + " WHERE " + databaseMeta.quoteField( meta.getKeyField() ) + " = " + start_tk;
  3. RowMetaAndData r = data.db.getOneRow( sql );
  4. Long count = r.getRowMeta().getInteger( r.getData(), 0 );
  5. if ( count.longValue() != 0 ) {
  6. "SELECT count(*) FROM "
  7. + data.schemaTable + " WHERE " + databaseMeta.quoteField( meta.getKeyField() ) + " = " + start_tk;
  8. RowMetaAndData r = data.db.getOneRow( sql );
  9. Long count = r.getRowMeta().getInteger( r.getData(), 0 );
  10. if ( count.longValue() == 0 ) {

代码示例来源:origin: pentaho/pentaho-kettle

  1. RowMetaAndData param = new RowMetaAndData();
  2. param.addValue( seqField, ValueMetaInterface.TYPE_STRING, name );
  3. RowMetaAndData row = db.getOneRow( sql, param.getRowMeta(), param.getData() );
  4. long value;
  5. if ( row != null && row.getData() != null ) {

代码示例来源:origin: pentaho/pentaho-kettle

  1. public synchronized int countNrTransAttributes( ObjectId id_transformation, String code ) throws KettleException {
  2. String sql =
  3. "SELECT COUNT(*) FROM "
  4. + databaseMeta
  5. .getQuotedSchemaTableCombination( null, KettleDatabaseRepository.TABLE_R_TRANS_ATTRIBUTE )
  6. + " WHERE " + quote( KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_ID_TRANSFORMATION ) + " = ? AND "
  7. + quote( KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_CODE ) + " = ?";
  8. RowMetaAndData table = new RowMetaAndData();
  9. table.addValue(
  10. new ValueMetaInteger(
  11. KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_ID_TRANSFORMATION ),
  12. id_transformation );
  13. table.addValue( new ValueMetaString(
  14. KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_CODE ), code );
  15. RowMetaAndData r = callRead( () -> database.getOneRow( sql, table.getRowMeta(), table.getData() ) );
  16. if ( r == null || r.getData() == null ) {
  17. return 0;
  18. }
  19. return (int) r.getInteger( 0, 0L );
  20. }

代码示例来源:origin: pentaho/pentaho-kettle

  1. public synchronized int countNrJobEntryAttributes( ObjectId id_jobentry, String code ) throws KettleException {
  2. String sql =
  3. "SELECT COUNT(*) FROM "
  4. + databaseMeta.getQuotedSchemaTableCombination(
  5. null, KettleDatabaseRepository.TABLE_R_JOBENTRY_ATTRIBUTE ) + " WHERE "
  6. + quote( KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_ID_JOBENTRY ) + " = ? AND "
  7. + quote( KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_CODE ) + " = ?";
  8. RowMetaAndData table = new RowMetaAndData();
  9. table.addValue(
  10. new ValueMetaInteger(
  11. KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_ID_JOBENTRY ),
  12. id_jobentry );
  13. table.addValue( new ValueMetaString(
  14. KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_CODE ), code );
  15. RowMetaAndData r = callRead( () -> database.getOneRow( sql, table.getRowMeta(), table.getData() ) );
  16. if ( r == null || r.getData() == null ) {
  17. return 0;
  18. }
  19. return (int) r.getInteger( 0, 0L );
  20. }

代码示例来源:origin: pentaho/pentaho-kettle

  1. sql += " ORDER BY " + dbMeta.quoteField( logTable.getLogDateField().getFieldName() ) + " DESC";
  2. RowMetaAndData oneRow = database.getOneRow( sql );
  3. String status = oneRow.getString( 0, "?" );
  4. Date date = oneRow.getDate( 1, null );

代码示例来源:origin: pentaho/pentaho-kettle

  1. public synchronized int countNrStepAttributes( ObjectId id_step, String code ) throws KettleException {
  2. if ( stepAttributesBuffer != null ) {
  3. // see if we can do this in memory...
  4. int nr = searchNrStepAttributes( id_step, code );
  5. return nr;
  6. } else {
  7. String sql =
  8. "SELECT COUNT(*) FROM "
  9. + databaseMeta.getQuotedSchemaTableCombination(
  10. null, KettleDatabaseRepository.TABLE_R_STEP_ATTRIBUTE ) + " WHERE "
  11. + quote( KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_ID_STEP ) + " = ? AND "
  12. + quote( KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_CODE ) + " = ?";
  13. RowMetaAndData table = new RowMetaAndData();
  14. table.addValue( new ValueMetaInteger(
  15. KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_ID_STEP ), id_step );
  16. table.addValue( new ValueMetaString(
  17. KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_CODE ), code );
  18. RowMetaAndData r = callRead( () -> database.getOneRow( sql, table.getRowMeta(), table.getData() ) );
  19. if ( r == null || r.getData() == null ) {
  20. return 0;
  21. }
  22. return (int) r.getInteger( 0, 0L );
  23. }
  24. }

代码示例来源:origin: pentaho/pentaho-kettle

  1. try {
  2. lastUpgrade = callRead( () ->
  3. database.getOneRow( "SELECT "
  4. + quote( KettleDatabaseRepository.FIELD_VERSION_MAJOR_VERSION ) + ", "
  5. + quote( KettleDatabaseRepository.FIELD_VERSION_MINOR_VERSION ) + ", "
  6. callRead( () -> database.getOneRow( "SELECT * FROM " + userTable ) );

代码示例来源:origin: pentaho/pentaho-kettle

  1. RowMetaAndData row = db.getOneRow( countSQLStatement );
  2. if ( row != null ) {
  3. rowsCount = row.getInteger( 0 );

代码示例来源:origin: pentaho/pentaho-kettle

  1. RowMetaAndData r1 = maxdb.getOneRow( sql );
  2. if ( r1 != null ) {
  3. RowMetaAndData r1 = depdb.getOneRow( sql );
  4. if ( r1 != null ) {

代码示例来源:origin: pentaho/pentaho-kettle

  1. if ( upgrade ) {
  2. lookup =
  3. database.getOneRow( "SELECT "
  4. + repository.quote( KettleDatabaseRepository.FIELD_DATABASE_CONTYPE_ID_DATABASE_CONTYPE )
  5. + " FROM " + schemaTable + " WHERE "
  6. if ( upgrade ) {
  7. lookup =
  8. database.getOneRow( "SELECT "
  9. + repository.quote( KettleDatabaseRepository.FIELD_LOGLEVEL_ID_LOGLEVEL ) + " FROM "
  10. + schemaTable + " WHERE " + database.getDatabaseMeta().quoteField( "CODE" ) + " = '" + code[i]
  11. if ( upgrade ) {
  12. lookup =
  13. database.getOneRow( "SELECT "
  14. + repository.quote( KettleDatabaseRepository.FIELD_USER_ID_USER ) + " FROM " + schemaTable
  15. + " WHERE " + repository.quote( KettleDatabaseRepository.FIELD_USER_LOGIN ) + " = '" + user[i]

相关文章