*/
public static PgDatabase loadDatabaseSchema(final InputStream inputStream,
final String charsetName, final boolean outputIgnoredStatements,
final boolean ignoreSlonyTriggers) {
final PgDatabase database = new PgDatabase();
BufferedReader reader = null;
try {
reader = new BufferedReader(
new InputStreamReader(inputStream, charsetName));
} catch (final UnsupportedEncodingException ex) {
throw new UnsupportedOperationException(
Resources.getString("UnsupportedEncoding") + ": "
+ charsetName, ex);
}
String statement = getWholeStatement(reader);
while (statement != null) {
if (PATTERN_CREATE_SCHEMA.matcher(statement).matches()) {
CreateSchemaParser.parse(database, statement);
} else if (PATTERN_DEFAULT_SCHEMA.matcher(statement).matches()) {
final Matcher matcher =
PATTERN_DEFAULT_SCHEMA.matcher(statement);
matcher.matches();
database.setDefaultSchema(matcher.group(1));
} else if (PATTERN_CREATE_TABLE.matcher(statement).matches()) {
CreateTableParser.parse(database, statement);
} else if (PATTERN_ALTER_TABLE.matcher(statement).matches()) {
AlterTableParser.parse(
database, statement, outputIgnoredStatements);
} else if (PATTERN_CREATE_SEQUENCE.matcher(statement).matches()) {
CreateSequenceParser.parse(database, statement);
} else if (PATTERN_ALTER_SEQUENCE.matcher(statement).matches()) {
AlterSequenceParser.parse(
database, statement, outputIgnoredStatements);
} else if (PATTERN_CREATE_INDEX.matcher(statement).matches()) {
CreateIndexParser.parse(database, statement);
} else if (PATTERN_CREATE_VIEW.matcher(statement).matches()) {
CreateViewParser.parse(database, statement);
} else if (PATTERN_ALTER_VIEW.matcher(statement).matches()) {
AlterViewParser.parse(
database, statement, outputIgnoredStatements);
} else if (PATTERN_CREATE_TRIGGER.matcher(statement).matches()) {
CreateTriggerParser.parse(
database, statement, ignoreSlonyTriggers);
} else if (PATTERN_CREATE_FUNCTION.matcher(statement).matches()) {
CreateFunctionParser.parse(database, statement);
} else if (PATTERN_COMMENT.matcher(statement).matches()) {
CommentParser.parse(
database, statement, outputIgnoredStatements);
} else if (PATTERN_SELECT.matcher(statement).matches()
|| PATTERN_INSERT_INTO.matcher(statement).matches()
|| PATTERN_UPDATE.matcher(statement).matches()
|| PATTERN_DELETE_FROM.matcher(statement).matches()) {
// we just ignore these statements
} else if (outputIgnoredStatements) {
database.addIgnoredStatement(statement);
} else {
// these statements are ignored if outputIgnoredStatements
// is false
}