Package org.xorm.tools.editor

Source Code of org.xorm.tools.editor.QueryAction

/*
    $Header: /cvsroot/xorm/xorm/tools/src/org/xorm/tools/editor/QueryAction.java,v 1.6 2002/04/28 00:34:31 wbiggs Exp $

    This file is part of XORM.

    XORM is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    XORM is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Foobar; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
package org.xorm.tools.editor;

import org.xorm.XORM;
import java.io.*;
import java.util.*;
import javax.jdo.PersistenceManager;
import javax.jdo.Query;
import javax.jdo.spi.PersistenceCapable;

public class QueryAction extends Action {
    public QueryAction(PersistenceManager mgr) {
  super(mgr);
    }

    public Object go() {
  System.out.println("QUERY FOR OBJECTS");
  PersistenceCapable pc = null;
  try {
      Class clazz = null;
      while (clazz == null) {
    System.out.print("Enter result class: ");
    clazz = readClass();
      }

      System.out.print("Enter query: ");
      String queryText = readLine();

      if ("".equals(queryText)) queryText = null;

      Query query = mgr.newQuery(clazz, queryText);
      List args = new ArrayList();

      if (queryText != null) {
    System.out.print("Declare parameters: ");
    String params = readLine();
    query.declareParameters(params);

    // TODO take different arg types
    String arg = null;
    do {
        System.out.print("Parameter value or ENTER when done: ");
        arg = readLine();
        if (!"".equals(arg)) args.add(arg);
    } while (!"".equals(arg));
   
      }
      Collection results = (Collection) query.executeWithArray(args.toArray());

      System.out.println("Query returned " + results.size() + " results");

      Action action = new EditCollectionAction(mgr, results);
      return action.go();
  } catch (Exception e) {
      e.printStackTrace();
  }
  return pc;
    }
}
TOP

Related Classes of org.xorm.tools.editor.QueryAction

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.