Coverage Report - net.wotonomy.access.EODatabaseChannel
 
Classes in this File Line Coverage Branch Coverage Complexity
EODatabaseChannel
0% 
0% 
1.231
 
 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.EOClassDescription;
 21  
 import net.wotonomy.control.EOEditingContext;
 22  
 import net.wotonomy.control.EOFetchSpecification;
 23  
 import net.wotonomy.control.EOGlobalID;
 24  
 import net.wotonomy.control.EOKeyValueCodingAdditions;
 25  
 import net.wotonomy.foundation.NSArray;
 26  
 import net.wotonomy.foundation.NSDictionary;
 27  
 import net.wotonomy.foundation.NSMutableArray;
 28  
 
 29  
 /**
 30  
 *
 31  
 * @author ezamudio@nasoft.com
 32  
 * @author $Author: cgruber $
 33  
 * @version $Revision: 894 $
 34  
 */
 35  
 public class EODatabaseChannel {
 36  
 
 37  
         protected EODatabaseContext _context;
 38  
         protected EOAdaptorChannel _channel;
 39  
         protected EOEntity _currEntity;
 40  
         protected EOEditingContext _currEC;
 41  
         protected NSArray _attributes;
 42  
         protected boolean _locking;
 43  
         protected boolean _refreshing;
 44  
 
 45  
         public EODatabaseChannel(EODatabaseContext context) {
 46  0
                 super();
 47  0
                 _context = context;
 48  0
                 _channel = _context.adaptorContext().createAdaptorChannel();
 49  0
         }
 50  
 
 51  
         public EOAdaptorChannel adaptorChannel() {
 52  0
                 return _channel;
 53  
         }
 54  
 
 55  
         public EODatabaseContext databaseContext() {
 56  0
                 return _context;
 57  
         }
 58  
 
 59  
         public void cancelFetch() {
 60  0
                 _channel.cancelFetch();
 61  0
         }
 62  
 
 63  
         public Object fetchObject() {
 64  0
                 NSDictionary r = _channel.fetchRow();
 65  0
                 EOGlobalID gid = _currEntity.globalIDForRow(r);
 66  0
                 Object eo = _currEC.objectForGlobalID(gid);
 67  0
                 if (eo == null) {
 68  0
                         eo = EOClassDescription.classDescriptionForEntityName(_currEntity.name()).createInstanceWithEditingContext(_currEC, gid);
 69  0
                         if (eo instanceof EOKeyValueCodingAdditions)
 70  0
                                 ((EOKeyValueCodingAdditions)eo).takeValuesFromDictionary(r);
 71  
                         else
 72  0
                                 EOKeyValueCodingAdditions.DefaultImplementation.takeValuesFromDictionary(eo, r);
 73  0
                 } else {
 74  0
                         if (isRefreshingObjects()) {
 75  
                                 //TODO: refresh object (how?)
 76  
                         }
 77  
                 }
 78  0
                 return eo;
 79  
         }
 80  
 
 81  
         public boolean isFetchInProgress() {
 82  0
                 return _channel.isFetchInProgress();
 83  
         }
 84  
 
 85  
         public void setIsLocking(boolean flag) {
 86  0
                 _locking = flag;
 87  0
         }
 88  
 
 89  
         public boolean isLocking() {
 90  0
                 return _locking;
 91  
         }
 92  
 
 93  
         public void setIsRefreshingObjects(boolean flag) {
 94  0
                 _refreshing = flag;
 95  0
         }
 96  
 
 97  
         public boolean isRefreshingObjects() {
 98  0
                 return _refreshing;
 99  
         }
 100  
 
 101  
         public void selectObjectsWithFetchSpecification(EOFetchSpecification fspec, EOEditingContext ec) {
 102  0
                 setIsLocking(fspec.locksObjects());
 103  0
                 setIsRefreshingObjects(fspec.refreshesRefetchedObjects());
 104  0
                 setCurrentEditingContext(ec);
 105  0
                 setCurrentEntity(databaseContext().database().entityNamed(fspec.entityName()));
 106  0
                 NSMutableArray atts = new NSMutableArray();
 107  0
                 atts.addObjectsFromArray(_currEntity.attributes());
 108  0
                 adaptorChannel().selectAttributes(atts, fspec, isLocking(), _currEntity);
 109  0
                 adaptorChannel().setAttributesToFetch(atts);
 110  0
                 _attributes = atts;
 111  0
         }
 112  
 
 113  
         public void setCurrentEditingContext(EOEditingContext ec) {
 114  0
                 _currEC = ec;
 115  0
         }
 116  
 
 117  
         public void setCurrentEntity(EOEntity entity) {
 118  0
                 _currEntity = entity;
 119  0
         }
 120  
 
 121  
 }
 122  
 /*
 123  
  * $Log$
 124  
  * Revision 1.2  2006/02/16 16:47:14  cgruber
 125  
  * Move some classes in to "internal" packages and re-work imports, etc.
 126  
  *
 127  
  * Also use UnsupportedOperationExceptions where appropriate, instead of WotonomyExceptions.
 128  
  *
 129  
  * Revision 1.1  2006/02/16 13:19:57  cgruber
 130  
  * Check in all sources in eclipse-friendly maven-enabled packages.
 131  
  *
 132  
  * Revision 1.2  2003/08/29 21:15:46  chochos
 133  
  * use EOEntity's globalIDForRow method.
 134  
  *
 135  
  * Revision 1.1  2003/08/19 01:54:43  chochos
 136  
  * The EODatabase layer still needs a lot of work, but it's on its way...
 137  
  *
 138  
  */