Vaadin SQLContainer

If you have an updated Vaadin Eclipse plugin (version 1.3.1) you should be able to just create a new Vaadin project at the same location as your check out of the SQLContainer sources. This should then be deployable to e.g. Tomcat.

The included build.xml ant-script also packages a WAR file with the demos that can be deployed to your favorite container.

HTH,
/Jonatan

Is there coming in near future, any kind of fix for SQLContainer LazyLoading problem with Opera 11. When scrolling table, rows just won’t show properly. I think Table component had same kind of problem, but it is fixed. You can see what i mean just by scrolling SQLContainer
Sample
application with Opera 11.

It is actually a problem in Opera 11 that has been worked around in Table in 6.5.0. It is not related to SQLContainer in any way and the reason it is visible in the SQLContainer demo application is that the demo still uses Vaadin 6.4.x.

Edit: Updated the demo to use 6.5.0 and still some extra scrollbars appear in Opera 11.01 (Opera 10.63 works fine). Hopefully the Opera team will get the browser to work correctly again soon. It is anyhow not a SQLContainer problem.

Hi I’m using SQLContainer with MYSQL database and I’m doing the SQLContainer’s tutorial.
My Application shows datas from database but when I calling table.setVisibleColumns(DatabaseHelper.NATURAL_COL_ORDER);
It’s gives me an error >>>
Ids must exist in the Container or as a generated column , missing id: FIRSTNAME

Please help me to solute my problem…

It’s my NATURAL_COL_ORDER


public static final Object[] NATURAL_COL_ORDER = new Object[]
 {
      "FIRSTNAME", "LASTNAME", "EMAIL", "PHONENUMBER", "STREETADDRESS",
      "POSTALCODE", "CITYID" };

Hello,

The “Ids must exist in the Container or as a generated column , missing id: FIRSTNAME” message means that SQLContainer doesn’t have such a property ID registered. This could be due to any number of things. For instance, the query that fills the SQLContainer might not contain the FIRSTNAME column. Or maybe the column’s name really is “firstname” (small characters instead of caps).

You could place a breakpoint on line 1170 in SQLContainer.java (cachedItems.put(id, new RowItem(this, id, itemProperties))) and inspect the value of itemProperties to see what properties have been registered with the container.

Perhaps we should add a debug message for this in a future release…

HTH,
/Jonatan

Thank you Jonatan Kronqvist. I appreciate your attention to my problem.
It’s ok now, it was because of capital letters. :slight_smile:

Hi,
Now I’m having following issue →
I’m getting my container. and setting it as tables dataSource.


[color=#DE1717]
//con.getContainer().addFilter(new Filter("firstname", ComparisonType.STARTS_WITH, "ga"));
[/color]
tbl.setContainerDataSource(con.getContainer());


After I created and added a button. When I’m click the button It creates a Form and is adding an item(addItem()). Here is the code :


add.addListener(new ClickListener() {
				
			public void buttonClick(ClickEvent event) {[color=#DE1717]

[/color]
				//con.getContainer().removeAllContainerFilters();
				try {
					con.getContainer().rollback();
				} catch (UnsupportedOperationException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

				final Form myForm = new Form();

				Object tempItemId = con.getContainer().addItem();
							
				Item [color=#FD0000]
surce 
[/color]= con.getContainer().getItem(tempItemId); // When my filter is on getting NULL ????
							
				myForm.setItemDataSource(surce);
			
				HorizontalLayout buttonsLayout = new HorizontalLayout();
				Button save = new Button("save", new ClickListener() {
					
					public void buttonClick(ClickEvent event) {
						
						try {
							con.getContainer().commit();
						} catch (UnsupportedOperationException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} catch (SQLException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						
					}
				});

And as you have seen I also have a Filter, when It’s off-> My form works ok, But when I turning it on My form don’t get the
surce
.
Please tell me how to solve my problem.

Hi!

getItem only returns items that pass the filters, so you need to clear the filters before you can retrieve the Item and then re-filter the container. This is also how the stock Vaadin containers are implemented, however I see that this might be a case where SQLContainer perhaps could diverge from other containers or provide a method for bypassing the filtering… What do you think?

Please
create
an enhancement ticket for such a feature if you’d like to have.

HTH,
/Jonatan

Hi Jonatan Kronqvist.

I think It would be better to have a such method to ease the query process.
And I also would like to know how does SQLContainer escaping works when I’m filtering. I have a login form where I’m retriving ID of my user by filtering my Login table. I’ve tried to write some data to login and password fields to get free access like ->> ’ OR ‘’ = '.
But the trick didn’t worked so I guessed that SQLContainer is using string escapes, but I would like to know how does this escapes work in SQLContainer and to know how do I have to write right filtering not to allow not well-wishers to get free access to my application and some data when they are searching in my database. I write my login filters like this:


 addListener(new LoginForm.LoginListener() {
	            public void onLogin(LoginEvent event) {
	            	Connection loginConnection = new Connection();
	            	
	            	///////// Geting Container//////
	            	loginContainer = loginConnection.getContainer();
	            	///////////// Creating filters ////////////////
	            	Filter login = new  Filter("login", ComparisonType.EQUALS , event.getLoginParameter("username"));
	            	Filter pass = new  Filter("pass", ComparisonType.EQUALS , event.getLoginParameter("password"));
	            	
	            	////////////////// Setting filters ////////////////////////
	                loginContainer.setFilteringMode(FilteringMode.FILTERING_MODE_INCLUSIVE);
	            	loginContainer.addFilter(login);
	
	            	loginContainer.addFilter(pass);
	
	                if(loginContainer.getItemIds().size() == 1){
	                	Object aa = loginContainer.getIdByIndex(0);
	             
	                	System.out.println(loginContainer.getItem(aa).getItemProperty("id"));
	                	
	                }
	                
	                
	            }
	        });
	       
	}

Best regards
Manvel Saroyan

Hi,

SQLContainer uses
prepared statements
, so you should not need to worry about escaping strings.

HTH,
/Jonatan

Hi Again.
Thanks for fast reply. Now I’m relaxed about escaping, but I’m stil having a problem. I can’t write UTF-8 formated data to my database. Please tell me is there a way to enable UTF-8 writing in SQLContainer.

Best Regards,
Manvel Saroyan

Hi,

SQLContainer should not affect the charset in any way. Make sure that your DB is configured to use UTF-8. In some cases you need to specify this on the connection URL.

HTH,
/Jonatan

Thanks Jonatan Kronqvist.
After your answere I’ve solved that problem :slight_smile:

I’ve changed The URL in this way → “jdbc:mysql://192.168.1.222:3306/manager?useUnicode=true&characterEncoding=UTF-8”

And now Everything work greate
:grin:

com.vaadin.addon.sqlcontainer.query.generator.DefaultSQLGenerator
identifier quote MUST be configurable parameter.

Not " (quote) constant- as now.

MySQL server, which I use, isn’t under my control and ANSI_QUOTES opt is disabled there.

So SQLContainer just failed.

DefaultSQLGenerator must have two settings
String identifierQuoteStart
String identifierQuoteEnd

for MySql they can have values: “`”, “"”, “” (empty str is i sure that all identifiers are ok)
for MSSQL they can have values: “[” & "]
", “"”, “”

ticket: http://dev.vaadin.com/ticket/6511

Also I will be happy if You include in SQLContainer package my simple DataSource wrapper.

It is useful for BoneCP (http://jolbox.com/ - best JDBC Connection Pool now), c3p0 or DBCP users.


/**
 * {@link DataSource} delegating {@link JDBCConnectionPool} implementation.
 *
 * @author Andrew Fink [aprpda -at- gmail.com]
 http://magicprinc.blogspot.com/
 */
public class DataSourceJDBCConnectionPool implements JDBCConnectionPool {

	private final DataSource dataSource;
	private final String username;
	private final String password;


	public DataSourceJDBCConnectionPool (DataSource dataSource) {
		this(dataSource, null, null);
	}//new


	public DataSourceJDBCConnectionPool (DataSource dataSource, final String username, final String password) {
		this.dataSource = dataSource;
		this.username = username;
		this.password = password;
	}//new


	@Override public Connection reserveConnection () throws SQLException {
		return username == null ? dataSource.getConnection() : dataSource.getConnection(username, password);
	}


	@Override	public void releaseConnection (Connection conn) {
		try {
		    conn.close();
		} catch (SQLException e) {
		    e.printStackTrace();
		}
	}


	@Override public void destroy () {}
}


http://dev.vaadin.com/ticket/6511

contains my “Improved bug-fixed optimized version” (just rename to DefaultSQLGenerator and change package)
works like a breeze


http://dev.vaadin.com/ticket/6512

DataSourceJDBCConnectionPool “just works”

not important ideas:

RowId +=


public static RowId of (Object... pkIds) {
  return new RowId(pkIds);
}

Usage:
myrowId = RowId.of(mypkvalue);

com.vaadin.addon.sqlcontainer.RowId#equals should use safer / shorter
java.util.Arrays#equals(Object, Object
)

not important ideas:

It’s good to have configurable property “selectTableHints”, where user can set “(nolock”) for example.

i.e. generated sql: select count(*) from mytable (nolock)

Ohoho…
SqlContainer’s Filter suffers from same “ident quote” problem too…

I think it’s toPreparedStatementString must accept same settings…

===after some time
OK!

ticket 6511

contains now all necessary sources

sqlcontainer_adaptive.zip

  • SqlSettings with your individual Sql Server settings (default values backward compatible)
  • MyFilter - Filter “fixer” must be merged to Filter
  • MySQLGenerator == new DefaultSQLGenerator

Hi, Andrew!

Thanks for the suggestions and patches! I will look in to them as soon as I have a chance to.

/Jonatan