Thursday, November 13, 2008

Java persistence thought

I had a thought about Java there are number of persistent object systems and database links but my perception of them is that they are all rather complicated ( to define the relations between the two). 

I'm wondering if it would be better to think about making databases that look like a collection class. For example you might say

Map m  = new DatabaseMap( Address.class, // so we can make new ones. 
"mySimpleAddressDB" ,// name of table defaults to stored class name  
"username" , "pasword" // with standard defaults.
DatabaseMap.MYSQL_driver ) // database driver to use 

m.put( 34 , jonAddress ) ; // inserts  0verrides 
m.update( 34, jonAddress ) ; // update this item 
jonAddess = m.get( 34) ;  // override fetch 

for( Address a : m ) { println(a.toString(); } // look over whole table. 
for(DBMapQurey itter = m.itterator('WHERE name like 'bob') ; itter.empty(); a = itter.next())
println(a.toString(); 
} // extension to implement filter. 

This the map would look like a map to a programmer but operate exclusively on disk base storage. The Map uses methods of the class to get the values for address and gets/sets them. 

This would be a zero configuration approach to databases but limit people to simple objects. Worst case use annotations ( @db_field_name('INDEX' )  or @db_IS_PRIMAY_INDEX to help line up information between the class and the database.

Shurly someone must have done this -but what is it called?

No comments: