All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.databasesandlife.util.jooq.PostgresXmlDomElementArrayConverter Maven / Gradle / Ivy

There is a newer version: 21.0.1
Show newest version
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