我有一个带有3个分布式dataSources的应用程序(com.atomikos.jdbc.AtomikosDataSourceBean).我正在使用Atomikos事务管理器作为JTA实现.每个dataSource都适用于PostgreSQL数据库.现在,我正在调用我对每个dataSource的查询,一切正常.
我想知道,如果有可能,使用JTA,并行调用我的查询(多线程,并发)?
我试过简单地使用jdbcTemplate(Spring)在新创建的线程中调用查询.首先,我遇到了一个春天问题.Spring将事务上下文存储在ThreadLocal字段中,因此在我的新线程中无法正确解析(Spring事务管理器和多线程)).我已经通过将相同的事务上下文设置为新创建的线程的ThreadLocal来解决了这个问题.但是我在Atomikos代码中面临同样的问题.它们还将CompositeTransactionImp存储在线程范围映射(BaseTrancationManager#getCurrentTx)中.但在Atomikos案例中,不可能为新线程设置值.所以我不能同时执行我的查询,因为似乎Atomikos不支持这种方法.但我也查看了JTA规范并发现了以下内容:"多个线程可能同时与同一个全局事务关联." ("3.2 TransactionManager接口",http://download.oracle.com/otndocs/jcp/jta-1.1-spec-oth-JSpec/?submit=Download)
问题:如何在一个全局事务的范围内使用JTA(2阶段提交)同时调用两个或多个查询到不同的dataSource?
在tomcat上下文中配置DataSources:
<Resource name="jdbc/db1" auth="Container" type="com.atomikos.jdbc.AtomikosDataSourceBean"
factory="com.company.package.AtomikosDataSourceBeanFactory"
xaDataSourceClassName="org.postgresql.xa.PGXADataSource"
xaProperties.serverName="localhost"
xaProperties.portNumber="5451"
xaProperties.databaseName="db1"
uniqueResourceName="jdbc/db1"
xaProperties.user="secretpassword"
xaProperties.password="secretpassword"
minPoolSize="5"
maxPoolSize="10"
testQuery="SELECT 1" />
<Resource name="jdbc/db2" auth="Container" type="com.atomikos.jdbc.AtomikosDataSourceBean"
factory="com.company.package.AtomikosDataSourceBeanFactory"
xaDataSourceClassName="org.postgresql.xa.PGXADataSource"
xaProperties.serverName="localhost"
xaProperties.portNumber="5451"
xaProperties.databaseName="db2"
uniqueResourceName="jdbc/db2"
xaProperties.user="secretpassword"
xaProperties.password="secretpassword"
minPoolSize="5"
maxPoolSize="10"
testQuery="SELECT 1" />
<Resource name="jdbc/db3" auth="Container" type="com.atomikos.jdbc.AtomikosDataSourceBean"
factory="com.company.package.AtomikosDataSourceBeanFactory"
xaDataSourceClassName="org.postgresql.xa.PGXADataSource"
xaProperties.serverName="localhost"
xaProperties.portNumber="5451"
xaProperties.databaseName="db3"
uniqueResourceName="jdbc/db3"
xaProperties.user="secretpassword"
xaProperties.password="secretpassword"
minPoolSize="5"
maxPoolSize="10"
testQuery="SELECT 1" />
Run Code Online (Sandbox Code Playgroud)
Spring环境中的事务管理器配置:
<bean id="transactionManager" class="com.atomikos.icatch.jta.UserTransactionManager"
init-method="init" destroy-method="close" lazy-init="true">
<property name="forceShutdown" value="false" />
</bean>
Run Code Online (Sandbox Code Playgroud)
码:
final SqlParameterSource parameters = …Run Code Online (Sandbox Code Playgroud) 我有一个CellTable,可以使用SingleSelectionModel进行单选,并在详细信息面板中显示一些信息.此外,我还将CheckBoxCell列添加到此CellTable中,该列与另一个MultipleSelectionModel一起进行批量删除操作.
当我尝试单击CheckBoxCell列中的复选框时,GWT选择行,然后在第二次单击复选框后更改复选框状态.所以我们应该点击两下,但我需要点击一下(更改复选框状态).
我尝试了不同的方法来解决它:
但它不起作用.
我在Internet上发现了类似的问题,但它们都使用一个MultipleSelectionModel.它与我想要的不一样,因为有详细的面板(所以我只做一次选择).
任何人都可以帮我弄清楚如何解决它?
UPD: 我刚刚删除了SingleSelectionModel并重新设计了UI以使用MultipleSelectionModel.这是GWT-hell ..
我有两个实体:
的resourcefile:
@Entity
@Table(name = "resource_file")
public class ResourceFile extends IdEntity<Integer> {
@Id
@SequenceGenerator(name = "resource_file_id_generator", sequenceName = "resource_file_id", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "resource_file_id_generator")
@Column(name = "id", unique = true, nullable = false)
@Nonnegative
private Integer id;
...
}
Run Code Online (Sandbox Code Playgroud)
FavoriteResourceFile:
@Entity
@Table(name = "favorite_resource_file")
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class FavoriteResourceFile extends IdEntity<FavoriteResourceFileId> {
@EmbeddedId
private FavoriteResourceFileId id;
@MapsId("resourceFileId")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "resource_file_id", nullable = false)
private ResourceFile resourceFile;
...
}
Run Code Online (Sandbox Code Playgroud)
我想进行以下查询"选择所有资源文件并按喜欢的资源文件的计数对它们进行排序".
在SQL中它看起来像:
select …Run Code Online (Sandbox Code Playgroud)