Example usage for org.hibernate.mapping Property getGetter

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

Introduction

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

Prototype

public Getter getGetter(Class clazz) throws PropertyNotFoundException, MappingException 

Source Link

Usage

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

License:Apache License

public PrimaryKey(PersistentClass persistentClass) {
    this.entityClass = persistentClass.getMappedClass();
    KeyValue keyValue = persistentClass.getKey();
    Table table = persistentClass.getTable();
    Map<String, Integer> columnIndexByNameMap = getColumnIndexByNameMap(table);
    KeyColumn[] positionWithinRow = new KeyColumn[keyValue.getColumnSpan()];
    int index = 0;
    if (keyValue instanceof Component) {
        Iterator propertyIterator = ((Component) keyValue).getPropertyIterator();
        while (propertyIterator.hasNext()) {
            Property property = (Property) propertyIterator.next();
            String columnName = ((Column) property.getColumnIterator().next()).getName();
            positionWithinRow[index++] = new KeyColumn(property.getName(),
                    columnIndexByNameMap.get(columnName));
        }/*from w  w w .j  a v a  2s . c o m*/
    } else {
        Iterator columnIterator = keyValue.getColumnIterator();
        while (columnIterator.hasNext()) {
            String columnName = ((Column) columnIterator.next()).getName();
            positionWithinRow[index++] = new KeyColumn(columnName, columnIndexByNameMap.get(columnName));
        }
    }
    if (positionWithinRow.length == 0) {
        throw new IllegalStateException("Unable to determine PK for " + table.getName());
    }
    Property identifierProperty = persistentClass.getIdentifierProperty();
    this.getter = identifierProperty.getGetter(this.entityClass);
    this.positionWithinRow = positionWithinRow;

}

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

License:Apache License

@SuppressWarnings("unchecked")
private void loadIndexingDirectives(Configuration configuration) {
    Map<String, IndexingDirective> directivesByEntityNameMap = new HashMap<String, IndexingDirective>();
    Collection<Property> allContainedInProperties = new ArrayList<Property>();
    for (Iterator<PersistentClass> classIterator = configuration.getClassMappings(); classIterator.hasNext();) {
        PersistentClass persistentClass = classIterator.next();
        boolean suppressSelfIndexing = true;
        Class mappedClass = persistentClass.getMappedClass();
        Indexed indexed = (Indexed) mappedClass.getAnnotation(Indexed.class);
        EntityIndexingInterceptor indexingInterceptor = null;
        if (indexed != null) {
            suppressSelfIndexing = false;
            Class<? extends EntityIndexingInterceptor> interceptorClass = indexed.interceptor();
            if (interceptorClass != DefaultEntityInterceptor.class) {
                try {
                    indexingInterceptor = interceptorClass.newInstance();
                } catch (InstantiationException e) {
                    throw new RuntimeException("Failed to instantiate " + interceptorClass, e);
                } catch (IllegalAccessException e) {
                    throw new RuntimeException("Failed to instantiate " + interceptorClass, e);
                }/* w  w  w . ja  v a  2s  .  c  o  m*/
            }
        }
        Collection<Property> containedInProperties = extractAnnotatedProperties(persistentClass,
                ContainedIn.class);
        if (suppressSelfIndexing && containedInProperties.isEmpty()) {
            continue;
        }
        allContainedInProperties.addAll(containedInProperties);
        PrimaryKey primaryKey = new PrimaryKey(persistentClass);
        Collection<Reference> containers = new ArrayList<Reference>();
        for (Property property : containedInProperties) {
            containers.add(new Reference(property.getGetter(mappedClass)));
        }
        IndexingDirective indexingDirective = new IndexingDirective(primaryKey, suppressSelfIndexing,
                indexingInterceptor, containers);
        Table table = persistentClass.getTable();
        directivesByTable.put(schema + "." + table.getName().toLowerCase(), indexingDirective);
        directivesByEntityClass.put(mappedClass, indexingDirective);
        directivesByEntityNameMap.put(persistentClass.getEntityName(), indexingDirective);
    }
    loadIndexingDirectivesForJoinTables(allContainedInProperties, directivesByEntityNameMap);
}

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

License:Apache License

@SuppressWarnings("unchecked")
private Collection<Property> extractAnnotatedProperties(PersistentClass persistentClass,
        Class<? extends Annotation> annotation) {
    Class mappedClass = persistentClass.getMappedClass();
    Collection<Property> properties = new ArrayList<Property>();
    for (Iterator<Property> propertyIterator = persistentClass.getPropertyIterator(); propertyIterator
            .hasNext();) {//from w  w w. jav  a 2 s  .  co m
        Property property = propertyIterator.next();
        Getter getter = property.getGetter(mappedClass);
        if (getter == null) {
            continue;
        }
        Member mappedClassMember = getter.getMember();
        boolean isRequestedAnnotationPresent = mappedClassMember instanceof AccessibleObject
                && ((AccessibleObject) mappedClassMember).isAnnotationPresent(annotation);
        if (isRequestedAnnotationPresent) {
            properties.add(property);
        }
    }
    return properties;
}

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

License:Apache License

/**
 * @return javadocs for a simple Hibernate property
 *//*from w w w . ja  v a  2  s .c  o  m*/
private String getSimpleValueJavadoc(Property property, Class<?> cls, JavaClass javaClass) {
    Getter getter = property.getGetter(cls);

    Member member = getter.getMember();

    if (member instanceof Field) {
        JavaField field = javaClass.getFieldByName(member.getName());
        if (field != null) {
            return field.getComment();
        }
    } else if (member instanceof Method) {
        Method method = (Method) member;
        Type[] types = getJavaDocTypes(method.getParameterTypes());
        JavaMethod javaMethod = javaClass.getMethodBySignature(method.getName(), types, true);
        if (javaMethod == null) {
            getLog().warn("can't find java method docs for " + javaClass.getName() + " . " + method.getName()
                    + " " + Arrays.asList(types));
        } else {
            DocletTag tag = javaMethod.getTagByName("return", true);

            if (tag != null && tag.getValue() != null) {
                return tag.getValue();
            }
        }
    }

    return null;
}

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

License:Apache License

public static GroovyAwareJavassistProxyFactory buildProxyFactory(PersistentClass persistentClass) {
    GroovyAwareJavassistProxyFactory proxyFactory = new GroovyAwareJavassistProxyFactory();

    @SuppressWarnings("unchecked")
    Set<Class<HibernateProxy>> proxyInterfaces = CollectionUtils.newSet(HibernateProxy.class);

    final Class<?> javaClass = persistentClass.getMappedClass();
    final Property identifierProperty = persistentClass.getIdentifierProperty();
    final Getter idGetter = identifierProperty != null ? identifierProperty.getGetter(javaClass) : null;
    final Setter idSetter = identifierProperty != null ? identifierProperty.getSetter(javaClass) : null;

    if (idGetter == null || idSetter == null)
        return null;

    try {// w w w. j  a  v  a  2 s .  c o m
        proxyFactory.postInstantiate(persistentClass.getEntityName(), javaClass, proxyInterfaces,
                idGetter.getMethod(), idSetter.getMethod(),
                persistentClass.hasEmbeddedIdentifier()
                        ? (CompositeType) persistentClass.getIdentifier().getType()
                        : null);
    } catch (HibernateException e) {
        LOG.warn("Cannot instantiate proxy factory: " + e.getMessage());
        return null;
    }

    return proxyFactory;
}

From source file:org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDORevisionTuplizer.java

License:Open Source License

@Override
protected Getter buildPropertyGetter(Property mappedProperty, PersistentClass mappedEntity) {
    initEClass(mappedEntity);//  w  w  w  . ja  v  a2  s.  c om
    if (TRACER.isEnabled()) {
        TRACER.trace("Building property getter for " + eClass.getName() + "." + mappedProperty.getName()); //$NON-NLS-1$ //$NON-NLS-2$
    }

    if (mappedProperty.isBackRef()) {
        return mappedProperty.getGetter(mappedEntity.getMappedClass());
    }
    final CDOPropertyGetter getter;
    if (mappedProperty == mappedEntity.getIdentifierProperty()) {
        getter = new CDOIDPropertyGetter(this, mappedProperty.getName());
    } else if (mappedProperty.getMetaAttribute("version") != null) {
        getter = new CDOVersionPropertyGetter(this, mappedProperty.getName());
    } else if (mappedProperty.getName().compareTo(CDOHibernateConstants.RESOURCE_PROPERTY) == 0) {
        getter = new CDOResourceIDGetter(this, mappedProperty.getName());
    } else if (mappedProperty.getName().compareTo(CDOHibernateConstants.CONTAINER_PROPERTY) == 0) {
        getter = new CDOContainerGetter(this, mappedProperty.getName());
    } else if (mappedProperty.getName().compareTo(CDOHibernateConstants.COMMITTIMESTAMP_PROPERTY) == 0) {
        getter = new CDOBranchTimeStampGetter(this, mappedProperty.getName());
    } else {
        EStructuralFeature feature = getEClass().getEStructuralFeature(mappedProperty.getName());
        if (feature instanceof EReference && feature.isMany()
                && HibernateUtil.getInstance().isCDOResourceContents(feature)) {
            getter = new CDOManyAttributeGetter(this, mappedProperty.getName());
        } else if (feature instanceof EReference && feature.isMany()) {
            getter = new CDOManyReferenceGetter(this, mappedProperty.getName());
        } else if (feature instanceof EReference) {
            getter = new CDOReferenceGetter(this, mappedProperty.getName());
        } else if (feature instanceof EAttribute && feature.isMany()) {
            getter = new CDOManyAttributeGetter(this, mappedProperty.getName());
        } else {
            getter = new CDOPropertyGetter(this, mappedProperty.getName());
        }
    }

    HibernateStore hbStore = HibernateStore.getCurrentHibernateStore();
    getter.setPersistenceOptions(hbStore.getCDODataStore().getPersistenceOptions());
    return getter;
}

From source file:org.eclipse.emf.teneo.hibernate.mapping.eav.EAVObjectTuplizer.java

License:Open Source License

@Override
protected Getter buildPropertyGetter(Property mappedProperty, PersistentClass mappedEntity) {
    if (mappedProperty.getName().equals("values")) {
        return mappedProperty.getGetter(EObjectImpl.class);
    }// w  w w.jav  a2s . c  o m
    return getPropertyAccessor(mappedProperty, mappedEntity).getGetter(null, mappedProperty.getName());
}

From source file:org.eclipse.emf.teneo.hibernate.tuplizer.EMFTuplizer.java

License:Open Source License

@Override
protected Getter buildPropertyGetter(Property mappedProperty, PersistentClass mappedEntity) {
    if (HbUtil.isEAVMapped(mappedEntity) && mappedProperty.getName().equals(Constants.EAV_EOBJECT_VALUES)) {
        final HbDataStore ds = HbHelper.INSTANCE.getDataStore(mappedEntity);
        final Getter getter = mappedProperty.getGetter(EObjectImpl.class);
        if (getter instanceof EAVPropertyHandler) {
            ((EAVPropertyHandler) getter).setHbDataStore(ds);
        }//w  w  w  .  ja va 2s .  c o m
        return getter;
    }
    return getPropertyAccessor(mappedProperty, mappedEntity).getGetter(null, mappedProperty.getName());
}

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

License:Apache License

/**
 * Constructs a proxy factory instance//from w  w  w  .j  av a2 s. c  om
 *
 * @param persistentClass The persistent class
 * @return The factory
 */
public static ProxyFactory buildProxyFactory(PersistentClass persistentClass) {
    ProxyFactory proxyFactory = ProxyFactorySupport.createProxyFactory();

    @SuppressWarnings("unchecked")
    Set<Class> proxyInterfaces = new HashSet<>();
    proxyInterfaces.add(HibernateProxy.class);

    final Class<?> javaClass = persistentClass.getMappedClass();
    final Property identifierProperty = persistentClass.getIdentifierProperty();
    final Method idGetterMethod = identifierProperty != null
            ? identifierProperty.getGetter(javaClass).getMethod()
            : null;
    final Method idSetterMethod = identifierProperty != null
            ? identifierProperty.getSetter(javaClass).getMethod()
            : null;
    final Type identifierType = persistentClass.hasEmbeddedIdentifier()
            ? persistentClass.getIdentifier().getType()
            : null;

    try {
        proxyFactory.postInstantiate(persistentClass.getEntityName(), javaClass, proxyInterfaces,
                idGetterMethod, idSetterMethod,
                identifierType instanceof CompositeType ? (CompositeType) identifierType : null);
    } catch (HibernateException e) {
        LOG.warn("Cannot instantiate proxy factory: " + e.getMessage());
        return null;
    }

    return proxyFactory;
}

From source file:org.openbravo.dal.core.OBDynamicTuplizer.java

License:Open Source License

@Override
protected Getter buildPropertyGetter(Property mappedProperty, PersistentClass mappedEntity) {
    return mappedProperty.getGetter(mappedEntity.getMappedClass());
}