com.databasesandlife.util.jooq.PostgresXmlDomElementArrayConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-common Show documentation
Show all versions of java-common Show documentation
Utility classes developed at Adrian Smith Software (A.S.S.)
package com.databasesandlife.util.jooq;
import com.databasesandlife.util.DomParser;
import com.databasesandlife.util.gwtsafe.ConfigurationException;
import org.jooq.Converter;
import org.jooq.XML;
import org.w3c.dom.Element;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import static com.databasesandlife.util.gwtsafe.ConfigurationException.prefixExceptionMessage;
public class PostgresXmlDomElementArrayConverter implements Converter> {
@Override
public Class fromType() {
return XML[].class;
}
@SuppressWarnings({"unchecked", "rawtypes"})
@Override
public Class> toType() {
return (Class>) (Object) List.class;
}
@Override
public List from(XML[] dbList) {
if (dbList == null) return null;
return Arrays.stream(dbList).map(db -> {
try { return DomParser.from(db.data()); }
catch (ConfigurationException e) {
throw new RuntimeException(prefixExceptionMessage("While parsing XML from DB '"+db.data()+"'", e));
}
}).collect(Collectors.toList());
}
@Override
public XML[] to(List javaList) {
if (javaList == null) return null;
return javaList.stream().map(java -> XML.valueOf(DomParser.formatXml(java))).toArray(XML[]::new);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy