Hi,
I was sitting the whole night on this problem, and still couldnt solve it.
In my application i have a table set up with JPAContainer. I need to update this table at least every half minute. The polling i ve solved with the Refresher Addon. But with JPAContainer update I have stucked because of its performance. To minimize the range of possible problem indicators, i ve took the most simple entity class and populated 1 entry of it in the database. My Entity looks as following:
@RooJavaBean
@RooToString
@RooEntity
@RooSerializable
public class Locale {
@Size(max = 6)
private String localeKey;
}
My extended Table component:
public class TestTable extends Table {
/**
*
*/
private static final long serialVersionUID = -421902620415105156L;
private JPAContainer<Locale> ticketsContainer;
private final static String[] visibleColumns = { "localeKey"};
public TestTable() {
super();
EntityManager entityManager = EntityProviderUtil.getInstance()
.getEntityManager();
ticketsContainer = JPAContainerFactory.makeReadOnly(Locale.class,
entityManager);
setContainerDataSource(ticketsContainer);
setWidth("100%");
setSelectable(true);
setImmediate(true);
setSortContainerPropertyId("localeKey");
setSortAscending(false);
setVisibleColumns(visibleColumns);
setColumnHeaders(new String[] { "localeKey" });
}
public void update() {
ticketsContainer.refresh();
}
}
My Application init():
@Override
@Transactional
public void init() {
LOG.debug("start initializing the vaadin application");
Window window = new Window("test table");
Locale locale = new Locale();
locale.setLocaleKey("de_DE");
locale.persist();
final TestTable table = new TestTable();
window.addComponent(table);
Refresher refresher = new Refresher();
refresher.setRefreshInterval(10000);
refresher.addListener(new RefreshListener() {
@Override
public void refresh(Refresher source) {
table.update();
}
});
window.addComponent(refresher);
super.setMainWindow(window);
}
And now the sql preparedstatement log.
The funny thing is, the first log isnt so awesome like the following request logs.
This is the first request log:
[EL Fine]
: 2012-01-28 10:33:11.097--ServerSession(1097828000)--Connection(1924646449)--Thread(Thread["http-bio-9090"-exec-9,5,main]
)--SELECT id, LOCALEKEY, version FROM LOCALE WHERE (id = ?)
bind => [1]
[EL Fine]
: 2012-01-28 10:33:11.109--ServerSession(1097828000)--Connection(1538527370)--Thread(Thread["http-bio-9090"-exec-9,5,main]
)--SELECT COUNT(id) FROM LOCALE
[EL Fine]
: 2012-01-28 10:33:11.114--ServerSession(1097828000)--Connection(921720151)--Thread(Thread["http-bio-9090"-exec-9,5,main]
)--SELECT id AS a1 FROM LOCALE ORDER BY LOCALEKEY DESC, id ASC LIMIT ? OFFSET ?
bind => [150, 0]
This request happened 2 minuteslater:
[EL Fine]
: 2012-01-28 10:35:11.097--ServerSession(1097828000)--Connection(380750143)--Thread(Thread["http-bio-9090"-exec-9,5,main]
)--SELECT id, LOCALEKEY, version FROM LOCALE WHERE (id = ?)
bind => [1]
[EL Fine]
: 2012-01-28 10:35:11.105--ServerSession(1097828000)--Connection(1025036841)--Thread(Thread["http-bio-9090"-exec-9,5,main]
)--SELECT id, LOCALEKEY, version FROM LOCALE WHERE (id = ?)
bind => [1]
[EL Fine]
: 2012-01-28 10:35:11.109--ServerSession(1097828000)--Connection(1783266943)--Thread(Thread["http-bio-9090"-exec-9,5,main]
)--SELECT id, LOCALEKEY, version FROM LOCALE WHERE (id = ?)
bind => [1]
[EL Fine]
: 2012-01-28 10:35:11.111--ServerSession(1097828000)--Connection(753864924)--Thread(Thread["http-bio-9090"-exec-9,5,main]
)--SELECT id, LOCALEKEY, version FROM LOCALE WHERE (id = ?)
bind => [1]
[EL Fine]
: 2012-01-28 10:35:11.114--ServerSession(1097828000)--Connection(1420938648)--Thread(Thread["http-bio-9090"-exec-9,5,main]
)--SELECT id, LOCALEKEY, version FROM LOCALE WHERE (id = ?)
bind => [1]
[EL Fine]
: 2012-01-28 10:35:11.117--ServerSession(1097828000)--Connection(1814754830)--Thread(Thread["http-bio-9090"-exec-9,5,main]
)--SELECT id, LOCALEKEY, version FROM LOCALE WHERE (id = ?)
bind => [1]
[EL Fine]
: 2012-01-28 10:35:11.12--ServerSession(1097828000)--Connection(773797778)--Thread(Thread["http-bio-9090"-exec-9,5,main]
)--SELECT id, LOCALEKEY, version FROM LOCALE WHERE (id = ?)
bind => [1]
[EL Fine]
: 2012-01-28 10:35:11.122--ServerSession(1097828000)--Connection(404192466)--Thread(Thread["http-bio-9090"-exec-9,5,main]
)--SELECT id, LOCALEKEY, version FROM LOCALE WHERE (id = ?)
bind => [1]
[EL Fine]
: 2012-01-28 10:35:11.125--ServerSession(1097828000)--Connection(2065389480)--Thread(Thread["http-bio-9090"-exec-9,5,main]
)--SELECT id, LOCALEKEY, version FROM LOCALE WHERE (id = ?)
bind => [1]
[EL Fine]
: 2012-01-28 10:35:11.128--ServerSession(1097828000)--Connection(1832585859)--Thread(Thread["http-bio-9090"-exec-9,5,main]
)--SELECT id, LOCALEKEY, version FROM LOCALE WHERE (id = ?)
bind => [1]
[EL Fine]
: 2012-01-28 10:35:11.132--ServerSession(1097828000)--Connection(1020708261)--Thread(Thread["http-bio-9090"-exec-9,5,main]
)--SELECT id, LOCALEKEY, version FROM LOCALE WHERE (id = ?)
bind => [1]
[EL Fine]
: 2012-01-28 10:35:11.134--ServerSession(1097828000)--Connection(659105842)--Thread(Thread["http-bio-9090"-exec-9,5,main]
)--SELECT COUNT(id) FROM LOCALE
[EL Fine]
: 2012-01-28 10:35:11.136--ServerSession(1097828000)--Connection(1751455376)--Thread(Thread["http-bio-9090"-exec-9,5,main]
)--SELECT id AS a1 FROM LOCALE ORDER BY LOCALEKEY DESC, id ASC LIMIT ? OFFSET ?
bind => [150, 0]
And this is all because of the call of the refresh method!
My database table still contains only 1 Locale entry.
I ve tried to use JPAContainer with Hibernate and EclipseLink (2.2.0). The result is the same.
DBMS is PostGreSQL
I use Spring Roo in my Application.
My EntityManager I get over the @PersistenceContext. I ve never had problems with that before.
Vaadin 6,7,4
JPAContainer 2.0.0
Is there maybe any other possibility to synchronize my table with the database?
PS. This was a very simple example.
Can you imagine how many selects it generates if I use more complex entities and multiple entries (for example 10)?
One request with the first refresh() call took 0,8 seconds for its job and generated nearly ~100 selects