Wiki source code of EOF-Using EOF-Bulk Operations

Last modified by Ray Kiddy on 2007/09/03 13:56

Hide last authors
Pascal Robert 9.1 1 == Overview ==
Pascal Robert 3.1 2
Pascal Robert 10.1 3 The standard techniques for using EOF can potentially break down when you are dealing with extremely large datasets. The techniques described here are useful for taking advantage of EOF's benefits while not at the same time running out of memory.
Pascal Robert 3.1 4
Ray Kiddy 12.1 5 There is quite a bit of overlap between this topic and the [[Memory Management>>doc:documentation.Home.Development Architecture.EOF Architecture.EOF.EOF-Using EOF-Memory Management.WebHome]] section. It is recommended that you review the general memory management methodologies prior to reading this.
Pascal Robert 3.1 6
Pascal Robert 9.1 7 == Moving Large Amounts of Data Between Databases ==
Pascal Robert 3.1 8
Pascal Robert 9.1 9 === Chuck Hill ===
Pascal Robert 3.1 10
11 Call unlock() then dispose() on the ec, then set the reference to null, then force garbage collection with:
Pascal Robert 10.1 12 [[http:~~/~~/java.sun.com/docs/books/tutorial/essential/system/garbage.html>>url:http://java.sun.com/docs/books/tutorial/essential/system/garbage.html||shape="rect"]]
Pascal Robert 3.1 13
Pascal Robert 10.1 14 You will need to do this often with a large database, maybe more than once per entity. I don't know if that would work while maintaining the object graph.
Pascal Robert 3.1 15
Pascal Robert 9.1 16 === Pierce T Wetter III ===
Pascal Robert 3.1 17
18 There used to be an EOUtil that could do something like this. Does that still exists?
19
20 Otherwise, it depends on how the ER relationship chart works. In our case, we have a set of objects that would more or less "own" all the other objects in the ER tree. So the code would look something like this:
21
Pascal Robert 9.1 22 {{noformat}}
Pascal Robert 3.1 23
Pascal Robert 9.1 24 get master editing context
Pascal Robert 3.1 25
Pascal Robert 9.1 26 fetch copies of all the master objects into the master ec (not that many, so ok)
Pascal Robert 3.1 27
Pascal Robert 9.1 28 for each master object:
Pascal Robert 3.1 29
Pascal Robert 9.1 30 make a local ec
Pascal Robert 3.1 31
Pascal Robert 9.1 32 copy the master object into the local ec (localInstanceOfObject())
33 do stuff with master object (i.e. copy them into the sink model)
34 toss local ec
Pascal Robert 3.1 35
Pascal Robert 9.1 36 {{/noformat}}
Pascal Robert 3.1 37
38 Using the local EC is the key.
39
40 If you have a large number of master objects enough that you can't load all of them into memory at once, then it gets trickier. One way is to just fetch a list of primary keys using raw rows, then use objectWithPrimaryKeyValue() to build the objects in the local editing context.
41
42 If your ER tree is more complex (there is no "owner" object, then YMMV).
43
Pascal Robert 9.1 44 === EOImportExportApplication from Cassini ===
Pascal Robert 3.1 45
Pascal Robert 10.1 46 Cassini is available at [[Sourceforge>>url:http://sourceforge.net/projects/oce||shape="rect"]].
Pascal Robert 3.1 47
Pascal Robert 9.1 48 === Anjo Krank ===
Pascal Robert 3.1 49
50 There is some stuff in Wonder's ERXJDBCUtilities that should be able to copy from one DB to another. I never tried it, but maybe it gives you some hints. There is no real need to use EOs anyway as you just want to copy the data.
51
Pascal Robert 9.1 52 === David Teran ===
Pascal Robert 3.1 53
Pascal Robert 10.1 54 Hmpf! 'that should be able to copy from one DB to another.' NoNo, Anjo, that is not fair
55 In fact it works perfectly (% style="text-decoration: line-through;" %)if(%%) the JDBC driver is not buggy. Here is a quick documentation:
56 OK, you need to use ERExtensions and ERJars. Not a big deal, drop me a line and i'll send a demo app to you.
57 Then you need this code here, the example takes data from frontbase and saves it to a postgres database:
Pascal Robert 3.1 58
Pascal Robert 9.1 59 {{code}}
Pascal Robert 3.1 60
Pascal Robert 9.1 61 NSMutableDictionary sourceDict = new NSMutableDictionary();
62 sourceDict.setObjectForKey("", "password");
63 sourceDict.setObjectForKey("_SYSTEM", "username");
64 sourceDict.setObjectForKey("jdbc:FrontBase://195.135.143.205/merces/user=_system", "url");
65 sourceDict.setObjectForKey("com.frontbase.jdbc.FBJDriver", "driver");
66 sourceDict.setObjectForKey(Boolean.FALSE, "autoCommit");
67 sourceDict.setObjectForKey(Boolean.TRUE, "readOnly");
Pascal Robert 3.1 68
Pascal Robert 9.1 69 NSMutableDictionary destDict = sourceDict.mutableClone();
70 destDict.setObjectForKey("jdbc:postgresql://195.135.143.205/merces", "url");
71 destDict.setObjectForKey("dev", "password");
72 destDict.setObjectForKey("dev", "username");
73 destDict.setObjectForKey("org.postgresql.Driver", "driver");
74 destDict.setObjectForKey(Boolean.FALSE, "autoCommit");
75 destDict.setObjectForKey(Boolean.FALSE, "readOnly");
Pascal Robert 3.1 76
Pascal Robert 9.1 77 EOModel yourModel = EOModelGroup.defaultGroup().modelNamed("YourEOModelName");
78 ERXJDBCUtilities.copyDatabaseDefinedByEOModelAndConnectionDictionaryToDatabaseWithConnectionDictionary(yourModel, sourceDict, destDict);
smmccraw 7.1 79
Pascal Robert 9.1 80 {{/code}}
smmccraw 7.1 81
Pascal Robert 10.1 82 Thas_all!
smmccraw 7.1 83
Pascal Robert 9.1 84 === BulkMover from 360works ===
Pascal Robert 3.1 85
Pascal Robert 10.1 86 [[BulkMover>>url:http://omnivore.360works.com/360Site-3.0/dev_tools/BulkMover.tgz||shape="rect"]] provides these capabilities, though it is a ProjectBuilder project.