com.aoindustries.aoserv.client.MySQLServerTable Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aoserv-client Show documentation
Show all versions of aoserv-client Show documentation
Java client for the AOServ Platform.
/*
* aoserv-client - Java client for the AOServ platform.
* Copyright (C) 2006-2012, 2016 AO Industries, Inc.
* [email protected]
* 7262 Bull Pen Cir
* Mobile, AL 36695
*
* This file is part of aoserv-client.
*
* aoserv-client 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 3 of the License, or
* (at your option) any later version.
*
* aoserv-client 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 aoserv-client. If not, see .
*/
package com.aoindustries.aoserv.client;
import com.aoindustries.io.TerminalWriter;
import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;
import java.util.List;
/**
* @see MySQLServer
*
* @author AO Industries, Inc.
*/
final public class MySQLServerTable extends CachedTableIntegerKey {
MySQLServerTable(AOServConnector connector) {
super(connector, MySQLServer.class);
}
private static final OrderBy[] defaultOrderBy = {
new OrderBy(MySQLServer.COLUMN_AO_SERVER_name+'.'+AOServer.COLUMN_HOSTNAME_name, ASCENDING),
new OrderBy(MySQLServer.COLUMN_NAME_name, ASCENDING)
};
@Override
OrderBy[] getDefaultOrderBy() {
return defaultOrderBy;
}
int addMySQLServer(
String name,
AOServer aoServer,
TechnologyVersion version,
int maxConnections
) throws SQLException, IOException {
if(!version.name.equals(TechnologyName.MYSQL)) throw new SQLException("TechnologyVersion must have name of "+TechnologyName.MYSQL+": "+version.name);
return connector.requestIntQueryIL(
true,
AOServProtocol.CommandID.ADD,
SchemaTable.TableID.MYSQL_SERVERS,
name,
aoServer.pkey,
version.pkey,
maxConnections
);
}
@Override
public MySQLServer get(int pkey) throws IOException, SQLException {
return getUniqueRow(MySQLServer.COLUMN_PKEY, pkey);
}
MySQLServer getMySQLServer(NetBind nb) throws IOException, SQLException {
return getUniqueRow(MySQLServer.COLUMN_NET_BIND, nb.pkey);
}
List getMySQLServers(AOServer ao) throws IOException, SQLException {
return getIndexedRows(MySQLServer.COLUMN_AO_SERVER, ao.pkey);
}
MySQLServer getMySQLServer(String name, AOServer ao) throws IOException, SQLException {
// Use the index first
List table=getMySQLServers(ao);
int size=table.size();
for(int c=0;c getMySQLServers(Package pk) throws IOException, SQLException {
return getIndexedRows(MySQLServer.COLUMN_PACKAGE, pk.name);
}
@Override
public SchemaTable.TableID getTableID() {
return SchemaTable.TableID.MYSQL_SERVERS;
}
@Override
boolean handleCommand(String[] args, Reader in, TerminalWriter out, TerminalWriter err, boolean isInteractive) throws IllegalArgumentException, IOException, SQLException {
String command=args[0];
if(command.equalsIgnoreCase(AOSHCommand.CHECK_MYSQL_SERVER_NAME)) {
if(AOSH.checkParamCount(AOSHCommand.CHECK_MYSQL_SERVER_NAME, args, 1, err)) {
try {
SimpleAOClient.checkMySQLServerName(args[1]);
out.println("true");
out.flush();
} catch(IllegalArgumentException iae) {
err.print("aosh: "+AOSHCommand.CHECK_MYSQL_SERVER_NAME+": ");
err.println(iae.getMessage());
err.flush();
}
}
return true;
} else if(command.equalsIgnoreCase(AOSHCommand.IS_MYSQL_SERVER_NAME_AVAILABLE)) {
if(AOSH.checkParamCount(AOSHCommand.IS_MYSQL_SERVER_NAME_AVAILABLE, args, 2, err)) {
try {
out.println(
connector.getSimpleAOClient().isMySQLServerNameAvailable(
args[1],
args[2]
)
);
out.flush();
} catch(IllegalArgumentException iae) {
err.print("aosh: "+AOSHCommand.IS_MYSQL_SERVER_NAME_AVAILABLE+": ");
err.println(iae.getMessage());
err.flush();
}
}
return true;
} else if(command.equalsIgnoreCase(AOSHCommand.RESTART_MYSQL)) {
if(AOSH.checkParamCount(AOSHCommand.RESTART_MYSQL, args, 2, err)) {
connector.getSimpleAOClient().restartMySQL(
args[1],
args[2]
);
}
return true;
} else if(command.equalsIgnoreCase(AOSHCommand.START_MYSQL)) {
if(AOSH.checkParamCount(AOSHCommand.START_MYSQL, args, 2, err)) {
connector.getSimpleAOClient().startMySQL(
args[1],
args[2]
);
}
return true;
} else if(command.equalsIgnoreCase(AOSHCommand.STOP_MYSQL)) {
if(AOSH.checkParamCount(AOSHCommand.STOP_MYSQL, args, 2, err)) {
connector.getSimpleAOClient().stopMySQL(
args[1],
args[2]
);
}
return true;
} else if(command.equalsIgnoreCase(AOSHCommand.WAIT_FOR_MYSQL_SERVER_REBUILD)) {
if(AOSH.checkParamCount(AOSHCommand.WAIT_FOR_MYSQL_SERVER_REBUILD, args, 1, err)) {
connector.getSimpleAOClient().waitForMySQLServerRebuild(args[1]);
}
return true;
}
return false;
}
boolean isMySQLServerNameAvailable(String name, AOServer ao) throws IOException, SQLException {
return connector.requestBooleanQuery(true, AOServProtocol.CommandID.IS_MYSQL_SERVER_NAME_AVAILABLE, name, ao.pkey);
}
void waitForRebuild(AOServer aoServer) throws IOException, SQLException {
connector.requestUpdate(
true,
AOServProtocol.CommandID.WAIT_FOR_REBUILD,
SchemaTable.TableID.MYSQL_SERVERS,
aoServer.pkey
);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy