Thursday, February 10, 2011

Thursday, December 23, 2010

Grails Bean builder for Compass Search on Appengine using JPA

Need to put this down in case i forget

beans = {
    compass(org.compass.spring.LocalCompassBean){
mappingScan = "persisted"
compassSettings = ["compass.engine.connection":"gae://index",
"compass.executorManager.type":"disabled",
"compass.engine.store.gae.cacheMetaData":"true",
"compass.engine.store.gae.flushRate":"50"]
    }

    sameThreadParallelIndexExecutor(org.compass.gps.device.support.parallel.SameThreadParallelIndexExecutor){

    }

    jpaGpsDevice(org.compass.gps.device.jpa.JpaGpsDevice){
name="appengine"
entityManagerFactory = entityManagerFactory
parallelIndexExecutor = sameThreadParallelIndexExecutor
    }
  
    compassGps(org.compass.gps.impl.SingleCompassGps){
compass = compass
gpsDevices = [jpaGpsDevice]
    }
}

Sunday, December 5, 2010

Setting Solid Color to DrawableShape loaded from XML

So yea, tried to set a solid color to a ShapeDrawable resource loaded from XML
initially tried:

ShapeDrawable drawable = (ShapeDrawable)getResources().getDrawable(R.drawable.shape)
drawable.getPaint().setColor(color);

Didn't work,

So cast to GradientDrawable instead:
GradientDrawable drawable = (GradientDrawable)getResources().getDrawable(R.drawable.shape)
drawable.setColor(color);

Saturday, September 4, 2010

Working with TimeZones

import java.util.TimeZone;

def tz = TimeZone.getTimeZone("Asia/Kuala_Lumpur")
def date = new Date();
def time = date.getTime()+tz.getOffset(date.getTime())
date.setTime(time)

In GAE:

Wrap the above in a method to bypass Reflections which GAE doesn't support

TimeZone.getAvailableIDs() also doesn't work in GAE because of Reflections

Correction, below works

public Date getDateWithTimeZone(Date date, String timeZone){
def tz = TimeZone.getTimeZone(timeZone);
def cal = Calendar.getInstance()
cal.setTimeInMillis( date.getTime() )
cal.setTimeZone( tz )
def offset = cal.get(Calendar.ZONE_OFFSET)
date.setTime( date.getTime()+offset )
return date;
}

Wednesday, September 1, 2010

Localization i18n for Grails and App Engine

Getting localization working on Grails on GAE
see below for workaround

checkout this jira:
http://jira.codehaus.org/browse/GRAILSPLUGINS-1905

Tuesday, August 31, 2010

JPA query syntax

Within a controller:

def query = entityManager.createQuery("select from Account a where a.key=:key order by ${params.sort} ${params.order}")
query.setParameter("key",session.key)
query.setMaxResults( params.max )
query.setFirstResult( params.offset )
def accounts = query.resultList;

EntityManager isn't injected in Services but jpaTemplate is so:

private getEntityManager(){
jpaTemplate.execute({EntityManager entityManager->
return entityManager;
} as JpaCallback);
}

Thursday, July 22, 2010

Android Development

I know i've been neglecting this blog for a while, but i've recently picked up a Samsung Galaxy S and will be refocusing on developing apps on Android and posting what i learn here.