Announcement Announcement Module
Collapse
No announcement yet.
NamedQuery in Roo Controller ? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • NamedQuery in Roo Controller ?

    I am trying to load the contents of a csv file directly to a MySQL DB. The normal query is something like:

    "LOAD DATA LOCAL INFILE '/path/to/file/items.csv' INTO TABLE items ..."

    which works fine in a MySQL shell.

    I would like to upload an items.csv file in a roo controller and use the above MySQL query to store it in the DB.

    Do I use a named query ?

    @PersistenceContext
    EntityManager em;

    then in the method:

    em.createNamedQuery("pushFile").executeUpdate();

    but where do I put the "pushFile" named query? In the controller its not found in the "Item" domain file it causes errors.

    Any ideas or another way of going about this.

    Thanks

  • #2
    Hi, springflan

    Did you find the solution to this issue ? I am also thinking of doing similar thing.

    Thanks,
    Jin

    Comment


    • #3
      Have you tried Spring Integration

      Hi,

      did you give Spring Integration a try?

      For many cases this could be a great alternative to a self-written Controller.
      See this for a MultiPartController sample with a REST interface/ URI:
      http://static.springsource.org/sprin...t-rest-inbound

      and this on "how to read from the file system":
      http://static.springsource.org/sprin.../#file-reading

      and this for "writing into a database":
      http://static.springsource.org/sprin...hannel-adapter

      I created a quite complex CSV-Importer using Spring Integration and OpenCSV. Therefore I created a parameterized "CSVToBeanTransformer". I'll post here when I finished the samples and uploaded it to github.

      Cheers
      Alex

      Comment


      • #4
        I noticed that I could use Spring Batch to do the data bulk load. The batch job can be triggered from web container.

        http://static.springsource.org/sprin...ng-batch-intro

        Jin

        Comment

        Working...
        X