7
7
import java .lang .reflect .Method ;
8
8
9
9
import com .rishal .exception .InvalidSqlException ;
10
+
10
11
/**
11
12
* Main Class used to launch the application.
13
+ *
12
14
* @author Rishal
13
15
*
14
16
*/
15
17
public class Application {
16
-
17
- public static void main (String [] args ) throws IOException , InvalidSqlException , ClassNotFoundException , InstantiationException , IllegalAccessException , NoSuchMethodException , SecurityException , IllegalArgumentException , InvocationTargetException {
18
- //Taking Query input from user
19
- LoadData a =LoadData .getInstance ();
20
- BufferedReader br =new BufferedReader (new InputStreamReader (System .in ));
21
-
22
- System .out .println ("CommandLine SQL- Enter the SQl query to get the result" );
23
- String inputQuery =br .readLine ();
24
- QueryType query =new QueryType ();
25
- QueryType .Type typeOfQuery = query .getLineType (inputQuery );
26
- if (!typeOfQuery .equals (QueryType .Type .NOMATCH ))
27
- {
28
- Class <?> c = Class .forName ("com.rishal.queryOperation" +"." +typeOfQuery .toString ());
29
- Object t = c .newInstance ();
30
- Method method = c .getDeclaredMethod ("display" , String .class );
31
- method .invoke (t , inputQuery );
32
- }
33
- else
34
- {
35
- throw new InvalidSqlException ("Invalid Sql! Please enter valid SQL query." );
18
+
19
+ public static void main (String [] args ) throws IOException ,
20
+ InvalidSqlException , ClassNotFoundException ,
21
+ InstantiationException , IllegalAccessException ,
22
+ NoSuchMethodException , SecurityException , IllegalArgumentException ,
23
+ InvocationTargetException {
24
+ // Taking Query input from user
25
+ LoadData a = LoadData .getInstance ();
26
+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
27
+ System .out
28
+ .println ("CommandLine SQL- Enter the SQl query to get the result. Enter (Exit/Quit) to exit!" );
29
+ String inputQuery = "" ;
30
+ while (!inputQuery .equalsIgnoreCase ("Exit" )
31
+ || !inputQuery .equalsIgnoreCase ("Quit" )) {
32
+ inputQuery = br .readLine ();
33
+ QueryType query = new QueryType ();
34
+ QueryType .Type typeOfQuery = query .getLineType (inputQuery );
35
+ if (!typeOfQuery .equals (QueryType .Type .NOMATCH )) {
36
+ Class <?> c = Class .forName ("com.rishal.queryOperation" + "."
37
+ + typeOfQuery .toString ());
38
+ Object t = c .newInstance ();
39
+ Method method = c .getDeclaredMethod ("display" , String .class );
40
+ method .invoke (t , inputQuery );
41
+ } else if (!(inputQuery .equalsIgnoreCase ("Exit" ))
42
+ && !(inputQuery .equalsIgnoreCase ("Quit" ))) {
43
+ throw new InvalidSqlException (
44
+ "Invalid Sql! Please enter valid SQL query." );
45
+ } else if (inputQuery .equalsIgnoreCase ("Exit" )
46
+ || inputQuery .equalsIgnoreCase ("Quit" )) {
47
+ System .out .println ("Sql Engine Closing !Bye" );
48
+ break ;
49
+
50
+ }
51
+
36
52
}
37
53
38
54
}
39
55
40
- }
56
+ }
0 commit comments