Package net.sourceforge.squirrel_sql.plugins.mysql.action

Source Code of net.sourceforge.squirrel_sql.plugins.mysql.action.AbstractMultipleSQLCommand

package net.sourceforge.squirrel_sql.plugins.mysql.action;
/*
* Copyright (C) 2003 Colin Bell
* colbell@users.sourceforge.net
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
import net.sourceforge.squirrel_sql.client.session.IObjectTreeAPI;
import net.sourceforge.squirrel_sql.client.session.ISession;
import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
import net.sourceforge.squirrel_sql.fw.util.ICommand;
import net.sourceforge.squirrel_sql.plugins.mysql.MysqlPlugin;
/**
* This abstract command is a MySQL command that takes a table
* as a parameter.
*
* @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
*/
abstract class AbstractMultipleSQLCommand implements ICommand
{
  /** Current session. */
  private ISession _session;

  /** Current plugin. */
  private final MysqlPlugin _plugin;

  /**
   * Ctor specifying the current session.
   *
   * @throws  IllegalArgumentException
   *       Thrown if a?<TT>null</TT> <TT>ISession</TT>,
   *       <TT>Resources</TT> or <TT>MysqlPlugin</TT> passed.
   */
  public AbstractMultipleSQLCommand(ISession session, MysqlPlugin plugin)
  {
    super();
    if (session == null)
    {
      throw new IllegalArgumentException("ISession == null");
    }
    if (plugin == null)
    {
      throw new IllegalArgumentException("MysqlPlugin == null");
    }

    _session = session;
    _plugin = plugin;
  }

  /**
   * Execute this command.
   */
  public void execute()
  {
    final StringBuffer buf = new StringBuffer(2048);
    final String sep = " " + _session.getQueryTokenizer().getSQLStatementSeparator();

    final IObjectTreeAPI api = _session.getSessionInternalFrame().getObjectTreeAPI();
    final IDatabaseObjectInfo[] dbObjs = api.getSelectedDatabaseObjects();

    for (int i = 0; i < dbObjs.length; ++i)
    {
      final String cmd = getMySQLCommand(dbObjs[i]);
      if (cmd != null && cmd.length() > 0)
      {
        buf.append(cmd).append(" ").append(sep).append('\n');
      }
    }

    // Execute the SQL command in the SQL tab and then display the SQL tab.
    if (buf.length() > 0)
    {
      _session.getSessionInternalFrame().getSQLPanelAPI().appendSQLScript(buf.toString(), true);
      _session.getSessionInternalFrame().getSQLPanelAPI().executeCurrentSQL();
      _session.selectMainTab(ISession.IMainPanelTabIndexes.SQL_TAB);
    }
  }

  /**
   * Retrieve the MySQL command to run.
   *
   * @return  the MySQL command to run.
   */
  protected abstract String getMySQLCommand(IDatabaseObjectInfo dbObj);
}
TOP

Related Classes of net.sourceforge.squirrel_sql.plugins.mysql.action.AbstractMultipleSQLCommand

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.