Oracle “sleep” procedure: DBMS_LOCK.SLEEP

There’s a nice little “sleep” procedure in Oracle: A procedure that stops the execution of the current thread for n seconds.

Strangely, this method can be called in SQL*Plus like so:

EXEC dbms_lock.sleep(10);

but not in another stored procedure or function like so

CREATE OR REPLACE PROCEDURE FOOBAR AS
BEGIN
  DBMS_LOCK.SLEEP(1);
END;
/

To use “sleep” in your procedures or functions, login as administrator to your database (or ask you admin to to so) and create the following objects:

CREATE OR REPLACE PROCEDURE sleep(seconds NUMBER) AS
BEGIN
  DBMS_LOCK.SLEEP(seconds);
END;
/
 
CREATE OR REPLACE public synonym sleep FOR sleep;
 
GRANT EXECUTE ON sleep TO public;

and in your procedure just use “sleep”.

| Comments (18) »

07-Sep-10


Preparing for Rails 2.3.9

As much as i wish to upgrade my Rails 2.3.x application Daily Fratze to the newest tag of the Rails 2.3.x branch, i cannot.

First there was the epic fail of release 2.3.6, that broke all HTML Helpers and forced the Rails XSS protection upon us. This release was immediately followed by 2.3.7 and 2.3.8. With my tests, this version was still enforcing Rails XSS and breaking helpers like “h”.

Rails 2.3.9, released last week, puts en end to this.

I just was about to upgrade, when i read this error: Textarea input silently truncated in 2.3.8!. The input of a textarea is truncated if the text entered consists of two lines or more with one of them quoted as the Rack middleware messes with the input.

I can confirm that this behavior still applies to 2.3.9.

It’s a shame, that all the talk is about Rails 3 with bugs like this in an older branch. I understand that this is a Rack problem but as it is already fixed in newer Rack versions, i cannot understand that the Rails team doesn’t bump the required Rack version respectively has no tests for problems like these.

So i’m hoping that Rails 2.3.10 sees the light of day anytime soon.

Anyway, as Rails 2.3.9 suddenly uses a new interpolation syntax for the translation files (“Hello {{name}}” becomes ” Hello %{name}”), here is a one-liner to update i18n files to the new syntax:

find . -iname "*.yml" -exec sed 's/{{\([^\{\}]*\)}}/%{\1}/g' -i {} \;

If you like some less escapism use xargs

find . -iname "*.yml"  | xargs sed 's/{{\([^{}]*\)}}/%{\1}/g' -i;

Commands need to be executed inside your locale directory.

| Comments (2) »

06-Sep-10


How to get UIDefaults in Java

If you’re loocking for Javas UIDefaults, use the UIManager class. This snippet gives you all installed UIDefaults:

UIDefaults defaults = UIManager.getDefaults();		 
for(Enumeration e = defaults.keys(); e.hasMoreElements(); ){
    String key = e.nextElement().toString();
    System.out.println(key + " = " + defaults.get(key));	         
}

| Comments (0) »

06-Sep-10


Find all non “.java” files but not in .svn directories

I’m migrating some old projects to Maven and i need to move all resources out of the source tree.

find . -type d -name '\.svn' -prune -o -type f -not -iname "*.java" -print
  • Prune every directory named ‘.svn’
  • Or
  • Type is file and the name ends not with “*.java”

I tried to create the necessary directories within the same command but after about half an hour xargs trial and error, i’ll do it manually, the list of files is small enough 😉

| Comments (0) »

19-Aug-10