Regarding Vaadin, the "Application" class/idea was one of the major changes 
in Vaadin 7 from Vaadin 6. That class/idea are gone. Now we have the much 
more flexible "VaadinSession" that wraps a Servlet session, and owns one or 
more instances of one or more "UI" classes. Each "UI" instance is the 
entire content present in a web browser's window/tab (or a Portlet 
<https://en.wikipedia.org/wiki/Portlet>). In other words, your Vaadin app 
can have multiple open browser window/tabs running simultaneously. I made a 
diagram <http://i.stack.imgur.com/Qp1XB.png> of this architecture. This 
Question <http://stackoverflow.com/q/21777067/642706> and this Question 
<http://stackoverflow.com/questions/15439761/how-to-put-data-in-session-variable-and-get-the-data-in-different-page-in-vaadin>
 
on StackOverflow may be useful, as well as the *Application Lifecycle* 
chapter <https://vaadin.com/book/-/page/application.lifecycle.html> of The 
Book Of Vaadin.

You could hold one reference/connection to H2 in the VaadinSession for all 
the "UI" instances (all the open windows). Or each "UI" instance could have 
its own H2 reference/connection. I don’t know enough about H2 yet to know 
which is appropriate.

There are hooks for the creation & destruction 
<https://vaadin.com/book/-/page/application.lifecycle.html#application.lifecycle.session.init>
 
of the VaadinSession, where I would be starting/stopping that user's own H2 
database.

On Wednesday, July 1, 2015 at 10:11:49 PM UTC-7, Kartweel wrote:
>
>  Yep no probs at all. You can have multiple databases open at the same 
> time and open and close them on different threads as you like.
>
> You'll just need to do the appropriate connection handling linked to the 
> session open / close.
>
> Scaling is going to depend on your application architecture too. If you 
> are horizontally scaling it isn't going to work with embedded databases?. 
> Or are you using TCP and having a h2 server on a different server?
>
> The downside I can think of is that you can't query all databases for any 
> non-user tasks. Have to update all schemas individually, etc. So on each 
> session start it is going to almost be like starting a separate application.
>
> Probably fits quite nicely with vaadin architecture. Just link it to the 
> Application start and end (Don't they call a session an application?)
>
>
> Ryan
>
>
> On 2/07/2015 6:06 AM, Basil Bourque wrote:
>  
>  Is it possible to start up and shut down multiple H2 
> <http://h2database.com/html/main.html> databases within a JVM?
>
> My goal is to support multi-tenancy 
> <https://en.m.wikipedia.org/wiki/Multitenancy> by giving each 
> user/account their own database. Each account has very little data. Data 
> between the accounts is never accessed together, compared, or grouped; each 
> account is entirely separate from the others. Each account is only accessed 
> briefly once a day or a few times a month. So there are few upsides to 
> housing the data together in a single database, and some serious downsides.
>
> So my idea is that when a user logs in for a particular account, that 
> account’s database is loaded. When that user logs out, or their web app 
> session (Vaadin <https://www.vaadin.com/> app) times out, that account’s 
> database is closed, it's data flushed to storage, and possibly a backup 
> performed. This opening and closing would be happening for any number of 
> databases in parallel.
>
> Benefits include minimizing the amount of memory in use at any one time 
> for caching data and indexes, minimizing locking and other contention, and 
> allowing for smooth scaling.
>
> I'm new to H2, so I'm not sure if its architecture can support this. I'm 
> asking for a denial or confirmation of this capability, along with any tips 
> or caveats.
>  ----
>
>  Taken from my Question <http://stackoverflow.com/q/31150193/642706> on 
> StackOverflow.com. 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "H2 Database" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] <javascript:>.
> To post to this group, send email to [email protected] 
> <javascript:>.
> Visit this group at http://groups.google.com/group/h2-database.
> For more options, visit https://groups.google.com/d/optout.
>
>
> 

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.

Reply via email to