Probably is something known that SqlServer store xml type as UTF-16. You 
can insert UTF-8 but select always extract UTF-16 xml field.
I've got a binding to convert query xml field into String, see below...
I would like this binder to generate String as *new String(bytes,"UTF-16")* 
instead of default, I suppose default is something like *new String(bytes).*
I want also to do this just on sqlserver but not on other databases, cause 
this binding is in my parent pom (all db kinds).

How can I achieve this? Is it possible manage two difference forcedType 
choosing by database engine? Or is is possible to write a binder that define
different constructor of String on different db engines? Other 
possibilities?


In my maven configuration I've got 

<customType><name>XmlStringBinding</name><type>java.lang.String</type><binding>it.clesius.jooq.bindings.XmlStringBinding</binding></customType>


<forcedType>
    <name>XmlStringBinding</name>
    <expression>(\w+\.)?(?!UDT_PREFIX|PROC_PREFIX)\w+(\.\w+)?</expression>
    <types>XML</types></forcedType>


and java code for binding is:


public class XmlStringBinding implements Binding<Object, String> {
        /**      * Generated UID         */
        private static final long serialVersionUID = 358789452467943117L;

        @Override
        public Converter<Object, String> converter() {
                return new Converter<Object, String>() {
                        private static final long serialVersionUID = 
5005180607894678030L;

                        @Override
                        public String from(Object databaseObject) {
                                return null; // Not needed in the example
                        }

                        @Override
                        public Object to(String userObject) {
                                return null; // Not needed in the example
                        }

                        @Override
                        public Class<Object> fromType() {
                                return Object.class;
                        }

                        @Override
                        public Class<String> toType() {
                                return String.class;
                        }
                };
        }

        @Override
        public void sql(BindingSQLContext<String> ctx) throws SQLException {
                ctx.render().sql("?");
        }

        @Override
        public void register(BindingRegisterContext<String> ctx) throws 
SQLException {
                ctx.statement().registerOutParameter(ctx.index(), Types.SQLXML);
        }

        @Override
        public void set(BindingSetStatementContext<String> ctx) throws 
SQLException {
                if (ctx.value() == null)
                        ctx.statement().setObject(ctx.index(), null);
                else
                        ctx.statement().setString(ctx.index(), ctx.value());
        }

        @Override
        public void set(BindingSetSQLOutputContext<String> ctx) throws 
SQLException {
                if (ctx.value() == null)
                        ctx.output().writeObject(null);
                else
                        ctx.output().writeString(ctx.value());
        }

        @Override
        public void get(BindingGetResultSetContext<String> ctx) throws 
SQLException {
                ctx.value(ctx.resultSet().getString(ctx.index()));
        }

        @Override
        public void get(BindingGetStatementContext<String> ctx) throws 
SQLException {
                ctx.value(ctx.statement().getString(ctx.index()));
        }

        @Override
        public void get(BindingGetSQLInputContext<String> ctx) throws 
SQLException {
                ctx.value(ctx.input().readString());
        }}

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to