Archive for Dev Notes’ Category

5

Oct
2010
Comments Off on GAE: Querying on Child objects using parent Key

GAE: Querying on Child objects using parent Key

This post is about the Google App Engine and its limitations. I googled for a while to try and find an article on how to do better queries using the datastore, but I did not find what I needed. I hope this helps some of you out there. I have a a bunch of child entities, but I only want a select few of them, so I need to query like good old SQL. here is the scenario:
@Inheritance(strategy = InheritanceStrategy.SUBCLASS_TABLE)
public abstract class A {
}
 
public class B  extends A {
    List<D>members;
}
 
@Inheritance(strategy = InheritanceStrategy.SUBCLASS_TABLE)
public abstract class C extends A {
    B owner;
}
 
public class D extends C {
    boolean active;
}
 
public class E extends C {
    String otherProp;
}
As you can see A is my base object with some properties that I want all my objects to have. Now i want to get all Cs that are active and belong to a particular B. Well, the short answer is you cannot and that is because the relationship is not directly on the child class but is on its super class. This must be a bug!!! Solution is to move the property down to both D and E, then I can do the query I want and get on with the rest of my life. JDO:
1
2
3
4
5
6
Key ownerKey = KeyFactory.stringToKey(ownerKeyString); 
String queryStr = "select from " + C.class.getName() + 
                        " where owner == ownerParam && active == true"; 
Query q = pm.newQuery(queryStr); 
q.declareVariables(B.class.getName() + " ownerParam"); 
myCs = (List<C>)q.execute(ownerKey);
Here is a thread where I was discovering this.
read more

5

Oct
2010
Comments Off on Get going with Tomcat & Eclipse on OSX

Get going with Tomcat & Eclipse on OSX

I recently had to move a project off of Google App Engine. To my surprise, Google App Engines performance was just not fast enough for this project. In any case, this lead to my installation of Tomcat on OSX and integrating into Eclipse so here is how to do it:
  1. Get the latest tomcat: http://tomcat.apache.org/index.html. You need to make sure you get the tar or zip file.
  2. Move the download to /usr/local/.
  3. Start a super shell:
  4. $ sudo sh
  5. If you downloaded the tar, you may have noticed the warning that it will not work with OSX tar command, so make sure to use gnutar which comes with OSX.
  6. $ gnutar xzvf apache-tomcat-6.0.26.tar.gz
  7. Now you can change owner ship on this new folder so you can start and stop tomcat without having to sudo, but I left it as is.
  8. Create a link to the folder so that you make your life eaiser in the long term when you install newer versions:
  9. $ ln -s apache-tomcat-6.0.26 tomcat
  10. Go back to your home folder and create a new script :
  11. 1
    2
    3
    4
    5
    6
    7
    8
    
    #!/bin/sh
    export CATALINA_HOME=/usr/local/tomcat
    export JAVA_HOM=/usr
    if [ "$1" == "start" ] ; then
        $CATALINA_HOME/bin/startup.sh
    else
        $CATALINA_HOME/bin/shutdown.sh
    fi
  12. Now you can start and stop tomcat from your home folder
  13. $ sudo ./tomcat.sh start  <== To start
    $ sudo ./tomcat.sh        <== To stop
Now that Tomcat is setup, you need to configure it in Eclipse:
  1. Go to Eclipse Preferences ->Server -> Runtime Environments
  2. Click Add and select the right Tomcat Version
  3. Put in /usr/local/tomcat for the Tomcat Installation directory (the link we created above)
  4. Click Finish and you should be setup
    1. Good Luck!
      read more

Page 3 of 3123