Example usage for org.hibernate.mapping Formula getFormula

List of usage examples for org.hibernate.mapping Formula getFormula

Introduction

In this page you can find the example usage for org.hibernate.mapping Formula getFormula.

Prototype

public String getFormula() 

Source Link

Usage

From source file:org.unitime.commons.hibernate.util.HibernateUtil.java

License:Open Source License

public static void fixSchemaInFormulas(Configuration cfg) {
    cfg.buildMappings();/* ww w.  j  a  v a2 s .  c  om*/
    String schema = cfg.getProperty("default_schema");
    if (schema != null) {
        for (Iterator i = cfg.getClassMappings(); i.hasNext();) {
            PersistentClass pc = (PersistentClass) i.next();
            for (Iterator j = pc.getPropertyIterator(); j.hasNext();) {
                Property p = (Property) j.next();
                for (Iterator k = p.getColumnIterator(); k.hasNext();) {
                    Selectable c = (Selectable) k.next();
                    if (c instanceof Formula) {
                        Formula f = (Formula) c;
                        if (f.getFormula() != null && f.getFormula().indexOf("%SCHEMA%") >= 0) {
                            f.setFormula(f.getFormula().replaceAll("%SCHEMA%", schema));
                            sLog.debug("Schema updated in " + pc.getClassName() + "." + p.getName() + " to "
                                    + f.getFormula());
                        }
                    }
                }
            }
        }
    }
}