Re: Accessing the current SQL connection in agent execution

Sasa Bojanic <[email protected]> Tue, 30 Oct 2007 09:21:24 +0100
Newsgroups gmane.comp.java.enhydra.shark
Message-ID <[email protected]>
This is a multi-part message in MIME format...

------------=_1193732654-10408-1
Content-Type: text/plain; charset=ISO-8859-2; format=flowed
Content-Transfer-Encoding: 7bit

Hi Manrico,

as I see you are using shark1.1-2

Anyway, if you would not need a special transaction for this operation, 
you could simply use DODSUtilities.getNext(somename) to get a unique Id 
for the name you specify, and in Shark.conf you could set a cache to 1 
so if the machine crashes you do not lose too much Ids.

E.g:

BigDecimal bd=DODSUtilities.getNext("myname");

and in Shark.conf

DODS.IdGenerator.myname.CacheSize=1

This utility we use to generate unique Ids for shark tables. The Id you 
get is synchronized on a database, so you can safely use it from several 
VMs.

There might be the way to lock the table when implementing Id generator 
your way. There should be DODS's method to lock the table called 
lockDO(), but we never tried it and we do not guarantee if there are 
some side-effects.

One time we tried to implement your approach, but we had the same 
problems as you do, so we gave up. Anyway, your approach is not 
efficient enough if you ask for the Ids very often.

If you succeed to implement Id generator with your approach we would be 
interested to see it.

Greetings,
Sasa.

[email protected] wrote:
> Hi.
> I am trying to set up a very simple numbering system.
> I have this table:
> numbers (_year_, counter, oid, version)
> Each time I look up for a 'year' I get the corresponding counter and increase it; if I can't find the record, I create a new one.
> I reckon that's gotta be a lot like the 'objectid' table, isn't it?
> I had to do this through the same transaction the Shark agent is using so that - in case I have to rollback the transaction - the number doesn't get "wasted".
> That's how I did this:
> -----------------------
> public long next(Long year, Object transactionObject)
> {
> 				DBTransaction dbtransaction = ( (SharkDODSTransaction) transactionObject).getDODSTransaction();
>
>         NumberQuery numberQuery = new NumberQuery(this.dbTransaction);
>         numberQuery.setQueryYear(year.intValue());
>         numberQuery.requireUniqueInstance();
>
>         long result = 0;
>
>         synchronized(semaphore)
>         {
>             numberDO number = numberQuery.getNextDO();
>
>             if (number == null)
>             {
>                 number = numberDO.createVirgin();
>                 number.setYear(year.intValue());
>                 number.setCounter(0);
>             }
>             else
>             {
>                 result = number.getCounter();
>             }
>
>             result++;
>
>             number.setCounter(result);
>
>             number.save(dbTransaction);
>         }
>         
>         return result;
>     
> }
> -----------------------
> Now, to stir things up a bit, I tried to access the numbering facilty with multiple requests, ending up in an easily foreseeable:
>
> org.enhydra.shark.api.TransactionException: Update failed, but Table numbers id=2585665 does exist with version=51
>
> How do I get a write lock on the record / DO?
> I waded through the documentation to no avail. 
> Any hint?
>
> Thanks in advance, keep up the good work!
>
> Manrico Corazzi
>
>   
> ------------------------------------------------------------------------
>
>
> --
> You receive this message as a subscriber of the [email protected] mailing list.
> To unsubscribe: mailto:[email protected]
> For general help: mailto:[email protected]?subject=help
> ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
>   



------------=_1193732654-10408-1
Content-Type: text/plain; name="message-footer.txt"
Content-Disposition: inline; filename="message-footer.txt"
Content-Transfer-Encoding: 8bit


--
You receive this message as a subscriber of the [email protected] mailing list.
To unsubscribe: mailto:[email protected]
For general help: mailto:[email protected]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws

------------=_1193732654-10408-1--