mapping datetime to java.util.Date

92 views
Skip to first unread message

Darren S

unread,
Jan 27, 2014, 5:29:21 PM1/27/14
to jooq...@googlegroups.com
I swear I had this working before, but I just noticed that its not mapping datetime to java.util.Date anymore.  I'm running against master in github, but I tried against 3.2 also and its not working.  I really don't know what I'm doing wrong.  Here's my codegen.xml and also a sample table.  Is there something obviously wrong?



CREATE TABLE IF NOT EXISTS `account` (
  `id` bigint(19) NOT NULL AUTO_INCREMENT,
  `uuid` varchar(128) NOT NULL,
  `kind` varchar(255) NOT NULL,
  `name` varchar(255) DEFAULT NULL,
  `state` varchar(255) NOT NULL,
  `hold_data` bit(1) NOT NULL DEFAULT b'0',
  `created` datetime DEFAULT NULL,
  `removed` datetime DEFAULT NULL,
  `remove_time` datetime DEFAULT NULL,
  `data` mediumtext,
  `description` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_account_name` (`name`),
  KEY `idx_account_removed` (`removed`),
  KEY `idx_account_resource_remove_schedule` (`remove_time`),
  KEY `idx_account_resource_state` (`state`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=22 ;


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-3.2.0.xsd">
    <!-- Configure the database connection here -->
    <jdbc>
        <driver>org.drizzle.jdbc.DrizzleDriver</driver>
        <url>jdbc:mysql:thin://localhost:3306/dstack</url>
        <user>user</user>
        <password>password</password>
    </jdbc>

    <generator>
        <!-- The default code generator. You can override this one, to generate
            your own code style Defaults to org.jooq.util.DefaultGenerator -->
        <name>io.github.ibuildthecloud.dstack.db.jooq.generator.JavaGenerator</name>

        <strategy>
            <name>io.github.ibuildthecloud.dstack.db.jooq.generator.ModelStrategy</name>
        </strategy>

        <database>
            <!-- The database type. The format here is: org.util.[database].[database]Database -->
            <name>org.jooq.util.mysql.MySQLDatabase</name>

            <!-- The database schema (or in the absence of schema support,
                in your RDBMS this can be the owner, user, database name) to be generated -->
            <inputSchema>dstack</inputSchema>

            <!-- All elements that are generated from your schema (A Java
                regular expression. Use the pipe to separate several expressions) Watch out
                for case-sensitivity. Depending on your database, this might be important! -->
            <includes>.*</includes>

            <!-- All elements that are excluded from your schema (A Java
                regular expression. Use the pipe to separate several expressions). Excludes
                match before includes -->
            <!--  <excludes>.*proc</excludes> -->

            <unsignedTypes>false</unsignedTypes>

            <customTypes>
                <customType>
                    <name>java.util.Date</name>
                    <converter>io.github.ibuildthecloud.dstack.db.jooq.converter.DateConverter</converter>
                </customType>
            </customTypes>
            <customTypes>
                <customType>
                    <name>java.util.Map&lt;String,Object&gt;</name>
                    <converter>io.github.ibuildthecloud.dstack.db.jooq.converter.DataConverter</converter>
                </customType>
            </customTypes>
            <forcedTypes>
                <forcedType>
                    <name>java.util.Date</name>
                    <types>datetime</types>
                </forcedType>
                <forcedType>
                    <name>java.util.Map&lt;String,Object&gt;</name>
                    <expressions>.*\.data|.*\.log</expressions>
                </forcedType>
            </forcedTypes>
        </database>

        <target>
            <!-- The destination package of your generated classes (within
                the destination directory) -->
            <packageName>io.github.ibuildthecloud.dstack.core.model</packageName>

            <!-- The destination directory of your generated classes -->
            <directory>src/main/java</directory>
        </target>
        <generate>
            <interfaces>true</interfaces>
            <pojos>false</pojos>
            <daos>false</daos>
            <jpaAnnotations>true</jpaAnnotations>
            <immutablePojos>false</immutablePojos>
        </generate>
    </generator>
</configuration>

Darren S

unread,
Jan 27, 2014, 5:38:04 PM1/27/14
to jooq...@googlegroups.com
Oh, I feel like an idiot now.  So the problem is that I had two customTypes elements, not one customTypes element with two customType in it.

Darren

Lukas Eder

unread,
Jan 28, 2014, 7:52:07 AM1/28/14
to jooq...@googlegroups.com

2014-01-27 Darren S <darren.s...@gmail.com>

Oh, I feel like an idiot now.  So the problem is that I had two customTypes elements, not one customTypes element with two customType in it.

It happens to the best :-)
But did the jOOQ code generator emit a warning? There should be warnings in the logs when you provide invalid XML, as jOOQ uses a javax.xml.bind.ValidationEventHandler when unmarshalling the XML.

Another option to avoid such mistakes, of course, is to use programmatic configurations:

Cheers
Lukas

Darren Shepherd

unread,
Jan 28, 2014, 10:15:25 AM1/28/14
to jooq...@googlegroups.com
Yep, when I look back at the log it does emit a warning. But its part
of a maven build, so it just kind of gets lost in the noise. Nice
that there is a java approach, but I like the XML.

Darren
> --
> 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/CuyJmQOl8HI/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/groups/opt_out.
Reply all
Reply to author
Forward
0 new messages