• No results found

7. Implementation

7.1.1. Application Controller

The application controller is the main component of SQL Evaluation tool system. It has imple- mented various core functionalities of business logic for controlling core application system. It has included several important classes such asEvaluationWindow,ExtensionMechanism andSQLStatementEvaluation. TheEvaluationWindowClass is responsible for representing a Graphical User Interface (GUI) window for performing user interactions. Moreover, all necessary User Interface (UI) element and UI related actions are performing by this class. Whereas, theExtensionMechanismclass deals with the implementation of plugins mecha- nism for providing opportunity to enhance application functionalities in runtime and the SQLStatementExecutionclass controls the SQL statement execution related tasks.

In order to represent the SQL statement execution results and data service provider list, the tool has two extensible Java forms usingGridBagLayout. These forms allow application

7. Implementation

adding various Java UI components dynamically, which brings a great advantage for the application systems representing a number of data services providers’ identity based on chosen a number o data access classes. Also, using this facilities a variable number of SQL statement evaluation results table are drawn. These results tables are created based on checked data service providers. The access control of both data forms are implemented in classEvaluationWindow. UsingGridBagLayoutform, the advantages is that the component does not necessarily has to define explicitly related position and size, as the size and positions are controlling by theGridBagConstraintsobject associated with each component. So that, every new component will be added in the end position of the form. However, it is also possible to recognize the components position in runtime.

1 ...

2

3 // SQL execution progress bar is visible

4 sqlExcProcessBar.setVisible(true); 5

6 new SwingWorker<Void, Void>() { 7

8 // Method to perform the background computation

9 protected Void doInBackground() throws Exception {

10 /*

11 * Method calling form SQLStatementEvaluation class to execute

12 * a set of SQL statements while the progress bar is running

13 */

14 sqlStateEval.evaluateDataStoreService("dataServiceName");

15 return null;

16 };

17

18 // Mehod is called when the SwingWorker’s doInBackground finishes

19 protected void done() {

20 // Hide SQL execution progress bar 21 sqlExcProcessBar.setVisible(false);

22 };

23 }.execute(); 24

25 ...

Listing 7.1:Excerpt fromEvaluationWindow.javafocusing on implementation of Java multi-threaded application using Swing. OnlySwingWorkerimplementation is shown and the detail implementations are omitted.

Providing opportunity to execute several data store services simultaneously this tool has implemented multi-thread method execution. To ensure this facility, and to make the process visible, a JavaSwingWorkerhas been implemented, whereSwingWorkeris an abstract class to carry out long running GUI interacting tasks in an enthusiastic thread. Implementing doInBackgroud()method inSwingWorkerclass, it makes feasible a long running tasks (i.e. a set of SQL statement execution) run in a background thread and gives update to the process bar. In this implementation, it is considered that while a set of SQL statement execution process is running the corresponding process bar will be visible to ensure the execution process updates and upon completing the tasks the process bar will invisible from the

7.1. Software Tool Implementation

window. The code example in Listing 7.1 shows a sample ofSwingWorkerimplementation, theSwingWorkeris used to implement a Java multi-threaded application.

Moreover, theExtensionMechanismclass is responsible for providing functionalities to ex- tend the data access functionality by loading a data access class to the extension mechanism in runtime. Also, it provides the functionality to remove an added class from the extension mechanism container. As it is considered extending the application functionality by loading only classes, aClassLoaderhas been implemented. The implementation ofClassLoaderis straightforward and in implementedClassLoadera multiple number of classes can be loaded. So that it makes feasible adding any number of data access classes in the application systems for accessing different data store services. Listing 7.2 shows a part ofExtensionMechanism class, where a JavaClassLoaderhas been implemented. Usually, a as standard Java extension mechanism offers the possibility to add a complete Java Archive (JAR) API into the extension mechanism. As we are implementing individual data access classes for different data service providers, it is considered implementing JavaClassLoaderfor loading different data access classes.

1 public class ExtensionMechanism {

2

3 public ClassLoader dalClassLoader; // Java ClassLoader

4 public Class<?> dalClass; // Associated class object

5 private String classToBeLoaded = classPath + "." + dalClassName; // Class loading path

6 ...

7

8 public void loadDataAccessClasses(){

9 ...

10 try{

11 /*

12 * Load data access class to the extension mechanism and

13 * instantiate with local class object

14 */ 15 dalClass = dalClassLoader.loadClass(classToBeLoaded); 16 } 17 ... 18 catch (ClassNotFoundException e) { 19 /*

20 * Thrown when application tries to load in a class through its string name,

21 * but no definition for the class with the specified name could be found.

22 */

23 }

24 ...

25 }

26 }

Listing 7.2:Excerpt fromExtensionMechanism.javaemphasizing the implementation of Java plugins mechanism to extend application functionality of data access layer. OnlyClassLoaderimplementation is shown and the detail implementations are omitted.

Furthermore, the classSQLStatementExecutionis the main class for starting SQL statement execution. It provides the methods for routing statement execution to a specific Cloud data

7. Implementation

store service and comparing the execution results with expected results for representing the outcomes of the execution, whether the SQL statement execution is passed or failed. The evaluateDataStoreService()methods routes SQL statement execution by calling explicit execution method to a specific Cloud data store service based on given service name.

1 private void evaluteRdsOracleDataStoreService(){

2 ...

3 try{

4 // Create new instance for rdsOracleClass which is loaded in extension mechanism 5 Object rdsOracleInstance = extMechanism.rdsOracleClass.newInstance();

6 // Data access method instanciation

7 Method sqlExecMethod = extMechanism.rdsOracleClass.getMethod("sqlStatementExecute",

8 new Class[] { Vector.class, String.class, int.class}

9 );

10 // Receive query results with method invocation for Cloud data access 11 String queryResult = (String) sqlExecMethod.invoke(rdsOracleInstance, 12 new Object[] { dssConf, sqlStatement });

13 // Comparing actual SQL statement execution results with expected results

14 boolean resComp = compareResult(expectedResult, queryResult);

15 ... 16 }catch (SecurityException e) { 17 18 } 19 ... 20 }

Listing 7.3:Excerpt fromSQLStatementEvaluation.javafocusing on data access method invocation in the extension mechanism. The detail implementations are omitted and only a pseudo code ofevaluteRdsOracleDataStoreService()

method is shown.

Listing 7.3) shows an abstract overview how application instantiate with the data access functionality in order of evaluating SQL statement execution in Oracle data store service in Amazon RDS and compare the results. First of all, the method of data access class has been instantiate with a method variable with given specific number of parameters. Then invoke the data access method calling with defined types of values (i.e. database configuration and SQL statement) to perform the data access method execution. So that the data access method returns the SQL statement execution results set in string format. Then the achieved results are compared to the expected results for determining the outcomes decision, the status of the SQL execution (i.e. passed or failed).

Related documents