Originally published at Fiberglass flowers. You can comment here or there.

It hasn’t even been a ten years that DB2, one of the most, er, expensive DBMSes, got a feature needed by every other application – dataset paging.
Before, you had to use window functions rownumber() and fetch first 40 rows only. When used by Hibernate, this resulted ugliness like:
select * from (
select inner2_.*, rownumber() over(order by order of inner2_) as rownumber_
from (
select ...
fetch first 40 rows only
) as inner2_
) as inner1_
where rownumber_ > 20
order by rownumber_
Since this summer version – DB2 9.7.2 – you can just append LIMIT and OFFSET:
Originally published at Fiberglass flowers. You can comment here or there.

Just installed a shiny new Google Buzz button for Wordpress by Tejaswini, Sanjeev.
I hacked it a bit, to align to the right. Download this plugin version here, until author updates it.
I’m replacing a diggIt button; Buzz fits my color scheme better
Enjoy.
Originally published at Fiberglass flowers. You can comment here or there.
Just in case someone needs a code snippet.
This one groups Prices by PriceProvider and was intended to pick only last 5 values for each PriceProvider – but sadly, it’s impossible without window functions. Which are not supported in Hibernate in any way.
Hibernate join bug
3/9/09 20:35Originally published at Fiberglass flowers. You can comment here or there.
Hibernate bug 1895 seems to be still there since 2006.
If, for instance, in Grails, such a syntax won’t work for you (it won’t):
def books = Book.findAll("FROM Book AS b JOIN Chapter AS c WHERE c.active = :isActive")
with a NullPointerException in “HqlSqlWalker.createFromJoinElement” — just use alternative join syntax, via WHERE:
def books = Book.executeQuery("select b FROM Book AS b, Chapter AS c WHERE c.active = :isActive")
Move “WITH” conditions to “WHERE” as needed.
Unit tests quickstart
24/6/08 13:57Originally published at Fiberglass flowers. You can comment here or there.
A friend asked me for it, so probably someone might need a jumpstart in unit tests.
Here’s a short list of short (though very deep, if not best) intros.
- Except for JUnit cookbook (~2 pages) (which has a lot of “ports”, like CppUnit cookbook), I’d name:
- “Endo-Testing: Unit Testing with Mock Objects” at mockobjects.com (Tim Mackinnon, Steve Freeman, Philip Craig) (7 pages);
- “Mocks aren’t stubs” by Martin Fowler (about 7 pages);
For deeper dive, take a “xUnit patterns” book (this one is longer).
For Kent Beck’s book on TDD, shame on me - I never read it. Though after “XP explained” I don’t strive for reading his books.
// If you’re interested in XP and “XP explained” criticism, take a look at “Extreme Programming Considered Harmful for Reliable Software Development” by Gerald Keefer.
Originally published at Fiberglass flowers. You can comment here or there.
My not-so-humble evaluation of VS tests distinctions from NUnit is (in points on -10 to 10 scale).
- (-4) To run tests, VS launches an entire process which takes no less then 3 seconds to start. If you’re in “F5 hit breakpoint - Shift-F5″ loop, that’s disgusting. NUnit tests can be run in-process by Resharper or TestDriver.NET;
- (-2) GUI that shows where test failed is ugly. You don’t get to failed line on double-click, you first get to test log page. Status and call stack are necessary, but I’d like not to trash my document tabs, I already have enough of them open. You can’t make that kind of windows docked/floating;
- (-1) You got a “
public TestContext TestContext;” sticking in your code. You’ll need it only when it comes to testing on data, which doesn’t always happen, even in a data-driven application; - (-1) It’s a “not invented here” technology, while NUnit was around for years;
Edit: In a moment of madness, I mixed together coverage profiling and unit testing tools. May God and readers forgive my aberration.
Edit2: If you need a half-page kickstart in unit testing techniques, the next post can help.
Please meet: Lua
15/5/08 12:00Originally published at Fiberglass flowers. You can comment here or there.
Lua recently became very popular. I encountered Lua scripting in several applications including popular games, I believe it’s used in even more then Wikipedia says.
It’s extremely simple:
- 6 data types (that’s counting “nul” and “function”),
- no C++-style OOP out-of-box (but you can program one, he-he),
- 400K of pure-C code
but is loaded with in-fashion features like
- first-class functions,
- closures,
- coroutines…
- again, Wikipedia is the best.
The only metaprogramming tutorial (with a ready code to implement virtual methods) is “Programming in Lua” book. Still, I don’t see a code to implement ad-hoc polymorphism… Maybe it’s a reason for another post
Redistributed book removed: it violated copyright.
MSBuild don’ts
15/4/08 14:15Originally published at Fiberglass flowers. You can comment here or there.
A couple of notes how NOT to use MSBuild.
- Don’t generate files with AssemblyInfo task. It screws comments, screws InternalsVisibleTo attributes, and whatever else it doesn’t account for.
( Read more... )
Auto-update with WiX
12/3/08 14:43Originally published at Fiberglass flowers. Please leave any comments there.
Update: for a ready solution (library), see official release announcement
Windows Installer on itself is a pain. WiX saves you from it, mostly wrapping the complexity into XML constructs understandable to non-gurus.
Well, not completely – you still have to know:
- why the heck shortcut didn’t appear in start menu;
- how to create a web site shortcut;
- why to create RegistryValue for a program directory you create, and that’s the simplest things. Still better then MFC…
But a very good tutorial exists, maillist is very active and it’s easy to get support.
Maybe it’s another reason to love Unix-es, where “install IS just a copy”.
Though, one has to admit that installing Windows application involves somewhat more desktop integration.
I was looking for an auto-update, so that:
- application could say “New version available, download? Restart now?“;
- would use MSI;
- download should preferably use BITS.
Simple automatic updaters like this on Codeproject won’t do, because you can’t just download necessary files: Windows Installer will revert them back. Or you would have to “disable WI’s Resiliency“, which is also a bad idea.
Solution of my choice
ClickThrough subproject of WiX promises that, but it’s still beta and crashes. Still you can easily compare two MSI files, generate a MSP patch, and a RSS feed that client can check, download and even read by eye, so simple it is – a pretty tasty feature.
There is no .NET client code. For now, there is only a separate update.exe that will find, download and install new version. Still, you cannot ask user whether to download now or not, cannot tell what’s new, when to restart, etc.
But you can painlessly add a Start menu shortcut that will update your application.
Come later, I’m going to create a C# code that will check for updates, and probably publish it.
Other solutions
You can use Updater ApplicationBlock, or more exactly, latest version now lives at CodePlex. But Enterprise Library wasn’t updated for .NET 3.5, and I believe it’s abandoned.
You can use NSIS. Though, it’s not Windows Installer MSI packager, it creates own files and scripts.
For ClickOnce application, you can use Application.Deployment.
Originally published at Fiberglass flowers. You can comment here or there.
As it’s common for Java GUI frameworks, only main thread should access GUI objects (see respective MSDN article). Alright, real requirement is a bit weaker: Only the thread that the Dispatcher was created on may access the DispatcherObject directly. Effectively same, just keep it in mind.
First thing to know
From other threads, to call main one, do:
someControl.Dispatcher.BeginInvoke(DispatcherPriority.Normal, invokedMethodDelegate, parameters);
Know that all the BeginInvoke()s go through ThreadPool. .NET’s ThreadPool is static utility class, with a single task queue for everything.
Which means client call can freeze all the application, including WPF internal tasks.
Can you think of any reason to do so? I can’t. It’s another “we’ll never know“.
If you need a thread pool, I recommend a SmartThreadPool by Ami Bar. It can be instantiated, so different pools of tasks won’t clash with each other.
Second thing
Read Kent Boogaart’s post about binding to collections. Modifying or even iterating a collection across threads needs some workarounds, if you can’t afford to lock it entirely. Kent’s .NET blog is worth reading anyway.
One more little thing
is: unhandled exceptions go to <Application DispatcherUnhandledException=”your handler”>. You didn’t expect main thread to handle them, right? Especially as there is no Main() function… Oh, once I missed that too. So, have a proper handler in each function you start as a thread.
Current “to-reads” are:
- http://msdn2.microsoft.com/en-us/library/ms741870.aspx
- WPF threading model;
- Tutorial on SynchronizationContext
Sorry if this looks more like a linkdump; will update when I get more into this. I know I will…
