001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.ejb.cfg21;
031:
032: import com.caucho.ejb.cfg.*;
033: import com.caucho.config.ConfigException;
034: import com.caucho.ejb.gen21.AmberQueryMethod;
035: import com.caucho.ejb.gen21.ViewClass;
036: import com.caucho.ejb.ql.EjbSelectQuery;
037: import com.caucho.ejb.ql.QLParser;
038: import com.caucho.java.gen.BaseMethod;
039: import com.caucho.util.L10N;
040:
041: /**
042: * Configuration for find method.
043: */
044: public class EjbAmberFindMethod extends EjbMethod {
045: private static final L10N L = new L10N(EjbAmberFindMethod.class);
046:
047: private String _query;
048: private String _location;
049:
050: private boolean _queryLoadsBean = true;
051:
052: /**
053: * Creates a new method.
054: *
055: * @param view the owning view
056: * @param apiMethod the method from the view
057: * @param implMethod the method from the implementation
058: */
059: public EjbAmberFindMethod(EjbView view, ApiMethod apiMethod,
060: String query, String location) throws ConfigException {
061: super (view, apiMethod, null);
062:
063: if (apiMethod == null)
064: throw new NullPointerException();
065:
066: _query = query;
067: _location = location;
068: }
069:
070: /**
071: * Sets true if the query loads the bean.
072: */
073: public void setQueryLoadsBean(boolean queryLoadsBean) {
074: _queryLoadsBean = queryLoadsBean;
075: }
076:
077: /**
078: * Assembles the method.
079: */
080: public BaseMethod assemble(ViewClass viewAssembler,
081: String fullClassName) throws ConfigException {
082: ApiMethod apiMethod = getApiMethod();
083: EjbEntityBean bean = (EjbEntityBean) getView().getBean();
084:
085: QLParser parser = new QLParser(bean, apiMethod.getName(),
086: apiMethod, apiMethod.getReturnType());
087:
088: if (_location != null)
089: parser.setLocation(_location);
090:
091: EjbSelectQuery query = (EjbSelectQuery) parser
092: .parseQuery(_query);
093:
094: String returnEJB = parser.getReturnEJB();
095:
096: if (returnEJB == null || !returnEJB.equals(bean.getEJBName()))
097: throw new ConfigException(L.l(
098: "{0}: '{1}' query must return collection of '{2}'",
099: bean.getEJBClass().getName(), apiMethod.getName(),
100: bean.getLocal().getName()));
101:
102: AmberQueryMethod queryMethod = new AmberQueryMethod(bean,
103: getApiMethod(), fullClassName, getViewPrefix(), query);
104:
105: queryMethod.setQueryLoadsBean(_queryLoadsBean);
106:
107: return queryMethod;
108: }
109: }
|