Monday, July 22, 2013

Gradle Projects In Jdee

Gradle is really great automatization system. The combination of scripting language and dependency management produces simple and powerfull tool. Influenced by idea of Maven2 Jdee plugin I have made small task that generates Jdee project file. Although the script is not comprehensive (because it does not handle all Gradle features such as source sets, tasks, and so on) I think that is can be very useful, particularly in learning Gradle.

jdee.gradle Save the script and apply it into your main project file (build.gradle):
apply from:'jdee.gradle'
then run the task
gradle jdee

Please note that the task is applied only for subprojects of multi-project builds. To make it works for standalone projects just substitute subprojects to projects in line 38.

Tuesday, December 25, 2012

Solr Functions in Action

The DataImportHandler is great contrib which provides methods to import data into Solr from relational databases. It operates in two modes "full build" and "incremental updates". Delta import calculates changed items then executes query to extract data from the source. It spawns multiple round-trips between Solr and datasource which is often an undesirable behavior. Moreover sometimes it causes "out of memory" exception. So that authors suggest an alternative way by using the same query for both full and delta updates distinguishing them with request and "dataimporter.*" parameters.

What's wrong here? Certainly an XML attribute isn't the best place for writing SQL text. It's better to keep SQL in files (no need to to escape characters, highlighting and so on). Second painful thing is pretty complex query. Such constructions often cause bad execution plans, especially when query runs on complicated views. So there are two options: tune query (it may become overtuned or non-portable soon) or make query simpler.

I've written a few functions. They are very simple in itself but together they produce really great cumulative effect:

  • decode is remake of Oracle's decode
  • load reads query from file
  • run executes statements

Here is rewritten configuration file:

This is query for full index. Note what 'before-full.sql' runs before query execution:

Completely different table can be used in delta update:

Please find functions sources.

Monday, October 29, 2012

Java Development With Emacs

I would like to share my J2EE development environment. Currently it's Emacs 23 on Linux, Maven and few additional pieces of software.


The JDE is a major mode for editing java sources. I will not describe the whole package, just emphasize customizations and a way I use it. Since JDE has lack of Maven support I use Maven2 Jdee plugin to transforms pom.xml to prj.el. Here is oneliner which periodically performs such transformation on projects tree:

Unfortunately this script is quite complex because there are multi-module Maven POMs and we have to exclude their subprojects.

The JDE's settings are quite simple. I just set compiler output directory to the temporary folder to prevent the source directories from useless compiled files.


The JDE has nice feature "Context-Sensitive Class Help". There are no problems when you have graphical UI (XServer, Windows, etc.), you just specify your favorite browser (I'm sure it's Conkeror) and use it. I wish I had graphical UI. Console is all that I have. So I use text mode browser w3. It's unable to display local files so there is small fix:


One of the most boring routine in Java language is specifying imports. The JDE may do it for us automatically. All we need is just to append calls to "before-save-hook". To provide fast call back each file is compiled after saving, so you can efficiently fix cause of error without full project rebuilding.

I use "compile" command to run Maven goals. It's suitable for all targets such as building, testing, running. Torstein K. Johansen suggests to use "C-z" binding to call "compile". Setting "jde-compile" variable to "compile" seems reasonable as well. Also it's necessary to set additional regexps to parse compiler output.

I list frequently used compilations commands in special file which then load as compilation history. Header of each line is part of effective command so is possible to find a line in mini-buffer's history by pressing "M-r" + "HEADER":

Here is an example of predefined command lines


I use GNU GLOBAL as tagging system. It provides more correct tags table for Java then ctags or etags.


Log4j mode nice and only mode for viewing log4j logs in Emacs.


There are no special settings for Auto Complete Mode except adding "jde-mode" to "ac-list" and adding "gtags" as source.


I use jdb as debugger. Its default behavior is good and all what we need is to set source paths. I've made module jdb-sourcepath.el which appends source paths to rc-file (~/.jdbrc). Function jdb-sourcepath-from-rc helps us to read settings in jdb-mode:

The brilliant Jdb feature is redefining class on fly. Here is a shortcut for it:

Make Jdb Sourcepath

I've reimplemented script which scans sources and makes rc file for the Jdb. Now it's in Elisp jdb-sourcepath.el.

Here is init.el snippet:

Connection Manager for the Sqlplus Mode

As a developer you have to deal with several different databases. It's not easy to keep all of your environments in mind. Let's use Org-mode to help yourself.

Keep an environment's description in "org-mode" table:

Place the point to a connection line, call sqlplus-x-connect and you will get connected sqlplus-mode buffer. If different users have the same password you can write them in one cell.

Here is the sqlplus-x-connect

Advice. Use EasyPG package to keep your connections table in secret.