use of org.hibernate.type.CollectionType in project dhis2-core by dhis2.
the class AbstractPropertyIntrospectorService method updateJoinTables.
protected void updateJoinTables() {
if (!roleToRole.isEmpty()) {
return;
}
Map<String, List<String>> joinTableToRoles = new HashMap<>();
SessionFactoryImplementor sessionFactoryImplementor = (SessionFactoryImplementor) sessionFactory;
Iterator<?> collectionIterator = sessionFactory.getAllCollectionMetadata().values().iterator();
while (collectionIterator.hasNext()) {
CollectionPersister collectionPersister = (CollectionPersister) collectionIterator.next();
CollectionType collectionType = collectionPersister.getCollectionType();
if (collectionPersister.isManyToMany() && collectionType.isAssociationType()) {
Joinable associatedJoinable = collectionType.getAssociatedJoinable(sessionFactoryImplementor);
if (!joinTableToRoles.containsKey(associatedJoinable.getTableName())) {
joinTableToRoles.put(associatedJoinable.getTableName(), new ArrayList<>());
}
joinTableToRoles.get(associatedJoinable.getTableName()).add(collectionPersister.getRole());
} else if (collectionPersister.isInverse()) {
if (SetType.class.isInstance(collectionType)) {
SetType setType = (SetType) collectionType;
setType.getAssociatedJoinable(sessionFactoryImplementor);
}
}
}
Iterator<Map.Entry<String, List<String>>> entryIterator = joinTableToRoles.entrySet().iterator();
while (entryIterator.hasNext()) {
Map.Entry<String, List<String>> entry = entryIterator.next();
if (entry.getValue().size() < 2) {
entryIterator.remove();
}
}
for (Map.Entry<String, List<String>> entry : joinTableToRoles.entrySet()) {
roleToRole.put(entry.getValue().get(0), entry.getValue().get(1));
roleToRole.put(entry.getValue().get(1), entry.getValue().get(0));
}
}
Aggregations