Example usage for org.hibernate.mapping RootClass getClassName

List of usage examples for org.hibernate.mapping RootClass getClassName

Introduction

In this page you can find the example usage for org.hibernate.mapping RootClass getClassName.

Prototype

public String getClassName() 

Source Link

Usage

From source file:com.enonic.cms.store.hibernate.cache.invalidation.InvalidationRulesBuilder.java

License:Open Source License

/**
 * Build the root class./*from  w  ww.  j  a  v  a  2s .c  o m*/
 */
private void createTableRule(RootClass mapping) {
    addTableRule(mapping.getTable().getName(), mapping.getClassName());
}

From source file:com.wavemaker.runtime.data.hibernate.DataServiceMetaData_Hib.java

License:Open Source License

private void initMappingData() {

    RootClass rc;
    // for (Iterator<RootClass> iter = CastUtils.cast(getConfiguration()
    for (Iterator iter = CastUtils.cast(getConfiguration().getClassMappings()); iter.hasNext();) {

        // RootClass rc = iter.next();
        Object obj = iter.next();
        if (obj instanceof RootClass) {
            rc = (RootClass) obj;/*from   ww w  . j  a v a 2s . c om*/
        } else {
            rc = ((Subclass) obj).getRootClass();
        }

        String s = rc.getClassName();
        this.entityClassNames.add(s);
        this.entityNames.add(StringUtils.splitPackageAndClass(s).v2);

        this.rootClasses.put(rc.getMappedClass(), rc);
        this.entityClasses.add(rc.getMappedClass());

        Map<String, Property> propertiesMap = new HashMap<String, Property>();
        this.allPropertiesMap.put(rc.getClassName(), propertiesMap);

        for (Iterator<Property> iter2 = CastUtils.cast(rc.getPropertyIterator()); iter2.hasNext();) {

            Property p = iter2.next();
            initProperty(rc.getClassName(), p, propertiesMap);
        }

        Property id = rc.getIdentifierProperty();
        initProperty(rc.getClassName(), id, propertiesMap);
    }
}

From source file:com.wavemaker.runtime.data.hibernate.DataServiceMetaData_Hib.java

License:Open Source License

@Override
public String getDataPackage() {
    Configuration cfg = getConfiguration();
    RootClass rc = (RootClass) cfg.getClassMappings().next();
    String className = rc.getClassName();
    return StringUtils.fromLastOccurrence(className, ".", -1);
}

From source file:gov.nih.nci.system.util.ClassCache.java

License:BSD License

/**
 * initialize with a list of the classes obtained from each DAO class within
 * the System//from   w w w  .j  av a  2 s  .  c o m
 */
private void initialize() throws DAOException {

    String unqualifiedClassName = null;
    Class klass = null;

    HashSet<String> tmpPackageNames = new HashSet<String>();

    List<String> allClassNames;
    Set<String> implicitClassNames = new HashSet<String>();

    for (DAO dao : daoList) {

        allClassNames = dao.getAllClassNames();

        // Implicit superclasses have no hibernate mapping and so are not
        // part of the dao class names
        String implicitSuperclass = null;
        for (String klassName : allClassNames) {
            implicitSuperclass = klassName;
            do {
                try {
                    implicitSuperclass = Class.forName(implicitSuperclass).getSuperclass().getName();
                    log.debug("Checking if class " + implicitSuperclass + " is implicit");

                    if (!(implicitSuperclass.equalsIgnoreCase("java.lang.Object"))
                            && !(allClassNames.contains(implicitSuperclass))) {
                        log.debug("Adding " + implicitSuperclass + " as an implicit superclass");
                        implicitClassNames.add(implicitSuperclass);
                    }
                } catch (ClassNotFoundException e) {
                    log.error("Error:  Class not found: " + implicitSuperclass);
                    implicitSuperclass = null;
                }
            } while ((!implicitSuperclass.equalsIgnoreCase("java.lang.Object"))
                    && !(implicitSuperclass == null));
        }

        log.debug("Number of implicit superclasses found: " + implicitClassNames.size());
        allClassNames.addAll(implicitClassNames);

        // Certain metadata needs to be generated prior to caching the rest
        // of the info
        for (String klassName : allClassNames) {

            try {
                klass = Class.forName(klassName);
            } catch (ClassNotFoundException e) {
                log.error("ClassNotFoundException caught: ", e);
            }
            String packageName = klass.getPackage().getName();
            unqualifiedClassName = klassName.substring(klassName.lastIndexOf(".") + 1);
            log.debug("Unqualified class name: " + unqualifiedClassName);

            if ((pkgNameForClassCache.get(klassName.toLowerCase()) != null)
                    || (pkgNameForClassCache.get(unqualifiedClassName) != null)) {
                throw new DAOException(
                        "Duplicate Class name found while initializing ClassCache: " + klassName);
            }
            // Cache the package name for each klass
            pkgNameForClassCache.put(klassName.toLowerCase(), packageName);
            pkgNameForClassCache.put(unqualifiedClassName.toLowerCase(), packageName);
            nonPrimitiveFieldsCache.put(klassName, cacheNonPrimitiveFieldNames(klass));

            allFieldsCache.put(klassName, cacheAllFieldNames(klass));

            log.debug("Adding class " + klass.getName() + " to Class Cache.");
            classCache.put(klassName, klass);
            classCache.put(klassName.toLowerCase(), klass);
            classCache.put(unqualifiedClassName, klass);
            classCache.put(unqualifiedClassName.toLowerCase(), klass);

            log.debug("Adding class " + klass.getName() + " to DAO Cache for DAO: " + dao.getClass().getName());
            daoCache.put(klassName, dao);
            daoCache.put(klassName.toLowerCase(), dao);
            daoCache.put(unqualifiedClassName, dao);
            daoCache.put(unqualifiedClassName.toLowerCase(), dao);

            // Cache the identifier (id key) for each class
            if (dao instanceof ORMDAOImpl)
                classIdCache.put(klassName, ((ORMDAOImpl) dao).getClassIdentiferName(klassName));
        }

        // Certain metadata needs to be cached prior to caching the rest,
        // so here we loop through the second time now that we have the data
        // we need
        for (String klassName : allClassNames) {
            log.debug("Adding class " + klassName + " to allClassNames List");

            allQualClassNames.add(klassName);
            unqualifiedClassName = klassName.substring(klassName.lastIndexOf(".") + 1);
            log.debug("Unqualified class name: " + unqualifiedClassName);
            allUnqualClassNames.add(unqualifiedClassName);

            List<String> pkgClassNames = new ArrayList<String>();
            try {
                klass = Class.forName(klassName);

                String packageName = klass.getPackage().getName();

                // Cache all package names
                tmpPackageNames.add(packageName);

                // Cache associations for klass
                classAssociationsCache.put(klassName, cacheAssociations(klassName));

                // Collect all class names within a package
                if (!pkgClassNamesCache.containsKey(packageName)) {
                    pkgClassNames.add(klassName);
                    pkgClassNamesCache.put(packageName, pkgClassNames);
                } else {
                    List<String> existingCollection = pkgClassNamesCache.get(packageName);
                    existingCollection.add(klassName);
                }

            } catch (ClassNotFoundException cnfe) {
                log.error("Exception caught while initializing ClassCache for class: " + klassName, cnfe);
            }
        }

        for (String klassName : allClassNames) {
            log.debug("Adding class " + klassName + " to subClassCache List");
            try {
                klass = Class.forName(klassName);

                String currentKlassName = klassName;
                Class superKlass = klass.getSuperclass();
                String superKlassName = superKlass.getName();
                while (!"java.lang.Object".equals(superKlass.getName())) {
                    List<String> subKlassNames = subClassCache.get(superKlassName);
                    if (subKlassNames == null) {
                        subKlassNames = new ArrayList<String>();
                        subClassCache.put(superKlassName, subKlassNames);
                    }
                    if (!subKlassNames.contains(currentKlassName))
                        subKlassNames.add(currentKlassName);
                    currentKlassName = superKlass.getName();
                    superKlass = superKlass.getSuperclass();
                    superKlassName = superKlass.getName();
                }
            } catch (ClassNotFoundException e) {
                log.error("Exception caught while initializing ClassCache for class: " + klassName, e);
            }
        }

        if (dao instanceof ORMDAOImpl) {
            Configuration cfg = ((ORMDAOImpl) dao).getConfig();

            Iterator iter = cfg.getClassMappings();
            while (iter.hasNext()) {
                PersistentClass pklass = (PersistentClass) iter.next();
                Object identifier = null;
                log.debug("Getting discriminator details for : " + pklass.getClassName() + ":");
                if (pklass instanceof Subclass) {
                    Subclass subklass = (Subclass) pklass;
                    if (subklass.isJoinedSubclass())
                        identifier = subklass.getSubclassId();
                    else
                        identifier = getShortClassName(subklass.getClassName());
                } else if (pklass instanceof RootClass) {

                    RootClass rootklass = (RootClass) pklass;
                    if (rootklass.getDiscriminator() == null)
                        identifier = rootklass.getSubclassId();
                    else
                        identifier = getShortClassName(rootklass.getClassName());
                }
                log.debug(identifier);
                discriminatorMap.put(pklass.getClassName(), identifier);
            }
        }
        if (dao instanceof ORMDAOImpl) {
            Configuration cfg = ((ORMDAOImpl) dao).getConfig();
            for (String className : allClassNames) {
                Map<String, Map<String, List<Object>>> tempSearchFieldForObject = getMapOfSearchFields(cfg,
                        className);
                if (tempSearchFieldForObject != null)
                    searchableFieldsMap.putAll(tempSearchFieldForObject);
            }
        }
    }

    allPackageNamesCache = new ArrayList<String>(tmpPackageNames);

    Collections.sort(allPackageNamesCache);
    Collections.sort(allQualClassNames);
    Collections.sort(allUnqualClassNames);
}

From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java

License:Apache License

/**
 * Creates and binds the discriminator property used in table-per-hierarchy inheritance to
 * discriminate between sub class instances
 *
 * @param table    The table to bind onto
 * @param entity   The root class entity
 * @param mappings The mappings instance
 *///from  ww w  . j a  v a2s  .c o m
protected void bindDiscriminatorProperty(Table table, RootClass entity, Mappings mappings) {
    Mapping m = getMapping(entity.getMappedClass());
    SimpleValue d = new SimpleValue(mappings, table);
    entity.setDiscriminator(d);
    entity.setDiscriminatorValue(
            m != null && m.getDiscriminator() != null ? m.getDiscriminator() : entity.getClassName());

    if (m != null && m.getDiscriminatorMap().get("insert") != null) {
        entity.setDiscriminatorInsertable((Boolean) m.getDiscriminatorMap().get("insert"));
    }
    if (m != null && m.getDiscriminatorMap().get("type") != null) {
        d.setTypeName((String) m.getDiscriminatorMap().get("type"));
    }

    if (m != null && m.getDiscriminatorMap().get("formula") != null) {
        Formula formula = new Formula();
        formula.setFormula((String) m.getDiscriminatorMap().get("formula"));
        d.addFormula(formula);
    } else {
        bindSimpleValue(STRING_TYPE, d, false, RootClass.DEFAULT_DISCRIMINATOR_COLUMN_NAME, mappings);

        ColumnConfig cc = m == null ? null : m.getDiscriminatorColumn();
        if (cc != null) {
            Column c = (Column) d.getColumnIterator().next();
            if (cc.getName() != null) {
                c.setName(cc.getName());
            }
            bindColumnConfigToColumn(c, cc);
        }
    }

    entity.setPolymorphic(true);
}

From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.java

License:Apache License

/**
 * Creates and binds the discriminator property used in table-per-hierarchy inheritance to
 * discriminate between sub class instances
 *
 * @param table    The table to bind onto
 * @param entity   The root class entity
 * @param mappings The mappings instance
 *///from  w ww  . jav a 2 s  . c  om
private static void bindDiscriminatorProperty(Table table, RootClass entity, Mappings mappings) {
    Mapping m = getMapping(entity.getMappedClass());
    SimpleValue d = new SimpleValue(mappings, table);
    entity.setDiscriminator(d);
    entity.setDiscriminatorValue(
            m != null && m.getDiscriminator() != null ? m.getDiscriminator() : entity.getClassName());

    if (m != null && m.getDiscriminatorMap().get("insert") != null) {
        entity.setDiscriminatorInsertable((Boolean) m.getDiscriminatorMap().get("insert"));
    }
    if (m != null && m.getDiscriminatorMap().get("type") != null) {
        d.setTypeName((String) m.getDiscriminatorMap().get("type"));
    }

    if (m != null && m.getDiscriminatorMap().get("formula") != null) {
        Formula formula = new Formula();
        formula.setFormula((String) m.getDiscriminatorMap().get("formula"));
        d.addFormula(formula);
    } else {
        bindSimpleValue(STRING_TYPE, d, false, RootClass.DEFAULT_DISCRIMINATOR_COLUMN_NAME, mappings);

        ColumnConfig cc = m == null ? null : m.getDiscriminatorColumn();
        if (cc != null) {
            Column c = (Column) d.getColumnIterator().next();
            if (cc.getName() != null) {
                c.setName(cc.getName());
            }
            bindColumnConfigToColumn(c, cc);
        }
    }

    entity.setPolymorphic(true);
}

From source file:org.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java

License:Apache License

/**
 * Creates and binds the discriminator property used in table-per-hierarchy inheritance to
 * discriminate between sub class instances
 *
 * @param table    The table to bind onto
 * @param entity   The root class entity
 * @param mappings The mappings instance
 *//*from w  w w  .  j av a  2s. c om*/
protected void bindDiscriminatorProperty(Table table, RootClass entity, Mappings mappings) {
    Mapping m = getMapping(entity.getMappedClass());
    SimpleValue d = new SimpleValue(mappings, table);
    entity.setDiscriminator(d);
    entity.setDiscriminatorValue(
            m != null && m.getDiscriminator() != null ? m.getDiscriminator() : entity.getClassName());

    if (m != null && m.getDiscriminatorMap().get("insert") != null) {
        entity.setDiscriminatorInsertable((Boolean) m.getDiscriminatorMap().get("insert"));
    }
    if (m != null && m.getDiscriminatorMap().get("type") != null) {
        d.setTypeName((String) m.getDiscriminatorMap().get("type"));
    }

    if (m != null && m.getDiscriminatorMap().get("formula") != null) {
        Formula formula = new Formula();
        formula.setFormula((String) m.getDiscriminatorMap().get("formula"));
        d.addFormula(formula);
    } else {
        bindSimpleValue(STRING_TYPE, d, false, RootClass.DEFAULT_DISCRIMINATOR_COLUMN_NAME, mappings);

        ColumnConfig cc = m == null ? null : m.getDiscriminatorColumn();
        if (cc != null) {
            Column c = (Column) d.getColumnIterator().next();
            if (cc.getName() != null) {
                c.setName(cc.getName());
            }
            bindColumnConfigToColumn(null, c, cc);
        }
    }

    entity.setPolymorphic(true);
}

From source file:org.grails.orm.hibernate.cfg.GrailsDomainBinder.java

License:Apache License

/**
 * Creates and binds the discriminator property used in table-per-hierarchy inheritance to
 * discriminate between sub class instances
 *
 * @param table    The table to bind onto
 * @param entity   The root class entity
 * @param mappings The mappings instance
 *///from   w w  w .  j  a v a2  s .c  o  m
protected void bindDiscriminatorProperty(Table table, RootClass entity, InFlightMetadataCollector mappings) {
    Mapping m = getMapping(entity.getMappedClass());
    SimpleValue d = new SimpleValue(mappings, table);
    entity.setDiscriminator(d);
    DiscriminatorConfig discriminatorConfig = m != null ? m.getDiscriminator() : null;

    boolean hasDiscriminatorConfig = discriminatorConfig != null;
    entity.setDiscriminatorValue(
            hasDiscriminatorConfig ? discriminatorConfig.getValue() : entity.getClassName());

    if (hasDiscriminatorConfig) {
        if (discriminatorConfig.getInsertable() != null) {
            entity.setDiscriminatorInsertable(discriminatorConfig.getInsertable());
        }
        Object type = discriminatorConfig.getType();
        if (type != null) {
            if (type instanceof Class) {
                d.setTypeName(((Class) type).getName());
            } else {
                d.setTypeName(type.toString());
            }
        }
    }

    if (hasDiscriminatorConfig && discriminatorConfig.getFormula() != null) {
        Formula formula = new Formula();
        formula.setFormula(discriminatorConfig.getFormula());
        d.addFormula(formula);
    } else {
        bindSimpleValue(STRING_TYPE, d, false, RootClass.DEFAULT_DISCRIMINATOR_COLUMN_NAME, mappings);

        ColumnConfig cc = !hasDiscriminatorConfig ? null : discriminatorConfig.getColumn();
        if (cc != null) {
            Column c = (Column) d.getColumnIterator().next();
            if (cc.getName() != null) {
                c.setName(cc.getName());
            }
            bindColumnConfigToColumn(null, c, cc);
        }
    }

    entity.setPolymorphic(true);
}

From source file:org.jboss.tools.hibernate.ui.diagram.editors.model.OrmShape.java

License:Open Source License

@Override
public Object getPropertyValue(Object propertyId) {
    Object res = null;//from   w  ww.j  a v a 2s .c o  m
    RootClass rootClass = null;
    Table table = null;
    Object ormElement = getOrmElement();
    if (ormElement instanceof RootClass) {
        rootClass = (RootClass) ormElement;
    } else if (ormElement instanceof Subclass) {
        //rootClass = ((Subclass)ormElement).getRootClass();
    } else if (ormElement instanceof Table) {
        table = (Table) getOrmElement();
    }
    if (rootClass != null) {
        if (ENTITY_isAbstract.equals(propertyId)) {
            if (rootClass.isAbstract() != null) {
                res = rootClass.isAbstract().toString();
            }
        } else if (ENTITY_isCustomDeleteCallable.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isCustomDeleteCallable()).toString();
        } else if (ENTITY_isCustomInsertCallable.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isCustomInsertCallable()).toString();
        } else if (ENTITY_isCustomUpdateCallable.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isCustomUpdateCallable()).toString();
        } else if (ENTITY_isDiscriminatorInsertable.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isDiscriminatorInsertable()).toString();
        } else if (ENTITY_isDiscriminatorValueNotNull.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isDiscriminatorValueNotNull()).toString();
        } else if (ENTITY_isDiscriminatorValueNull.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isDiscriminatorValueNull()).toString();
        } else if (ENTITY_isExplicitPolymorphism.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isExplicitPolymorphism()).toString();
        } else if (ENTITY_isForceDiscriminator.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isForceDiscriminator()).toString();
        } else if (ENTITY_isInherited.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isInherited()).toString();
        } else if (ENTITY_isJoinedSubclass.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isJoinedSubclass()).toString();
        } else if (ENTITY_isLazy.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isLazy()).toString();
        } else if (ENTITY_isLazyPropertiesCacheable.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isLazyPropertiesCacheable()).toString();
        } else if (ENTITY_isMutable.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isMutable()).toString();
        } else if (ENTITY_isPolymorphic.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isPolymorphic()).toString();
        } else if (ENTITY_isVersioned.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isVersioned()).toString();
        } else if (ENTITY_batchSize.equals(propertyId)) {
            res = Integer.valueOf(rootClass.getBatchSize()).toString();
        } else if (ENTITY_cacheConcurrencyStrategy.equals(propertyId)) {
            res = rootClass.getCacheConcurrencyStrategy();
        } else if (ENTITY_className.equals(propertyId)) {
            res = rootClass.getClassName();
        } else if (ENTITY_customSQLDelete.equals(propertyId)) {
            res = rootClass.getCustomSQLDelete();
        } else if (ENTITY_customSQLInsert.equals(propertyId)) {
            res = rootClass.getCustomSQLInsert();
        } else if (ENTITY_customSQLUpdate.equals(propertyId)) {
            res = rootClass.getCustomSQLUpdate();
        } else if (ENTITY_discriminatorValue.equals(propertyId)) {
            res = rootClass.getDiscriminatorValue();
        } else if (ENTITY_entityName.equals(propertyId)) {
            res = rootClass.getEntityName();
        } else if (ENTITY_loaderName.equals(propertyId)) {
            res = rootClass.getLoaderName();
        } else if (ENTITY_nodeName.equals(propertyId)) {
            res = rootClass.getNodeName();
        } else if (ENTITY_optimisticLockMode.equals(propertyId)) {
            res = Integer.valueOf(rootClass.getOptimisticLockMode()).toString();
        } else if (ENTITY_table.equals(propertyId)) {
            if (rootClass.getTable() != null) {
                res = rootClass.getTable().getName();
            }
        } else if (ENTITY_temporaryIdTableDDL.equals(propertyId)) {
            res = rootClass.getTemporaryIdTableDDL();
        } else if (ENTITY_temporaryIdTableName.equals(propertyId)) {
            res = rootClass.getTemporaryIdTableName();
        } else if (ENTITY_where.equals(propertyId)) {
            res = rootClass.getWhere();
        }
    }
    if (table != null) {
        if (TABLE_catalog.equals(propertyId)) {
            res = table.getCatalog();
        } else if (TABLE_comment.equals(propertyId)) {
            res = table.getComment();
        } else if (TABLE_name.equals(propertyId)) {
            res = table.getName();
        } else if (TABLE_primaryKey.equals(propertyId)) {
            if (table.getPrimaryKey() != null) {
                res = table.getPrimaryKey().getName();
            }
        } else if (TABLE_rowId.equals(propertyId)) {
            res = table.getRowId();
        } else if (TABLE_schema.equals(propertyId)) {
            res = table.getSchema();
        } else if (TABLE_subselect.equals(propertyId)) {
            res = table.getSubselect();
        } else if (TABLE_hasDenormalizedTables.equals(propertyId)) {
            res = Boolean.valueOf(table.hasDenormalizedTables()).toString();
        } else if (TABLE_isAbstract.equals(propertyId)) {
            res = Boolean.valueOf(table.isAbstract()).toString();
        } else if (TABLE_isAbstractUnionTable.equals(propertyId)) {
            res = Boolean.valueOf(table.isAbstractUnionTable()).toString();
        } else if (TABLE_isPhysicalTable.equals(propertyId)) {
            res = Boolean.valueOf(table.isPhysicalTable()).toString();
        }
    }
    if (res == null) {
        res = super.getPropertyValue(propertyId);
    }
    return toEmptyStr(res);
}