Answering my own question..

I was able to get the database name using Internal H2 API

String databaseName = ((Session)
((JdbcConnection)conn).getSession()).getDatabase().getName();


On May 2, 1:20 pm, Anthony <[email protected]> wrote:
> Hi,
>
> Is there a way to get a unique database or catalog name?
>
> eg:
> jdbc:h2:mem:abc/test -> catalog name=test
> jdbc:h2:mem:xyz/test -> catalog name=test
>
> But abc/test and xyz/test are different databases and they have the
> same catalog name.
>
> So why do I need a unique database name?
> I'm implementing a Trigger class but H2 only use one classloader for
> the entire database engine, multiple database will gets the same
> Trigger class, which means static variables in this class is
> accessible in different databases.
>
> I'm was planning to store the per database static data in a map keyed
> by a unique database name.
>
> public class MyTrigger implements Trigger{
>
>         private static HashMap<String,String> map = new
> HashMap<String,String>();
>
>         public void init(Connection conn, String schemaName, String
> triggerName,
>                         String tableName, boolean before, int type) throws 
> SQLException {
>
>                 DatabaseMetaData dbMetaData = conn.getMetaData();
>
>                 ResultSet rs = dbMetaData.getCatalogs();
>                 while(rs.next()){
>                         String databaseName = rs.getObject(1);
>                         map.put(databaseName, ....); //this will override my 
> value when
> catalog name is same
>                 }
>
>                 ...
>         }
>
>         public void close() throws SQLException {
>                 ...
>         }
>
>         public void fire(Connection conn, Object[] oldRow, Object[] newRow)
> throws SQLException {
>                 ...
>         }
>
>         public void remove() throws SQLException {
>                 ...
>         }
>
>
>
> }

-- 
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.

Reply via email to