diff options
author | Feideus <erwan.ulrich@gmail.com> | 2018-07-31 15:18:53 +0200 |
---|---|---|
committer | Feideus <erwan.ulrich@gmail.com> | 2018-07-31 15:18:53 +0200 |
commit | 7f56d23b2411371811eded5d4e8779df61d5252a (patch) | |
tree | 72d087a0621da62da04c64fed09a14e81370a80f /src/main | |
parent | 99d6adff0f959b4ddd3cbd964c75e13bcd1b5f74 (diff) | |
download | schemafuzz-7f56d23b2411371811eded5d4e8779df61d5252a.tar.gz schemafuzz-7f56d23b2411371811eded5d4e8779df61d5252a.tar.bz2 schemafuzz-7f56d23b2411371811eded5d4e8779df61d5252a.zip |
finished implementing databaseStateRecovery parser. Dont know if it works yet tho.
Diffstat (limited to 'src/main')
-rwxr-xr-x | src/main/java/org/schemaspy/Main.java | 23 | ||||
-rwxr-xr-x | src/main/java/org/schemaspy/model/GenericTreeNode.java | 55 | ||||
-rwxr-xr-x | src/main/java/org/schemaspy/model/SingleChange.java | 7 |
3 files changed, 76 insertions, 9 deletions
diff --git a/src/main/java/org/schemaspy/Main.java b/src/main/java/org/schemaspy/Main.java index 52bbc8f..1aba6f6 100755 --- a/src/main/java/org/schemaspy/Main.java +++ b/src/main/java/org/schemaspy/Main.java @@ -20,10 +20,7 @@ package org.schemaspy; import org.schemaspy.cli.CommandLineArgumentParser; import org.schemaspy.cli.CommandLineArguments; -import org.schemaspy.model.ConnectionFailure; -import org.schemaspy.model.EmptySchemaException; -import org.schemaspy.model.InvalidConfigurationException; -import org.schemaspy.model.ProcessExecutionException; +import org.schemaspy.model.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -36,6 +33,7 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.lang.invoke.MethodHandles; +import java.util.ArrayList; import java.util.Arrays; @@ -78,6 +76,8 @@ public class Main implements CommandLineRunner { return; } + runAnalyzer(args); + /*if(arguments.getSetErrorState() != null) { File f = new File(arguments.getSetErrorState()); @@ -86,8 +86,6 @@ public class Main implements CommandLineRunner { } return; }*/ - - runAnalyzer(args); runFuzzer(args); System.out.println(Thread.getAllStackTraces()); } @@ -139,16 +137,25 @@ public class Main implements CommandLineRunner { private void setErrorState(File f) { + ArrayList<GenericTreeNode> MutationsOnPath = new ArrayList<>(); try { BufferedReader br = new BufferedReader(new FileReader(f)); StringBuilder sb = new StringBuilder(); String line = br.readLine(); + boolean foundPathStart=false; - while(line != null) + while(foundPathStart == false) { - System.out.println(line); + if(line.contains("path:")) + foundPathStart=true; + line = br.readLine(); + } + + while(!line.contains("endpath:")) { line = br.readLine(); + GenericTreeNode mut = GenericTreeNode.parseInit(line,analyzer,MutationsOnPath); + MutationsOnPath.add(mut); } } catch(Exception e) diff --git a/src/main/java/org/schemaspy/model/GenericTreeNode.java b/src/main/java/org/schemaspy/model/GenericTreeNode.java index bdf0b9f..b93b559 100755 --- a/src/main/java/org/schemaspy/model/GenericTreeNode.java +++ b/src/main/java/org/schemaspy/model/GenericTreeNode.java @@ -54,6 +54,12 @@ public class GenericTreeNode { this.potential_changes = discoverMutationPossibilities(sqlService); } + public GenericTreeNode( GenericTreeNode parentMutation) { + //this.cascadingFK = false; + this.parent = parentMutation; + id=new Random().nextInt(Integer.MAX_VALUE); + } + public boolean getIsFirstApperance() { return isFirstApperance; @@ -923,4 +929,53 @@ public class GenericTreeNode { }while(tmp != null); return res; } + + public static GenericTreeNode parseInit(String line, SchemaAnalyzer analyzer,ArrayList<GenericTreeNode> mutationsOnPath) throws Exception + { + String buffer = ""; + buffer = line.substring(line.indexOf("attachedToMutation : "),line.indexOf("|")); + GenericTreeNode parentMutation = null; + + for(GenericTreeNode tmp : mutationsOnPath) + { + if(tmp.getId().equals(Integer.parseInt(buffer))) + parentMutation = tmp; + } + if(parentMutation == null && mutationsOnPath.size() != 0) + throw new Exception("ParentMutation not found during parsing"); + + + line = line.substring(line.indexOf(buffer)); + + buffer = line.substring(line.indexOf("parentTable : "),line.indexOf("|")); + Table parentTable = analyzer.getDb().getTablesByName().get(buffer); + + + if(parentTable == null) + throw new Exception("ParentTable not found during parsing"); + + line.substring(line.indexOf(buffer)); + + buffer = line.substring(line.indexOf("parentTableColumn : "),line.indexOf("|")); + TableColumn parentTableColumn = analyzer.getDb().getTablesByName().get(parentTable.getName()).getColumn(buffer); + + if(parentTableColumn == null) + throw new Exception("ParentTableColumn not found during parsing"); + + line.substring(line.indexOf(buffer)); + + buffer = line.substring(line.indexOf("OV : "),line.indexOf("|")); + line.substring(line.indexOf(buffer)); + String buffer2 = line.substring(line.indexOf("NV : "),line.indexOf("|")); + + GenericTreeNode res = new GenericTreeNode(parentMutation); + SingleChange sg = new SingleChange(parentTableColumn,res,buffer,buffer2); + res.setChosenChange(sg); + + + if(res == null || res.getChosenChange() == null) + throw new Exception("SingleChange couldnt be parsed"); + + return res; + } } diff --git a/src/main/java/org/schemaspy/model/SingleChange.java b/src/main/java/org/schemaspy/model/SingleChange.java index fefb651..53951a9 100755 --- a/src/main/java/org/schemaspy/model/SingleChange.java +++ b/src/main/java/org/schemaspy/model/SingleChange.java @@ -2,6 +2,10 @@ package org.schemaspy.model; +import org.schemaspy.SchemaAnalyzer; + +import java.util.ArrayList; + public class SingleChange { private GenericTreeNode attachedToMutation; @@ -51,7 +55,7 @@ public class SingleChange @Override public String toString() { - return "\n[SG - attachedToMutation : "+this.getAttachedToMutation().getId()+"| OV :"+oldValue+" | NV :"+newValue+" ]\n"; + return "\n[SG - attachedToMutation : "+this.getAttachedToMutation().getId()+" | parentTable : "+this.getParentTableColumn().getTable()+" | parentTableColumn : "+this.getParentTableColumn().toString()+" | OV : "+oldValue+" | NV : "+newValue+" ]\n"; } public Object getOldValue() @@ -108,4 +112,5 @@ public class SingleChange return false; } + } |