help needed with addContainerFilter ....

I have ported the addressbook demo program to use MySQL

all is working great. I have one remaining problem. somehow the search/filter implamentation errors out with a weird error.

here is my code; the error reported is on line 145 (i marked the line bellow as 145); this same code works fine in the addressbook demo, but that example is not using MySQL. I am also including the error list.

what is wrong with my code?

thanks for any help…

[font=courier new]
private void initSearch() {
searchField.setInputPrompt(“Search Zipcode”);

    searchField.setTextChangeEventMode(TextChangeEventMode.LAZY);
    
    searchField.addTextChangeListener(new TextChangeListener() {
        public void textChange(final TextChangeEvent event) {
            containerZipcode.removeAllContainerFilters();
            containerZipcode.addContainerFilter(new ZipcodeFilter(event.getText()));  //145
        }
    });
}

private class ZipcodeFilter implements Filter {
    private String needle;

    public ZipcodeFilter(String needle) {
        this.needle = needle.toLowerCase();
    }

    public boolean passesFilter(Object itemId, Item item) {
        String haystack = ("" 
                + item.getItemProperty(ZIPCODE).getValue()).toLowerCase();
        return haystack.contains(needle);
    }

    public boolean appliesToProperty(Object id) {
        return true;
    }
}

error list:

Feb 17, 2015 6:50:24 PM com.vaadin.server.DefaultErrorHandler doDefault
SEVERE:
java.lang.RuntimeException: Failed to update item set size.
at com.vaadin.data.util.sqlcontainer.SQLContainer.updateCount(SQLContainer.java:1176)
at com.vaadin.data.util.sqlcontainer.SQLContainer.size(SQLContainer.java:403)
at com.vaadin.ui.Table.containerItemSetChange(Table.java:4524)
at com.vaadin.data.util.sqlcontainer.SQLContainer.fireContentsChange(SQLContainer.java:1628)
at com.vaadin.data.util.sqlcontainer.SQLContainer.refresh(SQLContainer.java:911)
at com.vaadin.data.util.sqlcontainer.SQLContainer.refresh(SQLContainer.java:893)
at com.vaadin.data.util.sqlcontainer.SQLContainer.addContainerFilter(SQLContainer.java:550)
at com.example.zipcode.ZipcodeUI$2.textChange(ZipcodeUI.java:145)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:508)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:198)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:161)
at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:979)
at com.vaadin.ui.AbstractTextField.firePendingTextChangeEvent(AbstractTextField.java:398)
at com.vaadin.ui.AbstractTextField.changeVariables(AbstractTextField.java:207)
at com.vaadin.server.communication.ServerRpcHandler.changeVariables(ServerRpcHandler.java:485)
at com.vaadin.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:301)
at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:180)
at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:93)
at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:41)
at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1406)
at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:305)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘’ at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:377)
at com.mysql.jdbc.Util.getInstance(Util.java:360)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:978)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3887)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3823)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2435)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2582)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2530)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1907)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2030)
at com.vaadin.data.util.sqlcontainer.query.TableQuery.executeQuery(TableQuery.java:529)
at com.vaadin.data.util.sqlcontainer.query.TableQuery.getCount(TableQuery.java:210)
at com.vaadin.data.util.sqlcontainer.SQLContainer.updateCount(SQLContainer.java:1165)
… 45 more

Feb 17, 2015 6:50:24 PM com.vaadin.server.DefaultErrorHandler doDefault
SEVERE:
java.lang.RuntimeException: Failed to update item set size.
at com.vaadin.data.util.sqlcontainer.SQLContainer.updateCount(SQLContainer.java:1176)
at com.vaadin.data.util.sqlcontainer.SQLContainer.size(SQLContainer.java:403)
at com.vaadin.ui.AbstractSelect.size(AbstractSelect.java:762)
at com.vaadin.ui.Table.doPaintContent(Table.java:3284)
at com.vaadin.ui.Table.paintContent(Table.java:3268)
at com.vaadin.server.LegacyPaint.paint(LegacyPaint.java:65)
at com.vaadin.server.communication.LegacyUidlWriter.write(LegacyUidlWriter.java:82)
at com.vaadin.server.communication.UidlWriter.write(UidlWriter.java:116)
at com.vaadin.server.communication.UidlRequestHandler.writeUidl(UidlRequestHandler.java:151)
at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:99)
at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:41)
at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1406)
at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:305)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘’ at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:377)
at com.mysql.jdbc.Util.getInstance(Util.java:360)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:978)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3887)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3823)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2435)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2582)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2530)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1907)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2030)
at com.vaadin.data.util.sqlcontainer.query.TableQuery.executeQuery(TableQuery.java:529)
at com.vaadin.data.util.sqlcontainer.query.TableQuery.getCount(TableQuery.java:210)
at com.vaadin.data.util.sqlcontainer.SQLContainer.updateCount(SQLContainer.java:1165)
… 33 more
[/font]

Hi,

I experience this same issue with custom filters in SQLContainer. When using custom filter "
Failed to update item set size.
" exception is thrown.
Does anyone have any idea what I’m doing wrong or not doing right?
I have browsed through endless number of tutorials with no help.

I’m using Vaadin version 7.4.1.

If I use standard filters such as

container.addContainerFilter( new Compare.Equal("GUID", this.getGUID) everything goes smoothly.

I have defined
CustomFilter
as follows. The real one of course has some more code in passesFilter and appliesToProperty, but this does not work even with this implementation:

[code]
public class CustomFilter implements Container.Filter {

private static final long serialVersionUID = 1L;
protected String propertyId;
protected String regex;
public CustomFilter(String propertyId, String guid) {
    this.propertyId = propertyId;
    this.regex = guid;
}
@Override
public boolean passesFilter(Object itemId, Item item) throws UnsupportedOperationException {
    return true;
}
@Override
public boolean appliesToProperty(Object propertyId) {
    return true;
}

}
[/code]I have a table called a "
table
" with a varchar(36) column called
GUID
and column called
LastChanged
.
I apply the filter with following code:

TableQuery sqlQuery = new TableQuery("table", ConnectionPool.getConnPool());
sqlQuery.setVersionColumn("LastChanged");
SQLContainer container = null;
try {
    container = new SQLContainer(sqlQuery);                        
    container.removeAllContainerFilters();
    container.addContainerFilter(  new CustomFilter("GUID", this.getGUID() ) );        
} catch (Exception e) {
    e.printStackTrace();
}        

I use the container with table as follows:

tableGuid.setContainerDataSource( container ) Creating the view containing "
tableGuid
" goes off without a problem, but when I try to navigate to the view containing tableGuid starts to happen.

SQLContainer-class throws a RuntimeException("Failed to update item set size.",e). This is caused by SQLException
"
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘’ at line 1
"
thrown from
com.vaadin.addon.sqlcontainer.query.QueryDelegate#getCount()
.


QueryDelegate#getCount
throws exception because sql statement is formed as such:

"SELECT COUNT(*) FROM table WHERE ". The WHERE clause is missing and this causes the SQLException.

I can track this further and further, but
QueryBuilder#getWhereStringForFilter
seems to be ending point for this.

return ft.getWhereStringForFilter(filter, sh); while iterating Filters returns nothing from CustomFilter.

My head soon starts to bleed from all the head scratching. Does anyone have any help with this issue?

I have been facing this same issue for the last few weeks. Judging from the above posts, I think this a bug in the SQL generator class. I have been facing this issue with the Oracle Generator.

I have created a ticket for this issue here:
https://dev.vaadin.com/ticket/19403

Hope someone takes this up.