I am using H2 in embedded mode to unit test some DAO classes. I found
one of the DAOs calls a user-defined function in the PostgreSQL
database. I tried to mock the function by writing a java method under
an alias in H2. I used this simple class for my test:
public class UserDefinedDbFunctions {
private static int id = 0;
public final static String getNextIdAndUpdate() {
id++;
return ("" + id);
}
}
Then in my unit test, I created the alias like so:
postgresqlStatement.executeUpdate("CREATE ALIAS IF NOT EXISTS
getNextIdAndUpdate FOR \"UserDefinedDbFunctions.getNextIdAndUpdate
\";");
After running the unit test, it threw a SQLException. It said it
couldn't find the column "getNextIdAndUpdate".
After taking a look inside the DAO, I found that the value was being
retrieved by column name:
String query = "SELECT getNextIdAndUpdate()";
// snip
id = resultSet.getString("getNextIdAndUpdate");
I then added some debug code to look at the ResultSet's metadata and
found that the name of the result column from my function is
"PUBLIC.GETNEXTIDANDUPDATE". The qualified name seems to be breaking
the code.
Without changing any of the original DAO code, is there a way that I
can change the name of the result column to not use its fully-
qualified name? Possibly another workaround?
--
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/h2-database?hl=en.