Le blog d'Olivier

Aller au contenu | Aller au menu | Aller à la recherche

mercredi 17 décembre 2008

How to create Oracle function (trunc, decode, ...) in H2 ?

I use Oracle in production environment, but I use an embedded H2 database in unit tests. H2 does not support Oracle functions like TRUNC or DECODE.

So, you can write yourself these functions ... in Java :)

// Oracle trunc like
public class H2Trunc {
    public final static Date trunc(Timestamp timeStamp) {
        return new Date(timeStamp.getTime());
    }
}
// Oracle decode like
public class H2Decode {
    public final static String decode(String expression, String param1, String value1, String param2, String value2, String param3,
            String value3, String param4, String value4, String param5, String value5, String param6, String value6, String param7,
            String value7, String param8, String value8, String defaultValue) {

        if (StringUtils.equals(expression, param1)) {
            return value1;
        }
        if (StringUtils.equals(expression, param2)) {
            return value2;
        }
        if (StringUtils.equals(expression, param3)) {
            return value3;
        }
        if (StringUtils.equals(expression, param4)) {
            return value4;
        }
        if (StringUtils.equals(expression, param5)) {
            return value5;
        }
        if (StringUtils.equals(expression, param6)) {
            return value6;
        }
        if (StringUtils.equals(expression, param7)) {
            return value7;
        }
        if (StringUtils.equals(expression, param8)) {
            return value8;
        }
        return defaultValue;
    }
}

In H2, create these functions with sql:

CREATE ALIAS IF NOT EXISTS DECODE FOR \"com.my.package.H2Decode.decode\"; CREATE ALIAS IF NOT EXISTS TRUNC FOR \"com.my.package.H2Trunc.trunc\"

jeudi 31 juillet 2008

How to speed up the GWT compiler ? (Part I)

English version

I am working on an international CRM project based on JDK 6, GWT 1.5, MyGWT/Ext GWT, tomcat 6, maven, hibernate, spring, Oracle, ...

This business application must worked with Firefox 2, IE 6/7 and 9 locales (the target is about 15 locales).

This a very large GWT application and it takes a long time to compile, about 12 mn "only" for GWT maven module : this is a long time in development mode.

GWT spends time to compute permutations : create javascript file per browser/locale. With this kind of application, GWT produces 50 permutations :

  • 5 browsers : ie6, opera, gecko1_8, safari, gecko
  • 10 locales : default, de_DE, en_UK, fr_FR, hr_HR, hu_HU, it_IT, nl_NL, pl_PL, pt_PT

This is my module.gwt.xml :

<module>
    <!-- Inherit the core Web Toolkit stuff. -->
    <inherits name="com.google.gwt.user.User" />
    <inherits name="com.google.gwt.i18n.I18N" />

    <!-- Add support -->
    <inherits name="com.aaa.bbb.ccc.XXXCore" />
    <!-- Add mygwt support -->
    <inherits name="net.mygwt.ui.MyGWT" />
    <!-- Add hibernate4gwt support -->
    <inherits name="net.sf.hibernate4gwt.Hibernate4Gwt" />
    <inherits name="net.sf.hibernate4gwt.SqlDates"/>
    <!-- Add gwt-log support -->
    <inherits name="com.allen_sauer.gwt.log.gwt-log" />

    <!-- Add ftr-gwt-library-date -->
    <inherits name='org.cobogw.gwt.user.User' />
    <inherits name="eu.future.earth.gwt.FtrGwtLibrary" />

    <!-- GWT locale -->
    <extend-property name="locale" values="de_DE" />
    <extend-property name="locale" values="en_UK" />
    <extend-property name="locale" values="fr_FR" />
    <extend-property name="locale" values="hr_HR" />
    <extend-property name="locale" values="hu_HU" />
    <extend-property name="locale" values="it_IT" />
    <extend-property name="locale" values="pt_PT" />
    <extend-property name="locale" values="pl_PL" />
    <extend-property name="locale" values="nl_NL" />

    <!-- Logging -->
    <extend-property name="log_level" values="DEBUG,INFO,WARN,FATAL,EROR,OFF" />
    <set-property name="log_level" value="INFO" />

    <!-- Turn off "DivLogger" -->
    <set-property name="log_DivLogger" value="DISABLED" />

    <!-- Specify the app entry point class. -->
    <entry-point class="com.aaa.bbb.ccc.XXXEntryPoint" />

</module>

The main idea is to reduce permutations.

How to speed up the GWT compiler ? (Part II).

How to speed up the GWT compiler ? (Part III).

French version

Coming soon.

mercredi 9 avril 2008

Commandes utiles Oracle IV

Dropper les synonymes :

SELECT 'DROP SYNONYM ', synonym_name, ';' FROM user_synonyms;

mercredi 28 novembre 2007

Commandes utiles Oracle III

Encore quelques commandes utiles pour la vie de tous les jours sous Oracle :

1. Liste des tables

SELECT table_name FROM user_tables;

2. Liste des vues

SELECT view_name FROM user_views;

3. Informations sur les contraintes

SELECT * FROM user_constraints WHERE constraint_name='FKXXXXXXXXXXXXXXXX';

4. Liste des procédures

SELECT DISTINCT procedure_name FROM all_procedures;

mardi 11 septembre 2007

Commandes utiles Oracle II

Un autre commande en plus de celles déjà blogger :

Lister les séquences (et générer un script de destruction de l'ensemble) :

select 'drop sequence ', SEQUENCE_NAME, ';' from user_sequences;

'DROPSEQUENCE' SEQUENCE_NAME                  ';' 
-------------- ------------------------------ --- 
drop sequence  SEQ_XXX                                   ;   
drop sequence  SEQ_XXX                                   ;   

- page 1 de 2