Hi there,On 05/08/2005, at 3:35 PM, Anjo Krank wrote: Am 05.08.2005 um 07:14 schrieb Chuck Hill:
Point taken. I'll get around to utilising PW... just getting as comfortable as I can with WO first.
Although Project Wonder is, erm, wonderful, there is no need to use it to reap the benefits of prototypes. EOPrototypes are part of EOF.
Well... we have neat code that allows you to switch them based on properties and not on the mumbo-jumbo that normally gets used. And we allow you to actually support multiple types of DBs, which is not possible with the EOJDBCPrototypes.
Okay, I'm sold on Project Wonder - too many "Oh, and PW does that already..." :-) I need a bit more time before I can spend enough time to grapple with an additional setup... However, I'd advise prototypes only when you have either only one model or are very disciplined:
I've using 4 simple models. I can see the benefits even with my simple list of entities. The annoying thing, however, is with EOModeler. i.e., if I define some prototypes with properties for value type, value class, allowsNull etc but _without_ a column name - then when I assign that prototype to an attribute that already has a column name the silly thing will remove the column name after you close the model.
Just a some quirks that need ironing out with EOModeler - not the concept itself. - I don't know if that's still the case, but they get deleted when you open the model from the Finder and then save. You *must* open it from XCode
- Terrible things happen if you don't change the load order so that the model with the prototyp gets loaded first. So basically - if you have more than one model - you should have a framework just for prototypes (no code) and drag it in the load order at the top.
That's what I've done, placing an EOJDBCPrototypes model in a framework, EOPostgreSQLPrototypes.framework. Hence the use of the PostgresqlPlugIn.framework. Works well (with my slight alteration to the plugin).
What "alterations"?
The alteration was to the HexDreams 1.2 version (see below [1]). Now, you're going to tell me that Project Wonder already has a better postgresql plugin. It's okay - you can say it ;-)
-- [1] PostgresqlPlugIn.java (from HexDreams with alterations) --
public class PostgresqlPlugIn extends JDBCPlugIn { <...> public NSArray newPrimaryKeys (int count, EOEntity entity, JDBCChannel channel) { String sequenceName; PostgresqlExpression _expression_; NSDictionary row; NSMutableArray results; int i; String priKeyAttributeName; NSDictionary priKey;
NSMutableArray sequenceNames; // LD Addition
// ORIGINAL - makes a bad assumption about the sequence name! //sequenceName = entity.primaryKeyRootName() + "_SEQ"; //sequenceName = entity.primaryKeyRootName() + "_SEQ"; //_expression_ = new PostgresqlExpression(entity); //_expression_.setStatement("SELECT NEXTVAL('" + sequenceName + "')"); //results = new NSMutableArray(); //priKeyAttributeName = ((EOAttribute)entity.primaryKeyAttributes().objectAtIndex(0)).name(); //for ( i = 0 ; i < count ; i++ ) { // try { // channel.evaluateExpression(_expression_); // // There should be a single attribute called 'NEXTVAL' // channel.setAttributesToFetch(channel.describeResults()); // row = channel.fetchRow(); // channel.cancelFetch(); // priKey = new NSDictionary(row.objectForKey("NEXTVAL"), priKeyAttributeName); // results.addObject(priKey); // } catch (Exception e) { // System.out.println("Couldn't get new primary key"); // e.printStackTrace(); // } //} //return results;
// ------ LD Additions [BEGIN] --------- // LD Improvement: try differing/likely sequence names: // (1) <entityName>_<pkColumnName>_SEQ (default postgres sequence) // (2) <entityName>_SEQ (some developer's preferred name) // (3) <pkColumnName>_SEQ (unlikely but possible) sequenceNames = new NSMutableArray();
// (1): // sequenceName form: <entityName>_<pkColumnName>_SEQ sequenceName = entity.primaryKeyRootName(); sequenceName += "_"; sequenceName += ((EOAttribute)entity.primaryKeyAttributes().objectAtIndex(0)).columnName(); sequenceName += "_SEQ"; sequenceNames.addObject(new String(sequenceName));
// (2): sequenceName = entity.primaryKeyRootName() + "_SEQ"; sequenceNames.addObject(new String(sequenceName));
// (3): sequenceName = ((EOAttribute)entity.primaryKeyAttributes().objectAtIndex(0)).columnName(); sequenceName += "_SEQ"; sequenceNames.addObject(new String(sequenceName));
// Set _expression_/results objects for primaryKey _expression_ = new PostgresqlExpression(entity); results = new NSMutableArray(); priKeyAttributeName = ((EOAttribute)entity.primaryKeyAttributes().objectAtIndex(0)).name();
// Find sequence name for (i = 0; i < sequenceNames.count(); i++) { sequenceName = (String) sequenceNames.objectAtIndex(i); _expression_.setStatement("SELECT NEXTVAL('" + sequenceName + "')"); try { channel.evaluateExpression(_expression_); break; } catch (Exception e) { sequenceName = null; } }
for ( i = 0 ; i < count ; i++ ) { try { if (i > 0) channel.evaluateExpression(_expression_); // There should be a single attribute called 'NEXTVAL' channel.setAttributesToFetch(channel.describeResults()); row = channel.fetchRow(); channel.cancelFetch(); priKey = new NSDictionary(row.objectForKey("NEXTVAL"), priKeyAttributeName); results.addObject(priKey); } catch (Exception e) { System.out.println("Couldn't get new primary key"); System.out.println("No Sequences found with the following names:"); for ( int j = 0; j < sequenceNames.count(); j++) { System.out.println(" " + (String) sequenceNames.objectAtIndex(i)); } e.printStackTrace(); } } return results; }
}
|