本文整理了Java中org.pentaho.di.core.database.Database.lockTables()
方法的一些代码示例,展示了Database.lockTables()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Database.lockTables()
方法的具体详情如下:
包路径:org.pentaho.di.core.database.Database
类名称:Database
方法名:lockTables
[英]Lock a tables in the database for write operations
[中]为写操作锁定数据库中的表
代码示例来源:origin: pentaho/pentaho-kettle
public synchronized void lockRepository() throws KettleException {
if ( database.getDatabaseMeta().needsToLockAllTables() ) {
database.lockTables( getQuotedSchemaTablenames( KettleDatabaseRepository.repositoryTableNames ) );
} else {
database
.lockTables( getQuotedSchemaTablenames( new String[] { KettleDatabaseRepository.TABLE_R_REPOSITORY_LOG, } ) );
}
}
代码示例来源:origin: pentaho/pentaho-kettle
@Override
public Long getNextBatchIdUsingLockTables( DatabaseMeta dbm, Database ldb, String schemaName, String tableName,
String fieldName ) throws KettleDatabaseException {
Long rtn = null;
// Make sure we lock that table to avoid concurrency issues
ldb.lockTables( new String[] { dbm.getQuotedSchemaTableCombination( schemaName, tableName ), } );
try {
rtn = ldb.getNextValue( null, schemaName, tableName, fieldName );
} finally {
ldb.unlockTables( new String[] { tableName, } );
}
return rtn;
}
代码示例来源:origin: pentaho/pentaho-kettle
public Long getNextBatchIdUsingLockTables( DatabaseMeta dbm, Database ldb, String schemaName, String tableName,
String fieldName ) throws KettleDatabaseException {
// The old way of doing things...
Long rtn = null;
// Make sure we lock that table to avoid concurrency issues
String schemaAndTable = dbm.getQuotedSchemaTableCombination( schemaName, tableName );
ldb.lockTables( new String[] { schemaAndTable, } );
try {
// Now insert value -1 to create a real write lock blocking the other
// requests.. FCFS
String sql = "INSERT INTO " + schemaAndTable + " (" + dbm.quoteField( fieldName ) + ") values (-1)";
ldb.execStatement( sql );
// Now this next lookup will stall on the other connections
//
rtn = ldb.getNextValue( null, schemaName, tableName, fieldName );
} finally {
// Remove the -1 record again...
String sql = "DELETE FROM " + schemaAndTable + " WHERE " + dbm.quoteField( fieldName ) + "= -1";
ldb.execStatement( sql );
ldb.unlockTables( new String[] { schemaAndTable, } );
}
return rtn;
}
内容来源于网络,如有侵权,请联系作者删除!