Created
April 13, 2016 03:26
-
-
Save oboenikui/6b53deece072233e3a3fe5735182841c to your computer and use it in GitHub Desktop.
GitBucketのデータベースを修復するやつ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.util.HashMap; | |
import java.util.regex.Matcher; | |
import java.util.regex.Pattern; | |
public class Recovery { | |
public static void main(String[] args) throws IOException { | |
BufferedReader reader1 = new BufferedReader(new InputStreamReader(new FileInputStream(new File("to.txt")))); | |
BufferedReader reader2 = new BufferedReader(new InputStreamReader(new FileInputStream(new File("from.txt")))); | |
String line = "", line1 = reader1.readLine(), line2 = reader2.readLine(); | |
HashMap<String, String> dic = new HashMap<>(); | |
while (line1 != null) { | |
dic.put(line2, line1); | |
line1 = reader1.readLine(); | |
line2 = reader2.readLine(); | |
} | |
reader1.close(); | |
reader2.close(); | |
Pattern p = Pattern.compile("(READ_CLOB_DB\\([0-9]+, [0-9]+\\))"); | |
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(new File("data.h2.sql")))); | |
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File("recovery.sql")))); | |
while ((line = reader.readLine()) != null) { | |
Matcher m = p.matcher(line); | |
if(line.contains("READ_CLOB_DB(383")) { | |
int j = 1; | |
} | |
while (m.find()) { | |
if(dic.get(m.group(1)) != null) { | |
line = line.replace(m.group(1), "STRINGDECODE('" + dic.get(m.group(1)).replace("'", "''") + "')"); | |
} else { | |
break; | |
} | |
m = p.matcher(line); | |
} | |
writer.write(line); | |
writer.newLine(); | |
} | |
reader.close(); | |
writer.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment