Saturday, August 18, 2012

Desktop Reinstallation Struggle

For many years, I struggled to stay with KDE 3.5 in my primary desktop computer, as I found it much more stable than the KDE 4, which had serious issues every time I tried it. Kubuntu 8 was the last system version to come with KDE 3.5, so I was stuck with it. After a hard drive failure some two years ago, I finally installed a newer Kubuntu, and also went for 64-bit to get a bit more memory. My life has been struggle since then.

Issues, issues

Often after some upgrades, the machine has worked well for a day or two, and then become sluggish as hell, with random jams that can last from 5 to 30 seconds. Some applications cause especially much problems. One is Thunderbird, for some odd reason. Another is Digikam, for which the reason is that it doesn't really scale up very well and hogs memory (2.5 GB currently).

Also, successive system upgrades from Kubuntu 9 to 12 had also broken something. One of the most problematic background processes was "semantic Nepomuk Desktop". Do not even ask me what that is, but it is currently an integrated part of KDE. It can be disabled, but doing so causes a lot of annoying alerts that it should not be disabled, even though those alerts are only relevant if you use KMail, which I don't.

I've been struggling to identify the underlying problem. I've suspected an interrupt in DMAs, interrupts, or some other resources. However, the most probable cause is the Nvidia GeForce 8800 GT, which was the source of most problems with this installation as well.

I wholeheartedly agree with Linus's opinion about Nvidia. While they do offer a proprietary driver for Linux, it is riddled with problems and they refuse to give out specs for making a possibly better driver.


Linus delicately expressing his opinion about Nvidia

For the most time in these two years of struggle, the system has worked reasonably well for a few days, before the memory has fragmented, etc. So, after the two years, I finally bought another 4 GB of memory this week, hoping that it would make the problems easier. It didn't at all. So, I finally decided to reinstall everything, even as annoying that is.

Installing the Pangolin

Running the installation for Kubuntu 12.04 LTS (nicknamed Precise Pangolin) was really easy and simple. I have it on two other machines as well, my work computer and my netbook. The only slightly worrying step was not formatting the drive. I took full backups to an external drive (took almost a day), then started the Live Kubuntu, mounted the drive from console, and moved everything under root to an "old" directory. Then, did not allow the installation to partition and format the drive, but assigned the root mount point for the partition. Well, I've done that probably dozens of times, but you can never be too careful with that.

Nvidia Problems

However, after the installation, the computer didn't work at all. Simply clicking anything with the mouse didn't work. The reason was apparently that compositing was not enabled. The quick (and unobvious) fix to be able to use the system at all was to disable the 3D effects mode with Alt+Shift+F12. Also, all fonts were so tiny that I couldn't read them. The reason was probably with my monitor (a 42" TV actually), which detects the signal so slow that the system can't detect it, and then calculates the DPI resolution with some insane defaults.

So, to edit xorg.conf. Actually, it wasn't really initialized at all, but running nvidia-xconfig in console reinitialized it with a bit more sane values. Then, make the following monitor settings to get the DPI resolution sane:

Section "Monitor"
    Identifier     "Monitor0"
    VendorName     "Unknown"
    ModelName      "Philips FTV"
    HorizSync       15.0 - 70.0
    VertRefresh     48.0 - 62.0
    Option         "DPMS"
    Option         "UseEdidDpi" "False"
    Option         "DPI" "120 x 120"
EndSection

Those aren't really the correct DPI values for the TV, which would be about 47 DPI, but something that makes it readable from 1,5 meters.

Then, the compositing:

Section "Extensions"
    Option         "Composite" "Enable"
EndSection

The biggest issue was the nvidia 290.40 display driver, which was essentially broken, so that the user interface became unbearably slow. Simply switching between windows would take some 15 seconds. The driver had broken at about version 290.33 or so, and while many versions had made some fixes for some cards, they didn't work for me. After struggling for hours, the finally working solution was to install the latest driver from an alternative repository:

sudo apt-add-repository ppa:ubuntu-x-swat/x-updates
sudo apt-get update
sudo apt-get install nvidia-current

This installed the 304.37 driver version from the 304.37-0ubuntu1~precise~xup1 package, which actually worked.

So, for the first time in two years, everything seems to work pretty well. For now.

The Rest of It

The rest of the installation was very boring routine. KDE has a zillion settings with which I'm not satisfied and making it bearable always takes half a day, which is the reason I don't want to make installs very often. I did my netbook install just a month earlier, so most of the difficult-to-find settings were in almost fresh memory.

The required KDE configurations change a bit from time to time, as some defaults become better and some worse. Just to mention some:

  • Disable unnecessary desktop effects and configure others
  • Change desktop theme to a prettier one
  • Configure Task (window) Switcher to a vertical layout
  • Configure virtual desktops (I always use 8)
  • Configure desktop animations, etc.
  • Configure switching desktops with Win+Tab and Win+Ctrl+Tab (this actually has couple of bugs in KDE 4 which makes the configuration difficult)
  • Configure window behavior rules (force certain windows to always start in certain desktop)
  • Disable annoying confirmations for the KDEWallet
  • Configure other global shortcuts (minimize/maximize windows, etc)
  • Configure session control - restore manually saved session
  • Disable logout confirmation
  • Disable screensaver
  • Disable screen power saving from Power Management
  • Disable network settings in KDE and set them in /etc/network/interfaces
  • Configure printer
  • Configure screen resolution if not correct
  • Delete unnecessary default folders from home folder
  • Change the location of the Desktop folder
  • Set up Firefox as default browser in KDE and with update-alternatives
  • Set up Konsole configurations for root, Irc, and normal use
  • Set up panel
    • Change the terrible new Windows-style application launcher to traditional launcher (great that it's still there as an alternative)
    • Set up application launchers
    • Set up Konsole configuration launchers
    • Set up clock
    • Set up other panel layout
    • Enable auto-hiding
  • Set up desktop background photo
  • ...and other small tuning...

So, there it is (with my System desktop).

Addendum

2012-08-20: Some occasional jams still occur, typically freezing the keyboard for half a minute in one application, such as Firefox. But it's quite different, system loads stay quite low, but one core jumps to 100% when a jam occurs.

Friday, August 3, 2012

Enjoying the Finnish Archipelago

One of my activities this summer has been exploring the Turku archipelago with my kayak. The Finnish archipelago is the largest in the world by some measures. There are 179 584 counted islands in Finland, some of them in the lakes, but most of them in the sea. The largest archipelago area, the Archipelago Sea, is around Turku, where I live, with about 50 000 islands. Most of the islands are tiny, some just ten meters wide, but yet make great places to visit. The archipelago is also really tightly packed, and you could usually throw a rock to the neighbouring islands.

Not amazingly, many people here have a boat. So did my family when I was a child. We had a rather small motorboat, and my family and other kindred would all gather at the Maisaari island. My brother has a motorboat, and many of my friends have had one, or a sailboat. I kind of like sailboats, so I may get myself one some day.

The number of islands is so high that even though thousands of people go out there every summer weekend, everyone can always get their own island to stay in, if they like. Some of the islands are just small treeless rocks, but most have some forest.

Nevertheless, most of us who live here take the archipelago for granted, and rarely even think about it. So have I for most of my life. I kind of rediscovered it last year when I got into paddling. A kayak is really very useful for exploring the archipelago, as you can get everywhere with it. Many parts of the archipelago are unreachable by motorboats or sailboats, as they are too shallow and have too many underwater rocks, but with a kayak or canoe you can get everywhere. It is a bit slow and requires some effort, but on the plus side, it keeps you in shape. Not surprisingly, kayaking and canoeing have become really popular in Finland, and especially so in the Turku area.

I started kayaking mostly last year, and after some trips with rented kayaks, I got myself one. So far, most of my trips have been just daytrips or one-night trips, and one two-night trip for a weekend. But why stay longer, as you can always go next weekend as well.

At Ominainen, the most famous haunted island in Finland. They used to bury criminals and other nasty bastards here.

A private boat is by no way the only way to explore the archipelago. There are many "water buses" that go to some islands daily, and bigger ferries to the more remote islands. Most of these ferries, especially to the most remote islands, are actually totally free of charge. The ferries go also in the winter, pushing through ice. There's also an Archipelago Route, which you can go by car or bicycle, with free ferries between the islands.

Oh, Finland also has 187 888 lakes (larger than an acre). The number of lakes by the land area is also probably the highest or among the highest in the world.

Tuesday, July 17, 2012

Book of Vaadin - Vaadin 7 Draft Edition

I just sent the Book of Vaadin, Vaadin 7 Draft Edition, to print. I've been really busy with it for the last month, as there is so much to do. Some years ago, when we went from IT Mill Toolkit 4 to 5, it took over six months to rewrite it. Now the book is many times bigger and the changes in Vaadin 7 are really radical.


The edition is really a draft, and it says so right in the title and in many places inside the book. Many of the changes in Vaadin 7 require going through the book almost word by word, so I hope to get it done before the end of the year.

Also, the last batch of Vaadin 7 enhancements is yet to be released in the first beta, which should be out at the end of August.

The printed book will be available at JavaOne, and at some other locations. We try not to print this draft in huge numbers, just for the most important conferences in fall of 2012.

Big Changes in Vaadin 7

The first big thing in Vaadin 7 is the renewal of the basic application API. You no longer extend Application to write an application, but a Root (name is subject to change). Root is much what Window used to be, and the Window now means only a sub-window. There's also a separate Page object associated with a Root.



Another big topic is the client-side API, which has been essentially rewritten to use connectors that communicate between a client-side widget and the server-side component. The framework handles state object serialization transparently, and there is also an RPC mechanism. Hence, the client-side development chapter has been rewritten from scratch and it still needs a lot of work.

For most developers, also forms and data conversions are very important. There is no longer a Form component, but a FieldGroup that helps in binding fields and data together. I have written probably a hundred examples that use the old Form, so there's quite a lot work in converting them all to the new model.

And there are dozens of other significant changes.

Vaadin += GWT

Then perhaps the biggest thing in Vaadin 7 is that it now includes GWT. Just putting the GWT classes inside the Vaadin JAR sounds does not itself sound significant, the significance comes from the consequence that as we provide support for Vaadin, which now includes GWT, we also provide support for GWT. Vaadin now also effectively supports two development models: one for the server-side as before, but also for pure client-side applications.

Pure client-side Vaadin applications are of course more restricted, but they have their uses. Not all applications need data from a server, but just work on data input by the user. Also, pure client-side application can work off-line, unlike server-side Vaadin applications (unless you install the server on the client machine). For example, the Vornitologist demo for TouchKit has an off-line mode that displays a pure client-side version of the application when the network is not reachable. It uses HTML5 local storage to store the application itself, as well as the data, until the network is reached again and it can send the data back to the server. Then, the application can revert back to the full-featured server-side application. To try it out, run the demo on either an Android or iOS device.

References

Some links:
Notice again, that the Book and the book examples are really unfinished drafts at this point, and will be in better shape at the end of the year when Vaadin 7 is planned to be released.

Sunday, July 8, 2012

Installing Kubuntu 12.04 LTS on Acer Aspire One D270

I finally bought a new netbook, an Acer Aspire One D270.
  • 10.1" display
  • Dual 1,6 GHz Intel Atom N2600 processor
  • GMA 3600 graphics chip integrated on processor
  • 320 GB hard drive
  • 1 GB RAM, extendable to 2 GB
It appears that the D270 model has many variants. I accidentally purchased a model with a 3-cell battery, as there was another model with the same designation in another shop, but with a 6-cell battery. I read the specs from the other shop, and bought the machine from the shop with the inferior machine. Oh well, can't take it back anymore. On a positive side, it's a bit lighter and smaller with the 3-cell battery. There were a few other alternatives, but this was the cheapest and I thought they were so cheap that I could buy a new one later. There's never enough netbooks lying aroung.

The nasty trade-offs with the D270 are:
  • A glossy screen (oh I hate them)
  • No Bluetooth
  • No built-in 3g
  • The small battery in this model
But it was cheap, so.

The machine came with Windows 7 Starter. It's actually the first Windows I've ever paid for myself, which is kind of shameful. Unfortunately, it's no longer possible to find a netbook/laptop without Windows (Update: Looks like they sell D270 with Linux in Germany). My EeePC 910 was quite great, with almost same performance as this one, but unfortunately they don't sell those any longer. Too bad I managed to soak it in pear juice.

It should be noted that there are no vendor-provided drivers for the GMA 3600 graphics controller in Kubuntu. (Update: Looks like Intel has published a Linux driver last month! But it's only for 32-bit Fedora...)

Some of the configuration given in this article are specific to the Aspire, but perhaps most are quite generic, especially the KDE configuration.

About KDE

I'm a long-standing KDE user and wouldn't really use anything else. The problem is that KDE has been getting worse over the years, not better. I guess it's because KDE imitates Windows a lot, and Windows has gone worse. The problems started with the redesigned KDE 4, which had all sorts of bells and whistles that still don't work some 5 years after the first version. The window manager crashes occasionally, and there are other issues, some of which I will mention later.

One of the most annoying issues is deteriorating keyboard support, some of which issues I mention later. While I initially switched to KDE because of its excellent keyboard support, it has been getting worse. Shortcuts disappear, and no one seems to care about it. I imagine there is nowadays a newer generation of developers who went to school learning to always use mouse for everything. Despite using the keyboard for writing a lot, they nevertheless seem to stick to mouse a lot. Not good.

Mounting the Cow

In any case, Kubuntu, the KDE version of Ubuntu, was my choise. Downloading the ISO image was just a minute. The trouble started with writing the image on USB memory. The instructions give a "normal way" to use "usb-creator-kde" application. The problems started while using it, as it crashed the first time I used it. Trying again, I managed to write the image to the USB drive (or actually an SD card with an adapter). However, trying to boot from it consistently failed and the system dropped to shell prompt. I first feared that it might be a display driver issue, but going through the errors gave me a hint that the USB image might have some issues. It couldn't even mount the system in read-write mode, which caused everything to fail.

The problem was that it couldn't mount a cow. More technically, I got "Can not mount /dev/loop1 on /cow". It has something to do with an overlay filesystem where there is a read-only filesystem on the bottom and a ramdisk read-write filesystem on top of it that takes any modifications. Anyhow, I didn't get the cow error consistently, so it took a bit time to figure out. Well, the installation instructions actually mentioned the issue and adviced to use UNetBootin, another application to create bootable USB disks.

The problems didn't exactly end with UNetBootin, I have no idea why. I managed to boot once, but subsequent attempts didn't work, the boot just got stuck. At this point, I gave up and went to sleep. On the next day, I went to a supermarket and bought a real USB drive instead of the SD+adapter, and tried that. Worked, excellent.

The installer allowed to repartition the 320 GB drive nicely so that it preserved the Windows 7 installation. Not sure what I could use it for, perhaps for some games or something. Not that the machine is fast enough for games. Even basic use with Windows 7 Starter is horribly slow. But I did pay for it! Installing Firefox instead of the IE made browsing much faster though.

Installing Kubuntu was a breeze initially, nothing much to say about that.

The Biggest Task: Basic Configuration

While KDE is great, it unfortunately is not great out of the box. In fact, it appears rather broken in many ways.

Using Regular Desktop

Kubuntu seems to start the "Plasma Netbook" workspace by default. It might be nice for your grandmom or your kids, but for you it isn't. To use a regular desktop, select in the Control Panel "Workspace Appearance and Behavior / Workspace Behavior / Workspace" and select "Desktop" in the Workspace Type. Click Apply and you're much happier.

Tree View in Control Panel

The KDE Control Panel originally had a tree view. In some 3.x version, it was changed to a more "iconic" view, for worse I think. It is still possible to get the tree view simply by clicking Configure in the Control Panel and selecting the Classic Tree View.

With trees or icons, the KDE Control panel is really a huge forest and it can sometimes take ages to find what you want. Sometimes the search functionality helps, sometimes you have to resort to Google to find the settings you want, sometimes it's somewhere else.

Traditional Start Menu

At some point in recent history, KDE wanted to mimick the Vista start menu, which is just as awful in KDE as it is in Windows. To replace it with a traditional start menu, right-click the panel and select Panel Options / Add Widgets. Drag and drop the Application Launcer Menu to the panel. To reposition it in the panel, click the Panel Tool Box at the right end of the panel, select the button, and move it to left. To remove the default launcher, right-click it and select Remove this Application Launcher.

While you're viewing the Panel Tool Box, also select More Settings / Auto Hide. This gives you plenty of more space in the already too small screen.

Desktops and Keyboard Navigation

One of the most important features in KDE is built-in desktop navigation. It has multiple desktops in which you can group windows. These were actually disabled after installation for some reason. To configure them in Control Panel, select Workspace Appearance and Behavior / Workspace Behavior / Virtual Desktops. Often the default is four desktops, I like to use eight. After using same configuration for 15 years, navigation has come pretty easy.

Very importantly, you can navigate between the desktops quickly from keyboard, just like you can navigate between windows with Alt+Tab and Alt+Shift+Tab. The keyboard navigation was actually the reason why I switched to it some 15 years ago from fvwm2 (don't even ask what that is).

The problem is that the proper desktop navigation keys are no longer enabled by default. In fact, because of a bug introduced in Kubuntu 11, they can't be configured from any of the settings at all! The only way to set them is to edit
.kde/share/config/kglobalshortcutsrc and set the following:
Walk Through Desktop List=Meta+Tab,none,Walk Through Desktop List 
Walk Through Desktop List (Reverse)=Meta+Ctrl+Tab,none,Walk Through Desktop List (Reverse)
("Meta" means the "Win" key.) Strangely, the issue was fixed in last October (2011), but the fix was apparently not included in Kubuntu 12.04.

Because of another bug, it's no longer possible to use Win+Shift+Tab in KDE. The keyboard combination simply doesn't work. It was quite annoying to lose that shortcut, as I used it for al-most 15 years, until it was broken in KDE 4.

To get the settings in use, you need to restart KDE by logging out and in again.

Basic Window Management

Unbelievably, KDE windows do not have a "Minimize" button by default! The only way to minimize them is to click the window menu (at the top-left corner) and select Minimize. To enable a Minimize button, you have to customize window buttons. In the Control Panel, select Workspace Appearance and Behavior / Workspace Appearance / Window Decorations, then Configure Buttons. In the dialog, you can drag&drop buttons, such as the Minimize, to the window title bar.

To be able to minimize windows from the keyboard, the shortcut is defined entirely elsewhere in the Control Panel. Select Common Appearance and Behavior / Shortcuts and Gestures / Global Keyboard Shortcuts, and then select KWin in the KDE Component. So, I have to know that this simple shortcut is part of this "KWin" thing, reall obvious. There, set the Minimize Window button to Win+- (Meta+-). While you're at it, you could also set the "Maximize Window" to Win++ or something.

Forcing Windows to Particular Desktops

Normally, when an application opens up a child window, for example a warning, it appears in the current desktop. This is not normally desirable, as it messes up the grouping of windows in desktops. For example, if you have Skype pop up chat windows automatically, you soon have them in every desktop. It becomes a problem.

You can force the windows of a particular application to always open in a fixed desktop. In Control Panel, select Workspace Appearance and Behavior / Window Behavior / Window Rules. The configuration is somewhat complex so I won't go into much details.

You can actually do really many things with the functionality, it's almost like
programming. You can control the desktop, size, positioning, and countless other parameters of windows.

And of course, KDE allows saving the "session", so that after you shutdown the computer and start up and log in again, it restores the session with all the windows. The behaviour can be configured in Control Panel in System Administration / Startup and Shutdown / Session Management. You can choose to save the session automatically when logging out, or just manually, or not at all. Restoring does not restore the applications to the same state though. For some applications, it can save some state parameters, such as the current folder and such, and even which document you were editing. How much state information is restored depends on the application.

Optimizing Performance

It isn't really meaningful to have flashy graphics effects when using a slow netbook. While the basic 2D hardware acceleration seems to work quite well with the GMA 3600 graphics adapter, some effects can be really hard on the poor GPU. In the Workspace Appearance and Behavior / Desktop Effects, disable Enable desktop effects at startup and "Various animations".

You could set the "noatime" option in /etc/fstab. Normally, Linux keeps record of the latest access time for each file and directory. You can see the access times for example with "ls -lu". That recordkeeping requires writing to disk, which takes a bit time, and with flash disks would also consume the prescious rewrite cycles. Just edit the file (with sudo) and add the "noatime" option in the options column, separated with a comma. The setting is used after the next boot.

I am sure there are tons of other optimizations you could do, so the above are just the starters.

Update: The D270 came with just 1 GB of memory, which seemed to fill up pretty fast with KDE 4 and especially when running Java stuff. I got a 2 GB comb and now it works much faster.

Remaining Issues

The remaining problems are:
  • External display (VGA or HDMI) does not work and I have found no mentions how it should work. Apparently it is possible to get it work if they sell the D270 preinstalled with Linux.
  • The keys for changing display brightness do not work. The issue is known with the Aspire One and should be solvable.
  • Kwin has crashed once or twice during a day. This issue is really annoying on my home desktop computer as it can occur several times in an hour. I hope it isn't as bad.

Monday, June 11, 2012

Transit of Venus in Lapland

Last week was the transit of Venus between Earth and the Sun. This is a rare phenomenon that occurs just twice in 120 years. The last time was in 2004, when I was able to observe it in Turku, and the next time is in 2117. While the event has little astronomical significance today, it was quite significant historically, as it was used to determine the scale of the solar system. As I'm a bit interested about the history of astronomy, this was something I didn't want to miss.

So, last Monday I packed my car and headed towards Lapland. Well, actually on Tuesday morning at 2 am, as packing took a bit longer than I had planned. I drove all night and all day, taking just a short nap. The weather was a big question. Most of the Southern Finland was clear, as was Lapland, but the forecasts were changing more quickly than I could drive with my car. I had to make my final decision at Sodankylä and head either towards Utsjoki in the "head" of Finland, or to Kilpisjärvi in the "arm". I chose the arm over the head.

I had never been at Kilpisjärvi before and it was quite beautiful area, in all its barredness. The Kilpisjärvi lake was still almost completely frozen and there were many groups of reindeer on the road.

As was almost expected, it was totally cloudy when I arrived in Kilpisjärvi at Midnight, just an hour before the transit would begin. So, with 1400 kilometers behind in 22 hours, I turned back. If I had not, I would probably have completely missed the event. After driving some 100 km, I got a very short peek of the Sun at around 01:15, just a bit after the transit had begun, but I had to drive yet another 100 km before I found an area free of clouds.

Well, there it was, the Midnight Sun, hovering low behind the hills. It was unfortunate that I had missed the beginning, because measuring the time from the first to fourth or second to third contact was how the scale of the solar system was calculated using the parallax between different latitudes on Earth.

So, I continued driving to East, trying to find even better spot, even one with other amateur astronomers. I knew there was a group in Saariselkä, on top of the Kaunispää fell, some 400 km away, but while driving there I encountered another cloudfront and had to turn back. So, I settled on the top of the Levi fell, where there is a famous skiing center.


I had also my 30-year old RET-45 telescope with me for visual observations. It was a bit unstable and the secondary mirror was a bit loose, so using it wasn't exactly easy. I tried to take some photos through it with my cell phone, but wasn't successful. So, my main instrument was my Canon 40D with a 700-300 mm f/5.6 tube. It wasn't really long enough, but what could I do.

I left the Levi after some hours and observed the third and fourth contacts at a parking place nearby. I stopped there because I had noticed couple of German amateur astronomers there, taking photos of the phenomenon.


Trekking in Lapland

As I was in Lapland, I wanted to see it a bit. Just by coincidence, my brother had rented a cabin there for a few days and I was able to stay there for some nights. I visited mainly the national park around the Ylläs fell. There were quite a few interesting places.

Near the Ylläs fell and the Äkäslompolo village lie two very deep saivo lakes, Äkässaivo and Pakassaivo. The saivo were though to be sort of bottomless lakes that lead to the Underworld. In the other world, there lived some other people. There were also couple of sacred seita stones nearby. I took walks around them on Wednesday, Friday, and Saturday. On Thursday I had to work most of the day - isn't Internet wonderful? I logged four geocaches.

On Saturday evening, I went for a short trip over the Aakenus fell. It was a 17 km nature trail that goes over the fell and through some marshes. On the Eastern side of the fell there were remains of a German Junkers Ju-52 transport plane that had crashed in the fell during the 2nd World War. One of the crew had survived the crash, but was injured and killed himself as rescue proved hopeless. After the rescuers arrived after 2 months, they found a puppy at the site. It had survived by feeding upon the crew...

At the midway of the trail, there was a "Porokämppä", literally "Reindeer Hut", a small wilderness hut, which is free for trekkers. It was quite comfortable and I stayed there overnight. In the Sunday morning, I released Vaadin 6.8.0, as the location was more than convenient for our reindeer-themed product.


I arrived back at my car a bit late in the afternoon and headed back to Turku. The drive 1000 km south took almost 12 hours, so I arrived home at about 6 am. I was quite tired and slept a bit long.


Well, the trip was quite interesting. As I had left everything extra off my car (roof box, rack, bicycle), I managed to squeeze the gas consumption to well under 7 l/100 km. Next time I would probably take my kayak with me, or the roof box, which would raise the consumption a bit. It's usually been around 8 l/100 km with the roof box.

Tuesday, March 20, 2012

New revision of Book of Vaadin is out

Work stuff. We have been getting a new revision of the Book of Vaadin out about every six months and the latest came from print today. This time we didn't increment the edition number, so it is the 1st revision of the 4th Edition. Essentially, one major reason was that we ran out of colors in the Vaadin color palette so the new revision looks just as yellow-orange as the original 4th Edition.

Regardless of the similar appearance, the revision packs almost 100 pages more content. The biggest change is the reorganization into two parts: the core framework and the addons. Some new add-on documentation is included in the core part: Vaadin Control Panel for Liferay, Vaadin IPC, and Vaadin WSRP. The SQLContainer add-on is now part of the core framework.

Of the add-on documentation, the JPAContainer chapter was entirely rewritten couple of months ago and the Calendar chapter was revised more recently.

Unfortunately, there are some outdated parts that went to print. Most notably, there is a really outdated material in the Vaadin embedding section, related to version 5.2. I hope there isn't much Toolkit 4 stuff left, just cleaned some references out at the last minute.

This all applies only to the print edition, which you can pick up for free at some conferences. The web edition is always the latest and it gets all additions on the same day I edit it.

Vaadin 7 is in the works. We hope to get a preview edition of the Vaadin 7 book out in the summer, in July or so. Perhaps it could be red, if we begin the color cycle in the same order we did with Vaadin 6. The color is always a big decision.

Saturday, January 21, 2012

JPA and Vaadin JPAContainer

I've been finalizing the completely rewritten chapter about Vaadin JPAContainer this week. I still need to check that everything really important is included.

I don't have almost any previous experience with JPA, which is kind of good thing when you write documentation about something. That way, you personally know all the questions a beginner would have.

JPA and ORM in general seem pretty important technologies. Whatever your application is, you most probably need some data storage. Using ordinary files is possible, but not near as handy as proper databases. However, stuffing complex class structures through the square holes of database tables was a hell before the ORM technologies emerged. XML databases and NoSQL were much nicer for structured storage.

Some years ago I did some experiments with related technologies, such as JAXB and Hibernate, but using them was a bit too much effort at that time. Using Hibernate with Vaadin really required a Container implementation, but there wasn't one at that time. Well, JPA is quite close to Hibernate, and Hibernate is currently one of the JPA implementations.

Vaadin JPAContainer makes things really easy.
// Create a persistent person container
JPAContainer<Person> persons =
JPAContainerFactory.make(Person.class, "book-examples");

// You can add entities to the container as well
persons.addEntity(new Person("Marie-Louise Meilleur", 117));

// Bind it to a component
Table personTable = new Table("The Persistent People", persons);
personTable.setVisibleColumns(new String[]{"id","name","age"});
layout.addComponent(personTable);
So, just one command to get a container bound to data in a database table. JPAContainer is, however, just for binding user interface components directly to data. You can use it to add or edit the data, but using pure JPA is much nicer, easier, and more flexible for that.
EntityManager em = JPAContainerFactory.
createEntityManagerForPersistenceUnit("book-examples");
em.getTransaction().begin();
em.createQuery("DELETE FROM Person p").executeUpdate();
em.persist(new Person("Jeanne Calment", 122));
em.persist(new Person("Sarah Knauss", 119));
em.persist(new Person("Lucy Hannah", 117));
em.getTransaction().commit();
Well ok, here we got the entity manager from the JPAContainerFactory, which makes that a bit easier than normally.

JPAContainer is a commercial product. That shouldn't be a problem if you're coding for a company that can pay the license. For free software, you can use the AGPL license. I've always felt that this sort of dual-licensing scheme is most difficult for "potential startups" where you experiment with a business idea, but do not yet have a company to back it up financially. You do not normally have the money to invest in licenses at that point, and a company might not want to invest much in such experiments either.

There are of course alternatives for JPAContainer. Using pure JPA is quite OK approach as well, combined with BeanItemContainer in Vaadin. There's also SQLContainer. It is also something I don't know about, as I didn't write the chapter myself. I would need to review and reorganize it in next weeks though, and possibly rewrite at some point.

Well, I did make a couple of mistakes while writing the JPAContainer chapter. The first one was trying to just update a really complex design documentation written by someone else, in a topic I knew nothing about. Writing is always a learning experience and it's not sensible to try to write about something very complex that you don't have a clue about. Sometimes, it's best to start from scratch. Unfortunately, I didn't do that when I started, but just over a week before the release.

Another issue is learning by doing. I usually start writing documentation by experimenting how it works, making some example code. This time, as I was in a hurry, I tried to skip that phase. I only started it as the last effort when I was totally stuck, some 4 weeks of struggle behind and 2 work days before the release date. Just in those couple of days, all pieces fell into place and I finally understood how everything works.