if(!session.hasBegun()) begin() … if (!wasBegun) commit

John Abraham <[email protected]> Tue, 6 Mar 2012 15:16:49 -0700
Newsgroups gmane.comp.java.orm.simpleorm
Message-ID <[email protected]>
--Apple-Mail=_C437B89C-6CE7-4CFF-A1AF-EE26D3B25090
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=windows-1252

I have a system (calibrating a scientific simulation) that generally hits t=
he database early and grabs all the data it needs in the first 5 minutes.  =
It's been keeping the connection to the database open "Idle In Transaction"=
, which is a problem for the database since it runs for days and weeks.=20

A lot of the data never gets changed, so I've identified these and I've det=
ached a few datasets full of static data so I can query them at will and ju=
st toss them later.=20=20

But some data does get changed, and there is always a chance that some data=
 might not get queried until much later in the simulation.  So I think I ne=
ed to keep a connection open, just commit it after the initial burst of que=
ries, then <begin=85. commit> for any later queries that occur.

What's the best practice for begin.. commit wrapping like this?

I was thinking of wrapping a lot of my stuff in

boolean wasBegun =3D true;
if (!session.hasBegun()) {
   session.begin();
   wasBegun=3Dfalse;
}

=85 do my query and stuff=85.

if (!wasBegun) session.commit();


This way I can use a big begin() commit() wrap for the all the initial quer=
ies, then rely on smaller begin() commit() wraps for the stuff that occurs =
randomly later on.

What do you think of this plan?  Is there a better system?

--
John Abraham
[email protected]
--Apple-Mail=_C437B89C-6CE7-4CFF-A1AF-EE26D3B25090
Content-Type: text/html; charset=windows-1252
Content-Transfer-Encoding: quoted-printable





<head>

<style type=3D"text/css">
<!--

/* start of attachment style */
       .ygrp-photo-title{
         clear: both;
         font-size: smaller;
         height: 15px;
         overflow: hidden;
         text-align: center;
         width: 75px;
       }
       div.ygrp-photo{
         background-position: center;
         background-repeat: no-repeat;
         background-color: white;
         border: 1px solid black;
         height: 62px;
         width: 62px;
       }

       div.photo-title=20
         a,
         div.photo-title a:active,
         div.photo-title a:hover,
         div.photo-title a:visited {
           text-decoration: none;=20
       }

       div.attach-table div.attach-row {
         clear: both;
       }

       div.attach-table div.attach-row div {
         float: left;
         /* margin: 2px;*/
       }

       p {
         clear: both;
         padding: 15px 0 3px 0;
	 overflow: hidden;
       }

       div.ygrp-file {
         width: 30px;
         valign: middle;
       }
       div.attach-table div.attach-row div div a {
         text-decoration: none;
       }

       div.attach-table div.attach-row div div span {
         font-weight: normal;
       }

       div.ygrp-file-title {
         font-weight: bold;
       }
 /* end of attachment style */
        -->
        </style>
        </head>
<html><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: space; -webk=
it-line-break: after-white-space; ">




I have a system (calibrating a scientific simulation) that generally hits t=
he database early and grabs all the data it needs in the first 5 minutes. &=
nbsp;It's been keeping the connection to the database open "Idle In Transac=
tion", which is a problem for the database since it runs for days and weeks=
.&nbsp;<div><br></div><div>A lot of the data never gets changed, so I've id=
entified these and I've detached a few datasets full of static data so I ca=
n query them at will and just toss them later. &nbsp;</div><div><br></div><=
div>But some data does get changed, and there is always a chance that some =
data might not get queried until much later in the simulation. &nbsp;So I t=
hink I need to keep a connection open, just commit it after the initial bur=
st of queries, then &lt;begin=85. commit&gt; for any later queries that occ=
ur.</div><div><br></div><div>What's the best practice for begin.. commit wr=
apping like this?</div><div><br></div><div>I was thinking of wrapping a lot=
 of my stuff in</div><div><br></div><div><font class=3D"Apple-style-span" f=
ace=3D"'Courier New'">boolean wasBegun =3D true;</font></div><div><font cla=
ss=3D"Apple-style-span" face=3D"'Courier New'">if (!session.hasBegun()) {</=
font></div><div><font class=3D"Apple-style-span" face=3D"'Courier New'">&nb=
sp; &nbsp;session.begin();</font></div><div><font class=3D"Apple-style-span=
" face=3D"'Courier New'">&nbsp; &nbsp;wasBegun=3Dfalse;</font></div><div><f=
ont class=3D"Apple-style-span" face=3D"'Courier New'">}</font></div><div><f=
ont class=3D"Apple-style-span" face=3D"'Courier New'"><br></font></div><div=
><font class=3D"Apple-style-span" face=3D"'Courier New'">=85 do my query an=
d stuff=85.</font></div><div><font class=3D"Apple-style-span" face=3D"'Cour=
ier New'"><br></font></div><div><font class=3D"Apple-style-span" face=3D"'C=
ourier New'">if (!wasBegun) session.commit();</font></div><div><br></div><d=
iv><br></div><div>This way I can use a big begin() commit() wrap for the al=
l the initial queries, then rely on smaller begin() commit() wraps for the =
stuff that occurs randomly later on.</div><div><br></div><div>What do you t=
hink of this plan? &nbsp;Is there a better system?</div><div><br></div><div=
>--</div><div>John Abraham</div><div><a href=3D"mailto:[email protected]">j=
[email protected]</a></div>



<!-- |**|begin egp html banner|**| -->

<br>

=20=20=20=20
=20=20=20=20
<br>

<!-- |**|end egp html banner|**| -->


<div width=3D"1" style=3D"color: white; clear: both;"/>__._,_.___</div>

<!-- Start Recommendations -->
<!-- End Recommendations -->



<!-- |**|begin egp html banner|**| -->

  <img src=3D"http://geo.yahoo.com/serv?s=3D97476590/grpId=3D7360226/grpspI=
d=3D1705006905/msgId=3D2045/stime=3D1331072221" width=3D"1" height=3D"1"> <=
br>

<!-- |**|end egp html banner|**| -->

=20=20=20=20
<!-- |**|begin egp html banner|**| -->

<br>
      <div style=3D"font-family: verdana; font-size: 77%; border-top: 1px s=
olid #666; padding: 5px 0;" >
      Your email settings: Individual Email|Traditional <br>
      <a href=3D"http://groups.yahoo.com/group/SimpleORM/join;_ylc=3DX3oDMT=
JmMTAxNDVtBF9TAzk3NDc2NTkwBGdycElkAzczNjAyMjYEZ3Jwc3BJZAMxNzA1MDA2OTA1BHNlY=
wNmdHIEc2xrA3N0bmdzBHN0aW1lAzEzMzEwNzIyMjE-">Change settings via the Web</a=
> (Yahoo! ID required) <br>
      Change settings via email: <a href=3D"mailto:SimpleORM-digest@yahoogr=
oups.com?subject=3DEmail Delivery: Digest">Switch delivery to Daily Digest<=
/a> | <a href =3D "mailto:[email protected]?subject=3D=
Change Delivery Format: Fully Featured">Switch to Fully Featured</a> <br>
           <a href=3D"http://groups.yahoo.com/group/SimpleORM;_ylc=3DX3oDMT=
JkdnJhaTg2BF9TAzk3NDc2NTkwBGdycElkAzczNjAyMjYEZ3Jwc3BJZAMxNzA1MDA2OTA1BHNlY=
wNmdHIEc2xrA2hwZgRzdGltZQMxMzMxMDcyMjIx">
        Visit Your Group=20
      </a> |
      <a href=3D"http://docs.yahoo.com/info/terms/">
        Yahoo! Groups Terms of Use
      </a> |
      <a href=3D"mailto:[email protected]?subject=3DUns=
ubscribe">
       Unsubscribe=20
      </a>=20
 <br>
    </div>
  <br>

<!-- |**|end egp html banner|**| -->


<div style=3D"color: white; clear: both;"/>__,_._,___</div>
</body></html>
--Apple-Mail=_C437B89C-6CE7-4CFF-A1AF-EE26D3B25090--