Permalink
Browse files

Fix for HBX-1178

Made DefaultDatabaseCollectorTest to work with HSQLDB dialect

Fix HSQDB quesry problem with table name which should be quoted

Do not create predefined role
  • Loading branch information...
Dmitry Geraskov authored and maxandersen committed Mar 10, 2011
1 parent 5ff14f3 commit 82fde8eb8e21e68b5c5b403839a2337a422b43a1
@@ -47,7 +47,7 @@ public Iterator getSuggestedPrimaryKeyStrategyName(String catalog, String schema
Map element = new HashMap();
protected Object convertRow(ResultSet tableRs) throws SQLException{
String table = tableRs.getString("TABLE_NAME");
- String fullTableName = Table.qualify(cat, sc, quote(table));
+ String fullTableName = Table.qualify(quote(cat), quote(sc), quote(table));
String sql ="SELECT * FROM " + fullTableName + " WHERE 0>1"; // can't use FALSE constant since it would not work with older HSQL versions. (JBIDE-5957)
boolean isAutoIncrement = false;
@@ -25,8 +25,6 @@
import org.hibernate.cfg.reveng.SchemaSelection;
import org.hibernate.cfg.reveng.TableIdentifier;
import org.hibernate.cfg.reveng.dialect.MetaDataDialect;
-import org.hibernate.dialect.Dialect;
-import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.mapping.Table;
import org.hibernate.tool.JDBCMetaDataBinderTestCase;
@@ -37,8 +35,13 @@
public class DefaultDatabaseCollectorTest extends JDBCMetaDataBinderTestCase {
private static final String SCHEMA = "cat.cat";
+ private static final String QSCHEMA = quote(SCHEMA);
- private static final String QSCHEMA = "\"cat.cat\"";
+ private static final String TABLE1 = "cat.child";
+ private static final String QTABLE1 = quote(TABLE1);
+
+ private static final String TABLE2 = "cat.master";
+ private static final String QTABLE2 = quote(TABLE2);
public void testReadOnlySpecificSchema() {
@@ -56,25 +59,25 @@ public void testReadOnlySpecificSchema() {
Table catchild = (Table) tables.get(0);
Table catmaster = (Table) tables.get(1);
- if(catchild.getName().equals("cat.master")) {
+ if(catchild.getName().equals(TABLE2)) {
catchild = (Table) tables.get(1);
catmaster = (Table) tables.get(0);
}
TableIdentifier masterid = TableIdentifier.create(catmaster);
TableIdentifier childid = TableIdentifier.create(catchild);
- assertEquals(new TableIdentifier(null, "cat.cat", "cat.child"), childid);
- assertEquals(new TableIdentifier(null, "cat.cat", "cat.master"), masterid);
+ assertEquals(new TableIdentifier(null, SCHEMA, TABLE1), childid);
+ assertEquals(new TableIdentifier(null, SCHEMA, TABLE2), masterid);
}
public void testNeedQuote() {
Settings buildSettings = cfg.buildSettings();
MetaDataDialect realMetaData = JDBCReaderFactory.newMetaDataDialect( buildSettings.getDialect(), cfg.getProperties() );
assertTrue("The name must be quoted!", realMetaData.needQuote(SCHEMA));
- assertTrue("The name must be quoted!", realMetaData.needQuote("cat.child"));
- assertTrue("The name must be quoted!", realMetaData.needQuote("cat.master"));
+ assertTrue("The name must be quoted!", realMetaData.needQuote(TABLE1));
+ assertTrue("The name must be quoted!", realMetaData.needQuote(TABLE2));
}
/**
@@ -95,16 +98,16 @@ public void testQuotedNamesAndDefaultDatabaseCollector() {
DatabaseCollector dc = new DefaultDatabaseCollector(reader.getMetaDataDialect());
reader.readDatabaseSchema( dc, null, SCHEMA );
- assertNotNull("The table should be found", dc.getTable(SCHEMA, null, "cat.child"));
- assertNotNull("The table should be found", dc.getTable(SCHEMA, null, "cat.master"));
- assertNull("Quoted names should not return the table", dc.getTable(quote(SCHEMA), null, quote("cat.child")));
- assertNull("Quoted names should not return the table", dc.getTable(quote(SCHEMA), null, quote("cat.master")));
+ assertNotNull("The table should be found", dc.getTable(SCHEMA, null, TABLE1));
+ assertNotNull("The table should be found", dc.getTable(SCHEMA, null, TABLE2));
+ assertNull("Quoted names should not return the table", dc.getTable(quote(SCHEMA), null, QTABLE1));
+ assertNull("Quoted names should not return the table", dc.getTable(quote(SCHEMA), null, QTABLE2));
assertEquals("Foreign key 'masterref' was filtered!", 1, dc.getOneToManyCandidates().size());
}
- private String quote(String name) {
- return "`" + name + "`";
+ private static String quote(String name) {
+ return "\"" + name + "\"";
}
private List getTables(JDBCMetaDataConfiguration metaDataConfiguration) {
@@ -123,32 +126,28 @@ protected void tearDown() throws Exception {
protected String[] getCreateSQL() {
return new String[] {
- "create schema " + QSCHEMA,
- "create table " + QSCHEMA + ".\"cat.master\" (" +
+ "create schema " + QSCHEMA + " AUTHORIZATION dba",
+ "create table " + QSCHEMA + "." + QTABLE2 + " (" +
" id integer NOT NULL," +
" tt integer," +
" CONSTRAINT master_pk PRIMARY KEY (id)" +
")",
- "create table " + QSCHEMA + ".\"cat.child\" (" +
+ "create table " + QSCHEMA + "." + QTABLE1 + " (" +
" childid integer NOT NULL,\r\n" +
" masterref integer,\r\n" +
" CONSTRAINT child_pk PRIMARY KEY (childid),\r\n" +
- " CONSTRAINT masterref FOREIGN KEY (masterref) references "+ QSCHEMA + ".\"cat.master\"(id)" +
+ " CONSTRAINT masterref FOREIGN KEY (masterref) references "+ QSCHEMA + "." + QTABLE2 + "(id)" +
")",
};
}
protected String[] getDropSQL() {
return new String[] {
- "drop table " + QSCHEMA + ".\"cat.child\"",
- "drop table " + QSCHEMA + ".\"cat.master\"",
+ "drop table " + QSCHEMA + "." + QTABLE1,
+ "drop table " + QSCHEMA + "." + QTABLE2,
"drop schema " + QSCHEMA
};
}
- public boolean appliesTo(Dialect dialect) {
- return dialect instanceof PostgreSQLDialect;
- }
-
}

0 comments on commit 82fde8e

Please sign in to comment.