Lists all of the journal entries for the day.

Sat, 30 May 2009

10:02 PM - Apache Cayenne

 I've been working on converting just journal over to Apache Cayenne today.  I figured it would give me an opportunity to get better with it.  Cayenne has a nice modeling program, but their documentation is often lacking.

For example, suppose you're getting an error from your servlet container (Tomcat in my case) about a filter not loading.  With Cayenne, the "correct" way to use it is to load a filter mapped to /* that catches all the sessions and maps a DataContext to them.  You might find after pulling your hair out that there is a syntax error in your DomainNode.driver.xml file.  Even with logging cranked up in log4j, it will not tell you what's wrong with the filter.  However, if you initialize like a traditional app in a jsp page, you can see the error.  Invalid passwords are an example of what can cause this.

 

tags: cayenne apache java

()

10:14 PM - JSON in Java

I've been using JSON with Dojo Data Grids lately in PHP.  Now, I want to use something similar on this site.  I decided on the json-simple library.  It's actually quite easy to use.

Encoding examples:

http://code.google.com/p/json-simple/wiki/EncodingExamples 

<%@ page contentType="text/json;charset=UTF-8" language="java"%>

<%@ page import="com.justjournal.model.User" %>

<%@ page import="org.apache.cayenne.DataObjectUtils" %>

<%@ page import="org.apache.cayenne.access.DataContext" %>

<%@ page import="org.apache.cayenne.query.SelectQuery" %>

<%@ page import="org.json.simple.JSONObject" %>

<%@ page import="java.util.*" %>

<%@ page import="org.json.simple.JSONArray" %>

<%

    out.clearBuffer();

    SelectQuery query = new SelectQuery(User.class);

    query.addOrdering(User.USERNAME_PROPERTY, true);


    DataContext context = DataContext.getThreadDataContext();

    List users = context.performQuery(query);

    JSONObject obj = new JSONObject();

    JSONArray list1 = new JSONArray();


    Iterator it = users.iterator();

    while (it.hasNext()) {

        Map map = new HashMap();

        User u = (User) it.next();

        if (u.getUsername().length() > 2 && !new com.justjournal.User(u.getUsername()).isPrivateJournal())

        {

            map.put("id", DataObjectUtils.intPKForObject(u));

            map.put("username", u.getUsername());

            map.put("name", u.getName());

            map.put("since", u.getSince());

            list1.add(map);

        }

    }

    obj.put("items", list1);

    obj.put("label","id");

    obj.put("identifier", "id");

    obj.writeJSONString(out);

 

tags: json dojo java cayenne

()

10:20 PM - Annoying MySQL issue with jdbc

Ever get this?   Cannot convert value '0000-00-00 00:00:00' from column  to TIMESTAMP. 

The problem is that the MySQL jdbc driver doesn't map it to null.  There are flags to the connection that are supposed to do this for you, but I've had no luck getting them to work.  I have two timestamp fields on the User table for this site.  I wrote a MySQL to java data mapper years ago, but now that I'm converting to Cayenne, I can't use that anymore.  Time to fix the database :)

One "solution".  

tags: mysql jdbc errors

()