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

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

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

Database.lockTables介绍

[英]Lock a tables in the database for write operations
[中]为写操作锁定数据库中的表

代码示例

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

  1. public synchronized void lockRepository() throws KettleException {
  2. if ( database.getDatabaseMeta().needsToLockAllTables() ) {
  3. database.lockTables( getQuotedSchemaTablenames( KettleDatabaseRepository.repositoryTableNames ) );
  4. } else {
  5. database
  6. .lockTables( getQuotedSchemaTablenames( new String[] { KettleDatabaseRepository.TABLE_R_REPOSITORY_LOG, } ) );
  7. }
  8. }

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

  1. @Override
  2. public Long getNextBatchIdUsingLockTables( DatabaseMeta dbm, Database ldb, String schemaName, String tableName,
  3. String fieldName ) throws KettleDatabaseException {
  4. Long rtn = null;
  5. // Make sure we lock that table to avoid concurrency issues
  6. ldb.lockTables( new String[] { dbm.getQuotedSchemaTableCombination( schemaName, tableName ), } );
  7. try {
  8. rtn = ldb.getNextValue( null, schemaName, tableName, fieldName );
  9. } finally {
  10. ldb.unlockTables( new String[] { tableName, } );
  11. }
  12. return rtn;
  13. }

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

  1. public Long getNextBatchIdUsingLockTables( DatabaseMeta dbm, Database ldb, String schemaName, String tableName,
  2. String fieldName ) throws KettleDatabaseException {
  3. // The old way of doing things...
  4. Long rtn = null;
  5. // Make sure we lock that table to avoid concurrency issues
  6. String schemaAndTable = dbm.getQuotedSchemaTableCombination( schemaName, tableName );
  7. ldb.lockTables( new String[] { schemaAndTable, } );
  8. try {
  9. // Now insert value -1 to create a real write lock blocking the other
  10. // requests.. FCFS
  11. String sql = "INSERT INTO " + schemaAndTable + " (" + dbm.quoteField( fieldName ) + ") values (-1)";
  12. ldb.execStatement( sql );
  13. // Now this next lookup will stall on the other connections
  14. //
  15. rtn = ldb.getNextValue( null, schemaName, tableName, fieldName );
  16. } finally {
  17. // Remove the -1 record again...
  18. String sql = "DELETE FROM " + schemaAndTable + " WHERE " + dbm.quoteField( fieldName ) + "= -1";
  19. ldb.execStatement( sql );
  20. ldb.unlockTables( new String[] { schemaAndTable, } );
  21. }
  22. return rtn;
  23. }

相关文章