* Enabling use of ID sequence generators in H2 databases.
Patch by Robert Gaggl, fixes bug 562 - http://helma.org/bugs/show_bug.cgi?id=562
This commit is contained in:
parent
ae0536eb26
commit
beed995659
3 changed files with 28 additions and 2 deletions
|
@ -1230,6 +1230,21 @@ public final class DbMapping {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is the database behind this a H2 db?
|
||||||
|
*
|
||||||
|
* @return true if the dbsource is using a H2 JDBC driver
|
||||||
|
*/
|
||||||
|
public boolean isH2() {
|
||||||
|
if (dbSource != null) {
|
||||||
|
return dbSource.isH2();
|
||||||
|
}
|
||||||
|
if (parentMapping != null) {
|
||||||
|
return parentMapping.isH2();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a string representation for this DbMapping
|
* Return a string representation for this DbMapping
|
||||||
*
|
*
|
||||||
|
|
|
@ -36,7 +36,7 @@ public class DbSource {
|
||||||
private ResourceProperties props, subProps;
|
private ResourceProperties props, subProps;
|
||||||
protected String url;
|
protected String url;
|
||||||
private String driver;
|
private String driver;
|
||||||
private boolean isOracle, isMySQL, isPostgreSQL;
|
private boolean isOracle, isMySQL, isPostgreSQL, isH2;
|
||||||
private long lastRead = 0L;
|
private long lastRead = 0L;
|
||||||
private Hashtable dbmappings = new Hashtable();
|
private Hashtable dbmappings = new Hashtable();
|
||||||
// compute hashcode statically because it's expensive and we need it often
|
// compute hashcode statically because it's expensive and we need it often
|
||||||
|
@ -165,6 +165,7 @@ public class DbSource {
|
||||||
isMySQL = driver.startsWith("com.mysql.jdbc") ||
|
isMySQL = driver.startsWith("com.mysql.jdbc") ||
|
||||||
driver.startsWith("org.gjt.mm.mysql");
|
driver.startsWith("org.gjt.mm.mysql");
|
||||||
isPostgreSQL = driver.equals("org.postgresql.Driver");
|
isPostgreSQL = driver.equals("org.postgresql.Driver");
|
||||||
|
isH2 = driver.equals("org.h2.Driver");
|
||||||
// test if driver class is available
|
// test if driver class is available
|
||||||
Class.forName(driver);
|
Class.forName(driver);
|
||||||
|
|
||||||
|
@ -247,6 +248,16 @@ public class DbSource {
|
||||||
public boolean isPostgreSQL() {
|
public boolean isPostgreSQL() {
|
||||||
return isPostgreSQL;
|
return isPostgreSQL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if this DbSource represents a H2 database
|
||||||
|
*
|
||||||
|
* @return true if we're using a H2 JDBC driver
|
||||||
|
*/
|
||||||
|
public boolean isH2() {
|
||||||
|
return isH2;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a dbmapping by its table name.
|
* Register a dbmapping by its table name.
|
||||||
*
|
*
|
||||||
|
|
|
@ -822,7 +822,7 @@ public final class NodeManager {
|
||||||
if (map.isOracle()) {
|
if (map.isOracle()) {
|
||||||
q = new StringBuffer("SELECT ").append(map.getIDgen())
|
q = new StringBuffer("SELECT ").append(map.getIDgen())
|
||||||
.append(".nextval FROM dual").toString();
|
.append(".nextval FROM dual").toString();
|
||||||
} else if (map.isPostgreSQL()) {
|
} else if (map.isPostgreSQL() || map.isH2()) {
|
||||||
q = new StringBuffer("SELECT nextval('")
|
q = new StringBuffer("SELECT nextval('")
|
||||||
.append(map.getIDgen()).append("')").toString();
|
.append(map.getIDgen()).append("')").toString();
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Reference in a new issue