Monday, August 31, 2009

maven2 - define the context root of an webapp

Basically I have an application (ear) based on several jars and a war which I want to easily access with a context root of my choice.

Solution:


<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
<jboss>
<version>4</version>
</jboss>
<bundleFileName>
binbase-quality-control.ear
</bundleFileName>

<modules>
<webModule>
<groupId>edu.ucdavis.genomics.metabolomics.binbase.quality
</groupId>
<artifactId>quality-war</artifactId>
<contextRoot>/quality-war</contextRoot>
</webModule>
</modules>

</configuration>
</plugin>

Sunday, August 9, 2009

Method "ApplyConfiguration" with signature "" on interface "org.gnome.SettingsDaemon.XRANDR" doesn't exist

today I wanted todo nothing else than the change the primaery output of my laptop to the 40" display attached over DVI to watch movies on it.

Sadly since ubuntu 8.something I kept getting the following error message


Method "ApplyConfiguration" with signature "" on interface "org.gnome.SettingsDaemon.XRANDR" doesn't exist


So I upgraded to the newest ubuntu version. Didn't make it much better. So I could had given up here and start shouting all kinds off stuff about linux or trying to make it work.

So here is the solution:

the gui is basically broken and you need to execute the commands to adjust everything your self. Using 'xandr'

for example to turn off a monitor:


xandr --output LVDS --off


or to change the resolution


xandr --output DVI-0 --mode 1360x768 --pos 0x0


2 minutes later I had my configuration up and running.

Tuesday, August 4, 2009

synchornized groovy

Today I discovered the question:

I want to have a websites which fires calculations to a database server, but the controller should only execute one calculation at a time

how do you do this?

The first approach was to try to queue the ajax calls, which obviously won't work if two people run calculations at the same time.

So plan b was to use synchronized groovy code.



/**
* does the actual calculation
*/
def calculate_ajax = {

assert params.database != null, "you need to provide 'database' in the params object"
assert params.date != null, "you need to provide 'date' in the params object"
assert params.machine != null, "you need to provide 'machine' in the params object"
assert params.pattern != null, "you need to provide 'pattern' in the params object"
assert params.position != null, "you need to provide 'position' in the params object"

//needs to be synchronized so we don't kill the database server with this task
synchronized (LOCK) {
println new Date()
BinBaseQualityConnector.getQualityService().calculateSingleStandard(params.pattern, params.database, new Date(Long.parseLong(params.date)), params.machine, BinBaseQualityConnector.getKey())
render("<div class=\"after_complete\" style=\"width:${100 / BinBaseQualityConnector.getPattern(params).size()}%\"></div>")

}
}

static final def LOCK = "lock"


and a possible ajax call for this looks like this


<script type="text/javascript">
YAHOO.util.Event.onDOMReady(
function() {
new Ajax.Updater('${i}_${y}_${z}', '/quality-war/processing/calculate_ajax', {
method: 'get', frequency: 3,parameters:'date=${date.getTime()}&database=${database}&machine=${machine}&pattern=${pattern}&position=${z}'
});
});
</script>

Tuesday, July 28, 2009

updating more than one div with grails and ajax

sometimes it happens that you have to update several div's on one webpage, when you click on a form or a button.

Now you can either reload the complete page, which can take a while with a lot of data or just queue remote functions in a java script function like this


function addStandard() {

if (YAHOO.example.container.addstandard) {
YAHOO.example.container.addstandard.hide();
}

//get our element values
var conc = document.getElementsByName('qs_concentration')[0].value;
var pattern = document.getElementsByName('qs_pattern')[0].value;

//calls the remote functions
${remoteFunction(
controller: 'management',
action: 'addStandard_ajax',
params: '\'conc=\' + escape(conc) + \'&pattern=\' + escape(pattern)',
update: 'registered_standards')}

${remoteFunction(
controller: 'messenger',
action: 'showMessage',
params: '\'message=you should recalculate the database now!\'',
update: 'messenger')}
}

javascripts and maps

since java script contains no Maps, well use an object instead with dynamic properties.


var test = new Object();
test['tada'] = 'yada';

alert(test['yada']);
alert(test.yada);

distinct or group by, what's more expensive

today I was asking my self about the best approach for a performance critical application.

Distinct or group by '*'



select name from table group by name



or



select distinct name from table



after all they both return the exact same result.

Some explain statements later it turned out that the group by clause is 18% faster than the distinct statement.

Monday, July 27, 2009

sometimes it's simpler to use plain ajax...

today I was struggling for a bit with generating the update part of a remote function on the fly and after a couple of minutes. I started thinking, do I have to really use this tag? Why don't I use just plain Ajax, since grails will generate the same code anyway.

Solution:


<div class="center">
<img name="${bin.getId()}" src="${createLinkTo(dir: 'images', file: 'remove.gif')}" alt="zoom" onclick="new Ajax.Updater

('bin-container-${db}', '/quality-war/management/remove_bin_ajax', {asynchronous:true,evalScripts:true,parameters


:'bin=${bin.getId()}&database=${db}'});"/>
</div>


this also shows how to submit several parameters at once in plain ajax style.