Example usage for org.hibernate.persister.entity SingleTableEntityPersister getPropertyNames

List of usage examples for org.hibernate.persister.entity SingleTableEntityPersister getPropertyNames

Introduction

In this page you can find the example usage for org.hibernate.persister.entity SingleTableEntityPersister getPropertyNames.

Prototype

public String[] getPropertyNames() 

Source Link

Usage

From source file:to.etc.domui.hibernate.model.CriteriaCreatingVisitor.java

License:Open Source License

/**
 * Try to locate the property in the child that refers to the parent in a horrible way.
 * @param cm//from ww w  .ja v  a  2  s  . c  o m
 * @param keyCols
 * @return
 */
private String findCruddyChildProperty(ClassMetadata cm, String[] keyCols) {
    SingleTableEntityPersister fuckup = (SingleTableEntityPersister) cm;
    for (int i = fuckup.getPropertyNames().length; --i >= 0;) {
        String[] cols = fuckup.getPropertyColumnNames(i);
        if (Arrays.equals(keyCols, cols)) {
            return cm.getPropertyNames()[i];
        }
    }

    /*
     * The identifier property is fully separate from all other properties because that
     * makes it hard to use, of course. So explicitly check for a full identifying relation
     * initially.
     */
    String idname = fuckup.getIdentifierPropertyName();
    String[] cols = fuckup.getIdentifierColumnNames();
    if (Arrays.equals(keyCols, cols)) {
        return idname;
    }

    /*
     * The ID property can be compound, in that case we need to handle it's
     * component properties separately. This code is wrong because it only
     * handles one level of indirection - but that is enough for me now, this
     * is horrible. The proper way of implementing is to recursively determine
     * the smallest property accessing the columns specified in this call, and
     * to determine it's full path.
     */
    Type idtype = fuckup.getIdentifierType();
    if (idtype instanceof ComponentType) {
        ComponentType ct = (ComponentType) idtype;

        //         for(int scp = 0; scp < fuckup.countSubclassProperties(); scp++) { There's no end to the incredible mess.
        //            String scpn = fuckup.getSubclassPropertyName(scp);
        //            cols = fuckup.getSubclassPropertyColumnNames(scpn);
        //            System.out.println("prop: " + scpn + ", cols=" + Arrays.toString(cols));
        //         }
        //

        String[] xx = fuckup.getSubclassPropertyColumnNames(idname);
        String[] cpnar = ct.getPropertyNames();
        for (int i = 0; i < cpnar.length; i++) {
            String pname = cpnar[i];
            cols = fuckup.getSubclassPropertyColumnNames(idname + "." + pname);
            if (Arrays.equals(keyCols, cols)) {
                return idname + "." + pname;
            }
        }
    }

    //-- All has failed- mapping unknown.
    return null;
}