Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it possible to get XMLGregorianCalendar directly from MyBATIS?
    primarykey
    data
    text
    <p>I work with public StackOverflow dump and have everything stored in MySQL. Now, I want to perform some analyses using Java and MyBATIS. For some of these I need to extract timeseries for a user, or a particular question etc. So for this, lets say posts and their timestamps, I have a MyBatis query:</p> <pre><code> &lt;select id="GetAllPostsTimeStamps" resultType="java.util.Date"&gt; SELECT creationDate from posts &lt;/select&gt; </code></pre> <p>which hands the timestamp data to MyBatis ResultHandler, where I do this transformation:</p> <pre><code>@Override public void handleResult(ResultContext context) { TimeZone tz = TimeZone.getTimeZone("UTC"); TimeZone.setDefault(tz); Date tstamp = (Date) context.getResultObject(); XMLGregorianCalendar xmlTstam = Tstamp.makeTimestamp(tstamp.getTime()); ...etc... } </code></pre> <p>I really need to use <code>XMLGregorianCalendar</code> because all my downstream logic relies on this type.</p> <p>Is it possible to tell MyBatis with its handlers feature to make transformation of SQL datetime to XMLGregorianCalendar internally (i.e. I will code the handler only once), so I will get proper timestamps out of it everytime I need? </p> <p>Editing to add more clarity. </p> <p>So, when I save java objects with <code>XMLGregorianCalendar</code> fields into DB (MySQL datetime type) I use an implementation of MyBatis handler:</p> <pre><code>XMLGregorianCalendarDateTypeHandler implements TypeHandler&lt;XMLGregorianCalendar&gt; ... </code></pre> <p>which I specify in the <code>INSERT</code> query like this:</p> <pre><code> ..., #{creationDate, javaType=javax.xml.datatype.XMLGregorianCalendar, jdbcType=TIMESTAMP, typeHandler=...XMLGregorianCalendarTypeHandler},... </code></pre> <p>is there a way to specify the backward transform handler for <code>SELECT</code> type queries?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload