[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [dali-dev] IPersitentType.attributes() - wildcard parameterized type?
|
Hi Tom,
Funny you should ask, I just struggled with this very recently. In our
model JavaPersistentType and XmlPersistentType both implement
IPersistentType. They each have collections of more specific attributes
JavaPersistentAttribute and XmlPersistentAttribute. The reason I
changed the interface to have a wildcard-parameterized type was so that
I could use a CloneIterator (our own utility class) in
JavaPersistentType.attributes() to prevent concurrent modification
problems we were having. I did not change allAttributes() because those
iterators could contain xml and java PersistentAttributes due to
inheritance hierarchies that could possibly span both java and orm.xml.
I don't know that it is possible to use the wildcard-parameterized type
in those situations.
I agree this solution is not the best, we have compiler warnings in
JavaPersistentType that we haven't yet fixed. Given that background and
the fact that I am fairly new to generics, do you have any suggestions?
The method you are writing looks very similar to some of our interface
methods. You might want to take a look at IEntity.primaryKeyColumnName()
and IEntity.primaryKeyAttributeName().
thanks,
Karen
Tom Mutdosch wrote:
Hi there,
I was just wondering why the IPersitentType.attributes() method has a
return type of: Iterator<? extends IPersistentAttribute>
(whereas the other methods that return Iterators have types of
Iterator<IPersistentAttribute>).
Is the wildcard-parameterized type needed in this case? It's not a
problem; it just makes the usage of it seem somewhat unwieldy:
public static String getPrimaryKey(IPersistentType entity) {
for ( Iterator<? extends IPersistentAttribute> iter =
entity.attributes(); iter.hasNext(); ) {
IPersistentAttribute jpAtt = iter.next();
String attributeType = jpAtt.mappingKey();
// ... etc etc
Thanks
Tom
_______________________________________________
dali-dev mailing list
dali-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/dali-dev