WITH XML_Q AS ( SELECT TOP (10) NM_Notifiche.ID_Notifica ,NM_Notifiche.ID_Evento ,NM_Notifiche.ID_tp_notifica ,NM_Notifiche.data ,NM_Notifiche.data_notifica ,NM_Notifiche.data_evasione ,NM_Notifiche.nrTentativo ,NM_Notifiche.note ,NM_Eventi.ID_Evento AS Expr1 ,NM_Eventi.ID_tp_evento ,NM_Eventi.data AS Expr2 ,NM_Eventi.data_notifica AS Expr3 ,NM_Eventi.messaggio ,MAIL.value('subject[1]', 'nvarchar(255)') AS MAIL_SUBJECT ,MAIL.value('text[1]', 'nvarchar(255)') AS MAIL_TEXT ,MAIL.value('attachments[1]', 'nvarchar(255)') AS MAIL_ATTACHMENT ,MAIL.value('idNotifica[1]', 'nvarchar(255)') AS ID_NOTIFICAXML FROM NM_Notifiche INNER JOIN NM_Eventi ON NM_Notifiche.ID_Evento = NM_Eventi.ID_Evento CROSS APPLY [messaggio].nodes('/nmMsgMessage[1]/notifiers[1]/*[idNotifica=sql:column("NM_Notifiche.ID_Notifica")]') AS T_MESSAGGIO(MAIL) WHERE NM_Notifiche.ID_EVENTO = 2548 ) SELECT * FROM XML_Q WHERE MAIL_SUBJECT NOT LIKE 'Sql monitor%' AND MAIL_SUBJECT NOT LIKE '%SQLException%'
PG
WITH notifiers_xml AS ( SELECT e.id_evento ,n.id_notifica ,unnest(xpath('/nmMsgMessage/notifiers/*', e.messaggio)) AS notifier_xml ,unnest(xpath('/nmMsgMessage/notifiers/*/idNotifica/text()', e.messaggio)::TEXT []::INT []) AS id_notifica_xml FROM nm_eventi e INNER JOIN nm_notifiche n ON e.id_evento = n.id_evento WHERE e.id_evento = 7916 ) SELECT id_evento ,id_notifica ,notifier_xml ,(xpath('/nmMsgMailNotifier/from/text()', notifier_xml)::TEXT []) [1] AS FROM ,(xpath('/nmMsgMailNotifier/to/address/text()', notifier_xml)::TEXT []) [1] AS recipients ,(xpath('/nmMsgMailNotifier/cc/address/text()', notifier_xml)::TEXT []) [1] AS cc ,(xpath('/nmMsgMailNotifier/bcc/address/text()', notifier_xml)::TEXT []) [1] AS bcc ,(xpath('/nmMsgMailNotifier/subject/text()', notifier_xml)::TEXT []) [1] AS subject ,(xpath('/nmMsgMailNotifier/text/text()', notifier_xml)::TEXT []) [1] AS TEXT FROM notifiers_xml WHERE id_notifica = id_notifica_xml
package org.jooq.test.all.bindings;import java.sql.SQLException;import java.sql.SQLXML;import java.sql.SQLXML;import java.sql.Types;import org.jooq.Binding;import org.jooq.BindingGetResultSetContext;import org.jooq.BindingGetSQLInputContext;import org.jooq.BindingGetStatementContext;import org.jooq.BindingRegisterContext;import org.jooq.BindingSQLContext;import org.jooq.BindingSetSQLOutputContext;import org.jooq.BindingSetStatementContext;import org.jooq.Converter;public class OracleXmlAsSQLXMLBinding implements Binding<Object, SQLXML> {/*** Generated UID*/private static final long serialVersionUID = 358789452467943117L;@Overridepublic Converter<Object, SQLXML> converter() {return new Converter<Object, SQLXML>() {@Overridepublic SQLXML from(Object databaseObject) {return null; // Not needed in the example}@Overridepublic Object to(SQLXML userObject) {return null; // Not needed in the example}@Overridepublic Class<Object> fromType() {return Object.class;}@Overridepublic Class<SQLXML> toType() {return SQLXML.class;}};}@Overridepublic void sql(BindingSQLContext<SQLXML> ctx) throws SQLException {ctx.render().sql("?");}@Overridepublic void register(BindingRegisterContext<SQLXML> ctx) throws SQLException {ctx.statement().registerOutParameter(ctx.index(), Types.SQLXML);}@Overridepublic void set(BindingSetStatementContext<SQLXML> ctx) throws SQLException {if (ctx.value() == null)ctx.statement().setObject(ctx.index(), null);elsectx.statement().setSQLXML(ctx.index(), ctx.value());}@Overridepublic void set(BindingSetSQLOutputContext<SQLXML> ctx) throws SQLException {if (ctx.value() == null)ctx.output().writeObject(null);elsectx.output().writeSQLXML(ctx.value());}@Overridepublic void get(BindingGetResultSetContext<SQLXML> ctx) throws SQLException {ctx.value(ctx.resultSet().getSQLXML(ctx.index()));}@Overridepublic void get(BindingGetStatementContext<SQLXML> ctx) throws SQLException {ctx.value(ctx.statement().getSQLXML(ctx.index()));}@Overridepublic void get(BindingGetSQLInputContext<SQLXML> ctx) throws SQLException {ctx.value(ctx.input().readSQLXML());}}
<customType><name>OracleXmlAsSQLXML</name><type>java.sql.SQLXML</type><binding>org.jooq.test.all.bindings.OracleXmlAsSQLXMLBinding</binding></customType><forcedType><name>OracleXmlAsSQLXML</name><expression>ORACLE_XML_AS_SQLXML</expression></forcedType>
@Testpublic void testOracleNativeXML() throws Exception {TExoticTypes t = T_EXOTIC_TYPES;clean(t);assertEquals(1,create().insertInto(t, t.ID, t.ORACLE_XML_AS_SQLXML).values(1, null).execute());SQLXML xml = null;try {xml = connection.createSQLXML();xml.setString("<a><b/></a>");assertEquals(1,create().insertInto(t, t.ID, t.ORACLE_XML_AS_SQLXML).values(2, xml).execute());Result<TExoticTypesRecord> records =create().selectFrom(t).orderBy(t.ID).fetch();assertEquals(asList(1, 2),records.stream().map(TExoticTypesRecord::getId).collect(toList()));assertEquals(asList(null, "<a><b/></a>"),records.stream().map(Unchecked.function((TExoticTypesRecord r) -> r.getOracleXmlAsSqlxml() == null? null: r.getOracleXmlAsSqlxml().getString().replaceAll("\\s", ""))).collect(toList()));}finally {JDBCUtils.safeFree(xml);}}
public static Field<String> xpath(String xpath, Field<SQLXML> xml) {return new CustomField<String>("xpath", SQLDataType.VARCHAR) {@Overridepublic void accept(Context<?> ctx) {
switch (ctx.family()) {
case ORACLE:
ctx.visit(DSL.field("extract({0}, {1}).getStringVal()", String.class, xml, inline(xpath)));
break;
case POSTGRES:
ctx.visit(DSL.field("(xpath({0}, {1})::text[]) [1]", String.class, inline(xpath), xml));
break;
case ...
}
}}}
My question is have you in plan to support jdbc sqlxml in the future?
Also what about xpath operator native support?
I mean, do you think queries like the two following one could be supported (near to native way, I know you can write it using expressions ) in the future?
I would like to understand the approach to this kind of data managment on middle-long terms.
Very complete response. Thank you Lukas. Now tour plan is clear to me and i likeit.
--
You received this message because you are subscribed to a topic in the Google Groups "jOOQ User Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jooq-user/31XyeqdPtEM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jooq-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.