Rants, rambles, news and notes from another geek

Geek Notes 2003-11-09

Took yesterday off and didn’t touch my computer. Today I’m at work (ugh) and taking a 10 minute break to see what’s happened while I wasn’t looking…

PDC - Hands on Lab Content?

Has anyone found the HOL content online anywhere? I found the ASP.NET Whidbey HOLs on the [ASP.NET Site]((http://www.asp.net/whidbey/pdc.aspx?tabindex=0&tabid=1), but I’d like to find the rest… particularly the Longhorn labs.

Please tell me they will be posted somewhere… they’re just Word docs!

UPDATE: Benjamin pointed out in the comments that if I had dug a little deeper into MyMsEvents.com I would have found them. Thanks!

Geek Notes 2003-11-07

OK, I’ll admit I’ve been thinking about copying Mike Gunderloy’s posting style for a long time now… I finally decided today to give it a shot. Here’s how this will work:

  1. Links and such will be collected into one post instead of many small posts
  2. Original content or things that require more comment by me will get full posts of their own

That said, here is the Nov 7 2003 edition of Geek Notes:

PS. I know there are other pages and such out there called Geek Notes. I don’t care. This is my Geek Notes. :)

Technology Predictions Gone Wrong...

Thanks to Werner Vogels for posting this list… I immediately made a PowerPoint for when I’m giving presentations. If anyone has any more good ones, post them to your blog or in my comments. Thanks!

Back to the Blog...

After all that PDC blogging, I needed a few days away from this thing. I’m trying to catch up on my RSS feeds, but I have to admit to doing a bunch of “Mark All Read” to help me out. Oh well… anything really important will show up in more than one place, right?

Here are some of the interesting things that I found today:

That’ll do for├é now…

Geman Official Language of California

This made me laugh:

The New California Governor has just announced an agreement whereby English will be the official language of the state, rather than German, which was the other possibility. As part of the negotiations, The Terminator’s Government conceded that English spelling had some room for improvement and has accepted a 5-year phase-in plan that would become known as “Austro-English” (or, perhaps even better, “Austrionics”.)

In the first year, “s” will replace the soft “c”. Sertainly, this will make the sivil servants jump with joy. The hard “c” will be dropped in favour of the “k”. This should klear up konfusion, and keyboards kan have one less letter. There will be growing publik enthusiasm in the sekond year when the troublesome “ph” will be replaced with the “f”. This will make words like fotograf 20% shorter.

In the 3rd year, publik akseptanse of the new spelling kan be expekted to reach the stage where more komplikated changes are possible. Governments will enkourage the removal of double letters which have always ben a deterent to akurate speling. Also, al wil agre that the horibl mes of the silent “e” in the languag is disgrasful and it should go away.

By the 4th yer peopl wil be reseptiv to steps such as replasing “th” with “z” and “w” with “v”. During ze fifz yer, ze unesesary “o” kan be dropd from vords kontaining “ou” and after ziz fifz yer, ve vil hav a reil sensibl riten styl. Zer vil be no mor trubl or difikultis and evrivun vil find it ezi tu understand ech oza. Ze drem of a united urop vil finali kum tru. If zis mad yu smil, pleas pas it on to oza pepl.

Ha ha ha ha ha… “oza pepl”.

PDC - Attendee Party @ Universal Studios

Man… got a bit of a hangover this morning… Ugh.

When I arrived at the park with my coworkers, I immediately ran into the blogger meeting near the front. Too many tech bloggers to list here… needless to say, Scoble, Werner and Canter were the loudest.

The blogger group wandered around from beer station to beer station for an hour or two before splitting up. I ended up near the back hanging out with Werner Vogle, Jamie Cansdale and a few others. I really enjoyed getting to know Werner. He is a research professor with Cornell. Very cool guy. If you deal with anything in distributed computing, you should certainly be reading his blog.

Later in the evening Harry Pierson (aka DevHawk) came by and drank with us. I talked to too many bloggers to remember them all, so I won’t try anymore.

UPDATE: Werner has posted some photos from the party.

PDC - .NET Framework: Developing Applications Using the New Object-Relational Technologies in "Whidbey" - ADO.NET ObjectSpaces

I just got out of this session and am writing this from the bus on the way back to my hotel. From there we are off to Universal Studios for the attendee party. They’ve rented out the entire place for just us! Kick ass.

If you’ve read my blog for long, you’ve probably heard me rave about code generation tools like CodeSmith and LLBLGen. I’ve written a number of Object Relational Mapper (ORM) tes in CodeSmith and I’ve demoed LLBLGenPro. Both techniques work well, but I’ve always wanted something built into the framework. The ones I wrote were specifically for my needs and didn’t support things like relationships, lazy loading of child relationships, etc. LLBLGen supports some of that, maybe all, but it is still essentially a code generator.

I’ve been hearing about ObjectSpaces for a while now but it has been very hard to get any information about it. And with all the hype about the other Whidbey and Longhorn technologies, it seemed to be ignored by the community.

ObjectSpaces is three things:

  1. System.Data.ObjectSpaces is the namespace containing the core ORM subsystems in Whidbey
  2. Microsoft.Data.ObjectSpaces (or something like that) contains utilites for generating databases from object graphs and vice versa
  3. VS.NET (Whidbey) will have a very cool editor for mapping table and columns to objects and fields.

This stuff appears to be exactly wat I was hoping for. I tried my best to copy the code from the demos below, and for this kind of this the code is the best way to see what is going on. I cannot guarantee that this code is correct, and it certainly will not compile, as I was typing it in on the fly as the presenter switched between slides and code. But it is close enough to give you an idea of what I was seeing. Unfortunately I didn’t catch all of the code for ObjectSpaces -> ADO.NET interop (case 5), but I’m sure that will be pretty straightforward. This is the Good Stuff.

Look in the switch statement to see how database initialization, reading and then updating work. This stuff is VERY cool and is going to save us business app developers TONS of time and code.

Enjoy!

using Microsoft.Data.ObjectSpaces;
  
using System;
  
using System.Collections;
  
using System.Data.ObjectSpaces
  

  
public class Continent
  
{
  
 public Continent(string name, int area)
  
 {
  
  Name = name;
  
  Area = area;
  
 }
  
 public string Name;
  
 public int Area;
  
 public ArrayList Countries = new ArrayList();
  
 
  
 // Required? for object spaces
  
 private Continent();
  
}
  

  
public class ContinentDelayLoad
  
{
  
 public Continent(string name, int area)
  
 {
  
  Name = name;
  
  Area = area;
  
 }
  
 public string Name;
  
 public int Area;
  
 public ObjectList Countries = new ObjectList();
  
 
  
 // Required? for object spaces
  
 private Continent();
  
}
  

  

  
public class Country
  
{
  
 public Country( string Name, int pop, Continent cont ) { ... }
  
 public string Name;
  
 public int Population;
  
 public ArrayList Cities = new ArrayList()l
  
 public Continent Continent;
  
 private Country() {};
  
}
  

  
public class City
  
{
  
 public City() string name, int numberOfCats, Country myCountry )
  
 {
  
  _Name = name;
  
  NumberOfCats = numberOfCats;
  
  Country = myCountr;
  
 }
  

  
 private string _Name;
  
 
  
 public string Name
  
 {
  
  get { return _Name; }
  
  set { _name = value; }
  
  
  
 }
  
 
  
 public int NumberOfCats;
  
 public Country Country;
  
 private City() {}
  
}
  

  
public class WorldDriver
  
{
  
 static void InitializeDatabase()
  
 {
  
  Continent asia = new Continent("Asia", 17110 );
  
  ...
  
  
  
  Country china = new Country( "usa", 111, asia );  
  
  ...
  
  
  
  City beijing = new City( "Beijing", 1112, china );
  
  ...
  
  
  
  // This is not part of ObjectSpaces per se, it is used to generate a database based on a graph. If we already have a database
  
  // we don't need to do this. This is NOT part of the System.ObjectSpaces namespace.
  
  ObjectPersisitence op = new ObjectPersistence( "Data Source=(local); Integrated Security=true;", "World" );
  
  
  
  Print("Persisting Asia");
  
  op.Persist( asia );
  
  op.Persist( asia.COuntries );
  
  foreach( Country c in asia.Countries )
  
  {
  
   op.Persist( c.Cities );
  
  }
  
 }
  
 
  
 static void Main( int argc, char[] argv )
  
 {
  
  int whichDemo = Int32.Parse( argv[1] );
  
  
  
 
  
  switch( whichDemo )
  
  {
  
   case 1: //Build database
  
    InitializeDatabase();
  
    break;
  
    
  
   case 2: // Load graph of objects
  
    os = new ObjectSpace("World.msd.xml", cn);
  
    ObjectSet oset = os.GetObjectSet( typeof(City), "", "" );
  
    
  
    // Using OPath to filter
  
    // ObjectSet oset = os.GetObjectSet( typeof(City), "NumberOfCats < 1000", "" );
  
    // ObjectSet oset = os.GetObjectSet( typeof(City), "NumberOfCats < 1000 and Country.Population < 10000000", "" );
  
    // ObjectSet oset = os.GetObjectSet( typeof(City), "Name='Albisola'", "" );
  
    
  
    // Using span to get early loading (these load a predefined amount of the object graph)
  
    // ObjectSet oset = os.GetObjectSet( typeof(Continent), "", "Countries" ); // Tells it to load the countries too!
  
    // ObjectSet oset = os.GetObjectSet( typeof(Continent), "", "Countries.Cities" ); // Tells it to load the countries and the cities!
  
    
  
    Print( oset );
  
    break;
  
    
  
   case 3: // Update an object graph (optimistic concurrency -- first save wins)
  
    os = new ObjectSpace("World.msd.xml", cn);
  
    
  
    City gt = (City) os.GetObject( typeof(City), "Name='Absiola');
  
    
  
    Print("Got it");
  
    
  
    // Modify the object
  
    gt.NumberOfCats = new Random().Next();
  
    
  
    // Save it
  
    try
  
    {
  
     os.PersistChanges(gt);
  
    }
  
    catch( Exception e )
  
    {
  
     os.Rollback();
  
    }
  
    
  
    break;
  
    
  
   case 4: // Update an object graph (with transactions second to read will wait for the first to commit or not before saving)
  
    os = new ObjectSpace("World.msd.xml", cn);
  
    
  
    os.BeginTransaction( IsolationLevel.RepeatableRead);
  
    City gt = (City) os.GetObject( typeof(City), "Name='Absiola');
  
    
  
    Print("Got it");
  
    
  
    // Modify the object
  
    gt.NumberOfCats = new Random().Next();
  
    
  
    // Save it
  
    try
  
    {
  
     os.PersistChanges(gt);
  
     os.Commit();
  
    }
  
    catch( Exception e )
  
    {
  
     os.Rollback();
  
    }
  
    
  
    break;
  

  
   case 5: // ADO.NET Interop
  
    string cs1 = "DataSource=(local);Integrated security=true;...";
  
    string query = "select top 3 * from coutnry";
  
    
  
    SqlCommand cmd = new SqlCommand( query, new SqlCOnnection(cs1) );
  
    
  
    SqlDataReader r = cmd.ExecuteReader();
  
    
  
    MappingSchema map = new MappingSchema("Woeld.msd.xml");
  
    DbObjectReader reader = new DbObjectReader( r, typeof(  ) );
  
    
  
    // Didn't catch the rest of this but you can imagine what is going on here...
  
    
  
    
  
    break;
  
    
  
  }
  
 }
  
 
  
 static void Print( string s ) ...
  
 static void Print( IList c ) ...
  
 static void PrintContinents( IEnumerable e ) ...
  
 static void PrintCountries( IEnumerable e ) ...
  
 static void PrintCities( IEnumerable e ) ...
  
}