Search in sources :

Example 1 with DefaultColumnInfo

use of org.killbill.billing.util.validation.DefaultColumnInfo in project killbill by killbill.

the class DatabaseExportDao method exportDataForAccount.

public void exportDataForAccount(final DatabaseExportOutputStream out, final InternalTenantContext context) {
    if (context.getAccountRecordId() == null || context.getTenantRecordId() == null) {
        return;
    }
    final List<DefaultColumnInfo> columns = databaseSchemaDao.getColumnInfoList();
    if (columns.size() == 0) {
        return;
    }
    final List<ColumnInfo> columnsForTable = new ArrayList<ColumnInfo>();
    // The list of columns is ordered by table name first
    String lastSeenTableName = columns.get(0).getTableName();
    for (final ColumnInfo column : columns) {
        if (!column.getTableName().equals(lastSeenTableName)) {
            exportDataForAccountAndTable(out, columnsForTable, context);
            lastSeenTableName = column.getTableName();
            columnsForTable.clear();
        }
        columnsForTable.add(column);
    }
    exportDataForAccountAndTable(out, columnsForTable, context);
}
Also used : DefaultColumnInfo(org.killbill.billing.util.validation.DefaultColumnInfo) ArrayList(java.util.ArrayList) ColumnInfo(org.killbill.billing.util.api.ColumnInfo) DefaultColumnInfo(org.killbill.billing.util.validation.DefaultColumnInfo)

Example 2 with DefaultColumnInfo

use of org.killbill.billing.util.validation.DefaultColumnInfo in project killbill by killbill.

the class TestCSVExportOutputStream method testSimpleGenerator.

@Test(groups = "fast")
public void testSimpleGenerator() throws Exception {
    final ByteArrayOutputStream delegate = new ByteArrayOutputStream();
    final CSVExportOutputStream out = new CSVExportOutputStream(delegate);
    // Create the schema
    final String tableName = UUID.randomUUID().toString();
    out.newTable(tableName, ImmutableList.<ColumnInfo>of(new DefaultColumnInfo(tableName, "first_name", 0L, 0L, true, 0L, "varchar"), new DefaultColumnInfo(tableName, "last_name", 0L, 0L, true, 0L, "varchar"), new DefaultColumnInfo(tableName, "age", 0L, 0L, true, 0L, "tinyint")));
    // Write some data
    out.write(ImmutableMap.<String, Object>of("first_name", "jean", "last_name", "dupond", "age", 35));
    // Don't assume "ordering"
    out.write(ImmutableMap.<String, Object>of("last_name", "dujardin", "first_name", "jack", "age", 40));
    out.write(ImmutableMap.<String, Object>of("age", 12, "first_name", "pierre", "last_name", "schmitt"));
    // Verify the numeric parsing
    out.write(ImmutableMap.<String, Object>of("first_name", "stephane", "last_name", "dupont", "age", "30"));
    // Verify special characters
    out.write(ImmutableMap.<String, Object>of("first_name", "Jørgen", "last_name", "Jensen", "age", 31));
    out.write(ImmutableMap.<String, Object>of("first_name", "a|B", "last_name", "c||5", "age", 44));
    out.write(ImmutableMap.<String, Object>of("first_name", "q\nw", "last_name", "e\n\n.", "age", 1));
    Assert.assertEquals(delegate.toString("UTF-8"), "-- " + tableName + " first_name|last_name|age\n" + "jean|dupond|35\n" + "jack|dujardin|40\n" + "pierre|schmitt|12\n" + "stephane|dupont|30\n" + "Jørgen|Jensen|31\n" + "a\\N{VERTICAL LINE}B|c\\N{VERTICAL LINE}\\N{VERTICAL LINE}5|44\n" + "q\\N{LINE FEED}w|e\\N{LINE FEED}\\N{LINE FEED}.|1\n");
}
Also used : DefaultColumnInfo(org.killbill.billing.util.validation.DefaultColumnInfo) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.testng.annotations.Test)

Aggregations

DefaultColumnInfo (org.killbill.billing.util.validation.DefaultColumnInfo)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ArrayList (java.util.ArrayList)1 ColumnInfo (org.killbill.billing.util.api.ColumnInfo)1 Test (org.testng.annotations.Test)1