
org.apache.ibatis.migration.MigrationReader Maven / Gradle / Ivy
Go to download
The MyBatis SQL mapper framework makes it easier to use a relational database with object-oriented
applications. MyBatis couples objects with stored procedures or SQL statements using a XML descriptor or
annotations. Simplicity is the biggest advantage of the MyBatis data mapper over object relational mapping
tools.
package org.apache.ibatis.migration;
import org.apache.ibatis.parsing.PropertyParser;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.util.Properties;
public class MigrationReader extends Reader {
private static final String LINE_SEPARATOR = System.getProperty("line.separator","\n");
private Reader target;
public MigrationReader(Reader source, boolean undo, Properties variables) throws IOException {
try {
BufferedReader reader = new BufferedReader(source);
StringBuilder doBuilder = new StringBuilder();
StringBuilder undoBuilder = new StringBuilder();
StringBuilder currentBuilder = doBuilder;
String line;
while ((line = reader.readLine()) != null) {
if (line != null) {
if (line.trim().startsWith("--//")) {
if (line.contains("@UNDO")) {
currentBuilder = undoBuilder;
}
line = line.replace("--//", "-- ");
}
currentBuilder.append(line);
currentBuilder.append(LINE_SEPARATOR);
}
}
if (undo) {
target = new StringReader(PropertyParser.parse(undoBuilder.toString(), variables));
} else {
target = new StringReader(PropertyParser.parse(doBuilder.toString(), variables));
}
} finally {
source.close();
}
}
public int read(char[] cbuf, int off, int len) throws IOException {
return target.read(cbuf, off, len);
}
public void close() throws IOException {
target.close();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy