Revision 325d4d8e
Added by Andreas Müller almost 8 years ago
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/CdmGenericDaoImpl.java | ||
---|---|---|
93 | 93 |
Class<?> targetClass; //new as item class is used for isCollection we have a duplicate here |
94 | 94 |
public boolean isCollection(){return itemClass != null;} |
95 | 95 |
@Override |
96 |
public String toString(){return otherClass.getSimpleName() + "." + propertyName ;};
|
|
96 |
public String toString(){return otherClass.getSimpleName() + "." + propertyName ;} |
|
97 | 97 |
} |
98 | 98 |
|
99 | 99 |
public CdmGenericDaoImpl() { |
... | ... | |
106 | 106 |
|
107 | 107 |
Criteria criteria = session.createCriteria(clazz); |
108 | 108 |
criteria.add(Restrictions.eq(propertyName, referencedCdmBase)); |
109 |
return criteria.list(); |
|
109 |
@SuppressWarnings("unchecked") |
|
110 |
List<CdmBase> result = criteria.list(); |
|
111 |
return result; |
|
110 | 112 |
} |
111 | 113 |
|
112 | 114 |
@Override |
... | ... | |
134 | 136 |
String strKey = (String)oKey; |
135 | 137 |
if (! strKey.endsWith("_AUD")){ |
136 | 138 |
try { |
137 |
Class clazz = Class.forName(strKey);
|
|
139 |
Class<?> clazz = Class.forName(strKey);
|
|
138 | 140 |
boolean isAbstractClass = Modifier.isAbstract(clazz.getModifiers()); |
139 | 141 |
if (! isAbstractClass || includeAbstractClasses){ |
140 |
result.add(clazz); |
|
142 |
result.add((Class)clazz);
|
|
141 | 143 |
} |
142 | 144 |
} catch (ClassNotFoundException e) { |
143 | 145 |
logger.warn("Class not found: " + strKey); |
... | ... | |
334 | 336 |
|
335 | 337 |
} |
336 | 338 |
|
337 |
private boolean makeSingleProperty(Class<?> itemClass, Class<?> type, String propertyName, Class cdmClass, Set<ReferenceHolder> result,/*CdmBase item,*/ boolean isCollection){ |
|
339 |
private boolean makeSingleProperty(Class<?> itemClass, Class<?> type, String propertyName, Class<? extends CdmBase> cdmClass, Set<ReferenceHolder> result,/*CdmBase item,*/ boolean isCollection){
|
|
338 | 340 |
// String fieldName = StringUtils.rightPad(propertyName, 30); |
339 | 341 |
// String className = StringUtils.rightPad(cdmClass.getSimpleName(), 30); |
340 | 342 |
// String returnTypeName = StringUtils.rightPad(type.getSimpleName(), 30); |
... | ... | |
423 | 425 |
Session session; |
424 | 426 |
session = getSession(); |
425 | 427 |
//session = getSession().getSessionFactory().getCurrentSession(); |
426 |
Object o = session.get(clazz, id);
|
|
427 |
return (T)o;
|
|
428 |
T o = session.get(clazz, id);
|
|
429 |
return o; |
|
428 | 430 |
} |
429 | 431 |
|
430 | 432 |
@Override |
... | ... | |
501 | 503 |
logger.debug(criteria); |
502 | 504 |
//session.flush(); |
503 | 505 |
if (noMatch == false){ |
504 |
List<T> matchCandidates = criteria.list(); |
|
506 |
@SuppressWarnings("unchecked") |
|
507 |
List<T> matchCandidates = criteria.list(); |
|
505 | 508 |
matchCandidates.remove(objectToMatch); |
506 | 509 |
for (T matchCandidate : matchCandidates ){ |
507 | 510 |
if (matchStrategy.invoke(objectToMatch, matchCandidate)){ |
... | ... | |
616 | 619 |
} |
617 | 620 |
|
618 | 621 |
private boolean matchNonComponentType(Criteria criteria, |
619 |
FieldMatcher fieldMatcher, String propertyName, Object value, |
|
620 |
List<MatchMode> matchModes, Type propertyType) throws HibernateException, DataAccessException, MatchException, IllegalAccessException{ |
|
621 |
boolean noMatch = false; |
|
622 |
FieldMatcher fieldMatcher, |
|
623 |
String propertyName, |
|
624 |
Object value, |
|
625 |
List<MatchMode> matchModes, |
|
626 |
Type propertyType) |
|
627 |
throws HibernateException, DataAccessException, MatchException, IllegalAccessException{ |
|
628 |
|
|
629 |
boolean noMatch = false; |
|
622 | 630 |
if (isRequired(matchModes) && value == null){ |
623 | 631 |
noMatch = true; |
624 | 632 |
return noMatch; |
... | ... | |
756 | 764 |
getSession().saveOrUpdate(cdmMetaData); |
757 | 765 |
} |
758 | 766 |
|
759 |
/* (non-Javadoc) |
|
760 |
* @see eu.etaxonomy.cdm.persistence.dao.common.ICdmGenericDao#getMetaData() |
|
761 |
*/ |
|
767 |
|
|
762 | 768 |
@Override |
763 | 769 |
public List<CdmMetaData> getMetaData() { |
764 | 770 |
Session session = getSession(); |
765 | 771 |
Criteria crit = session.createCriteria(CdmMetaData.class); |
766 |
List<CdmMetaData> results = crit.list(); |
|
772 |
@SuppressWarnings("unchecked") |
|
773 |
List<CdmMetaData> results = crit.list(); |
|
767 | 774 |
return results; |
768 | 775 |
} |
769 | 776 |
|
... | ... | |
801 | 808 |
public boolean isEmpty(UUID ownerUuid, String fieldName) { |
802 | 809 |
Object col = initializeCollection(ownerUuid, fieldName); |
803 | 810 |
if(col instanceof Collection) { |
804 |
return ((Collection)col).isEmpty(); |
|
811 |
return ((Collection<?>)col).isEmpty();
|
|
805 | 812 |
} else if(col instanceof Map){ |
806 |
return ((Map)col).isEmpty(); |
|
813 |
return ((Map<?,?>)col).isEmpty();
|
|
807 | 814 |
} |
808 | 815 |
|
809 | 816 |
return false; |
... | ... | |
813 | 820 |
public int size(UUID ownerUuid, String fieldName) { |
814 | 821 |
Object col = initializeCollection(ownerUuid, fieldName); |
815 | 822 |
if(col instanceof Collection) { |
816 |
return ((Collection)col).size(); |
|
823 |
return ((Collection<?>)col).size();
|
|
817 | 824 |
} else if(col instanceof Map){ |
818 |
return ((Map)col).size(); |
|
825 |
return ((Map<?,?>)col).size();
|
|
819 | 826 |
} |
820 | 827 |
return 0; |
821 | 828 |
} |
... | ... | |
825 | 832 |
public Object get(UUID ownerUuid, String fieldName, int index) { |
826 | 833 |
Object col = initializeCollection(ownerUuid, fieldName); |
827 | 834 |
if(col instanceof List) { |
828 |
return ((List)col).get(index); |
|
835 |
return ((List<?>)col).get(index);
|
|
829 | 836 |
} else { |
830 | 837 |
throw new IllegalArgumentException("Field name provided does not correspond to a list"); |
831 | 838 |
} |
... | ... | |
835 | 842 |
public boolean contains(UUID ownerUuid, String fieldName, Object element) { |
836 | 843 |
Object col = initializeCollection(ownerUuid, fieldName); |
837 | 844 |
if(col instanceof Collection) { |
838 |
return ((Collection)col).contains(element); |
|
845 |
return ((Collection<?>)col).contains(element);
|
|
839 | 846 |
} else { |
840 | 847 |
throw new IllegalArgumentException("Field name provided does not correspond to a collection"); |
841 | 848 |
} |
... | ... | |
845 | 852 |
public boolean containsKey(UUID ownerUuid, String fieldName, Object key) { |
846 | 853 |
Object col = initializeCollection(ownerUuid, fieldName); |
847 | 854 |
if(col instanceof Map) { |
848 |
return ((Map)col).containsKey(key); |
|
855 |
return ((Map<?,?>)col).containsKey(key);
|
|
849 | 856 |
} else { |
850 | 857 |
throw new IllegalArgumentException("Field name provided does not correspond to a map"); |
851 | 858 |
} |
... | ... | |
857 | 864 |
public boolean containsValue(UUID ownerUuid, String fieldName, Object value) { |
858 | 865 |
Object col = initializeCollection(ownerUuid, fieldName); |
859 | 866 |
if(col instanceof Map) { |
860 |
return ((Map)col).containsValue(value); |
|
867 |
return ((Map<?,?>)col).containsValue(value);
|
|
861 | 868 |
} else { |
862 | 869 |
throw new IllegalArgumentException("Field name provided does not correspond to a map"); |
863 | 870 |
} |
Also available in: Unified diff
Cleanup