I attached the instructions and the classes that you need to work on below . if you have questions please ask. i need someone expert on java programming.
package core;
import adt.Response;
import java.util.List;
import java.util.Scanner;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
/**
* This class implements an interactive console
* for a database server.
*
* Finish implementing the required features
* but do not modify the protocols.
*/
public class Console {
/**
* This is the entry point for running the
* console as a stand-alone program.
*/
public static void main(String[] args) {
prompt(new Server(), System.in, System.out);
}
public static void prompt (Server server, InputStream in_stream, OutputStream
out_stream) {
final Scanner in = new Scanner(in_stream);
final PrintStream out = new PrintStream(out_stream);
/*
* TODO: Use a REPL to prompt the user for inputs,
* and send each input to the server for parsing.
* No inputs are to be parsed in the console, except
* for the case-insensitive sentinel EXIT, which
* terminates the console.
*/
out.print(“>> “);
String text = in.nextLine();
in.close();
List responses = server.interpret(text);
/*
* TODO: This wrongly assumes that there is only
* one response from the server. However, there
* may be one or more responses, and each response
* should be reported in the order listed.
*/
out.println(“Success: ” + responses.get(0).get(“success”));
out.println(“Message: ” + responses.get(0).get(“message”));
out.println(“Table: ” + responses.get(0).get(“table”));
// TODO: Support tabular view, in a later module.
}
}
package core;
import driver.*;
import adt.Response;
import adt.Database;
import java.util.List;
import java.util.LinkedList;
/**
* This class implements a server with an active
* connection to a backing database.
*
* Finish implementing the required features
* but do not modify the protocols.
*/
public class Server {
@SuppressWarnings(“unused”)
private static final String
STUDENT_NAME = “Kawthar Abushaheen”,
STUDENT_IDNUM = “800160602”,
STUDENT_EMAIL = “ka0003@mix.wvu.edu”;
private Database database;
private List drivers;
public Server() {
this(new Database());
}
public Server(Database database) {
this.database = database;
// TODO: Add each new driver as it is implemented.
drivers = new LinkedList();
drivers.add(new Dsquare());
// drivers.add(new DRange());
}
public Database database() {
return database;
}
public List interpret(String script) {
/*
* TODO: This wrongly assumes the entire script
* is a single query. However, there may be
* one or more semicolon-delimited queries in
* the script to be split and parsed distinctly.
*/
List queries = new LinkedList();
queries.add(script);
/* TODO: This only checks the first driver for a
* response to the first query. Instead, iterate over
* all drivers until one of them gives a response
* for the first query. Default to a failure response
* only if no driver gave a response for a query.
* Then iterate again for the next query.
*/
List responses = new LinkedList();
Response response = drivers.get(0).execute(null, queries.get(0));
if (response != null)
responses.add(response);
else
responses.add(new Response(false, “Unrecognized query”, null));
return responses;
}
}
SYNTACTIC CONVENTIONS
The following syntactic conventions are used in this document.
> Keywords are shown in UPPER case by convention must be case-insensitive in implementation.
> Names and data are shown in lower case by convention but must be case-sensitive by implementation.
> Avalid name of any sort is understood to be one letter followed by zero or more letters, digits, or underscores.
> Whitespace is only required where it is necessary to distinguish the boundaries between tokens.
Syntax, data, and literals are shown in blue formatting.
Metasymbols are shown in orange formatting and are used to describe the syntax, but they are not literally part of the syntax.
They indicate optionall portions, lists of several possible alternatives), or implied … repetition.
MODULE 1 » TABLES
GitLab M1
Topics: Relational databases, data definition (DDL) queries, regular expressions, table schemas.
Implement the core.Server.interpret method to accept a script (a string of one or more semicolon-delimited queries) and
return a java.util.List instance containing the responses for each of the queries in the script in execution
order. Note that semicolons will be used exclusively as delimiters between queries in a script and never as data within a query.
Implement new drivers to support the following queries according to the given syntax and semantics.
CREATE TABLE table_name (column_defi, column_def2, .., column_defN)
The table_name is any valid name not already in the database.
Each column_def has the syntax (PRIMARY] (STRING | INTEGER | BOOLEAN) column_name indicating whether the column
is the primary column for the table, the data type of the column’s field values, and the name of the column. There must be
at least one column_def exactly one of which must be the indicated primary column for the table. Each column_name
must be a valid name distinct from the rest. The order the columns are given indicates the order the schema defines them.
The query should add a new stored table with the given name and column definitions to the database backed by the server
if there is not already a table with that name. The created table must include a standard schema.
In a successful response, state the name of the created table and how many columns it has, and return the created table.
In a failed response, state an appropriate explanation of the failure, and do not return any table.
DROP TABLE table_name
> The table_name is any valid name belonging to a table that already exists in the database.
The query should remove the stored table with the given name from the database backed by the server if it exists.
In a successful response, state the name of the dropped table and how many rows it had, and return the dropped table.
In a failed response, state an appropriate explanation of the failure, and do not return any table.
row_count
20
SHOW TABLES
The query should always succeed, because it is a pure accessor of data that is always defined
and cannot possibly fail
.
In a successful response, state how many tables there are, and return a computed table with
a primary string column table_name and an integer column row_count such that the rows
list all the table names in the database with their respective row counts. Refer to the tabular
view to the right for an example of the schema and the data for a successful response.
table_name*
abc
table_2
wxyz
11
0
pa
8
12
table_1
film
Note that any invalid or unrecognized queries should return a failure response with a message indicating a reason for the failure.
implement the core.Console.prompt method to provide a REPL prompt at which the user can input a script, see the immediate
response from sending the script to a locally instanced server to be interpreted, and continue looping until the non-query sentinel
value EXIT is inputted. Responses should be displayed in a legible format including the success flag, a message if any, and the
map-view of a table if any. There is no need to write a driver for the sentinel since it should only be recognized in the console.
For this and the remaining modules in the MODULE series, note that adt.Database is an alias of the provided noncompliant hash
map implementation. In the later HasH series of modules you will replace this noncompliant hash map with a compliant one, but
until then you may freely utilize the noncompliant one in all modules in the MODULE series.
3/9