RE: Re: New SimpleORM Whitepaper -- Oracle locking
Anthony Berglas <[email protected]>
| Newsgroups | gmane.comp.java.orm.simpleorm |
|---|---|
| Message-ID | <[email protected]> |
SimpleORM has changed in version 3. * By default does not add FOR UPDATE. * Always uses optimistic checks as well as any database locks. Be aware that Oracle default locking with no FOR UPDATE leads to corrupted databases, see the section in the new white paper -- goes into some detail with example. If you do not use SimpleORM you must use some locking. Good point about nulls not being in indexes. There is still a read only mode, but not that useful now that FOR UPDATE is not the default. The FOR UPDATE clause may create deadlocks, or it may prevent them! This is a complex area, and hard to predict. Your application needs to be able to handle the occasional deadlock. Anthony At 02:05 AM 9/09/2008, Harry wrote: >Hi Anthony, > >About your second question : > >I don't use locking at all; I always have let Oracle handle it. After >all, this is one reason we spent all the clams on this database. >However, when using SimpleOrm v.2 with the default locking mechanism, >every SELECT was followed by a FOR UPDATE clause. >Now my DBA found the problem that caused the deadlocks : I was >querying a very large table routinely for values with the >WHERE XX IS NULL clause. And this, as I learned, >*turns off the use of indexes* in Oracle, because Oracle does not put >any NULLs in its indexes !! So these queries with their joins were >holding write locks for all records that matched the criteria, and >this for 2 to 3 minutes. When I replaced NULL with the character '0', >and the queries to look for the character '0', the indexes got used >again and query execution time dropped to a few ms; this fixed the >problem. >In my application there are a lot of values that I read that are >nomenclature values; I only read them, they get modified elsewhere >once every year or two. So it is certainly not necessary to issue a >FOR UPDATE clause for these records. They are sort of "read-only". >So some sort of "readonly" mode for SRecordInstance(s) would be nice, >I guess. > > > Harry Karadimas >______________________________________________________________________ >Dr Harry Karadimas Medecin Ingenieur >resp. Recherche et Developpement, Administration Wintel >Departement d'Information Hospitalier (DIH) >C.H.U. Albert Chenevier - Henri Mondor >51, av. du Marechal de Lattre de Tassigny 94010 CRETEIL >tel : (00 33 1) 49 81 21 79 fax : (00 33 1) 49 81 27 08 >secr.: (00 33 1) 49 81 23 82 m.el.:[email protected] > > > > > -----Message d'origine----- > > De : Anthony Berglas [mailto:[email protected]] > > Envoyé : lundi 8 septembre 2008 12:35 > > À : Harry; [email protected] > > Objet : RE: [SimpleORM] Re: New SimpleORM Whitepaper > > > > Hello Harry, > > > > Good point, I fixed isEmpty, but to the code > > below (avoids creating the trimmed object). > > > > You mentioned "Oracle Locking", what are you doing with it? > > > > Anthony > > > > public boolean isEmpty(SFieldMeta field) { > > Object obj = getObject(field); > > if (obj == null) return true; > > if (obj instanceof String) { > > String str = (String)obj; > > for (int sx=0; sx < str.length(); sx++) > > if (str.charAt(sx) != ' ') return false; > > return true; > > } > > return false; > > } > > > > At 12:54 AM 3/09/2008, Harry wrote: > > >Hi Anthony, > > > > > >I have downloaded version 3.0 and also revision 806 on svn. > > > > > >For the moment I have just recompiled and it does not recompile > > >against 1.5. Here are 2 modifications I made to make it compile > > >against 1.5 : > > > > > >------------------------------------------------------------- > > ------------------ > > >Method : > > > > > >simpleorm.dataset.SRecordInstance.isEmpty(SFieldMeta) > > > > > >Replaced > > > > > >public boolean isEmpty(SFieldMeta field) { > > > Object obj = getObject(field); > > > if (obj == null) return true; > > > if (obj instanceof String) { > > > String str = (String)obj; > > > if (str.isEmpty()) return true; > > > if (str.trim().isEmpty()) return true; // > > little expensive > > > } > > > return false; > > >} > > > > > >With > > > > > >public boolean isEmpty(SFieldMeta field) { > > > Object obj = getObject(field); > > > if (obj == null) return true; > > > if (obj instanceof String) { > > > String str = (String)obj; > > > if (str.trim().equals("")) return true; > > > } > > > return false; > > >} > > > > > >Rationale : > > > > > >String.isEmpty() only exists since java 6, and comparing > > with "" does the job > > >also. > > >Most of the time the object is not empty, so comparing with > > "" and then > > >trimming and comparing again with "" is actually more expensive than > > >systematically trimming and comparing with "". > > > > > > > > >------------------------------------------------------------- > > ------------------ > > >Method: > > >simpleorm.sessionjdbc.SQueryExecute.addJoinedSelectFields(SFi > > eldScalar[], > > >Map<SRecordMeta<?>, SSelectMode>, SRecordMeta<?>) > > > > > >Replaced > > > > > > private SFieldScalar[] addJoinedSelectFields( > > > SFieldScalar[] selectList, > > > Map<SRecordMeta<?>, SSelectMode> joinTables, > > >SRecordMeta<?> mainMeta) { > > > > > > SFieldScalar[] result = selectList == null ? > > >mainMeta.getQueriedScalarFields() : selectList; > > > for (Map.Entry<SRecordMeta<?>, SSelectMode> entry : > > >joinTables.entrySet()) { > > > int resSize = result.length; > > > if ( ! > > SSelectMode.SNONE.equals(entry.getValue())) { > > > SFieldScalar[] joinFlds = > > >entry.getKey().fieldsForMode(entry.getValue()); > > > result = Arrays.copyOf(result, > > >result.length+joinFlds.length); > > > for (int i = 0; i < > > joinFlds.length; i++) { > > > result[i+resSize] = > > joinFlds[i]; > > > } > > > } > > > } > > > return result; > > > } > > > > > >With > > > > > > private SFieldScalar[] addJoinedSelectFields( > > > SFieldScalar[] selectList, > > > Map<SRecordMeta<?>, SSelectMode> joinTables, > > >SRecordMeta<?> mainMeta) { > > > > > > SFieldScalar[] result = selectList == null ? > > >mainMeta.getQueriedScalarFields() : selectList; > > > ArrayList<SFieldScalar> resultLst = new > > >ArrayList<SFieldScalar>(Arrays.asList(result)); > > > for (Map.Entry<SRecordMeta<?>, SSelectMode> entry : > > >joinTables.entrySet()) { > > > int resSize = result.length; > > > if ( ! > > SSelectMode.SNONE.equals(entry.getValue())) { > > > SFieldScalar[] joinFlds = > > >entry.getKey().fieldsForMode(entry.getValue()); > > > > > resultLst.addAll(Arrays.asList(joinFlds)); > > > } > > > } > > > result = resultLst.toArray(new > > > SFieldScalar[resultLst.size()]); > > > return result; > > > } > > > > > >Rationale : > > > > > >Arrays.copyOf exists starting with jdk 6 only. > > >Using java collections and adding to a list is just as > > efficient, the list > > >is converted back to an array at the end. > > > > > >------------------------------------------------------------- > > ------------------ > > > > > >I am testing further aspects against my app. > > > > > >Best regards, > > > > > >Harry > > > > > > > > Harry Karadimas > > >_____________________________________________________________ > > _________ > > >Dr Harry Karadimas Medecin Ingenieur > > >resp. Recherche et Developpement, Administration Wintel > > >Departement d'Information Hospitalier (DIH) > > >C.H.U. Albert Chenevier - Henri Mondor > > >51, av. du Marechal de Lattre de Tassigny > > 94010 CRETEIL > > >tel : (00 33 1) 49 81 21 79 fax : (00 33 1) > > 49 81 27 08 > > >secr.: (00 33 1) 49 81 23 82 > > m.el.:[email protected] > > > > > > > > > > > > > -----Message d'origine----- > > > > De : Anthony Berglas [mailto:[email protected]] > > > > Envoyé : mardi 19 août 2008 04:30 > > > > À : hkara1 > > > > Objet : Re: [SimpleORM] Re: New SimpleORM Whitepaper > > > > > > > > Hello Harry, > > > > > > > > I have uploaded the new version 3.0. Is there any chance that you > > > > will have time to have a look at it, and ideally upgrade? This > > > > involves a bit of tedious typing, but should be fairly fast. > > > > > > > > (The old version is on a branch and could be pached if necessary.) > > > > > > > > Anthony > > > > > > > > > > > > >Hi, > > > > > > > > > >I welcome this change; I am heavily using Oracle with SimpleOrm > > > > >(storing and serving a few ten of thousands of > > biological results in > > > > >an 900 bed hospital), and every now and then, (once > > every month in > > > > >average) Oracle entered in a deadlock. I resolved the problem by > > > > >subclassing the Oracle driver and disabling locking, and then I > > > > >used the modified driver. > > > > >Otherwise SimpleOrm works quite well for me. > > > > > > > > > >Best regards, > > > > > > > > > >Harry > > > > > > > > > > > > > > > > > > Dr Anthony Berglas, [email protected] Mobile: +61 > > 4 4838 8874 > > > > Just because it is possible to push twigs along the ground > > > > with ones nose > > > > does not necessarily mean that is the best way to collect > > firewood. > > > > > > > > Dr Anthony Berglas, [email protected] Mobile: +61 4 4838 8874 > > Just because it is possible to push twigs along the ground > > with ones nose > > does not necessarily mean that is the best way to collect firewood. > > > > > > Dr Anthony Berglas, [email protected] Mobile: +61 4 4838 8874 Just because it is possible to push twigs along the ground with ones nose does not necessarily mean that is the best way to collect firewood. ------------------------------------ Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/SimpleORM/ <*> Your email settings: Individual Email | Traditional <*> To change settings online go to: http://groups.yahoo.com/group/SimpleORM/join (Yahoo! ID required) <*> To change settings via email: mailto:[email protected] mailto:[email protected] <*> To unsubscribe from this group, send an email to: [email protected] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/