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

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

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

Database.prepareSQL介绍

[英]Prepare a statement to be executed on the database. (does not return generated keys)
[中]准备要在数据库上执行的语句。(不返回生成的密钥)

代码示例

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

  1. /**
  2. * Prepare a statement to be executed on the database. (does not return generated keys)
  3. *
  4. * @param sql The SQL to be prepared
  5. * @return The PreparedStatement object.
  6. * @throws KettleDatabaseException
  7. */
  8. public PreparedStatement prepareSQL( String sql ) throws KettleDatabaseException {
  9. return prepareSQL( sql, false );
  10. }

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

  1. private PreparedStatement getPreparedStatement( String sql ) throws KettleDatabaseException {
  2. PreparedStatement ps = sqlMap.get( sql );
  3. if ( ps == null ) {
  4. ps = database.prepareSQL( sql );
  5. sqlMap.putIfAbsent( sql, ps );
  6. }
  7. return ps;
  8. }

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

  1. public synchronized void setLookupJobAttribute() throws KettleException {
  2. String sql =
  3. "SELECT "
  4. + quote( KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_VALUE_STR ) + ", "
  5. + quote( KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_VALUE_NUM ) + " 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 ) + " = ? AND "
  9. + KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_NR + " = ? ";
  10. psJobAttributesLookup = database.prepareSQL( sql );
  11. }

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

  1. public synchronized void setLookupTransAttribute() throws KettleException {
  2. String sql =
  3. "SELECT "
  4. + quote( KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_VALUE_STR )
  5. + ", "
  6. + quote( KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_VALUE_NUM )
  7. + " FROM "
  8. + databaseMeta
  9. .getQuotedSchemaTableCombination( null, KettleDatabaseRepository.TABLE_R_TRANS_ATTRIBUTE )
  10. + " WHERE " + quote( KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_ID_TRANSFORMATION ) + " = ? AND "
  11. + quote( KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_CODE ) + " = ? AND "
  12. + KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_NR + " = ? ";
  13. psTransAttributesLookup = database.prepareSQL( sql );
  14. }

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

  1. public synchronized void setLookupStepAttribute() throws KettleException {
  2. String sql =
  3. "SELECT "
  4. + quote( KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_VALUE_STR ) + ", "
  5. + quote( KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_VALUE_NUM ) + " FROM "
  6. + databaseMeta.getQuotedSchemaTableCombination( null, KettleDatabaseRepository.TABLE_R_STEP_ATTRIBUTE )
  7. + " WHERE " + quote( KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_ID_STEP ) + " = ? AND "
  8. + quote( KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_CODE ) + " = ? AND "
  9. + quote( KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_NR ) + " = ? ";
  10. psStepAttributesLookup = database.prepareSQL( sql );
  11. }

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

  1. /**
  2. * Prepare inserting values into a table, using the fields & values in a Row
  3. *
  4. * @param rowMeta The metadata row to determine which values need to be inserted
  5. * @param schemaName The name of the schema in which we want to insert rows
  6. * @param tableName The name of the table in which we want to insert rows
  7. * @throws KettleDatabaseException if something went wrong.
  8. */
  9. public void prepareInsert( RowMetaInterface rowMeta, String schemaName, String tableName )
  10. throws KettleDatabaseException {
  11. if ( rowMeta.size() == 0 ) {
  12. throw new KettleDatabaseException( "No fields in row, can't insert!" );
  13. }
  14. String ins = getInsertStatement( schemaName, tableName, rowMeta );
  15. if ( log.isDetailed() ) {
  16. log.logDetailed( "Preparing statement: " + Const.CR + ins );
  17. }
  18. prepStatementInsert = prepareSQL( ins );
  19. }

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

  1. public synchronized void setLookupJobEntryAttribute() throws KettleException {
  2. String sql =
  3. "SELECT "
  4. + quote( KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_VALUE_STR )
  5. + ", "
  6. + quote( KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_VALUE_NUM )
  7. + " FROM "
  8. + databaseMeta.getQuotedSchemaTableCombination(
  9. null, KettleDatabaseRepository.TABLE_R_JOBENTRY_ATTRIBUTE ) + " WHERE "
  10. + quote( KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_ID_JOBENTRY ) + " = ? AND "
  11. + quote( KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_CODE ) + " = ? AND "
  12. + quote( KettleDatabaseRepository.FIELD_JOBENTRY_ATTRIBUTE_NR ) + " = ? ";
  13. pstmt_entry_attributes = database.prepareSQL( sql );
  14. }

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

  1. public Long getNextBatchIdUsingAutoIncSQL( String autoIncSQL, DatabaseMeta dbm, Database ldb ) throws KettleDatabaseException {
  2. Long rtn = null;
  3. PreparedStatement stmt = ldb.prepareSQL( autoIncSQL, true );
  4. try {
  5. stmt.executeUpdate();
  6. RowMetaAndData rmad = ldb.getGeneratedKeys( stmt );
  7. if ( rmad.getRowMeta().size() > 0 ) {
  8. rtn = rmad.getRowMeta().getInteger( rmad.getData(), 0 );
  9. } else {
  10. throw new KettleDatabaseException( "Unable to retrieve value of auto-generated technical key : "
  11. + "no value found!" );
  12. }
  13. } catch ( KettleValueException kve ) {
  14. throw new KettleDatabaseException( kve );
  15. } catch ( SQLException sqlex ) {
  16. throw new KettleDatabaseException( sqlex );
  17. } finally {
  18. try {
  19. stmt.close();
  20. } catch ( SQLException ignored ) {
  21. // Ignored
  22. }
  23. }
  24. return rtn;
  25. }

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

  1. PreparedStatement ps = data.db.prepareSQL( sql );

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

  1. public synchronized ObjectId insertTransAttribute( ObjectId id_transformation, long nr, String code,
  2. long value_num, String value_str ) throws KettleException {
  3. ObjectId id = getNextTransAttributeID();
  4. RowMetaAndData table = new RowMetaAndData();
  5. table.addValue( new ValueMetaInteger( KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_ID_TRANS_ATTRIBUTE ), id );
  6. table.addValue( new ValueMetaInteger( KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_ID_TRANSFORMATION ),
  7. id_transformation );
  8. table.addValue( new ValueMetaInteger( KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_NR ), new Long( nr ) );
  9. table.addValue( new ValueMetaString( KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_CODE ), code );
  10. table.addValue( new ValueMetaInteger( KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_VALUE_NUM ),
  11. new Long( value_num ) );
  12. table.addValue( new ValueMetaString( KettleDatabaseRepository.FIELD_TRANS_ATTRIBUTE_VALUE_STR ), value_str );
  13. /*
  14. * If we have prepared the insert, we don't do it again. We asume that all the step insert statements come one after
  15. * the other.
  16. */
  17. if ( psTransAttributesInsert == null ) {
  18. String sql =
  19. database.getInsertStatement( KettleDatabaseRepository.TABLE_R_TRANS_ATTRIBUTE, table.getRowMeta() );
  20. psTransAttributesInsert = database.prepareSQL( sql );
  21. }
  22. database.setValues( table, psTransAttributesInsert );
  23. database.insertRow( psTransAttributesInsert, useBatchProcessing );
  24. if ( log.isDebug() ) {
  25. log.logDebug( "saved transformation attribute [" + code + "]" );
  26. }
  27. return id;
  28. }

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

  1. public synchronized ObjectId insertJobAttribute( ObjectId id_job, long nr, String code, long value_num,
  2. String value_str ) throws KettleException {
  3. ObjectId id = getNextJobAttributeID();
  4. // System.out.println("Insert job attribute : id_job="+id_job+", code="+code+", value_str="+value_str);
  5. RowMetaAndData table = new RowMetaAndData();
  6. table.addValue( new ValueMetaInteger( KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_ID_JOB_ATTRIBUTE ), id );
  7. table.addValue( new ValueMetaInteger( KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_ID_JOB ), id_job );
  8. table.addValue( new ValueMetaInteger( KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_NR ), new Long( nr ) );
  9. table.addValue( new ValueMetaString( KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_CODE ), code );
  10. table.addValue( new ValueMetaInteger( KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_VALUE_NUM ),
  11. new Long( value_num ) );
  12. table.addValue( new ValueMetaString( KettleDatabaseRepository.FIELD_JOB_ATTRIBUTE_VALUE_STR ), value_str );
  13. /*
  14. * If we have prepared the insert, we don't do it again. We asume that all the step insert statements come one after
  15. * the other.
  16. */
  17. if ( psJobAttributesInsert == null ) {
  18. String sql =
  19. database.getInsertStatement( KettleDatabaseRepository.TABLE_R_JOB_ATTRIBUTE, table.getRowMeta() );
  20. psJobAttributesInsert = database.prepareSQL( sql );
  21. }
  22. database.setValues( table, psJobAttributesInsert );
  23. database.insertRow( psJobAttributesInsert, useBatchProcessing );
  24. if ( log.isDebug() ) {
  25. log.logDebug( "saved job attribute [" + code + "]" );
  26. }
  27. return id;
  28. }

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

  1. public synchronized ObjectId insertStepAttribute( ObjectId id_transformation, ObjectId id_step, long nr,
  2. String code, double value_num, String value_str )
  3. throws KettleException {
  4. ObjectId id = getNextStepAttributeID();
  5. RowMetaAndData table = new RowMetaAndData();
  6. table.addValue( new ValueMetaInteger( KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_ID_STEP_ATTRIBUTE ), id );
  7. table.addValue( new ValueMetaInteger( KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_ID_TRANSFORMATION ),
  8. id_transformation );
  9. table.addValue( new ValueMetaInteger( KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_ID_STEP ), id_step );
  10. table.addValue( new ValueMetaInteger( KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_NR ), new Long( nr ) );
  11. table.addValue( new ValueMetaString( KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_CODE ), code );
  12. table.addValue( new ValueMetaNumber( KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_VALUE_NUM ),
  13. new Double( value_num ) );
  14. table.addValue( new ValueMetaString( KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_VALUE_STR ), value_str );
  15. /*
  16. * If we have prepared the insert, we don't do it again. We assume that all the step insert statements come one
  17. * after the other.
  18. */
  19. if ( psStepAttributesInsert == null ) {
  20. String sql =
  21. database.getInsertStatement( KettleDatabaseRepository.TABLE_R_STEP_ATTRIBUTE, table.getRowMeta() );
  22. psStepAttributesInsert = database.prepareSQL( sql );
  23. }
  24. database.setValues( table, psStepAttributesInsert );
  25. database.insertRow( psStepAttributesInsert, useBatchProcessing );
  26. if ( log.isDebug() ) {
  27. log.logDebug( "saved attribute [" + code + "]" );
  28. }
  29. return id;
  30. }

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

  1. data.insertStatement = data.db.prepareSQL( sql );
  2. data.preparedStatements.put( data.realSchemaTable + "insert", data.insertStatement );
  3. data.lookupStatement = data.db.prepareSQL( sql );
  4. data.preparedStatements.put( data.realSchemaTable + "lookup", data.lookupStatement );
  5. String sql = getUpdateStatement( data.inputRowMeta );
  6. data.updateStatement = data.db.prepareSQL( sql );
  7. data.preparedStatements.put( data.realSchemaTable + "update", data.updateStatement );
  8. if ( log.isDebug() ) {
  9. data.deleteStatement = data.db.prepareSQL( sql );
  10. data.preparedStatements.put( data.realSchemaTable + "delete", data.deleteStatement );
  11. if ( log.isDebug() ) {

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

  1. logDetailed( "Prepared statement : " + sql );
  2. insertStatement = data.db.prepareSQL( sql, meta.isReturningGeneratedKeys() );
  3. data.preparedStatements.put( tableName, insertStatement );

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

  1. PreparedStatement ps = db.prepareSQL( FILEBulkFile );
  2. ps.execute();

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

  1. data.lookupStatement = data.db.prepareSQL( sql );
  2. data.preparedStatements.put( data.realSchemaTable + "lookup", data.lookupStatement );
  3. data.insertStatement = data.db.prepareSQL( sql );
  4. data.preparedStatements.put( data.realSchemaTable + "insert", data.insertStatement );
  5. String sql = getUpdateStatement( data.inputRowMeta );
  6. data.updateStatement = data.db.prepareSQL( sql );
  7. data.preparedStatements.put( data.realSchemaTable + "update", data.updateStatement );
  8. if ( log.isDebug() ) {
  9. String sql = getDeleteStatement( data.inputRowMeta );
  10. data.deleteStatement = data.db.prepareSQL( sql );
  11. data.preparedStatements.put( data.realSchemaTable + "delete", data.deleteStatement );
  12. if ( log.isDebug() ) {

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

  1. data.pstmt = data.db.prepareSQL( sql );
  2. if ( log.isDebug() ) {
  3. logDebug( BaseMessages.getString( PKG, "DatabaseJoin.Log.SQLStatement", sql ) );

相关文章