use of org.hibernate.type.CompositeType in project hibernate-orm by hibernate.
the class AbstractPropertyMapping method initComponentPropertyPaths.
protected void initComponentPropertyPaths(final String path, final CompositeType type, final String[] columns, final String[] columnReaders, final String[] columnReaderTemplates, String[] formulaTemplates, final Mapping factory) throws MappingException {
Type[] types = type.getSubtypes();
String[] properties = type.getPropertyNames();
int begin = 0;
for (int i = 0; i < properties.length; i++) {
String subpath = extendPath(path, properties[i]);
try {
int length = types[i].getColumnSpan(factory);
String[] columnSlice = ArrayHelper.slice(columns, begin, length);
String[] columnReaderSlice = ArrayHelper.slice(columnReaders, begin, length);
String[] columnReaderTemplateSlice = ArrayHelper.slice(columnReaderTemplates, begin, length);
String[] formulaSlice = formulaTemplates == null ? null : ArrayHelper.slice(formulaTemplates, begin, length);
initPropertyPaths(subpath, types[i], columnSlice, columnReaderSlice, columnReaderTemplateSlice, formulaSlice, factory);
begin += length;
} catch (Exception e) {
throw new MappingException("bug in initComponentPropertyPaths", e);
}
}
}
use of org.hibernate.type.CompositeType in project hibernate-orm by hibernate.
the class PojoEntityTuplizer method buildProxyFactory.
@Override
protected ProxyFactory buildProxyFactory(PersistentClass persistentClass, Getter idGetter, Setter idSetter) {
// determine the id getter and setter methods from the proxy interface (if any)
// determine all interfaces needed by the resulting proxy
/*
* We need to preserve the order of the interfaces they were put into the set, since javassist will choose the
* first one's class-loader to construct the proxy class with. This is also the reason why HibernateProxy.class
* should be the last one in the order (on JBossAS7 its class-loader will be org.hibernate module's class-
* loader, which will not see the classes inside deployed apps. See HHH-3078
*/
Set<Class> proxyInterfaces = new java.util.LinkedHashSet<Class>();
Class mappedClass = persistentClass.getMappedClass();
Class proxyInterface = persistentClass.getProxyInterface();
if (proxyInterface != null && !mappedClass.equals(proxyInterface)) {
if (!proxyInterface.isInterface()) {
throw new MappingException("proxy must be either an interface, or the class itself: " + getEntityName());
}
proxyInterfaces.add(proxyInterface);
}
if (mappedClass.isInterface()) {
proxyInterfaces.add(mappedClass);
}
Iterator<Subclass> subclasses = persistentClass.getSubclassIterator();
while (subclasses.hasNext()) {
final Subclass subclass = subclasses.next();
final Class subclassProxy = subclass.getProxyInterface();
final Class subclassClass = subclass.getMappedClass();
if (subclassProxy != null && !subclassClass.equals(subclassProxy)) {
if (!subclassProxy.isInterface()) {
throw new MappingException("proxy must be either an interface, or the class itself: " + subclass.getEntityName());
}
proxyInterfaces.add(subclassProxy);
}
}
proxyInterfaces.add(HibernateProxy.class);
Iterator properties = persistentClass.getPropertyIterator();
Class clazz = persistentClass.getMappedClass();
while (properties.hasNext()) {
Property property = (Property) properties.next();
Method method = property.getGetter(clazz).getMethod();
if (method != null && Modifier.isFinal(method.getModifiers())) {
LOG.gettersOfLazyClassesCannotBeFinal(persistentClass.getEntityName(), property.getName());
}
method = property.getSetter(clazz).getMethod();
if (method != null && Modifier.isFinal(method.getModifiers())) {
LOG.settersOfLazyClassesCannotBeFinal(persistentClass.getEntityName(), property.getName());
}
}
Method idGetterMethod = idGetter == null ? null : idGetter.getMethod();
Method idSetterMethod = idSetter == null ? null : idSetter.getMethod();
Method proxyGetIdentifierMethod = idGetterMethod == null || proxyInterface == null ? null : ReflectHelper.getMethod(proxyInterface, idGetterMethod);
Method proxySetIdentifierMethod = idSetterMethod == null || proxyInterface == null ? null : ReflectHelper.getMethod(proxyInterface, idSetterMethod);
ProxyFactory pf = buildProxyFactoryInternal(persistentClass, idGetter, idSetter);
try {
pf.postInstantiate(getEntityName(), mappedClass, proxyInterfaces, proxyGetIdentifierMethod, proxySetIdentifierMethod, persistentClass.hasEmbeddedIdentifier() ? (CompositeType) persistentClass.getIdentifier().getType() : null);
} catch (HibernateException he) {
LOG.unableToCreateProxyFactory(getEntityName(), he);
pf = null;
}
return pf;
}
use of org.hibernate.type.CompositeType in project hibernate-orm by hibernate.
the class SimpleEmbeddableOverriddenConverterTest method testSimpleConvertOverrides.
/**
* Test outcome of annotations exclusively.
*/
@Test
public void testSimpleConvertOverrides() {
final EntityPersister ep = sessionFactory().getEntityPersister(Person.class.getName());
CompositeType homeAddressType = assertTyping(CompositeType.class, ep.getPropertyType("homeAddress"));
Type homeAddressCityType = findCompositeAttributeType(homeAddressType, "city");
assertTyping(StringType.class, homeAddressCityType);
}
use of org.hibernate.type.CompositeType in project hibernate-orm by hibernate.
the class DefaultRefreshEventListener method evictCachedCollections.
private void evictCachedCollections(Type[] types, Serializable id, EventSource source) throws HibernateException {
for (Type type : types) {
if (type.isCollectionType()) {
CollectionPersister collectionPersister = source.getFactory().getMetamodel().collectionPersister(((CollectionType) type).getRole());
if (collectionPersister.hasCache()) {
final CollectionRegionAccessStrategy cache = collectionPersister.getCacheAccessStrategy();
final Object ck = cache.generateCacheKey(id, collectionPersister, source.getFactory(), source.getTenantIdentifier());
final SoftLock lock = cache.lockItem(source, ck, null);
source.getActionQueue().registerProcess(new AfterTransactionCompletionProcess() {
@Override
public void doAfterTransactionCompletion(boolean success, SharedSessionContractImplementor session) {
cache.unlockItem(session, ck, lock);
}
});
cache.remove(source, ck);
}
} else if (type.isComponentType()) {
CompositeType actype = (CompositeType) type;
evictCachedCollections(actype.getSubtypes(), id, source);
}
}
}
use of org.hibernate.type.CompositeType in project hibernate-orm by hibernate.
the class JoinWalker method walkCollectionTree.
/**
* For a collection role, return a list of associations to be fetched by outerjoin
*/
private void walkCollectionTree(final QueryableCollection persister, final String alias, final PropertyPath path, final int currentDepth) throws MappingException {
if (persister.isOneToMany()) {
walkEntityTree((OuterJoinLoadable) persister.getElementPersister(), alias, path, currentDepth);
} else {
Type type = persister.getElementType();
if (type.isAssociationType()) {
// a many-to-many;
// decrement currentDepth here to allow join across the association table
// without exceeding MAX_FETCH_DEPTH (i.e. the "currentDepth - 1" bit)
AssociationType associationType = (AssociationType) type;
String[] aliasedLhsColumns = persister.getElementColumnNames(alias);
String[] lhsColumns = persister.getElementColumnNames();
// if the current depth is 0, the root thing being loaded is the
// many-to-many collection itself. Here, it is alright to use
// an inner join...
boolean useInnerJoin = currentDepth == 0;
final JoinType joinType = getJoinType(associationType, persister.getFetchMode(), path, persister.getTableName(), lhsColumns, !useInnerJoin, currentDepth - 1, //operations which cascade as far as the collection also cascade to collection elements
null);
addAssociationToJoinTreeIfNecessary(associationType, aliasedLhsColumns, alias, path, currentDepth - 1, joinType);
} else if (type.isComponentType()) {
walkCompositeElementTree((CompositeType) type, persister.getElementColumnNames(), persister, alias, path, currentDepth);
}
}
}
Aggregations