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

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

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

Database.getRows介绍

[英]Reads the result of an SQL query into an ArrayList
[中]将SQL查询的结果读入ArrayList

代码示例

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

  1. /**
  2. * Reads the result of an SQL query into an ArrayList
  3. *
  4. * @param sql The SQL to launch
  5. * @param limit <=0 means unlimited, otherwise this specifies the maximum number of rows read.
  6. * @return An ArrayList of rows.
  7. * @throws KettleDatabaseException if something goes wrong.
  8. */
  9. public List<Object[]> getRows( String sql, int limit ) throws KettleDatabaseException {
  10. return getRows( sql, limit, null );
  11. }

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

  1. /**
  2. * Reads the result of an SQL query into an ArrayList
  3. *
  4. * @param sql The SQL to launch
  5. * @param limit <=0 means unlimited, otherwise this specifies the maximum number of rows read.
  6. * @param monitor The progress monitor to update while getting the rows.
  7. * @return An ArrayList of rows.
  8. * @throws KettleDatabaseException if something goes wrong.
  9. */
  10. public List<Object[]> getRows( String sql, int limit, ProgressMonitorListener monitor )
  11. throws KettleDatabaseException {
  12. return getRows( sql, null, null, ResultSet.FETCH_FORWARD, false, limit, monitor );
  13. }

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

  1. public List<Object[]> getRows( String sql, int limit ) throws KettleDatabaseException {
  2. return callRead( () -> database.getRows( sql, limit ) );
  3. }

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

  1. public Map<String, LongObjectId> getValueToIdMap( String tablename, String idfield, String lookupfield )
  2. throws KettleException {
  3. String sql = new StringBuilder( "SELECT " ).append( lookupfield ).append( ", " ).append( idfield )
  4. .append( " FROM " ).append( tablename ).toString();
  5. Map<String, LongObjectId> result = new HashMap<String, LongObjectId>();
  6. for ( Object[] row : callRead(
  7. () -> database.getRows( sql, new RowMeta(), new Object[] {}, ResultSet.FETCH_FORWARD, false, -1, null ) ) ) {
  8. result.put( String.valueOf( row[ 0 ] ), new LongObjectId( ( (Number) row[ 1 ] ).longValue() ) );
  9. }
  10. return result;
  11. }

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

  1. /**
  2. * Return all sequence names from connection
  3. *
  4. * @return The sequences name list.
  5. * @throws KettleDatabaseException
  6. */
  7. public String[] getSequences() throws KettleDatabaseException {
  8. if ( databaseMeta.supportsSequences() ) {
  9. String sql = databaseMeta.getSQLListOfSequences();
  10. if ( sql != null ) {
  11. List<Object[]> seqs = getRows( sql, 0 );
  12. String[] str = new String[ seqs.size() ];
  13. for ( int i = 0; i < seqs.size(); i++ ) {
  14. str[ i ] = seqs.get( i )[ 0 ].toString();
  15. }
  16. return str;
  17. }
  18. } else {
  19. throw new KettleDatabaseException( "Sequences are only available for Oracle databases." );
  20. }
  21. return null;
  22. }

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

  1. /**
  2. * Reads the result of an SQL query into an ArrayList.
  3. *
  4. * @param sql The SQL to launch
  5. * @param params The types of any parameters to be passed to the query
  6. * @param data The values of any parameters to be passed to the query
  7. * @param fetch_mode The fetch mode for the query (ResultSet.FETCH_FORWARD, e.g.)
  8. * @param lazyConversion Whether to perform lazy conversion of the values
  9. * @param limit <=0 means unlimited, otherwise this specifies the maximum number of rows read.
  10. * @param monitor The progress monitor to update while getting the rows.
  11. * @return An ArrayList of rows.
  12. * @throws KettleDatabaseException if something goes wrong.
  13. */
  14. public List<Object[]> getRows( String sql, RowMetaInterface params, Object[] data, int fetch_mode,
  15. boolean lazyConversion, int limit, ProgressMonitorListener monitor )
  16. throws KettleDatabaseException {
  17. if ( monitor != null ) {
  18. monitor.setTaskName( "Opening query..." );
  19. }
  20. ResultSet rset = openQuery( sql, params, data, fetch_mode, lazyConversion );
  21. return getRows( rset, limit, monitor );
  22. }

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

  1. @Override public String[] call() throws Exception {
  2. ResultSet resultSet = database.openQuery( ps, parameterMeta, parameterData );
  3. List<Object[]> rows = database.getRows( resultSet, 0, null );
  4. if ( Utils.isEmpty( rows ) ) {
  5. return new String[ 0 ];
  6. }
  7. // assemble the result
  8. //
  9. RowMetaInterface rowMeta = database.getReturnRowMeta();
  10. String[] strings = new String[ rows.size() ];
  11. for ( int i = 0; i < strings.length; i++ ) {
  12. Object[] row = rows.get( i );
  13. strings[ i ] = rowMeta.getString( row, 0 );
  14. }
  15. return strings;
  16. }
  17. } );

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

  1. @Override public ObjectId[] call() throws Exception {
  2. ResultSet resultSet = database.openQuery( ps, parameterMeta, parameterData );
  3. List<Object[]> rows = database.getRows( resultSet, 0, null );
  4. if ( Utils.isEmpty( rows ) ) {
  5. return new ObjectId[ 0 ];
  6. }
  7. RowMetaInterface rowMeta = database.getReturnRowMeta();
  8. ObjectId[] ids = new ObjectId[ rows.size() ];
  9. for ( int i = 0; i < ids.length; i++ ) {
  10. Object[] row = rows.get( i );
  11. ids[ i ] = new LongObjectId( rowMeta.getInteger( row, 0 ) );
  12. }
  13. return ids;
  14. }
  15. } );

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

  1. public LongObjectId[] getIDsWithValues( String tablename, String idfield, String lookupfield,
  2. String[] values ) throws KettleException {
  3. String sql = createIdsWithValuesQuery( tablename, idfield, lookupfield, values.length );
  4. RowMeta params = new RowMeta();
  5. for ( int i = 0; i < values.length; i++ ) {
  6. ValueMetaInterface value = new ValueMetaString( Integer.toString( i ) );
  7. params.addValueMeta( value );
  8. }
  9. List<Object[]> rows =
  10. callRead( () -> database.getRows( sql, params, values, ResultSet.FETCH_FORWARD, false, -1, null ) );
  11. LongObjectId[] result = new LongObjectId[ rows.size() ];
  12. int i = 0;
  13. for ( Object[] row : rows ) {
  14. result[ i++ ] = new LongObjectId( ( (Number) row[ 0 ] ).longValue() );
  15. }
  16. return result;
  17. }

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

  1. private Database mockDatabase() throws KettleDatabaseException {
  2. Database databaseMock = mock( Database.class );
  3. RowMeta databaseRowMeta = new RowMeta();
  4. databaseRowMeta.addValueMeta( new ValueMetaString( "id" ) );
  5. databaseRowMeta.addValueMeta( new ValueMetaString( "value" ) );
  6. doReturn( databaseRowMeta ).when( databaseMock ).getTableFields( anyString() );
  7. doReturn( databaseRowMeta ).when( databaseMock ).getTableFieldsMeta( anyString(), anyString() );
  8. doReturn( Arrays.asList( new Object[][] { { "1", "value" } } ) ).when( databaseMock ).getRows( anyString(),
  9. anyInt() );
  10. doReturn( databaseRowMeta ).when( databaseMock ).getReturnRowMeta();
  11. return databaseMock;
  12. }

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

  1. @Test
  2. public void testGetValueToIdMap() throws KettleException {
  3. String tablename = "test-tablename";
  4. String idfield = "test-idfield";
  5. String lookupfield = "test-lookupfield";
  6. List<Object[]> rows = new ArrayList<Object[]>();
  7. int id = 1234;
  8. LongObjectId longObjectId = new LongObjectId( id );
  9. rows.add( new Object[] { lookupfield, id } );
  10. when( database.getRows( eq( "SELECT " + lookupfield + ", " + idfield + " FROM " + tablename ), any(
  11. RowMetaInterface.class ),
  12. eq( new Object[] {} ), eq( ResultSet.FETCH_FORWARD ),
  13. eq( false ), eq( -1 ), eq( (ProgressMonitorListener) null ) ) ).thenReturn( rows );
  14. Map<String, LongObjectId> valueToIdMap =
  15. kettleDatabaseRepositoryConnectionDelegate.getValueToIdMap( tablename, idfield, lookupfield );
  16. assertEquals( 1, valueToIdMap.size() );
  17. assertEquals( longObjectId, valueToIdMap.get( lookupfield ) );
  18. }
  19. }

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

  1. @Override public Collection<RowMetaAndData> call() throws Exception {
  2. ResultSet resultSet = null;
  3. try {
  4. resultSet = database.openQuery( ps, parameterMeta, parameterData );
  5. List<Object[]> rows = database.getRows( resultSet, 0, null );
  6. for ( Object[] row : rows ) {
  7. RowMetaAndData rowWithMeta = new RowMetaAndData( database.getReturnRowMeta(), row );
  8. long id =
  9. rowWithMeta.getInteger(
  10. quote( KettleDatabaseRepository.FIELD_DATABASE_ATTRIBUTE_ID_DATABASE_ATTRIBUTE ), 0 );
  11. if ( id > 0 ) {
  12. attrs.add( rowWithMeta );
  13. }
  14. }
  15. return attrs;
  16. } catch ( KettleDatabaseException e ) {
  17. throw e;
  18. } finally {
  19. database.closeQuery( resultSet );
  20. }
  21. }
  22. } );

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

  1. @Override public List<RepositoryElementMetaInterface> call() throws Exception {
  2. List<RepositoryElementMetaInterface> repositoryObjects = new ArrayList<RepositoryElementMetaInterface>();
  3. ResultSet rs = database.openQuery( sql, directoryIdRow.getRowMeta(), directoryIdRow.getData() );
  4. if ( rs != null ) {
  5. List<Object[]> rows = database.getRows( rs, -1, null );
  6. if ( rs != null ) {
  7. database.closeQuery( rs );
  8. }
  9. RowMetaInterface rowMeta = database.getReturnRowMeta();
  10. for ( Object[] r : rows ) {
  11. ObjectId id = new LongObjectId( rowMeta.getInteger( r, 4 ) );
  12. repositoryObjects.add( new RepositoryObject( id, rowMeta.getString( r, 0 ), repositoryDirectory, rowMeta
  13. .getString( r, 1 ), rowMeta.getDate( r, 2 ), objectType, rowMeta.getString( r, 3 ), false ) );
  14. }
  15. }
  16. return repositoryObjects;
  17. }
  18. } );

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

  1. private DatabaseLookupData getCreatedData( boolean allEquals ) throws Exception {
  2. Database db = mock( Database.class );
  3. when( db.getRows( anyString(), anyInt() ) )
  4. .thenReturn( Collections.singletonList( new Object[] { 1L } ) );
  5. RowMeta returnRowMeta = new RowMeta();
  6. returnRowMeta.addValueMeta( new ValueMetaInteger() );
  7. when( db.getReturnRowMeta() ).thenReturn( returnRowMeta );
  8. DatabaseLookupMeta meta = createTestMeta();
  9. DatabaseLookupData data = new DatabaseLookupData();
  10. DatabaseLookup step = createSpiedStep( db, mockHelper, meta );
  11. step.init( meta, data );
  12. data.db = db;
  13. data.keytypes = new int[] { ValueMetaInterface.TYPE_INTEGER };
  14. if ( allEquals ) {
  15. data.allEquals = true;
  16. data.conditions = new int[] { DatabaseLookupMeta.CONDITION_EQ };
  17. } else {
  18. data.allEquals = false;
  19. data.conditions = new int[] { DatabaseLookupMeta.CONDITION_LT };
  20. }
  21. step.processRow( meta, data );
  22. return data;
  23. }

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

  1. public synchronized List<Object[]> getJobAttributesWithPrefix( ObjectId jobId, String codePrefix )
  2. throws KettleException {
  3. String sql =
  4. "SELECT *"
  5. + " FROM "
  6. + databaseMeta.getQuotedSchemaTableCombination( null, KettleDatabaseRepository.TABLE_R_JOB_ATTRIBUTE )
  7. + " WHERE " + quote( KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_ID_JOB ) + " = ?" + " AND "
  8. + quote( KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_CODE ) + " LIKE '" + codePrefix + "%'";
  9. RowMetaAndData table = new RowMetaAndData();
  10. table.addValue(
  11. new ValueMetaInteger( KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_ID_JOB ),
  12. new LongObjectId( jobId ) );
  13. return callRead(
  14. () -> database.getRows( sql, table.getRowMeta(), table.getData(), ResultSet.FETCH_FORWARD, false, 0, null ) );
  15. }

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

  1. public synchronized List<Object[]> getTransAttributesWithPrefix( ObjectId id_transformation, String codePrefix )
  2. throws KettleException {
  3. String sql =
  4. "SELECT *"
  5. + " FROM "
  6. + databaseMeta
  7. .getQuotedSchemaTableCombination( null, KettleDatabaseRepository.TABLE_R_TRANS_ATTRIBUTE )
  8. + " WHERE " + quote( KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_ID_TRANSFORMATION ) + " = ?"
  9. + " AND " + quote( KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_CODE ) + " LIKE '" + codePrefix
  10. + "%'";
  11. RowMetaAndData table = new RowMetaAndData();
  12. table.addValue(
  13. new ValueMetaInteger(
  14. KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_ID_TRANSFORMATION ),
  15. new LongObjectId( id_transformation ) );
  16. return callRead(
  17. () -> database.getRows( sql, table.getRowMeta(), table.getData(), ResultSet.FETCH_FORWARD, false, 0, null ) );
  18. }

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

  1. public synchronized List<Object[]> getJobAttributes( ObjectId id_job, String code, long nr ) throws KettleException {
  2. String sql =
  3. "SELECT *"
  4. + " FROM "
  5. + databaseMeta.getQuotedSchemaTableCombination( null, KettleDatabaseRepository.TABLE_R_JOB_ATTRIBUTE )
  6. + " WHERE " + quote( KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_ID_JOB ) + " = ? AND "
  7. + quote( KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_CODE ) + " = ? AND "
  8. + quote( KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_NR ) + " = ?" + " ORDER BY "
  9. + quote( KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_VALUE_NUM );
  10. RowMetaAndData table = new RowMetaAndData();
  11. table.addValue( new ValueMetaInteger(
  12. KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_ID_JOB ), id_job );
  13. table.addValue( new ValueMetaString(
  14. KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_CODE ), code );
  15. table.addValue( new ValueMetaInteger(
  16. KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_NR ), new Long( nr ) );
  17. return callRead(
  18. () -> database.getRows( sql, table.getRowMeta(), table.getData(), ResultSet.FETCH_FORWARD, false, 0, null ) );
  19. }

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

  1. public synchronized List<Object[]> getTransAttributes( ObjectId id_transformation, String code, long nr )
  2. throws KettleException {
  3. String sql =
  4. "SELECT *"
  5. + " FROM "
  6. + databaseMeta
  7. .getQuotedSchemaTableCombination( null, KettleDatabaseRepository.TABLE_R_TRANS_ATTRIBUTE )
  8. + " WHERE " + quote( KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_ID_TRANSFORMATION ) + " = ? AND "
  9. + quote( KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_CODE ) + " = ? AND "
  10. + quote( KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_NR ) + " = ?" + " ORDER BY "
  11. + quote( KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_VALUE_NUM );
  12. RowMetaAndData table = new RowMetaAndData();
  13. table.addValue(
  14. new ValueMetaInteger(
  15. KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_ID_TRANSFORMATION ),
  16. new LongObjectId( id_transformation ) );
  17. table.addValue( new ValueMetaString(
  18. KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_CODE ), code );
  19. table.addValue( new ValueMetaInteger(
  20. KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_NR ), new Long( nr ) );
  21. return callRead(
  22. () -> database.getRows( sql, table.getRowMeta(), table.getData(), ResultSet.FETCH_FORWARD, false, 0, null ) );
  23. }

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

  1. public synchronized void fillStepAttributesBuffer( ObjectId id_transformation ) throws KettleException {
  2. String sql =
  3. "SELECT "
  4. + quote( KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_ID_STEP ) + ", "
  5. + quote( KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_CODE ) + ", "
  6. + quote( KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_NR ) + ", "
  7. + quote( KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_VALUE_NUM ) + ", "
  8. + quote( KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_VALUE_STR ) + " " + "FROM "
  9. + databaseMeta.getQuotedSchemaTableCombination( null, KettleDatabaseRepository.TABLE_R_STEP_ATTRIBUTE )
  10. + " " + "WHERE " + quote( KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_ID_TRANSFORMATION ) + " = ? "
  11. + "ORDER BY " + quote( KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_ID_STEP ) + ", "
  12. + quote( KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_CODE ) + ", "
  13. + quote( KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_NR );
  14. PreparedStatement ps = getPreparedStatement( sql );
  15. RowMetaAndData parameter = getParameterMetaData( id_transformation );
  16. stepAttributesBuffer = callRead(
  17. () -> database.getRows( database.openQuery( ps, parameter.getRowMeta(), parameter.getData() ), -1, null ) );
  18. stepAttributesRowMeta = database.getReturnRowMeta();
  19. // must use java-based sort to ensure compatibility with binary search
  20. // database ordering may or may not be case-insensitive
  21. // in case db sort does not match our sort
  22. //
  23. Collections.sort( stepAttributesBuffer, new StepAttributeComparator() ); //
  24. }

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

  1. public synchronized List<Object[]> getJobEntryAttributesWithPrefix( ObjectId jobId, ObjectId jobEntryId,
  2. String codePrefix ) throws KettleException {
  3. String sql =
  4. "SELECT *"
  5. + " FROM "
  6. + databaseMeta.getQuotedSchemaTableCombination(
  7. null, KettleDatabaseRepository.TABLE_R_JOBENTRY_ATTRIBUTE ) + " WHERE "
  8. + quote( KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_ID_JOB ) + " = ?" + " AND "
  9. + quote( KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_ID_JOBENTRY ) + " = ?" + " AND "
  10. + quote( KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_CODE ) + " LIKE '" + codePrefix + "%'";
  11. RowMetaAndData table = new RowMetaAndData();
  12. table
  13. .addValue(
  14. new ValueMetaInteger(
  15. KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_ID_JOB ),
  16. new LongObjectId( jobId ) );
  17. table.addValue(
  18. new ValueMetaInteger(
  19. KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_ID_JOBENTRY ),
  20. new LongObjectId( jobEntryId ) );
  21. return callRead(
  22. () -> database.getRows( sql, table.getRowMeta(), table.getData(), ResultSet.FETCH_FORWARD, false, 0, null ) );
  23. }

相关文章