Re: [EoDsql-users] Adding elements to a (disconnected) DataSet
Status: Beta
Brought to you by:
lemnik
|
From: Jason M. <le...@gm...> - 2007-06-23 09:32:55
|
Ricardo Palomares wrote: > Hi, > > First of all, thank you for the 0.9 beta release, Jason. The site new > look is nicer, too. > > At this moment I have in my program some classes whose persistence I > wrote before I know about EoDSQL, and I want to change that so all of > them use EoDSQL. Up to now, every entity in my database model has two > Java classes (three where EoDSQL is not yet used): > > - ASimpleClass > - ASimpleClassList > > ASimpleClass represents a single element, whereas ASimpleClassList > implements or extends things like MutableComboBoxModel or > AbstractListModel. This way, I have an easy way to put GUI controls > (JList, JComboBox, etc.) to access to the underlying database table. > I've even dared to use DataSet as the in-memory list view of the > database table (I'm using tables with very few rows, 10 or so). > > Now, in a specific entity (VERSION, which represents versions of > products and could have a UNIQUE constraint on product + version > fields) I have the need to add a "fake" element, like a "*" wildcard. > It will be used in a JComboBox and won't be persisted in the VERSION > table. To put some context on the why I need it, I have another table > "ROLES" managing permissions, in which I want to be able to have rows > like: > > Row Meaning > -------------------------------------------------------- > 1 UserA is owner of productA, version 1.0 > 2 UserB is owner of productA, version 1.5 > 3 UserA is translator of productB, version 2.0 > 4 UserB is owner of productB, version * > > as a quick way to make userB owner of every possible version of > productB (row 4), instead of requiring a new row every time a new > version of productB is created and, at the same time, allow different > users to be owners of different versions of the same product (rows 1 & 2). > > Obviously, the "*" fake element in the VERSION in-memory list would be > used in a JComboBox in the ROLES management window. > > Now, I'm not really sure if I could simply add an element to the > DataSet in disconnected mode and use it in the JComboBox model like a > simple List. I never write back the DataSet to disk; every time a > record is added, modified or deleted, the query is re-executed and the > DataSet is disconnected. I *believe* I may be in the safe side, but I > don't really know for sure. Is this a sensible approach? > > TIA > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > eodsql-users mailing list > eod...@li... > https://lists.sourceforge.net/lists/listinfo/eodsql-users > I would say that a possibly more sensible approach would be to implement the "fake" element in the Swing list/combobox model itself. If the element number request is 0, then return the "fake" element to display, otherwise return DataSet.get(row - 1); If that makes sense? You may want to implement a single combobox model and a list model which accepts a model of the same type and adds a fake element to the beginning of the list. A FakeElementComboBoxModel for example. You can't add elements to a DataSet in EoDSQL at all, it'll throw an UnsupportedOperationException since all DataSet's are considered to be read-only. It's a deviation from the EoD RI which did allow read/write DataSet's. I will implement read/write DataSets some day, but for the time being they're a lot of overhead for what I say as very little functionality (for now). Hope the idea helps ;) |