Example usage for org.hibernate.tuple.entity EntityTuplizerFactory registerDefaultTuplizerClass

List of usage examples for org.hibernate.tuple.entity EntityTuplizerFactory registerDefaultTuplizerClass

Introduction

In this page you can find the example usage for org.hibernate.tuple.entity EntityTuplizerFactory registerDefaultTuplizerClass.

Prototype

public void registerDefaultTuplizerClass(EntityMode entityMode, Class<? extends EntityTuplizer> tuplizerClass) 

Source Link

Document

Method allowing registration of the tuplizer class to use as default for a particular entity-mode.

Usage

From source file:lucee.runtime.orm.hibernate.HibernateORMEngine.java

License:Open Source License

private SessionFactoryData getSessionFactoryData(PageContext pc, int initType) throws PageException {
    ApplicationContextPro appContext = (ApplicationContextPro) pc.getApplicationContext();
    if (!appContext.isORMEnabled())
        throw ExceptionUtil.createException((ORMSession) null, null, "ORM is not enabled", "");

    // datasource
    ORMConfiguration ormConf = appContext.getORMConfiguration();
    String key = hash(ormConf);/*from www.  java  2  s. c  om*/
    SessionFactoryData data = factories.get(key);
    if (initType == INIT_ALL && data != null) {
        data.reset();
        data = null;
    }
    if (data == null) {
        data = new SessionFactoryData(this, ormConf);
        factories.put(key, data);
    }

    // config
    try {
        //arr=null;
        if (initType != INIT_NOTHING) {
            synchronized (data) {

                if (ormConf.autogenmap()) {
                    data.tmpList = HibernateSessionFactory.loadComponents(pc, this, ormConf);

                    data.clearCFCs();
                } else
                    throw ExceptionUtil.createException(data, null,
                            "orm setting autogenmap=false is not supported yet", null);

                // load entities
                if (data.tmpList != null && data.tmpList.size() > 0) {
                    data.getNamingStrategy();// called here to make sure, it is called in the right context the first one

                    // creates CFCInfo objects
                    {
                        Iterator<Component> it = data.tmpList.iterator();
                        while (it.hasNext()) {
                            createMapping(pc, it.next(), ormConf, data);
                        }
                    }

                    if (data.tmpList.size() != data.sizeCFCs()) {
                        Component cfc;
                        String name, lcName;
                        Map<String, String> names = new HashMap<String, String>();
                        Iterator<Component> it = data.tmpList.iterator();
                        while (it.hasNext()) {
                            cfc = it.next();
                            name = HibernateCaster.getEntityName(cfc);
                            lcName = name.toLowerCase();
                            if (names.containsKey(lcName))
                                throw ExceptionUtil.createException(data, null,
                                        "Entity Name [" + name + "] is ambigous, [" + names.get(lcName)
                                                + "] and [" + cfc.getPageSource().getDisplayPath()
                                                + "] use the same entity name.",
                                        "");
                            names.put(lcName, cfc.getPageSource().getDisplayPath());
                        }
                    }
                }
            }
        }
    } finally {
        data.tmpList = null;
    }

    // already initialized for this application context

    //MUST
    //cacheconfig
    //cacheprovider
    //...

    Log log = ((ConfigImpl) pc.getConfig()).getLog("orm");

    Iterator<Entry<Key, String>> it = HibernateSessionFactory.createMappings(ormConf, data).entrySet()
            .iterator();
    Entry<Key, String> e;
    while (it.hasNext()) {
        e = it.next();
        if (data.getConfiguration(e.getKey()) != null)
            continue;

        DatasourceConnection dc = CommonUtil.getDatasourceConnection(pc, data.getDataSource(e.getKey()));
        try {
            data.setConfiguration(log, e.getValue(), dc);
        } catch (Exception ex) {
            throw CommonUtil.toPageException(ex);
        } finally {
            CommonUtil.releaseDatasourceConnection(pc, dc);
        }
        addEventListeners(pc, data, e.getKey());

        EntityTuplizerFactory tuplizerFactory = data.getConfiguration(e.getKey()).getEntityTuplizerFactory();
        tuplizerFactory.registerDefaultTuplizerClass(EntityMode.MAP, AbstractEntityTuplizerImpl.class);
        tuplizerFactory.registerDefaultTuplizerClass(EntityMode.POJO, AbstractEntityTuplizerImpl.class);

        data.buildSessionFactory(e.getKey());
    }

    return data;
}