Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* aoserv-client - Java client for the AOServ Platform.
* Copyright (C) 2001-2013, 2016, 2017, 2018, 2019, 2020 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.schema;
import com.aoindustries.aoserv.client.AOServConnector;
import com.aoindustries.aoserv.client.AOServObject;
import com.aoindustries.aoserv.client.AOServTable;
import com.aoindustries.aoserv.client.GlobalTableIntegerKey;
import com.aoindustries.aoserv.client.aosh.AOSH;
import com.aoindustries.aoserv.client.aosh.Command;
import com.aoindustries.aoserv.client.sql.Parser;
import com.aoindustries.aoserv.client.sql.SQLExpression;
import com.aoindustries.exception.WrappedException;
import com.aoindustries.io.TerminalWriter;
import com.aoindustries.sql.SQLUtility;
import com.aoindustries.util.sort.JavaSort;
import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
/**
* @see Table
*
* @author AO Industries, Inc.
*/
final public class TableTable extends GlobalTableIntegerKey
{
TableTable(AOServConnector connector) {
super(connector, Table.class);
}
@Override
protected OrderBy[] getDefaultOrderBy() {
return null;
}
/**
* Supports Integer (table_id), String(name), and SchemaTable.TableID (table_id) keys.
*
* @deprecated Always try to lookup by specific keys; the compiler will help you more when types change.
*/
@Deprecated
@Override
public Table get(Object pkey) throws IOException, SQLException {
if(pkey == null) return null;
if(pkey instanceof Integer) return get(((Number)pkey).intValue());
else if(pkey instanceof String) return get((String)pkey);
else if(pkey instanceof Table.TableID) return get((Table.TableID)pkey);
else throw new IllegalArgumentException("Must be an Integer, a String, or a SchemaTable.TableID");
}
/** Avoid repeated array copies. */
private static final int numTables = Table.TableID.values().length;
@Override
public List
getRows() throws IOException, SQLException {
List
rows = super.getRows();
int size = rows.size();
if(size != numTables) {
throw new SQLException("Unexpected number of rows: expected " + numTables + ", got " + size);
}
return rows;
}
/**
* @see #get(java.lang.Object)
*/
@Override
public Table get(int table_id) throws IOException, SQLException {
return getRows().get(table_id);
}
/**
* @see #get(java.lang.Object)
*/
public Table get(String name) throws IOException, SQLException {
return getUniqueRow(Table.COLUMN_NAME, name);
}
/**
* @see #get(java.lang.Object)
*/
public Table get(Table.TableID tableID) throws IOException, SQLException {
return get(tableID.ordinal());
}
@Override
public Table.TableID getTableID() {
return Table.TableID.SCHEMA_TABLES;
}
@Override
public boolean handleCommand(String[] args, Reader in, TerminalWriter out, TerminalWriter err, boolean isInteractive) throws SQLException, IOException {
String command = args[0];
if (command.equalsIgnoreCase(Command.DESC) || command.equalsIgnoreCase(Command.DESCRIBE)) {
if(AOSH.checkParamCount(Command.DESCRIBE, args, 1, err)) {
String tableName = Parser.unquote(args[1]);
Table table = connector.getSchema().getTable().get(tableName);
if(table != null) {
table.printDescription(connector, out, isInteractive);
out.flush();
} else {
err.print("aosh: "+Command.DESCRIBE+": table not found: ");
err.println(Parser.quote(tableName));
err.flush();
}
}
return true;
} else if (command.equalsIgnoreCase(Command.SELECT)) {
int argCount = args.length;
if (argCount >= 4) {
if (argCount == 4 && args[1].equalsIgnoreCase("count(*)")) {
// Is a select count(*)
if ("from".equalsIgnoreCase(args[2])) {
String tableName = Parser.unquote(args[3]);
Table table = connector.getSchema().getTable().get(tableName);
if (table != null) {
SQLUtility.printTable(
new String[] {"count"},
(Iterable