Re: (Mis)use of transactions



Thomas Hawtin wrote:
RedGrittyBrick wrote:


In the JPanel's constructor I get a java.sql.Connection instance and thus open a connection to the DBMS.


Sounds like very confused code to me. Is it a UI class or a database class?

I simplified my description somewhat. In reality the JDBC methods are in a "model" class. I instantiate the model in the constructor of the "view".

I do find deciding what functionality should go in what classes to be confusing. I think its something people get better at with practice.

Maybe I should do
FooModel model = new FooModel();
FooView view = new FooView(model);
instead of
FooView view = new FooView();
...
class FooView {
FooModel model = new FooModel();
...
}
Though I can't see a significant benefit. I probably did it the latter way because I associate the model with the JTable more than with the container. So my instantiation of the model is close to the instantiation of the JTable. More to ponder.


In any case, I'd avoid subclassing unnecessarily.

I find extending JPanel is a convenient approach. I'm aware of the "composition vs inheritance" debate, so maybe I'll ponder this further.



<further good points snipped for brevity>

There is a problem in that updates that other actors make while the window is open wont be automatically shown. You can do that relatively efficiently by putting triggers on the main table that copy updates into shadow tables.

I'm not really familiar with that approach, anyone have pointers to further reading on this (preferably online) or relevant examples?


P.S. Thanks to Doug & Lew too, your good advice is much appreciated.
.