I just made a small update to the CodeSmith templates for Wilson’s O/R Mapper:
11/30/06: The default constructor for the EntityBase
For more details and to download the templates, go to CodeSmith Templates for Wilson’s O/R Mapper.
I just made a small update to the CodeSmith templates for Wilson’s O/R Mapper:
11/30/06: The default constructor for the EntityBase
For more details and to download the templates, go to CodeSmith Templates for Wilson’s O/R Mapper.
Last week, I wrote about a new version of CodeSmith templates for Paul Wilson’s O/R mapper that I’ve been working on. After fixing a few bugs and including some very simple unit tests, I’m pleased to announce the first public release!
Some important notes on this release:
Instructions and download links are available in the Articles section of my web site under Projects: CodeSmith Templates for Wilson’s O/R Mapper.
Last week, I released a compiled version of Microsoft’s CSSFriendly ASP.Net 2.0 Control Adapters (“CSSFriendly”). Since that post, the “1.0” RTM version of the adapters were released. I just finished porting the latest release to a compiled assembly.
Instructions for installing and using the compiled adapters, and download links, can be found in the Projects section of this web site.
UPDATE 11/24/06: The 1.0 version of the adapters was released, so I updated the compiled distribution. Read about the update here.
UPDATE: Added a link to download just the DLL at the bottom of the entry, and rewrote some of the “implementation” steps to make them a bit clearer.
I’ve been following the progress of the CSSFriendly ASP.Net 2.0 Control Adapters (“CSSAdapters”) since they were initially launched some 6+ months ago. The team has continually worked on revising them (with a little help from me), and the latest release (Beta 3.0) seems to be something that we can live and work with comfortably.
One thing I’ve hated about the adapters is the implementation, which basically involves the following steps:
Apparently, I’m not the only person who thinks there should be an easier way, and it seems that the folks working on the CSSAdapters agree (see the Serving Suggestions topic on the ASP.Net forums).
Inspired by the posts in that topic (especially the post by HardyE), I present to you a fully-compiled version of the CSSAdapters (Beta 3.0). A few notes on the implementation follow.
Implementation of the compiled CSSAdapters in a web site requires the following steps. Note that only the first step is the same as those listed above; steps #2 through #5 are eliminated by the “new” step #2 below.
This makes it much easier to implement and manage than before. Note that this implementation wasn’t heavily tested, but it worked flawlessly with the CSSAdapters demo app (which is included in the distribution I’m providing here). Let me know how it works for you, or if you have any problems or suggestions.
For instructions and download links, go to the Projects section of this web site.
I’ve been using Paul Wilson‘s excellent O/R mapper for a while now, and I’ve become so enamored by it that every project I’ve worked on in the past six months have used it. (All projects are web sites.) Wilson’s O/R Mapper (WORM for short), combined with Paul Welter‘s excellent CodeSmith templates, saved me many hours of coding and provided excellent functionality — well worth the $50 (for WORM) and $99 (for CodeSmith).
One thing that I often wanted to break away from is the ActiveRecord model used in Welter’s templates — not because it’s wrong (ActiveRecord is a very solid, easy-to-use pattern), but because I wanted more. Specifically, I wanted to separate my business objects from my data access code.
Over the past two weeks, while working on the next version of my online baseball game, CSFBL, I started hacking apart the code generated by Welter’s templates, to the point where I separated the data classes from the data access code. I then upgraded to CodeSmith 4.0 Professional and rewrote the templates to generate code based on my “new” way of doing things.
As of now, the templates generate code that compiles and does what it supposed to — however, before releasing it I want to test it a little more and perhaps write a few unit tests. Maybe even redo Welter’s unit test generator, too, to work with the modified templates. 😉
These modified CodeSmith templates generate two projects: one for your entity objects, and one for your data access objects. The templates (written using CodeSmith 4.0, but will probably work in 3.2 — I’ll test it before publishing) are for .Net 2.0 only, as they make heavy use of generics.
Each table gets a class using the same partial class and generated file technique we know and love. Each of these classes inherit from one or more of the following classes: EntityBase
The actual generated class would inherit from either EntityBase or PersistableEntity. Implementing the IObjectHelper interface is an option in the CodeSmith template (if you don’t implement it, your entity library will not need to reference WORM at all). The generated code creates fields and properties as you would expect. It also does the following:
Finally, the generated code has a second class in it that inherits from a new IIdentity interface. This simple class is used by the Data Access classes for “RetrieveByKey” and “DeleteByKey” methods (see below for details).
The DAL is not as much a DAL as it is a gateway between the entities and the O/R mapper, but since I’m no master of the right architecture pattern names to describe a situation, I’ll leave it named as such. After code generation this project will have five files.
Previously I mentioned the IIdentity interface. This is used by the RetrieveByKey and DeleteByKey methods and allows us to maintain generic data access classes while being able to use strongly-typed keys as well.
An example of how the data layer works is shown below. The examples assume entity classes exists called Teacher, whose primary key is TeacherID.
//retrieve a Teacher Teacher teacher = Retrieve<teacher>.RetrieveFirst(); //retrieve all Teachers IList</teacher><teacher> teachers = Retrieve</teacher><teacher>.RetrieveAll(); //retrieve a teacher whose primary key is 74 TeacherIdentity tid = new TeacherIdentity(74); Teacher teacher = Retrieve</teacher><teacher>.RetrieveByKey(tid); //you could also write the above in one line: Teacher teacher = Retrieve</teacher><teacher>.RetrieveByKey(new TeacherIdentity(74)); //saving changes to a teacher teacher.Name = "Dr. Spock"; Persist</teacher><teacher>.Save(teacher); //deleting a teacher Persist</teacher><teacher>.Delete(teacher); //deleting a teacher whose primary key is 74 Persist</teacher><teacher>.DeleteByKey(new TeacherIdentity(74)); //creating a new teacher record will not be tracked by WORM //this is perfectly valid Teacher teacher = new Teacher(); //you can start tracking by calling the Track() method Persist</teacher><teacher>.Track(teacher); //you can also instantiate a new teacher with tracking Teacher teacher = Persist</teacher><teacher>.New();
The unit tests I wrote pretty much did what you see above.
I will hopefully release the actual templates in a few days, once I do some more testing on them and clean up some of the output formatting a bit. In the meantime, feel free to let me know what you think!
My online baseball game, CSFBL, is a data hog to the tune of about 100GB. Yes, 100GB. That’s how much disk space it takes to store the play-by-play results of some 5 million baseball games (over 2,500 seasons) along with the related player data, historical statisics, and other fun stuff.
The server that powers this beast has three 146GB SCSI drives in a RAID5 configuration. That’s about 250GB of available disk space. Excluding data requirements for such necessities like Windows, SQL Server, tempdb files, web files, and the like, we typically have between 50GB and 100GB of free disk space.
Of course, backing up that database is another story entirely, and if I’m not diligent in keeping the disk clean (by deleting old and unneeded data files), the server can quickly run out of space. This has happened from time to time over the past few years, but a quick cleanup resolves the issue.
Over the weekend I decided to take on major maintenance, defragmenting all SQL indexes, cleaning up old data, removing unused applications, and similar fun weekend chores. During this, I checked the level of fragmentation on the SQL database file.
Over 40,000 file fragments.
Whoa! How long does it take to defragment that? About two days. Of course, a lot of that time was spent first defragmenting other files to make room for one big file. The built-in Windows defragger didn’t do the trick at all (it fails miserably unless you have gobs of free disk space or no large files to defragment). What did do the trick was an evaluation version of Raxco‘s PerfectDisk. Fortunately for my wallet, the eval version is full-featured for 30 days, and since my defrag needs are done, I don’t have to buy it — at least, not until I have to defrag the database again.
Then again, I’m planning ahead this time. I set the SQL database to have about 30GB of free space, so the only fragmentation should be internal, not external. By the time I need to worry about a fragmented SQL data file again, there will be another 1.5 million baseball games simulated, and hopefully a little more ad revenue coming in. 😉