Example usage for org.hibernate.mapping Property getType

List of usage examples for org.hibernate.mapping Property getType

Introduction

In this page you can find the example usage for org.hibernate.mapping Property getType.

Prototype

public Type getType() throws MappingException 

Source Link

Usage

From source file:com.googlecode.hibernate.audit.listener.AuditSessionFactoryObserver.java

License:Open Source License

private AuditType initializeEntityAuditType(Session session, String entityName, boolean initializeProperties) {
    PersistentClass classMapping = auditConfiguration.getMetadata().getEntityBinding(entityName);
    String auditTypeClassName = auditConfiguration.getExtensionManager().getAuditableInformationProvider()
            .getAuditTypeClassName(auditConfiguration.getMetadata(), entityName);

    AuditType auditType = HibernateAudit.getAuditType(session, auditTypeClassName);
    if (auditType == null) {
        auditType = new AuditType();
        auditType.setClassName(auditTypeClassName);
        auditType.setLabel(entityName);//from  w w  w  .j  a  v a2 s  .  c  o m
        auditType.setType(AuditType.ENTITY_TYPE);

        session.save(auditType);
        updateMetaModel(session);
    }

    if (initializeProperties) {
        Property identifierProperty = classMapping.getIdentifierProperty();
        if (identifierProperty != null) {
            initializeAuditField(session, auditTypeClassName, auditType, identifierProperty.getName(),
                    identifierProperty.getType());
        }

        for (Iterator propertyIterator = classMapping.getPropertyClosureIterator(); propertyIterator
                .hasNext();) {
            Property property = (Property) propertyIterator.next();
            initializeAuditField(session, auditTypeClassName, auditType, property.getName(),
                    property.getType());
        }
    }
    return auditType;
}

From source file:com.klistret.cmdb.utility.spring.LocalSessionFactoryBean.java

License:Open Source License

protected void postProcessMappings(Configuration config) throws HibernateException {
    logger.debug("Overriding the postProcessMappings method in the Spring LocalSessionFactoryBean");

    /**/*from  www. ja v a  2s.  c o m*/
     * http://stackoverflow.com/questions/672063/creating-a-custom-hibernate-usertype-find-out-the-current-entity-table-name
     */
    for (Iterator<PersistentClass> classMappingIterator = config.getClassMappings(); classMappingIterator
            .hasNext();) {
        PersistentClass persistentClass = (PersistentClass) classMappingIterator.next();

        for (Iterator<?> propertyIterator = persistentClass.getPropertyIterator(); propertyIterator
                .hasNext();) {
            Property property = (Property) propertyIterator.next();

            if (property.getType().getName().equals(JAXBUserType.class.getName())) {
                logger.debug("Setting ci context properties for Hibernate user type [{}]",
                        JAXBUserType.class.getName());

                SimpleValue simpleValue = (SimpleValue) property.getValue();
                Properties parameterMap = new Properties();

                parameterMap.setProperty("baseTypes", baseTypes);
                logger.debug("Base types [{}]", baseTypes);

                parameterMap.setProperty("assignablePackages", assignablePackages);
                logger.debug("Assignable packages [{}]", assignablePackages);

                simpleValue.setTypeParameters(parameterMap);
            }
        }
    }
}

From source file:com.netspective.tool.hibernate.document.diagram.HibernateDiagramGenerator.java

License:Open Source License

public HibernateDiagramGenerator(final Configuration configuration,
        final GraphvizDiagramGenerator graphvizDiagramGenerator,
        final HibernateDiagramGeneratorFilter schemaDiagramFilter) throws HibernateDiagramGeneratorException {
    this.configuration = configuration;
    this.graphvizDiagramGenerator = graphvizDiagramGenerator;
    this.diagramFilter = schemaDiagramFilter;

    // the following was copied from org.hibernate.cfg.Configuration.buildMapping() because buildMapping() was private
    this.mapping = new Mapping() {
        /**//from   w w  w  . j av  a  2 s. c  o  m
         * Returns the identifier type of a mapped class
         */
        public Type getIdentifierType(String persistentClass) throws MappingException {
            final PersistentClass pc = configuration.getClassMapping(persistentClass);
            if (pc == null)
                throw new MappingException("persistent class not known: " + persistentClass);
            return pc.getIdentifier().getType();
        }

        public String getIdentifierPropertyName(String persistentClass) throws MappingException {
            final PersistentClass pc = configuration.getClassMapping(persistentClass);
            if (pc == null)
                throw new MappingException("persistent class not known: " + persistentClass);
            if (!pc.hasIdentifierProperty())
                return null;
            return pc.getIdentifierProperty().getName();
        }

        public Type getPropertyType(String persistentClass, String propertyName) throws MappingException {
            final PersistentClass pc = configuration.getClassMapping(persistentClass);
            if (pc == null)
                throw new MappingException("persistent class not known: " + persistentClass);
            Property prop = pc.getProperty(propertyName);
            if (prop == null)
                throw new MappingException("property not known: " + persistentClass + '.' + propertyName);
            return prop.getType();
        }
    };

    String dialectName = configuration.getProperty(Environment.DIALECT);
    if (dialectName == null)
        dialectName = org.hibernate.dialect.GenericDialect.class.getName();

    try {
        final Class cls = Class.forName(dialectName);
        this.dialect = (Dialect) cls.newInstance();
    } catch (Exception e) {
        throw new HibernateDiagramGeneratorException(e);
    }

    for (final Iterator classes = configuration.getClassMappings(); classes.hasNext();) {
        final PersistentClass pclass = (PersistentClass) classes.next();
        final Table table = (Table) pclass.getTable();

        tableToClassMap.put(table, pclass);
    }
}

From source file:com.oy.shared.lm.ext.HBMCtoGRAPH.java

License:Open Source License

private void addToOneProp(Property prop, GraphNode current) {
    Value val = prop.getValue();

    String clazz = null;/*  w w  w.  j a va 2 s .  c om*/
    boolean owned = false;

    if (val instanceof Component) {
        clazz = ((Component) prop.getValue()).getComponentClassName();
        owned = true;
    } else {
        if (val instanceof ToOne) {
            clazz = prop.getType().getName();
            owned = ((ToOne) val).isCascadeDeleteEnabled();
        } else {
            throw new RuntimeException("Expected ToOne or Component.");
        }
    }

    GraphNode child = getOrCreateNode(clazz);

    // relation 
    GraphEdge edge = graph.addEdge(current, child);
    edge.getInfo().setCaption(prop.getName());
    edge.getInfo().setLineColor(colors[1]);

    // multiplicity
    if (val instanceof ManyToOne) {
        edge.getInfo().setTailCaption("0..n");
        edge.getInfo().setHeadCaption("");
    } else {
        edge.getInfo().setHeadCaption("");
    }

    // ownership vs. association
    if (owned) {
        edge.getInfo().setArrowTailDiamond();
    } else {
        edge.getInfo().setModeDashed();
    }

    // component attributes
    if (val instanceof Component) {
        processProperties(((Component) prop.getValue()).getPropertyIterator(), child);
    }
}

From source file:com.siemens.scr.avt.ad.query.common.DicomMappingDictionaryLoadingStrategy.java

License:Open Source License

private void loadProperty(DicomMappingDictionary dict, Property prop, Table table, String classPrefix) {
    String key = classPrefix + "." + prop.getName();
    Type type = prop.getType();
    String tableName = table.getSchema() + "." + table.getName();
    if (type.isAssociationType() || type.isCollectionType()) {
        // do nothing
    } else if (type.isComponentType()) {
        Component component = (Component) prop.getValue();
        Iterator<Property> it = component.getPropertyIterator();
        while (it.hasNext()) {
            Property subProp = it.next();
            loadProperty(dict, subProp, table, component.getRoleName());
        }//  w  w w.java  2s .  c  o m
    } else {
        int sqltype = sqlTypes(type);

        assert prop.getColumnSpan() == 1;
        Iterator<Column> it = prop.getColumnIterator();
        String column = it.next().getName();

        dict.addMappingEntry(key, tableName, column, sqltype);

        loadTag(dict, prop, key);
        loadDicomHeaderMetadata(dict, tableName, column, prop);
    }

}

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

License:Open Source License

private void initProperty(String owningClassName, Property p, Map<String, Property> propertiesMap) {
    this.allProperties.put(owningClassName, p);
    if (p != null) {
        this.allPropertyNames.put(owningClassName, p.getName());
        propertiesMap.put(p.getName(), p);
        Value v = p.getValue();//from  ww  w.  j  ava 2 s. co  m
        if (v.getType().isEntityType() || !v.isSimpleValue()) {
            this.relProperties.put(owningClassName, p);
            this.relPropertyNames.put(owningClassName, p.getName());
        }

        if (p.getType().isComponentType()) {
            addComponentProperties(p);
        }
    }
}

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

License:Open Source License

private void addComponentProperties(Property p) {
    String s = p.getType().getReturnedClass().getName();
    this.componentClassNames.add(s);
    Value v = p.getValue();/*w w  w .  java 2  s.  co m*/
    Component comp = (Component) v;
    Map<String, Property> propertiesMap = new HashMap<String, Property>();
    this.allPropertiesMap.put(s, propertiesMap);
    for (Iterator<Property> iter = CastUtils.cast(comp.getPropertyIterator()); iter.hasNext();) {
        Property p2 = iter.next();
        initProperty(s, p2, propertiesMap);
    }
}

From source file:com.wavemaker.runtime.data.task.AbstractReadTask.java

License:Open Source License

protected Class<?> getPropertyType(Class<?> rootType, String propertyPath, String dbName) {
    Property p = getProperty(rootType, propertyPath, NOOP_PROPERTY_TRAVERSAL, dbName);
    Type hbmType = p.getType();
    return hbmType.getReturnedClass();
}

From source file:com.wavemaker.runtime.data.task.AbstractReadTask.java

License:Open Source License

protected boolean isNulleable(Class<?> rootType, String propertyPath, String dbName) {
    Property p = getProperty(rootType, propertyPath, NOOP_PROPERTY_TRAVERSAL, dbName);
    if (isRelatedMany(p.getType().getReturnedClass())) {
        return true;
    }//  ww  w. ja v a2  s  .co  m
    return ((Column) p.getColumnIterator().next()).isNullable();
}

From source file:com.wavemaker.runtime.data.task.AbstractReadTask.java

License:Open Source License

private Property getProperty(Class<?> rootType, String propertyPath, PropertyTraversal traversalStrategy,
        String dbName) {//ww  w  .  j a  va  2s.  c o m

    Property rtn = null;

    DataServiceMetaData m = getMetaData(dbName);

    String entityName = rootType.getName();

    SessionFactory fac = getSessionFactory(dbName);

    for (String s : splitPropertyPath(propertyPath)) {

        rtn = m.getProperty(entityName, s);

        Type hbmType = rtn.getType();

        if (!traversalStrategy.keepGoing(hbmType)) {
            return null;
        }

        entityName = DataServiceUtils.getJavaTypeName(hbmType, fac);
    }

    return rtn;
}