Coverage Report - net.wotonomy.access.EOModelGroup
 
Classes in this File Line Coverage Branch Coverage Complexity
EOModelGroup
0% 
0% 
2.368
 
 1  
 /*
 2  
  Wotonomy: OpenStep design patterns for pure Java applications.
 3  
  Copyright (C) 2001 Michael Powers
 4  
 
 5  
  This library is free software; you can redistribute it and/or
 6  
  modify it under the terms of the GNU Lesser General Public
 7  
  License as published by the Free Software Foundation; either
 8  
  version 2.1 of the License, or (at your option) any later version.
 9  
 
 10  
  This library is distributed in the hope that it will be useful,
 11  
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13  
  Lesser General Public License for more details.
 14  
 
 15  
  You should have received a copy of the GNU Lesser General Public
 16  
  License along with this library; if not, see http://www.gnu.org
 17  
  */
 18  
 package net.wotonomy.access;
 19  
 
 20  
 import net.wotonomy.control.EOFetchSpecification;
 21  
 import net.wotonomy.control.EOObjectStoreCoordinator;
 22  
 import net.wotonomy.foundation.NSArray;
 23  
 import net.wotonomy.foundation.NSDictionary;
 24  
 import net.wotonomy.foundation.NSMutableDictionary;
 25  
 
 26  
 /**
 27  
 * A group of models that connect to the same database. Entities in
 28  
 * these models can have relationships that point to other entities
 29  
 * in any model of the same group.
 30  
 *
 31  
 * @author ezamudio@nasoft.com
 32  
 * @author $Author: cgruber $
 33  
 * @version $Revision: 894 $
 34  
 */
 35  
 public class EOModelGroup {
 36  
 
 37  
         private static EOModelGroup _defaultGroup;
 38  
         private static EOModelGroup _globalGroup;
 39  
         protected NSMutableDictionary _models;
 40  
 
 41  
         public EOModelGroup() {
 42  0
                 super();
 43  0
         }
 44  
 
 45  
         public void addModel(EOModel model) {
 46  0
                 if (model.name() == null)
 47  0
                         throw new IllegalArgumentException("Cannot add an unnamed model to a group.");
 48  0
                 if (_models.objectForKey(model.name()) != null)
 49  0
                         throw new IllegalArgumentException("Cannot add model " + model.name() +
 50  0
                                 " to group because it already contains a model with the same name.");
 51  0
                 NSArray ents = model.entityNames();
 52  0
                 for (int i = 0; i < ents.count(); i++) {
 53  0
                         String ename = (String)ents.objectAtIndex(i);
 54  0
                         if (entityNamed(ename) != null)
 55  0
                                 throw new IllegalArgumentException("Cannot add model " + model.name() +
 56  0
                                         " to group because it contains entity named " + ename);
 57  
                 }
 58  0
                 _models.setObjectForKey(model, model.name());
 59  0
         }
 60  
 
 61  
         public void removeModel(EOModel model) {
 62  0
                 _models.removeObjectForKey(model.name());
 63  0
         }
 64  
 
 65  
         public void addModelWithPath(String path) {
 66  0
                 EOModel model = new EOModel(path);
 67  0
                 addModel(model);
 68  0
         }
 69  
 
 70  
         public void addModelsFromDirectory(String dir) {
 71  0
         }
 72  
 
 73  
         public static void setDefaultGroup(EOModelGroup group) {
 74  0
                 _defaultGroup = group;
 75  0
         }
 76  
         public static EOModelGroup defaultGroup() {
 77  0
                 if (_defaultGroup == null) {
 78  0
                         _defaultGroup = globalModelGroup();
 79  
                 }
 80  0
                 return _defaultGroup;
 81  
         }
 82  
 
 83  
         public static EOModelGroup globalModelGroup() {
 84  0
                 if (_globalGroup == null) {
 85  0
                         _globalGroup = new EOModelGroup();
 86  
                         //TODO: read all frameworks and get models from them
 87  
                 }
 88  0
                 return _globalGroup;
 89  
         }
 90  
 
 91  
         public EOEntity entityForObject(net.wotonomy.control.EOEnterpriseObject eo) {
 92  0
                 return null;
 93  
         }
 94  
 
 95  
         public EOEntity entityNamed(String name) {
 96  0
                 java.util.Enumeration enumeration = _models.objectEnumerator();
 97  0
                 while (enumeration.hasMoreElements()) {
 98  0
                         EOModel m = (EOModel)enumeration.nextElement();
 99  0
                         if (m.entityNamed(name) != null)
 100  0
                                 return m.entityNamed(name);
 101  0
                 }
 102  0
                 return null;
 103  
         }
 104  
 
 105  
         public EOModel modelNamed(String name) {
 106  0
                 return (EOModel)_models.objectForKey(name);
 107  
         }
 108  
 
 109  
         public NSArray modelNames() {
 110  0
                 return _models.allKeys();
 111  
         }
 112  
 
 113  
         public NSArray models() {
 114  0
                 return _models.allValues();
 115  
         }
 116  
 
 117  
         public EOModel modelWithPath(String path) {
 118  0
                 java.util.Enumeration enumeration = _models.objectEnumerator();
 119  0
                 while (enumeration.hasMoreElements()) {
 120  0
                         EOModel m = (EOModel)enumeration.nextElement();
 121  0
                         if (m.path() != null && m.path().equals(path))
 122  0
                                 return m;
 123  0
                 }
 124  0
                 return null;
 125  
         }
 126  
 
 127  
         public EOStoredProcedure storedProcedureNamed(String name) {
 128  0
                 java.util.Enumeration enumeration = _models.objectEnumerator();
 129  0
                 while (enumeration.hasMoreElements()) {
 130  0
                         EOModel m = (EOModel)enumeration.nextElement();
 131  0
                         if (m.storedProcedureNamed(name) != null)
 132  0
                                 return m.storedProcedureNamed(name);
 133  0
                 }
 134  0
                 return null;
 135  
         }
 136  
 
 137  
         public EOFetchSpecification fetchSpecificationNamed(String fetchSpecName, String entityName) {
 138  0
                 EOEntity e = entityNamed(entityName);
 139  0
                 if (e == null)
 140  0
                         return null;
 141  0
                 return e.fetchSpecificationNamed(fetchSpecName);
 142  
         }
 143  
 
 144  
         public void loadAllModelObjects() {
 145  0
                 java.util.Enumeration enumeration = _models.objectEnumerator();
 146  0
                 while (enumeration.hasMoreElements()) {
 147  0
                         EOModel m = (EOModel)enumeration.nextElement();
 148  
                         //this causes all entities to be loaded
 149  0
                         NSArray ents = m.entities();
 150  0
                         for (int i=0; i<ents.count(); i++) {
 151  0
                                 EOEntity e = (EOEntity)ents.objectAtIndex(i);
 152  
                                 //this loads all the fetch specifications
 153  0
                                 e.fetchSpecificationNamed("whatever");
 154  
                         }
 155  0
                 }
 156  0
         }
 157  
 
 158  
         public static void setModelGroupForObjectStoreCoordinator(EOObjectStoreCoordinator coord, EOModelGroup group) {
 159  0
                 NSMutableDictionary d = new NSMutableDictionary(coord.userInfo());
 160  0
                 d.setObjectForKey(group, "ModelGroup");
 161  0
                 coord.setUserInfo(d);
 162  0
         }
 163  
         public static EOModelGroup modelGroupForObjectStoreCoordinator(EOObjectStoreCoordinator coord) {
 164  0
                 NSDictionary d = coord.userInfo();
 165  0
                 if (d == null)
 166  0
                         return defaultGroup();
 167  0
                 Object g = d.objectForKey("ModelGroup");
 168  0
                 if (g != null && g instanceof EOModelGroup)
 169  0
                         return (EOModelGroup)g;
 170  0
                 return defaultGroup();
 171  
         }
 172  
 
 173  
 }
 174  
 /*
 175  
  * $Log$
 176  
  * Revision 1.2  2006/02/16 16:47:14  cgruber
 177  
  * Move some classes in to "internal" packages and re-work imports, etc.
 178  
  *
 179  
  * Also use UnsupportedOperationExceptions where appropriate, instead of WotonomyExceptions.
 180  
  *
 181  
  * Revision 1.1  2006/02/16 13:19:57  cgruber
 182  
  * Check in all sources in eclipse-friendly maven-enabled packages.
 183  
  *
 184  
  * Revision 1.4  2005/05/11 15:21:53  cgruber
 185  
  * Change enum to enumeration, since enum is now a keyword as of Java 5.0
 186  
  *
 187  
  * A few other comments in the code.
 188  
  *
 189  
  * Revision 1.3  2003/08/08 00:44:04  chochos
 190  
  * manage model groups for object store coordinators.
 191  
  *
 192  
  * Revision 1.2  2003/08/08 00:36:41  chochos
 193  
  * add a little more functionality
 194  
  *
 195  
  * Revision 1.1  2003/08/07 02:42:28  chochos
 196  
  * EOModel can read an .eomodeld file. EOModelGroup doesn't do much for now.
 197  
  *
 198  
 */