Thursday, October 13, 2005

NHibernate 1.0 and Firebird

I've some experiences with Hibernate 2.1 but never touch NHibernate.
It's first time I play around NHibernate, just because I want to test it.
I found that NHibernate meets my all criterias (create DDL, gen mapping on the fly, etc.) to enable MDA.
I use mapping attributes from NHibernateContrib to model a domain class (see below).


// new configuration
Configuration config = new Configuration();
// set properties
IDictionary props = new Hashtable();
props["hibernate.connection.provider"] =
"NHibernate.Connection.DriverConnectionProvider";
props["hibernate.dialect" ] =
"NHibernate.Dialect.FirebirdDialect";
props["hibernate.connection.driver_class"] =
"NHibernate.Driver.FirebirdDriver" ;
props["hibernate.connection.connection_string"] =
"User=SYSDBA;Password=masterkey;" +
"Database=C:\\workspace\\FirebirdNET\\test.fdb;" +
"DataSource=;Port=3050;Dialect=3;Charset=NONE;Role=;" +
"Connection lifetime=0;Connection timeout=15;" +
"Pooling=True;Packet Size=8192;Server Type=0";
config.AddProperties(props);

// auto-generate Hbm on-the-fly
using( MemoryStream stream = new MemoryStream() ) {
HbmSerializer.Default.Serialize(stream, typeof(TestClass));
stream.Position = 0;
config.AddInputStream(stream);
}

// create database schema
SchemaExport s = new SchemaExport(config);
s.Create(true, true);

sf = config.BuildSessionFactory();

// create an object, then save
using(ISession ss = sf.OpenSession()) {
ITransaction tx = ss.BeginTransaction();
TestClass tc = new TestClass();
tc.Id = 1;
ss.Save(tc);
tx.Commit();
ss.Close();
}

// try find the object as IList
using(ISession ss = sf.OpenSession()) {
IList a = ss.Find("from TestClass");
Text = a.Count.ToString();
ss.Close();
}



A sample domain class:


using System;
using NHibernate.Mapping.Attributes;

namespace TestNHibernate {

[Serializable]
[Class(NameType=typeof(TestClass))]
public class TestClass {

public TestClass() {
}

private int id;

[Id(-2, Name="Id")]
[Generator(-1, Class="assigned")]
public int Id {
get{ return id;}
set{ id = value; }
}

}
}

Friday, September 30, 2005

ECO objects cannot be serialized !!!

I just understand that why Borland didnot promote enough their use of ECO for Web Services. I also realize that why there are only few discussion about Web Services issue on ECO news group. It is because we cannot directly use ECO types as WS complex types.


Here is my simple code:


[WebMethod]
public SystemUser[] ListAllUsers() {
SystemUserEA ea = (SystemUserEA)AccessFactory.Create(EcoSpace,
typeof(SystemUserEA));
return ea.FindAll();
}



However, I've already got the idea and trick how to make ECO fully support Web Services :).

Monday, September 26, 2005

Released EcoAccess 1.0 Final

I'm pround to present version 1.0 of EcoAccess, a free proxy-based declarative DAO library for Borland ECO.

I also updated a website to include one more tutorial - Query as List, and a special report to show that you can save many line of codes using EcoAccess.

You can download EcoAccess v.1.0 Final from http://www.centillex.com/ecoaccess/

Saturday, September 24, 2005

Considering Briefcase Model for ECO

After playing around ECO II, I found that it is quite difficult to make ECO's elements serialized with BinaryFormatter. So, I looked back to DTO pattern, and tried to make a utility to generate simple DTO for wrapping ECO objects.

I named this utility ETO - ECO Transfer Object, and I found that it can work correctly to clone my simple ECO object graph. But I hope it to work with more complicated graph.
If anyone'd like to try this utility please contact me.

Moreover, I also try to make generated ETO objects to be compatible with CompactFormatter and hope that it could work on .NET Compact Framework. That's right, I wanna see ECO working on Pocket PC :).