Franck Routier | 4 Mar 2013 11:43
Favicon

Insert/select...

Hi all,

I have added a new SInsertSelect construct in SimpleORM.

This is a low level tool to generate insert into ... select ... style 
sql based on Metas and SQueryTransient.
This has the advantage of:
- using object oriented SRecordMeta and SFieldScalar to build your query
- delegating the work to the database, which will be the most efficient 
at this task

But keep in mind this is a low level trick, closer to jdbc than to an 
ORM tool.
In particular:
- this will bypass any validation done by 
SRecordInstance.onValidateRecord().

So that said, here is how it works... Lets say you have a sales order 
table, and a stats tables.
You can do the following:

SQueryTransient qryTrs = new SQueryTransient(new SQuery<Order>(Order.meta));
qryTrs.groupBy(Order.productId).groupBy(Order.month).avg(Order.amount).selectRaw("nextval('mysequence')");

SInsertSelect<Stats> insSel = new SInsertSelect(Stats.meta, qryTrs);
insSel.addField(Stats.productId).addField(Stats.month).addField(Stats.averageOrder).addField(Stats.id);

session.begin();
session.rawInsertSelectNoFlush(insSel);
session.commit();
(Continue reading)

Franck Routier | 4 Feb 2013 15:17
Favicon

Re: Adding batch update support in SimpleORM

Hi Noël,

in fact the SDriver must announce if it supports batching or not.
In SDriver, we use this code to tell that :

DatabaseMetaData dbmeta = session.jdbcConnection.getMetaData();
              if (dbmeta != null) {
                  if (dbmeta.supportsBatchUpdates()) {
                      return true;
                  }
              }

But if metadata lies, we can override that method and force public 
boolean supportsBatchUpdates to return false in SDriverXXXX.

Franck

Le 04/02/2013 15:05, Noel Grandin a écrit :
>
> On 2013-02-01 18:22, Franck Routier wrote:
>>
>> I just commited a modification that add jdbc batch support in SimpleROM.
>>
> Cool!
>
>> By default, everything works as before, so this should have no impact 
>> on running projects.
>>
> Good, because not all JDBC drivers support batching (e.g. H2).
>
(Continue reading)

Franck Routier | 2 Feb 2013 15:21
Favicon

Re: Adding batch update support in SimpleORM

Hi Anthony,

Le 02/02/2013 01:42, anthony berglas a écrit :
 

Excellent work. 


Thanks :-)

(The batching is all wrong in JDBC/Dbs.  It should be just send any unrelated statements to the db, have them execute, and return a list of results for each.  I have recently been working on KMIP, which almost gets that aspect right.)

What sort of performane improvements did you get for Oracle and Postgresql?
First of all, let me say our banchmark tests are probably not totally accurate. Running Insert, then batch insert does not give the same result than in reverse order. The second test runs always a bit faster, so I did put batchInsert before insert to make sure there is a real gain...

On Postgres running localy (on SSD), I get the follonwing result:

[java] [no Session]  ------ simpleormBatchInsert                    90   (119) (microsecond/row) [Statistics Trans: 12 Flush: 10006 Finddb: 10009 Querydb: 0 CurTim: 1359812349318]
[java] [no Session]  ------ simpleormInsert                         242   (119) (microsecond/row) [Statistics Trans: 13 Flush: 20006 Finddb: 20012 Querydb: 0 CurTim: 1359812351745]

So batching is almost 3 time faster than row by row flush on Postgres. It's even kicker than raw jdbc (well, I expected so).

On Oracle, my tests run on a LAN Virtual Machine running a non optimized Oracle install.

jdbc : ~1500 microsecond/row
simpleormBatchInsert : ~50 microsecond/row (!!)
simpleormInsert : ~2500 microsecond/row

Here the result is really spectacular, as network overhead really counts in this situation.
I also think that batching in Oracle jdbc is much more efficient than with Postgres.
I think that Postgresql network protocol only allows for one parameter set to be sent at once (see  http://www.postgresql.org/docs/9.2/static/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY). Some initialisation steps are saved, but sending parameters is done multiple time... So basically with Postgres, PreparedStatement is created once and cached but each parameter set is sent separately (confirmed by running visualvm).

I'm going to make tests on a real life example on monday on a workload that takes about one hour (on Postgres), 60% of the time creating similar new records in the database.

Best regards,
Franck
Attachment (smime.p7s): application/pkcs7-signature, 4477 bytes
Franck Routier | 1 Feb 2013 17:22
Favicon

Adding batch update support in SimpleORM

Hi all,

I just commited a modification that add jdbc batch support in SimpleROM.

By default, everything works as before, so this should have no impact on 
running projects.

But SSessionJdbc now has a method setUseBatchUpdate(boolean useBatch) 
that will change its behaviour: when set to true, flushing will try to 
use batch.

For all subsenquent dirty records in the dataset that result in the same 
sql statement, it will create one only batch with different parameters, 
and execute that batch in one jdbc call.
If the statement changes, it will execute the current batch and create a 
new one.
This will be particularly useful if you want to insert or update a bunch 
of records of the same SRecordMeta, on the same columns. Then the whole 
dataset will be treated in one batch.
The main gain is that the network overhead is minimized when sending the 
jdbc command.

Benchmark shows significant performance improvements, even locally, with 
Hsql (default ant target), Postgresql and Oracle. I could not test other 
databases.

Oh, great, so why not make it the default ?

Well, this has a cost: as all (similar) records are sent in one batch, 
it is much more difficult to find the faulty record in case of a 
SQLException.
For example, if one of your records breaks a constraint in the database, 
you will get a SExecption.Jdbc error, but the getInstance() method will 
return null, and you won't have acces to the faulty record...

The other tradeoff, is that some SGenerator don't play well with this 
approach.
Specifically, those that try to get the generated key after the record 
is inserted, like SGeneratorInsertIdentity.
Then, if useBatchUpdate is set to true, it will gracefully fallback to 
the traditional flush(ri)... Notice that Hibernate behaves the same with 
IDENTITY.
If someone has an idea of a solution to that problem, I still created a 
void postUpdateWithGeneratedKey(SSessionJdbc session, SRecordInstance[] 
dirtyRecords, int[] result).
This method is called after the batch is executed, and has an array of 
all records in the batch... Then, I don't know what to do to get the 
ids... (I don't use IDENTITY at all on my projects).

Finally, I didn't test some databases I don't have access to: MS 
SqlServer for example. There might be some work to do on the method 
SDriverXXX.checkBrokenOptimisticLock, if the driver does not return 1 or 
Statement.SUCCESS_NO_INFO (-2) on success (MS SqlServer might return 
more than one, including records modified by triggers, etc...). That 
said, batchUpdate is off by default, so it does not break anything.

I added a benchmark test. I also ran all the tests with batchUpdate=true 
as default, and nothing broke, so I am pretty confident this works, but 
any feedback is welcome !

Best regards,

Franck

Attachment (smime.p7s): application/pkcs7-signature, 4477 bytes
Franck Routier | 30 Jan 2013 18:57
Favicon

New functionality in SQueryTransient, to retrieve data without grouping

Hi,

I have just added and commited a possibility in SQueryTransient to do:

trsQry.selectField(String tableAlias, SFieldScalar fld);

Of course, the same SQueryTransient cannot mix aggregate functions and 
selectFields.

This allows to create a query using SimpleORM objects and metadata, and 
to retrieve arbitrary fields from the relation without doing any 
aggregate nor creating SRecordInstances.
So you use Query part of our beloved ORM, and not the true ORM.
Much like doing jdbc and getting the ResultSet, but using SRecordMeta, 
SFieldMeta, SQuery joins, getting the SRecordGeneric casting 
capabilities, using the SDriver, etc...

Hope this will be useful to some of you. Any comment will be welcome, of 
course.

Regards,

Franck

Attachment (smime.p7s): application/pkcs7-signature, 4477 bytes
jea | 22 Jan 2013 00:48
Gravatar

Sourceforge SVN repository not working?

Strangely, I can't connect to the sourceforge svn repository at the recommended url

http://simpleorm.svn.sourceforge.net/svnroot/simpleorm/trunk/simpleorm

nor at the "version 2" url 

http://svn.code.sf.net/p/simpleorm/MOUNTPOINT/

Mind you, viewing the code using a web browser at
http://simpleorm.svn.sourceforge.net/viewvc/simpleorm/
seems to work. 

Is sourceforge having problems?  Weird...  Below is the error message

--
John 

Unable to connect to a repository at URL
 'http://simpleorm.svn.sourceforge.net/svnroot/simpleorm/trunk/simpleorm'
OPTIONS of
 'http://simpleorm.svn.sourceforge.net/svnroot/simpleorm/trunk/simpleorm':
 could not connect to server (http://simpleorm.svn.sourceforge.net)

------------------------------------

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:
    SimpleORM-digest <at> yahoogroups.com 
    SimpleORM-fullfeatured <at> yahoogroups.com

<*> To unsubscribe from this group, send an email to:
    SimpleORM-unsubscribe <at> yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/

jea | 20 Dec 2012 23:35
Gravatar

Help! License is...

A client has asked me to specify the libraries I use and their licenses, to ensure that I have permission to
release my entire project under Apache V2.

On the SimpleORM website is says "Apache style license".  I can't find any documentation of the actual
license used...  If you haven't decided, then Apache V2 would be the most convenient.

Thanks for your (hopefully prompt) response!

--
John 

------------------------------------

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:
    SimpleORM-digest <at> yahoogroups.com 
    SimpleORM-fullfeatured <at> yahoogroups.com

<*> To unsubscribe from this group, send an email to:
    SimpleORM-unsubscribe <at> yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/

Joachim Durchholz | 16 Jun 2012 00:03

Hooking into row loading?

Hi all,

is there a way to hook into the row loading process of SimpleORM?
I need to do some processing on the rows before the application sees them.

Regards,
Jo

P.S.: In case anybody is interested: I'm toying with ideas to cope with 
database schema version upgrades. I control the schema and its 
evolution, which helps a lot, but I can't take the application offline 
so I need to do conversions on the fly, i.e. during load.
I'm well aware that I need to handle a few more details than just 
loading, but that's the problem that I currently don't know how to solve :-)

------------------------------------

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:
    SimpleORM-digest <at> yahoogroups.com 
    SimpleORM-fullfeatured <at> yahoogroups.com

<*> To unsubscribe from this group, send an email to:
    SimpleORM-unsubscribe <at> yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/

Noel Grandin | 4 Jun 2012 11:23

[PATCH] fix for bug in SRecordGeneric [1 Attachment]

<*>[Attachment(s) from Noel Grandin included below]

Hi

There is a bug in SRecordGeneric.getBoolean that manifests in some odd 
situations.

Patch attached.

Regards, Noel Grandin

Disclaimer: http://www.peralex.com/disclaimer.html

<*>Attachment(s) from Noel Grandin:

<*> 1 of 1 File(s)
http://groups.yahoo.com/group/SimpleORM/attachments/folder/266025043/item/list 
  <*> patch.txt

------------------------------------

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:
    SimpleORM-digest <at> yahoogroups.com 
    SimpleORM-fullfeatured <at> yahoogroups.com

<*> To unsubscribe from this group, send an email to:
    SimpleORM-unsubscribe <at> yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/

Noel Grandin | 3 Feb 2012 07:59

[patch] add CLOB datatype [1 Attachment]

<*>[Attachment(s) from Noel Grandin included below]

Hi

The attached file adds the CLOB datatype.

Regards, Noel Grandin

Disclaimer: http://www.peralex.com/disclaimer.html

<*>Attachment(s) from Noel Grandin:

<*> 1 of 1 File(s)
http://groups.yahoo.com/group/SimpleORM/attachments/folder/838970561/item/list 
  <*> SFieldClob.java

------------------------------------

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:
    SimpleORM-digest <at> yahoogroups.com 
    SimpleORM-fullfeatured <at> yahoogroups.com

<*> To unsubscribe from this group, send an email to:
    SimpleORM-unsubscribe <at> yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/

anthony berglas | 3 Feb 2012 01:36

Re: Long Time No See - from Bartek Muszynski

Hello Bartek,

Good to hear from you.  

Your approach, as I understand it, seems roughly correct.  Having the DB Table as the union of fields rather than splitting them over multiple tables is generally the best option.  Discriminator should probably default to a string, so nice for reporting tools.  Obviously all subtypes would need the same key -- not sure what is the best way to handle common fields in a super class as currently SFieldMetas have a SRecordMeta.  So that could become quite messy.

However, standing back, I really do wonder whether this really adds a lot of value to offset the substantial added complexity.  One of the important issues is to decide what not to implement.  There is a lot of detail in doing something like this, eg. how does it affect Queries (Including queries across the subtypes)?  (One issue is that in a database, subtypes can change -- the student can become a lecturer -- but in Java they are fixed.)

I think that a read mostly cache could add more real value.  But it is also tricky to get right.  I also wonder if we could utilize something like EH-Cache, but have not thought about it much. But I would probably prefer to improve the existing querying of disconnected SDataSets.

I do hope that you submit improvements to the main repository.  But they have to be sound, with test cases, and not break other peoples code.

There is a list of little things that need to be done, which should probably be tackled first.

I have forwarded this to the list.  What do others think the priorities are?

Regards,

Anthony

On Wed, Feb 1, 2012 at 10:33 AM, Bartek Muszynski <bartek <at> auroracontrol.com> wrote:

Hi Anthony,

 

Do you remember me? I helped implement join() functionality in SimpleORM about 7 or 8 years ago!

 

Wow, I like the changes I’ve seen since then. And yet, it still simple and elegant!

 

After working at Epic Data, I ran my own business for about 6 years, where I used SimpleORM which I ported to C#. It worked great.

 

Now, I just started a new job and plan to use SimpleORM once again. I’ve taken a snapshot of the source, and I plan to implement the following features:

 

1.       Ability to store classes which are part of an inheritance hierarchy. I plan to implement this, roughly, as follows:

a.       The DB table would contain the union of all fields of all classes in a hierarchy

b.      It would also contain a special ‘Discriminator’ field (of datatype ‘int’) which indicates which class should be instantiated

c.       Add overloaded constructor to SRecordMeta which, rather than just taking a Class object, takes a Map of discriminator values to Classes)

d.      Postpone the call to SRecordMeta.newRecordInstance() until the actual DB access has been made, so that the discriminator is read and the proper class can be created

e.      Since right now you use an otherwise empty SRecordInstance to hold and pass the key (or even a NullKey value), this would have to be changed to just create and pass the key value fields, rather than the object.

 

2.       Ability to have a detached DataSet where an SSessionJDBC looks into to resolve records before going to the DB. This is the idea of a “Read Mostly” cache that you hinted at in earlier code, though I think never implemented. This is useful because in a typical DB application there is a large set of tables with very static data, and tons of DB accesses can be saved by caching this data between transactions. Please let me know if the current version of SimpleORM can do this already.

 

Questions:

Ø  Are you interested in putting any of these features into the official SimpleORM?

Ø  Did you ever make any money of SimpleORM? I’m curious for two reasons:

o   It’s such a great tool, and you deserve it

o   I’m considering launching my own Open Source project (related to test automation) and am curious about others’ experience in this area.

 

Bye for now.

I hope to hear from you soon, and all the best!

 

Bartek J

 

PS. After I make the above changes in Java, I plan to port the new version to C# again.

 

 

Bartek Muszynski

Senior Software Architect

Aurora Control Technologies Inc.
+1 778-241-5000

www.auroracontrol.com


 




--

Dr Anthony Berglas, anthony <at> berglas.org       Mobile: +61 4 4838 8874
Just because it is possible to push twigs along the ground with ones nose
does not necessarily mean that that is the best way to collect firewood.




__._,_.___

Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___

Gmane