use of org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Row in project googleads-java-lib by googleads.
the class Pql method combineResultSets.
/**
* Combines the first and second result sets, if and only if, the columns of both result sets
* match.
*
* @throws IllegalArgumentException if the columns of the first result set don't match the second
*/
public static ResultSet combineResultSets(ResultSet first, ResultSet second) {
Function<ColumnType, String> columnTypeToString = new Function<ColumnType, String>() {
@Override
public String apply(ColumnType input) {
return input.getLabelName();
}
};
List<String> firstColumns = Lists.transform(Lists.newArrayList(first.getColumnTypes()), columnTypeToString);
List<String> secondColumns = Lists.transform(Lists.newArrayList(second.getColumnTypes()), columnTypeToString);
if (!firstColumns.equals(secondColumns)) {
throw new IllegalArgumentException(String.format("First result set columns [%s] do not match second columns [%s]", Joiner.on(",").join(firstColumns), Joiner.on(",").join(secondColumns)));
}
List<Row> combinedRows = Lists.newArrayList(first.getRows());
if (second.getRows() != null) {
Collections.addAll(combinedRows, second.getRows());
}
ResultSet combinedResultSet = new ResultSet();
combinedResultSet.setColumnTypes(first.getColumnTypes());
combinedResultSet.setRows(combinedRows.toArray(new Row[] {}));
return combinedResultSet;
}
use of org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Row in project googleads-java-lib by googleads.
the class PqlTest method testCombineResultSet_badColumns.
@Test
public void testCombineResultSet_badColumns() {
Row row1 = new Row();
row1.getValues().addAll(Lists.newArrayList(textValue1, booleanValue1, numberValue1));
Row row2 = new Row();
row2.getValues().addAll(Lists.newArrayList(textValue2, booleanValue2, numberValue2));
Row row3 = new Row();
row3.getValues().addAll(Lists.newArrayList(textValue3, booleanValue3));
ResultSet resultSet1 = new ResultSet();
resultSet1.getColumnTypes().addAll(Lists.newArrayList(column1, column2, column3));
resultSet1.getRows().addAll(Lists.newArrayList(row1, row2));
ResultSet resultSet2 = new ResultSet();
resultSet2.getColumnTypes().addAll(Lists.newArrayList(column1, column2));
resultSet2.getRows().addAll(Lists.newArrayList(row3));
thrown.expect(IllegalArgumentException.class);
Pql.combineResultSets(resultSet1, resultSet2);
}
use of org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Row in project googleads-java-lib by googleads.
the class GetRecentChanges method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @param filePath file path where changes will be saved.
* @throws ApiException if the API request failed with one or more service errors.
* @throws RemoteException if the API request failed due to other errors.
* @throws IOException if unable to write the response to a file.
*/
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session, String filePath) throws IOException {
PublisherQueryLanguageServiceInterface pqlService = adManagerServices.get(session, PublisherQueryLanguageServiceInterface.class);
// Create statement to select recent changes. Change_History only supports ordering by
// descending ChangeDateTime. Offset is not supported. To page, use the change ID of
// the earliest change as a pagination token. A date time range is required
// when querying this table.
DateTime endDateTime = DateTime.now();
DateTime startDateTime = endDateTime.minusDays(1);
StatementBuilder statementBuilder = new StatementBuilder().select("Id, ChangeDateTime, EntityId, EntityType, Operation, UserId").from("Change_History").where("ChangeDateTime < :endDateTime AND ChangeDateTime > :startDateTime").orderBy("ChangeDateTime DESC").withBindVariableValue("startDateTime", DateTimes.toDateTime(startDateTime)).withBindVariableValue("endDateTime", DateTimes.toDateTime(endDateTime)).limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
// Retrieve a small amount of changes at a time, paging through
// until all changes have been retrieved.
ResultSet combinedResultSet = null;
ResultSet resultSet;
int i = 0;
do {
resultSet = pqlService.select(statementBuilder.toStatement());
// Combine result sets with previous ones.
combinedResultSet = combinedResultSet == null ? resultSet : Pql.combineResultSets(combinedResultSet, resultSet);
if (resultSet.getRows() != null && resultSet.getRows().length > 0) {
// Get the earliest change ID in the result set.
int numRows = resultSet.getRows().length;
Row lastRow = resultSet.getRows(numRows - 1);
String id = (String) Pql.getNativeValue(lastRow.getValues(0));
System.out.printf("%d) %d changes prior to ID %s were found.%n", i++, numRows, id);
// Use the earliest change ID in the result set to page.
statementBuilder.where("Id < :id AND ChangeDateTime < :endDateTime AND ChangeDateTime > :startDateTime").withBindVariableValue("id", id);
}
} while (resultSet.getRows() != null && resultSet.getRows().length > 0);
// Write the result set to a CSV.
CsvFiles.writeCsv(Pql.resultSetToStringArrayList(combinedResultSet), filePath);
System.out.printf("Recent changes saved to: %s%n", filePath);
}
use of org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Row in project BibleMultiConverter by schierlm.
the class USX3 method doImportBook.
@Override
protected ParatextBook doImportBook(File inputFile) throws Exception {
if (!inputFile.getName().toLowerCase().endsWith(".usx"))
return null;
ValidateXML.validateFileBeforeParsing(getSchema(), inputFile);
JAXBContext ctx = JAXBContext.newInstance(ObjectFactory.class.getPackage().getName());
XMLInputFactory xif = XMLInputFactory.newFactory();
XMLStreamReader xsr = xif.createXMLStreamReader(new FileInputStream(inputFile));
Unmarshaller u = ctx.createUnmarshaller();
u.setListener(unmarshallerLocationListener);
unmarshallerLocationListener.setXMLStreamReader(inputFile.getName(), xsr);
Usx doc = (Usx) u.unmarshal(xsr);
xsr.close();
ParatextBook.ParatextID id = ParatextBook.ParatextID.fromIdentifier(doc.getBook().getCode().toUpperCase());
if (id == null) {
System.out.println("WARNING: Skipping book with unknown ID: " + doc.getBook().getCode());
return null;
}
ParatextBook result = new ParatextBook(id, doc.getBook().getContent());
ParatextCharacterContent charContent = null;
for (Object o : doc.getParaOrTableOrChapter()) {
if (o instanceof Para) {
Para para = (Para) o;
if (BOOK_HEADER_ATTRIBUTE_TAGS.contains(para.getStyle().value())) {
String value = "";
for (Object oo : para.getContent()) {
if (oo instanceof String) {
value += ((String) oo).replaceAll("[ \r\n\t]+", " ");
} else {
throw new RuntimeException("Unsupported content in attribute: " + oo.getClass());
}
}
result.getAttributes().put(para.getStyle().value(), value);
charContent = null;
} else if (para.getStyle() == ParaStyle.PB) {
if (charContent == null) {
charContent = new ParatextCharacterContent();
result.getContent().add(charContent);
}
charContent.getContent().add(new ParatextCharacterContent.AutoClosingFormatting(ParatextCharacterContent.AutoClosingFormattingKind.PAGE_BREAK, false));
} else if (PARA_STYLE_UNSUPPORTED.contains(para.getStyle())) {
// skip
charContent = null;
} else {
result.getContent().add(new ParatextBook.ParagraphStart(PARA_STYLE_MAP.get(para.getStyle())));
charContent = null;
if (!para.getContent().isEmpty()) {
charContent = new ParatextCharacterContent();
result.getContent().add(charContent);
parseCharContent(para.getContent(), charContent);
}
}
} else if (o instanceof Table) {
Table table = (Table) o;
for (Row row : table.getRow()) {
result.getContent().add(new ParatextBook.ParagraphStart(ParatextBook.ParagraphKind.TABLE_ROW));
for (Object oo : row.getVerseOrCell()) {
if (oo instanceof Verse) {
Verse verse = (Verse) oo;
ParatextCharacterContent.ParatextCharacterContentPart verseStartOrEnd = handleVerse(verse);
charContent = new ParatextCharacterContent();
result.getContent().add(charContent);
charContent.getContent().add(verseStartOrEnd);
} else if (oo instanceof Cell) {
Cell cell = (Cell) oo;
result.getContent().add(new ParatextBook.TableCellStart(cell.getStyle().value()));
charContent = new ParatextCharacterContent();
result.getContent().add(charContent);
parseCharContent(cell.getContent(), charContent);
} else {
throw new IOException("Unsupported table row element: " + o.getClass().getName());
}
}
}
charContent = null;
} else if (o instanceof Chapter) {
Chapter chapter = (Chapter) o;
if (chapter.getSid() != null) {
// Assume start chapter
result.getContent().add(new ParatextBook.ChapterStart(new ChapterIdentifier(result.getId(), ((Chapter) o).getNumber().intValue())));
} else if (chapter.getEid() != null) {
// Assume end chapter
ChapterIdentifier location = ChapterIdentifier.fromLocationString(chapter.getEid());
if (location == null) {
throw new IOException("Invalid chapter eid found: " + chapter.getEid());
}
result.getContent().add(new ParatextBook.ChapterEnd(location));
} else {
throw new IOException("Invalid chapter found, both sid and eid are undefined: " + chapter);
}
charContent = null;
} else if (o instanceof Note) {
if (charContent == null) {
charContent = new ParatextCharacterContent();
result.getContent().add(charContent);
}
Note note = (Note) o;
ParatextCharacterContent.FootnoteXref nx = new ParatextCharacterContent.FootnoteXref(NOTE_STYLE_MAP.get(note.getStyle()), note.getCaller());
charContent.getContent().add(nx);
parseCharContent(note.getContent(), nx);
} else if (o instanceof Sidebar) {
System.out.println("WARNING: Skipping sidebar (study bible content)");
charContent = null;
} else {
throw new IOException("Unsupported book level element: " + o.getClass().getName());
}
}
return result;
}
use of org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Row in project BibleMultiConverter by schierlm.
the class USX3 method doExportBook.
@Override
protected void doExportBook(ParatextBook book, File outFile) throws Exception {
ObjectFactory of = new ObjectFactory();
Usx usx = of.createUsx();
usx.setVersion("3.0");
usx.setBook(of.createBook());
usx.getBook().setStyle("id");
usx.getBook().setCode(book.getId().getIdentifier());
usx.getBook().setContent(book.getBibleName());
for (Map.Entry<String, String> attr : book.getAttributes().entrySet()) {
Para para = new Para();
para.setStyle(ParaStyle.fromValue(attr.getKey()));
para.getContent().add(attr.getValue());
usx.getParaOrTableOrChapter().add(para);
}
book.accept(new ParatextBook.ParatextBookContentVisitor<IOException>() {
List<Object> currentContent = null;
Table currentTable = null;
@Override
public void visitChapterStart(ChapterIdentifier location) throws IOException {
Chapter ch = new Chapter();
ch.setStyle("c");
ch.setSid(location.toString());
ch.setNumber(BigInteger.valueOf(location.chapter));
usx.getParaOrTableOrChapter().add(ch);
currentContent = null;
currentTable = null;
}
@Override
public void visitChapterEnd(ChapterIdentifier location) throws IOException {
Chapter ch = new Chapter();
ch.setEid(location.toString());
usx.getParaOrTableOrChapter().add(ch);
currentContent = null;
currentTable = null;
}
@Override
public void visitParagraphStart(ParatextBook.ParagraphKind kind) throws IOException {
if (kind == ParatextBook.ParagraphKind.TABLE_ROW) {
if (currentTable == null) {
currentTable = new Table();
usx.getParaOrTableOrChapter().add(currentTable);
}
Row row = new Row();
row.setStyle("tr");
currentTable.getRow().add(row);
currentContent = currentTable.getRow().get(currentTable.getRow().size() - 1).getVerseOrCell();
} else {
Para para = new Para();
para.setStyle(PARA_KIND_MAP.get(kind));
usx.getParaOrTableOrChapter().add(para);
currentContent = para.getContent();
currentTable = null;
}
}
@Override
public void visitTableCellStart(String tag) throws IOException {
if (currentTable == null) {
System.out.println("WARNING: Table cell outside of table");
return;
}
Row currentRow = currentTable.getRow().get(currentTable.getRow().size() - 1);
Cell cell = new Cell();
cell.setAlign(tag.contains("r") ? CellAlign.END : CellAlign.START);
cell.setStyle(CellStyle.fromValue(tag));
currentRow.getVerseOrCell().add(cell);
currentContent = cell.getContent();
}
@Override
public void visitParatextCharacterContent(ParatextCharacterContent content) throws IOException {
if (currentContent == null)
visitParagraphStart(ParatextBook.ParagraphKind.PARAGRAPH_P);
content.accept(new USX3.USXCharacterContentVisitor(currentContent));
}
});
JAXBContext ctx = JAXBContext.newInstance(ObjectFactory.class.getPackage().getName());
Marshaller m = ctx.createMarshaller();
if (!Boolean.getBoolean("biblemulticonverter.skipxmlvalidation"))
m.setSchema(getSchema());
m.marshal(usx, new UnifiedScriptureXMLWriter(new FileWriter(outFile), "UTF-8"));
}
Aggregations