Skip to content

Commit

Permalink
Memorized Execution Added
Browse files Browse the repository at this point in the history
  • Loading branch information
sajedjalil committed Nov 23, 2018
1 parent 61dd446 commit 4da3ee3
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 97 deletions.
42 changes: 0 additions & 42 deletions results/1.c

This file was deleted.

51 changes: 41 additions & 10 deletions src/database/DatabaseLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
Expand All @@ -13,6 +14,9 @@
import java.util.ArrayList;
import java.util.Date;

import main.Start;
import parser.CParser;
//-Djava.library.path=”z3\bin;${env_var:PATH}”
public class DatabaseLoader {

public static String defaultDatabaseDirectory = "C:\\sqlite\\db\\";
Expand Down Expand Up @@ -41,11 +45,7 @@ public DatabaseLoader() {
selectAllFile(); */
}








private void createFileTable() {

Expand All @@ -54,6 +54,7 @@ private void createFileTable() {
+ " fileName text NOT NULL,\n"
+ " filePath text NOT NULL,\n"
+ " lastRun text NOT NULL,\n"
+ " outputPath text NOT NULL,\n"
+ " projectID integer,\n"
+ " FOREIGN KEY (projectID)"
+ " REFERENCES project(id)"
Expand All @@ -72,7 +73,7 @@ private void createFileTable() {
}

public void selectAllFile(){
String sql = "SELECT * FROM file";
String sql = "SELECT * FROM file where projectID='"+Start.currentProjectId+"'";

try (Connection conn = this.connect();
Statement stmt = conn.createStatement();
Expand All @@ -84,6 +85,7 @@ public void selectAllFile(){
rs.getString("fileName") + "\t" +
rs.getString("filePath") + "\t" +
rs.getString("lastRun") + "\t" +
rs.getString("outputPath") + "\t" +
rs.getInt("projectID") + "\t");
}
} catch (SQLException e) {
Expand All @@ -92,13 +94,29 @@ public void selectAllFile(){
}

public void insertINtoFileTable(String fileName, String filePath,
String lastRun, String projectID) {

String lastRun, String projectID, String outputPath) {

String sql = "select filePath from file where filePath = '"+filePath+"'";
System.out.println(sql);
try (Connection conn = this.connect();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql)){

while (rs.next()) {
//System.out.println(rs.getInt(""));
sql = "update file set lastRun = '"+lastRun+"', outputPath ='"+
outputPath+"' where filePath = '"+filePath+"'";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.executeUpdate();
return;
}
} catch (SQLException e) {
System.out.println(e.getMessage());
}

String sql = "INSERT INTO file (fileName, filePath, lastRun, projectID)\n" +
sql = "INSERT INTO file (fileName, filePath, lastRun, projectID, outputPath)\n" +
"VALUES ( '"+fileName+"', '"+filePath+"', '"+lastRun+"', '"
+projectID+"' );";
+projectID+"', '"+outputPath+"' );";

try (Connection conn = this.connect();
Statement stmt = conn.createStatement()) {
Expand Down Expand Up @@ -306,4 +324,17 @@ public String getLastRunFromDB(File file){
return "";
}


public void loadIntoFileTable() {

Date currentTime = new Date();
System.out.println(currentTime.toString());

for(String path: changedFiles) {
File file = new File(path);
insertINtoFileTable(file.getName(), file.getPath(),
currentTime.toString() , Integer.toString( Start.currentProjectId )
, CParser.testCaseOutputDirectory);
}
}
}
20 changes: 17 additions & 3 deletions src/main/Start.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Date;
import java.util.Comparator;

import database.DatabaseLoader;
import inputCodeBeautifier.CodeBeautifier;
Expand Down Expand Up @@ -74,18 +77,29 @@ public static String openSystemPathChooser() {
return null;
}

public static void run() {
public static void run(){

dbloader.changedFiles = new ArrayList<String>();

database();

try {
Files.walk( Paths.get(outputPath) ).sorted(Comparator.reverseOrder())
.map(Path::toFile)
.forEach(File::delete);
}catch (IOException e) {
e.printStackTrace();
}
new InputFileCopyMachine(inputPath, outputPath);

dbloader.directorySearcher( new File(outputPath) );

new CodeBeautifier( new File(outputPath));

dbloader.loadIntoFileTable();

new CParser(dbloader.getChangedFiles());
dbloader.selectAllFile();
}


Expand All @@ -97,7 +111,7 @@ private static void database() {
//dbloader.insertINtoFileTable("1.c", "results\\1.c", "Wed Nov 21 13:17:12 BDT 2018", "1");
//dbloader.insertINtoFileTable("2.c", "results\\2.c", "Wed Nov 21 13:17:12 BDT 2018", "1");
//dbloader.insertINtoFileTable("3.c", "results\\3.c", "Wed Nov 21 13:17:12 BDT 2018", "1");
dbloader.selectAllFile();
//dbloader.selectAllFile();

//System.out.println( dbloader.getLastRunFromDB( new File("results\\1.c") ) );;

Expand Down
42 changes: 0 additions & 42 deletions testcases/1.txt

This file was deleted.

0 comments on commit 4da3ee3

Please sign in to comment.