简体   繁体   English

使用toplink基本查询提示时指定查询超时

[英]specify query timeout when using toplink essential query hint

For glassfish v2, I have searched through the web and I cannot find anyway to specify query timeout when using TopLink essential query hint. 对于glassfish v2,我已经在网上搜索了,使用TopLink基本查询提示时,无论如何我都找不到指定查询超时的信息。 We have another option to migrate to EclipseLink but that is not feasible. 我们还有另一个选择可以迁移到EclipseLink,但这是不可行的。

have tried the solution in http://forums.oracle.com/forums/thread.jspa?threadID=974732&tstart=-1 but it seems the DatabaseQuery which one could set a timeout value is actually for Toplink, not TopLink essential. 已经在http://forums.oracle.com/forums/thread.jspa?threadID=974732&tstart=-1中尝试了该解决方案,但似乎可以设置超时值的DatabaseQuery实际上是对Toplink而言,而不是TopLink必不可少的。

Do we have some other way to instruct the JDBC driver for this timeout value other than the query hint? 除了查询提示以外,我们还有其他方法可以指示JDBC驱动程序获取此超时值吗? I need to do it on query-basis and not system-basis (which is just to change the value of DISTRIBUTED_LOCK_TIMEOUT) 我需要基于查询而不是基于系统(只是更改DISTRIBUTED_LOCK_TIMEOUT的值)

According to the documentation of Toplink JPA about Query Hints : 根据有关查询提示的Toplink JPA文档:

You can use the following TopLink JPA hints (for more details on these settings please refer to the TopLink documentation) 您可以使用以下TopLink JPA提示(有关这些设置的更多详细信息,请参阅TopLink文档)

  • fetchSize Takes an Integer. fetchSize取一个整数。 Allows the user to set the fetchSize of a TopLink query. 允许用户设置TopLink查询的fetchSize。
  • referenceClass Takes a class. referenceClass接受一个类。 Override the target class of the query. 覆盖查询的目标类。
  • cacheUsage Takes an Integer. cacheUsage取一个整数。 Describes how TopLink makes use of the cache for querying objects. 描述TopLink如何利用缓存来查询对象。
  • refresh Takes a Boolean. refresh需要一个布尔值。 Set to true if the cache should be refreshed from the database. 如果应从数据库刷新缓存,则设置为true。
  • lockMode Takes an Integer. lockMode取一个整数。 Set for Pessimistic Locking. 设置为悲观锁定。
  • expression Takes a TopLink Expression object. expression获取一个TopLink Expression对象。 Used for querying using TopLink API. 用于使用TopLink API进行查询。
  • timeout Takes an Integer. 超时接受一个整数。 Sets the the query timeout in milseconds. 设置查询超时(以毫秒为单位)。

So my understanding is that you should be able to do that: 因此,我的理解是您应该能够做到这一点:

Query queryEmployeesByFirstName = em.createNamedQuery("findAllEmployeesByFirstName");
queryEmployeesByFirstName.setHint("timeout", new Integer(5000));

Not tested though. 虽然没有测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM