Search in sources :

Example 36 with IoException

use of org.jumpmind.exception.IoException in project symmetric-ds by JumpMind.

the class HttpTransportManager method add.

protected String add(String base, String key, String value, String connector) {
    StringBuilder sb = new StringBuilder(base);
    sb.append(connector);
    sb.append(key);
    sb.append("=");
    try {
        sb.append(URLEncoder.encode(value, IoConstants.ENCODING));
    } catch (UnsupportedEncodingException e) {
        throw new IoException(e);
    }
    return sb.toString();
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) IoException(org.jumpmind.exception.IoException)

Example 37 with IoException

use of org.jumpmind.exception.IoException in project symmetric-ds by JumpMind.

the class DatabaseXmlUtil method write.

public static void write(Table table, Writer output) {
    try {
        output.write("\t<table name=\"" + StringEscapeUtils.escapeXml(table.getName()) + "\">\n");
        for (Column column : table.getColumns()) {
            output.write("\t\t<column name=\"" + StringEscapeUtils.escapeXml(column.getName()) + "\"");
            if (column.isPrimaryKey()) {
                output.write(" primaryKey=\"" + column.isPrimaryKey() + "\"");
            }
            if (column.isRequired()) {
                output.write(" required=\"" + column.isRequired() + "\"");
            }
            if (column.getMappedType() != null) {
                output.write(" type=\"" + column.getMappedType() + "\"");
            }
            if (column.getSize() != null) {
                output.write(" size=\"" + column.getSize() + "\"");
            }
            if (column.getDefaultValue() != null) {
                output.write(" default=\"" + StringEscapeUtils.escapeXml(column.getDefaultValue()) + "\"");
            }
            if (column.isAutoIncrement()) {
                output.write(" autoIncrement=\"" + column.isAutoIncrement() + "\"");
            }
            if (column.getJavaName() != null) {
                output.write(" javaName=\"" + column.getJavaName() + "\"");
            }
            if (column.isUnique()) {
                output.write(" unique=\"" + column.isUnique() + "\"");
            }
            if (column.getPlatformColumns() != null && column.getPlatformColumns().size() > 0) {
                Collection<PlatformColumn> platformColumns = column.getPlatformColumns().values();
                output.write(">\n");
                for (PlatformColumn platformColumn : platformColumns) {
                    output.write("\t\t\t<platform-column name=\"" + platformColumn.getName() + "\"");
                    output.write(" type=\"" + platformColumn.getType() + "\"");
                    if (platformColumn.getSize() > 0) {
                        output.write(" size=\"" + platformColumn.getSize() + "\"");
                    }
                    if (platformColumn.getDecimalDigits() > 0) {
                        output.write(" decimalDigits=\"" + platformColumn.getDecimalDigits() + "\"");
                    }
                    if (platformColumn.getDefaultValue() != null) {
                        output.write(" default=\"" + StringEscapeUtils.escapeXml(platformColumn.getDefaultValue()) + "\"");
                    }
                    output.write("/>\n");
                }
                output.write("\t\t</column>\n");
            } else {
                output.write("/>\n");
            }
        }
        for (ForeignKey fk : table.getForeignKeys()) {
            output.write("\t\t<foreign-key name=\"" + StringEscapeUtils.escapeXml(fk.getName()) + "\" foreignTable=\"" + StringEscapeUtils.escapeXml(fk.getForeignTableName()) + "\">\n");
            for (Reference ref : fk.getReferences()) {
                output.write("\t\t\t<reference local=\"" + StringEscapeUtils.escapeXml(ref.getLocalColumnName()) + "\" foreign=\"" + StringEscapeUtils.escapeXml(ref.getForeignColumnName()) + "\"/>\n");
            }
            output.write("\t\t</foreign-key>\n");
        }
        for (IIndex index : table.getIndices()) {
            if (index.isUnique()) {
                output.write("\t\t<unique name=\"" + StringEscapeUtils.escapeXml(index.getName()) + "\">\n");
                for (IndexColumn column : index.getColumns()) {
                    output.write("\t\t\t<unique-column name=\"" + StringEscapeUtils.escapeXml(column.getName()) + "\"/>\n");
                }
                output.write("\t\t</unique>\n");
            } else {
                output.write("\t\t<index name=\"" + StringEscapeUtils.escapeXml(index.getName()) + "\">\n");
                for (IndexColumn column : index.getColumns()) {
                    output.write("\t\t\t<index-column name=\"" + StringEscapeUtils.escapeXml(column.getName()) + "\"");
                    if (column.getSize() != null) {
                        output.write(" size=\"" + column.getSize() + "\"");
                    }
                    output.write("/>\n");
                }
                output.write("\t\t</index>\n");
            }
        }
        output.write("\t</table>\n");
    } catch (IOException e) {
        throw new IoException(e);
    }
}
Also used : IIndex(org.jumpmind.db.model.IIndex) Column(org.jumpmind.db.model.Column) IndexColumn(org.jumpmind.db.model.IndexColumn) PlatformColumn(org.jumpmind.db.model.PlatformColumn) Reference(org.jumpmind.db.model.Reference) IoException(org.jumpmind.exception.IoException) IOException(java.io.IOException) ForeignKey(org.jumpmind.db.model.ForeignKey) PlatformColumn(org.jumpmind.db.model.PlatformColumn) IndexColumn(org.jumpmind.db.model.IndexColumn)

Example 38 with IoException

use of org.jumpmind.exception.IoException in project symmetric-ds by JumpMind.

the class DatabaseXmlUtil method write.

/*
     * Writes the database model to the specified file.
     * 
     * @param model The database model
     * 
     * @param filename The model file name
     */
public static void write(Database model, String filename) {
    try {
        BufferedWriter writer = null;
        try {
            writer = new BufferedWriter(new FileWriter(filename));
            write(model, writer);
            writer.flush();
        } finally {
            if (writer != null) {
                writer.close();
            }
        }
    } catch (IOException ex) {
        throw new IoException(ex);
    }
}
Also used : FileWriter(java.io.FileWriter) IoException(org.jumpmind.exception.IoException) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter)

Example 39 with IoException

use of org.jumpmind.exception.IoException in project symmetric-ds by JumpMind.

the class DatabaseXmlUtil method write.

/*
     * Writes the database model to the given output stream. Note that this
     * method does not flush the stream.
     * 
     * @param model The database model
     * 
     * @param output The output stream
     */
public static void write(Database model, OutputStream output) {
    Writer writer = new OutputStreamWriter(output);
    write(model, writer);
    try {
        writer.flush();
    } catch (IOException e) {
        throw new IoException(e);
    }
}
Also used : IoException(org.jumpmind.exception.IoException) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter) StringWriter(java.io.StringWriter) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 40 with IoException

use of org.jumpmind.exception.IoException in project symmetric-ds by JumpMind.

the class DatabaseXmlUtil method read.

/*
     * Reads the database model given by the reader.
     * 
     * @param reader The reader that returns the model XML
     * 
     * @return The database model
     */
public static Database read(Reader reader, boolean validate) {
    try {
        boolean done = false;
        Database database = null;
        XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
        parser.setInput(reader);
        int eventType = parser.getEventType();
        while (eventType != XmlPullParser.END_DOCUMENT && !done) {
            switch(eventType) {
                case XmlPullParser.START_DOCUMENT:
                    database = new Database();
                    break;
                case XmlPullParser.START_TAG:
                    String name = parser.getName();
                    if (name.equalsIgnoreCase("database")) {
                        for (int i = 0; i < parser.getAttributeCount(); i++) {
                            String attributeName = parser.getAttributeName(i);
                            String attributeValue = parser.getAttributeValue(i);
                            if (attributeName.equalsIgnoreCase("name")) {
                                database.setName(attributeValue);
                            } else if (attributeName.equalsIgnoreCase("catalog")) {
                                database.setCatalog(attributeValue);
                            } else if (attributeName.equalsIgnoreCase("schema")) {
                                database.setSchema(attributeValue);
                            }
                        }
                    } else if (name.equalsIgnoreCase("table")) {
                        Table table = nextTable(parser, database.getCatalog(), database.getSchema());
                        if (table != null) {
                            database.addTable(table);
                        }
                    }
                    break;
                case XmlPullParser.END_TAG:
                    name = parser.getName();
                    if (name.equalsIgnoreCase("database")) {
                        done = true;
                    }
                    break;
            }
            eventType = parser.next();
        }
        if (validate) {
            database.initialize();
        }
        return database;
    } catch (XmlPullParserException e) {
        throw new IoException(e);
    } catch (IOException e) {
        throw new IoException(e);
    }
}
Also used : Table(org.jumpmind.db.model.Table) Database(org.jumpmind.db.model.Database) XmlPullParser(org.xmlpull.v1.XmlPullParser) IoException(org.jumpmind.exception.IoException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException)

Aggregations

IoException (org.jumpmind.exception.IoException)48 IOException (java.io.IOException)41 File (java.io.File)8 Table (org.jumpmind.db.model.Table)8 BufferedReader (java.io.BufferedReader)6 Column (org.jumpmind.db.model.Column)6 BufferedWriter (java.io.BufferedWriter)5 FileInputStream (java.io.FileInputStream)5 FileOutputStream (java.io.FileOutputStream)4 FileWriter (java.io.FileWriter)4 OutputStreamWriter (java.io.OutputStreamWriter)4 IncomingBatch (org.jumpmind.symmetric.model.IncomingBatch)4 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)4 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 SymmetricException (org.jumpmind.symmetric.SymmetricException)3 ProcessInfo (org.jumpmind.symmetric.model.ProcessInfo)3 ProcessInfoKey (org.jumpmind.symmetric.model.ProcessInfoKey)3 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)2 BufferedInputStream (java.io.BufferedInputStream)2