Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[stellation-res] Yet another DB abstraction idea...

I'm still unhappy with the DB abstraction stuff. It's still too darned
hard to read and to write. Following some suggestion, I took
a look at Jakarta Velocity. Velocity is clearly an overkill, and I'm
not suggesting that we push that into the code. But looking at it,
it struck me that we can easily throw together a lightweight dynamic
template system, which will be really easy to read and write.

So... Going back to the example that I keep using:

> > Here's the original SQL:
> >
> > 	CREATE TABLE Properties (INTEGER aid,
> > 					        INTEGER vid,
> > 					        INTEGER inheritable,
> > 						VARCHAR(200) name,
> > 						VARCHAR(1600) value,
> > 			CONSTRAINT fk3 FOREIGN KEY (aid, vid) REFERENCES Versions(aid, vid)
> > 			PRIMARY KEY(aid, vid, name))
>
> OK... Here's the new version:
> AbstractDatabase db;
> String command = "CREATE TABLE Properties" +
> 		db.getIntegerType() + " aid, " +
> 		db.getIntegerType() + " vid, " +
> 		db.getIntegerType() + " inheritable, " +
> 		db.getShortStringType() + " name, " +
> 		db.getLongStringType() + " value," +
> 	        "CONSTRAINT fk3 FOREIGN KEY (aid, vid) " +
> 		" REFERENCES Versions(aid, vid), " +
> 		 "PRIMARY KEY(aid, vid, name)" +
> 		 db.getCreateTrailer();

The template version would be:

String command = 
	db.expandCommand("CREATE TABLE Properties " +
		"($INT aid, $INT vid, $INT inheritable, $SHORTSTRING name" +
		"$LONGSTRING value, " +
		"CONSTRAINT fk4 FOREIGN KEY (aid, vid) REFERENCES Versions(aid,vid), " +
		"PRIMARY KEY(aid, vid, name))$CREATE_TRAILER");

DB implementations would provide a set of mappings of keywords to
the appropriate value for the database.

It looks like SQL, it's easy to write, and it'll be easy to implement. Seems
like an obvious answer, much less stupid than the earlier idea. What do
you all think?

	-Mark


-- 
Mark Craig Chu-Carroll,  IBM T.J. Watson Research Center  
*** The Stellation project: Advanced SCM for Collaboration
***		http://www.eclipse.org/stellation
*** Work Email: mcc@xxxxxxxxxxxxxx  ------- Personal Email: markcc@xxxxxxxxxxx




Back to the top