Coverage Report - net.wotonomy.access.EOSQLExpressionFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
EOSQLExpressionFactory
0% 
0% 
1.9
 
 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 java.lang.reflect.Constructor;
 21  
 
 22  
 import net.wotonomy.control.EOFetchSpecification;
 23  
 import net.wotonomy.control.EOQualifier;
 24  
 import net.wotonomy.foundation.NSArray;
 25  
 import net.wotonomy.foundation.NSDictionary;
 26  
 
 27  
 /**
 28  
 *
 29  
 * @author ezamudio@nasoft.com
 30  
 * @author $Author: cgruber $
 31  
 * @version $Revision: 894 $
 32  
 */
 33  
 public class EOSQLExpressionFactory {
 34  
 
 35  
         protected EOAdaptor _adaptor;
 36  
         protected Class _expressionClass;
 37  
         private Constructor _instantiator;
 38  
 
 39  
         public EOSQLExpressionFactory(EOAdaptor adaptor) {
 40  0
                 super();
 41  0
                 _adaptor = adaptor;
 42  0
                 _expressionClass = _adaptor.expressionClass();
 43  0
                 if (_expressionClass == null)
 44  0
                         throw new IllegalStateException("EOAdaptor " + _adaptor.name() + " returned null for expressionClass()");
 45  0
         }
 46  
 
 47  
         public EOAdaptor adaptor() {
 48  0
                 return _adaptor;
 49  
         }
 50  
 
 51  
         /**
 52  
          * Creates an instance of the adaptor's expression class,
 53  
          * with entity assigned to it.
 54  
          * @param entity The entity with which to initialize the expression.
 55  
          * @return An EOSQLExpression.
 56  
          */
 57  
         public EOSQLExpression createExpression(EOEntity entity) {
 58  0
                 EOSQLExpression expr = null;
 59  0
                 if (_instantiator == null) {
 60  
                         try {
 61  0
                                 _instantiator = _expressionClass.getConstructor(new Class[]{ EOEntity.class });
 62  0
                         } catch (Exception ex) {
 63  0
                                 throw new IllegalArgumentException("The expression class " + _expressionClass.getName() + " has no constructor with an entity parameter.");
 64  0
                         }
 65  
                 }
 66  
                 try {
 67  0
                         expr = (EOSQLExpression)_instantiator.newInstance(new Object[]{ entity });
 68  0
                 } catch (Exception ex) {
 69  0
                         throw new IllegalArgumentException("Cannot create new expression of class " + _expressionClass.getName());
 70  0
                 }
 71  0
                 return expr;
 72  
         }
 73  
 
 74  
         public EOSQLExpression expressionForEntity(EOEntity entity) {
 75  0
                 return createExpression(entity);
 76  
         }
 77  
 
 78  
         public EOSQLExpression deleteStatementWithQualifier(EOQualifier qualifier, EOEntity entity) {
 79  0
                 EOSQLExpression expr = createExpression(entity);
 80  0
                 expr.prepareDeleteExpressionForQualifier(qualifier);
 81  0
                 return expr;
 82  
         }
 83  
 
 84  
         public EOSQLExpression insertStatementForRow(NSDictionary row, EOEntity entity) {
 85  0
                 EOSQLExpression expr = createExpression(entity);
 86  0
                 expr.prepareInsertExpressionWithRow(row);
 87  0
                 return expr;
 88  
         }
 89  
 
 90  
         public EOSQLExpression selectStatementForAttributes(NSArray atts, boolean lock, EOFetchSpecification fspec, EOEntity entity) {
 91  0
                 EOSQLExpression expr = createExpression(entity);
 92  0
                 expr.prepareSelectExpressionWithAttributes(atts, lock, fspec);
 93  0
                 return expr;
 94  
         }
 95  
 
 96  
         public EOSQLExpression updateStatementForRow(NSDictionary row, EOQualifier qualifier, EOEntity entity) {
 97  0
                 EOSQLExpression expr = createExpression(entity);
 98  0
                 expr.prepareUpdateExpressionWithRow(row, qualifier);
 99  0
                 return expr;
 100  
         }
 101  
 
 102  
         public EOSQLExpression expressionForString(String sql) {
 103  0
                 EOSQLExpression expr = null;
 104  
                 try {
 105  0
                         expr = (EOSQLExpression)_expressionClass.newInstance();
 106  0
                 } catch (Exception e) {
 107  0
                         return null;
 108  0
                 }
 109  0
                 expr.setStatement(sql);
 110  0
                 return expr;
 111  
         }
 112  
 
 113  
         public Class expressionClass() {
 114  0
                 return _expressionClass;
 115  
         }
 116  
 
 117  
 }
 118  
 /*
 119  
  * $Log$
 120  
  * Revision 1.2  2006/02/16 16:47:14  cgruber
 121  
  * Move some classes in to "internal" packages and re-work imports, etc.
 122  
  *
 123  
  * Also use UnsupportedOperationExceptions where appropriate, instead of WotonomyExceptions.
 124  
  *
 125  
  * Revision 1.1  2006/02/16 13:19:57  cgruber
 126  
  * Check in all sources in eclipse-friendly maven-enabled packages.
 127  
  *
 128  
  * Revision 1.1  2003/08/13 01:04:32  chochos
 129  
  * the SQL generation classes. EOSQLExpression still needs a lot of work, but the factory is pretty much done.
 130  
  *
 131  
  */