Example usage for org.hibernate.mapping Property getValue

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

Introduction

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

Prototype

public Value getValue() 

Source Link

Usage

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

License:Open Source License

/**
 * Build the property mapping./*from w ww . j  a v  a 2  s  .c o  m*/
 */
private void buildMapping(Property mapping) {
    Value value = mapping.getValue();
    if (value != null) {
        buildMapping(value);
    }
}

From source file:com.github.shyiko.rook.target.hibernate4.fulltextindex.SynchronizationContext.java

License:Apache License

private void loadIndexingDirectivesForJoinTables(Collection<Property> allContainedInProperties,
        Map<String, IndexingDirective> directivesByEntityNameMap) {
    for (Property property : allContainedInProperties) {
        Value value = property.getValue();
        if (value instanceof org.hibernate.mapping.Collection) {
            org.hibernate.mapping.Collection collection = (org.hibernate.mapping.Collection) value;
            Table collectionTable = collection.getCollectionTable();
            String tableName = schema + "." + collectionTable.getName().toLowerCase();
            if (directivesByTable.containsKey(tableName)) {
                continue;
            }//  w  ww . j a v a 2 s . c o  m
            PrimaryKey primaryKey = resolveForeignPrimaryKey(collection, directivesByEntityNameMap);
            if (primaryKey == null) {
                continue;
            }
            IndexingDirective containerIndexingDirective = directivesByEntityClass
                    .get(primaryKey.getEntityClass());
            directivesByTable.put(tableName,
                    new IndexingDirective(primaryKey, containerIndexingDirective.isSuppressSelfIndexing(),
                            containerIndexingDirective.getEntityIndexingInterceptor(),
                            containerIndexingDirective.getContainerReferences()));
        }
    }
}

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");

    /**//  w  w w .j av  a2s  .  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.oy.shared.lm.ext.HBMCtoGRAPH.java

License:Open Source License

private void processProperties(Iterator iter, GraphNode current) {
    List attrs = new ArrayList();
    while (iter.hasNext()) {
        Property prop = (Property) iter.next();
        Value val = prop.getValue();

        // one-to-one/many-to-one
        if (val instanceof ToOne || val instanceof Component) {
            addToOneProp(prop, current);
            continue;
        }//from   ww w.j  a v  a 2  s .co  m

        // collections
        if (val instanceof Collection) {
            addCollectionProp(prop, current);
            continue;
        }

        // simple value
        if (options.detailed) {
            if (val instanceof SimpleValue) {
                Attribute attr = addSimpleProp((SimpleValue) prop.getValue(), prop.getName());
                attrs.add(attr);
                continue;
            }
        }

    }

    String label = renderAttributes((Attribute[]) attrs.toArray(new Attribute[] {}));
    current.getInfo().setCaption(label);
}

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;//from  ww  w  .  ja v a2s .  co m
    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.oy.shared.lm.ext.HBMCtoGRAPH.java

License:Open Source License

private void addCollectionProp(Property prop, GraphNode current) {
    Value val = prop.getValue();
    if (!(val instanceof Collection)) {
        throw new RuntimeException("Expected Collection.");
    }//from w  w  w. ja  v  a  2  s .co m

    Collection col = (Collection) prop.getValue();
    Value elem = col.getElement();

    if (elem instanceof OneToMany) {
        String clazz = col.getElement().getType().getName();
        GraphNode child = getOrCreateNode(clazz);

        // relation         
        GraphEdge edge = graph.addEdge(current, child);
        edge.getInfo().setCaption(prop.getName());
        edge.getInfo().setLineColor(colors[2]);
        edge.getInfo().setHeadCaption("0..n");
        edge.getInfo().setArrowTailDiamond();

        return;
    }

    if (elem instanceof ManyToOne) {
        String clazz = col.getElement().getType().getName();
        GraphNode child = getOrCreateNode(clazz);

        // relation         
        GraphEdge edge = graph.addEdge(current, child);
        edge.getInfo().setCaption(prop.getName());
        edge.getInfo().setLineColor(colors[2]);
        edge.getInfo().setArrowTailDiamond();
        edge.getInfo().setHeadCaption("0..n");
        edge.getInfo().setTailCaption("0..n");
        return;
    }

    if (elem instanceof Component) {
        String clazz = prop.getName();
        GraphNode child = getOrCreateNode("<<" + col.getClass().getName() + ">>\n" + clazz);

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

        processProperties(((Component) elem).getPropertyIterator(), child);
        return;
    }

    if (elem instanceof SimpleValue) {
        String clazz = prop.getName();
        GraphNode child = getOrCreateNode("<<" + col.getClass().getName() + ">>\n" + clazz);

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

        List attrs = new ArrayList();
        Attribute attr = addSimpleProp((SimpleValue) elem, null);
        attrs.add(attr);
        String label = renderAttributes((Attribute[]) attrs.toArray(new Attribute[] {}));
        child.getInfo().setCaption(label);

        return;
    }

    throw new RuntimeException("Unexpected collection element.");
}

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();/*from   www  .  j a v a2s.  c o m*/
    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());
        }
    } 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.tomitribe.reveng.codegen.FreemarkerObject.java

License:Apache License

public String generateManyToOneAnnotation(final BasicPOJOClass pojo, final Property p, String table) {

    // @ForeignKey(name="FK_recipe_tree_node")
    final Value value = p.getValue();
    final int span;
    final Iterator columnIterator;
    if (value != null && value instanceof Collection) {
        final Collection collection = (Collection) value;
        span = collection.getKey().getColumnSpan();
        columnIterator = collection.getKey().getColumnIterator();
    } else {//from  w w  w  . jav a2s .  co m
        span = p.getColumnSpan();
        columnIterator = p.getColumnIterator();
    }
    final Selectable selectable = (Selectable) columnIterator.next();
    final Column column = (Column) selectable;
    table += "_" + column.getName(); // id_tree_node
    table = "FK_" + table.replace("_id_", "_");

    String s = EntityPOJOClass.class.cast(pojo).generateManyToOneAnnotation(p);
    s += "\n@ForeignKey(name=\"" + table + "\")";

    // log.info(s);

    return s;
}

From source file:com.vecna.maven.hibernate.HibernateDocMojo.java

License:Apache License

/**
 * Populate Hibernate properties with comments from javadocs (including nested properties).
 * @param propertyIterator iterator over top-level properties
 * @param accumulatedJavadoc comments accumulated so far (for nested properties)
 *///  www .j av  a  2s .c  o m
private void processProperties(Iterator<Property> propertyIterator, Class<?> cls, JavaDocBuilder javaDocs,
        String accumulatedJavadoc) {
    JavaClass javaClass = javaDocs.getClassByName(cls.getName());

    if (javaClass != null) {
        while (propertyIterator.hasNext()) {
            Property prop = propertyIterator.next();

            Value value = prop.getValue();

            if (value instanceof Collection) {
                Collection collection = (Collection) value;

                Value elementValue = collection.getElement();

                if (elementValue instanceof Component) {
                    processComponent((Component) elementValue, javaDocs, accumulatedJavadoc);
                }

                Table collectionTable = collection.getCollectionTable();

                if (collectionTable.getComment() == null) {
                    collectionTable.setComment(getSimpleValueJavadoc(prop, cls, javaClass));
                }
            } else if (value instanceof Component) {
                String comment = getSimpleValueJavadoc(prop, cls, javaClass);
                comment = accumulateJavadoc(comment, accumulatedJavadoc);
                processComponent((Component) value, javaDocs, comment);
            } else if (value instanceof SimpleValue) {
                String comment = getSimpleValueJavadoc(prop, cls, javaClass);
                comment = accumulateJavadoc(comment, accumulatedJavadoc);
                setComment(comment, 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();
        if (v.getType().isEntityType() || !v.isSimpleValue()) {
            this.relProperties.put(owningClassName, p);
            this.relPropertyNames.put(owningClassName, p.getName());
        }/*  w  ww .j  a  va2  s.c om*/

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