Saturday 19 October 2013

Netbeans 7.x and Debian

Switched my laptop from Fedora 19 to Debian 7.1 for some peace, quiet and stability. It appears that the latest transitions to kernel 3.11 and the issues with the nvidia drivers were too much for it. So here I am, enjoying the Debian way of life without yum and gstreamer.

A goodie available only to Debian and Ubuntu users is the Oracle Java PPA available through this link. Andrew at webupd8,org has set up a PPA that downloads and installs the latest Oracle Java packages keeping your computer up to date along with the rest of normal updates.

So now it's Netbeans turn to get installed. I prefer to download the Java SE version and then manually add the PHP and CakePHP plugins that I require for my everyday use.

The first time I tried to install the normal way I ended up with an Exception: java.lang.NoClassDefFoundError thrown from the UncaughtExceptionHandler in thread "main". A little bit of digging revealed that that one way to install netbeans is to use the --silent installer option. The will install netbeans to the default /usr/local/netbeans-7.x location which is perfectly all right. After that you can run it from your desktop Development menu. So to start the installer just become root and type:

root@nb-thanassis:/home/thanassis/Downloads/Netbeans# ./netbeans-7.4-javase-linux.sh --silent

in a similar manner, in order to uninstall netbeans from your system, go to the installation directory and type

root@nb-thanassis:/usr/local/netbeans-7.4# ./uninstall.sh  --slinent

There is one small thing that I noticed. in order for all this to work you must cd to the same directory as the installer script before issueing any commands. In my case -- hence the blog post -- all other attempts failed.

.

Monday 7 October 2013

CakePHP locking tables

Here are my two cents on the issue.

The code below is a function from a behaviour that tries to create an additional unique key on a field named code, by counting the number of records created this year. The important part in the locking procedure is that we must specify the AS clause in the LOCK TABLES statement or otherwise the $model->find() function will not work complaining that the table is locked.

    public function getNextCode(&$model)
    {
        $thisYear = date('Y');
        $dbo = $model->getDataSource();
        $dbo->execute(
            sprintf('LOCK TABLES %s AS %s WRITE;',
                $model->table,
                $model->alias
            )
        );
        $recordsThisYear = $model->find(
            'count',
            array(
                'recursive' => -1,
                'conditions' => array(
                    $model->alias .'.code LIKE' => $thisYear.'%'
                )
            )
        );
        $dbo->execute('UNLOCK TABLES');
        return sprintf('%d-%06d', $thisYear, $recordsThisYear + 1);
    }

The original idea for the post and function cake from a doWeb posting available through here.