001    package org.cumulus4j.store.model;
002    
003    import java.util.Collection;
004    
005    import javax.jdo.JDOObjectNotFoundException;
006    import javax.jdo.PersistenceManager;
007    import javax.jdo.identity.LongIdentity;
008    
009    import org.cumulus4j.store.model.FieldMeta.NamedQueries;
010    
011    public class FieldMetaDAO extends AbstractDAO {
012    
013            public FieldMetaDAO() { }
014    
015            public FieldMetaDAO(PersistenceManager pm) {
016                    super(pm);
017            }
018    
019            public Collection<FieldMeta> getFieldMetasForClassMeta(ClassMeta classMeta) {
020                    if (classMeta == null)
021                            throw new IllegalArgumentException("classMeta == null");
022    
023                    javax.jdo.Query query = pm.newNamedQuery(FieldMeta.class, NamedQueries.getFieldMetasForClassMeta_classID);
024                    @SuppressWarnings("unchecked")
025                    Collection<FieldMeta> result = (Collection<FieldMeta>) query.execute(classMeta.getClassID());
026                    return result;
027            }
028    
029            public Collection<FieldMeta> getSubFieldMetasForFieldMeta(FieldMeta fieldMeta) {
030                    if (fieldMeta == null)
031                            throw new IllegalArgumentException("fieldMeta == null");
032    
033                    javax.jdo.Query query = pm.newNamedQuery(FieldMeta.class, NamedQueries.getSubFieldMetasForFieldMeta_fieldID);
034                    @SuppressWarnings("unchecked")
035                    Collection<FieldMeta> result = (Collection<FieldMeta>) query.execute(fieldMeta.getFieldID());
036                    return result;
037            }
038    
039            public FieldMeta getFieldMeta(long fieldID, boolean throwExceptionIfNotFound)
040            {
041                    LongIdentity identity = new LongIdentity(FieldMeta.class, fieldID);
042                    try {
043                            FieldMeta fieldMeta = (FieldMeta) pm.getObjectById(identity);
044                            return fieldMeta;
045                    } catch (JDOObjectNotFoundException x) {
046                            if (throwExceptionIfNotFound)
047                                    throw x;
048                            else
049                                    return null;
050                    }
051            }
052    
053    }