Re: PostgreSQL Adaptor and Plugin
Re: PostgreSQL Adaptor and Plugin
- Subject: Re: PostgreSQL Adaptor and Plugin
- From: Michael Parlee <email@hidden>
- Date: Thu, 11 Nov 2004 22:41:21 -0800
Johan,
It is relatively easy to make a custom primary key generation delegate. Just construct your sequence names according to your own convention. Then assign the delegate as the default in your Application constructor like so:
EODatabaseContext.setDefaultDelegate(new MyPostgresKeyGenerationDelegate());
the delegate code:
import com.webobjects.eoaccess.*;
import com.webobjects.foundation.*;
import com.webobjects.eocontrol.EOEditingContext;
import er.extensions.ERXLogger;
public class MyPostgresKeyGenerationDelegate {
/** logging support */
public final static ERXLogger log = ERXLogger.getERXLogger(MyPostgresKeyGenerationDelegate.class);
public NSDictionary databaseContextNewPrimaryKey(EODatabaseContext dbCtxt, Object object, EOEntity entity) {
// I only do this for single primary keys. I leave compound keys to fail.
if (entity.primaryKeyAttributes().count() == 1) {
// construct sequence name from primary key
NSArray entityPrimaryKeys = entity.primaryKeyAttributeNames();
String pkName = (String)entityPrimaryKeys.objectAtIndex(0);
String sequenceName = "seq_" + EOEntity.externalNameForInternalName(pkName, "_", false);
// increment sequence to obtain pk value
NSArray rawRows = EOUtilities.rawRowsForSQL(new EOEditingContext(),"MyModel",
"select nextval('"+sequenceName+"')",
new NSArray(new String[]{"nextval"}));
NSDictionary rowWithPK = (NSDictionary)rawRows.objectAtIndex(0);
Object maxPK = rowWithPK.objectForKey("nextval");
// create new primary key dictionary with the new value.
NSMutableDictionary newPrimaryKey = new NSMutableDictionary();
newPrimaryKey.takeValueForKey(new Integer(maxPK.toString()), pkName);
return newPrimaryKey;
}
return null;
}
}
Cheers,
Mike
On Nov 11, 2004, at 7:46 AM, Johan Henselmans wrote:
On 11-nov-04, at 16:18, Arturo Perez wrote:
Benjamin J Doherty wrote:
On Nov 10, 2004, at 2:47 PM, Arturo Perez wrote:
I've worked on the pgSQL plugin in the past and I've not had these problems. Usually the above is caused by not having the necessary SEQUENCE in place.
maybe we're talking about two different plug ins:
the hexdreams plug in DOES require sequences. it's also required for EOModeler to generate valid postgresql SQL scripts.
the wonder plug in will create a sequence when one does not exist. it does it on the fly. it happens to be that it will create a sequence with the same name as the one created by the hexdreams EOM Plugin.
Right. But the sequence still needs to be there one way or another. So, maybe the plug has a problem creating the sequence. Did you try creating the sequence yourself and seeing if the problem goes away?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
It seems to me that the wonder plugin is very picky on what is a proper sequence. I have used the HexDream plugin for years, and wanted to try the wonder plugin. Unfortunately, the wonder plugin did not recognize the sequences that had been used for year as proper plugins for the database and wanted to create it's own sequences. That was where I bailed out. The auto-generation of sequences is fine, but it should be able to recognize existing sequences.
The reason some people don't have these problems is that they are apparently hava a database with the sequences that the wonder plugin expects, or create a new database (where the problem will not occur, of course).
-johan
Johan Henselmans
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden