22
Jun 11

Fetch Multiple Objects by key in JDO using getObjectsById

On Google Appengine I needed to fetch multiple objects, the key to which is present with me. I tried using PersistenceManager#getObjectsById(Collection) method and passed a list of keys to it. But that threw an exception. On further probing I realized this is not how #getObjectsById works.

There might be other ways of doing it but this is how I’ve done it :

List list = new ArrayList();

for(Key key : <iterate-over-list-of-keys>){

list.add(persistenceManager.newObjectIdInstance(<class-name-here>, key));

}

Collection objects = persistenceManager.getObjectsById(list);

Hopefully this helps you use the getObjectsById method in JDO on google appengine.


22
Jun 11

Change Google Chrome Google Search Country

I recently moved to Chile to work on our new startup buffr.com which is an easy way to manage multiple social networks. We call it the social media dashboard.

The first time I used the internet on my laptop in Chile, Google Chrome prompted me if I had changed to a different location. Unaware that clicking yes would make the default search bar use Google Chile, I clicked yes!

After a few searches I realized it was easy changing the chrome google search country back to my own country.

Here’s how you change the country specific google search to the one you want :

1. Close Google Chrome
2. Navigate to \Users\\AppData\Local\Google\Chrome\User Data
3. There will be a file named “Local State”
4. Search for “last_known_google_url” and/or “last_prompted_google_url” and change the extension of the value here to the one you want.
5. Start Google Chrome

You should now have the Google search engine in Chrome belonging to the country that you want. Chrome will prompt you again to use Google specific to your location, just select No!


03
Apr 11

Convert json string to Map in Java using Gson

I’ve been using Gson from quite some time now. It’s a Java library developed by Google that is used to convert JSON to Java objects and vice versa. You can read more about Gson here.

I came across this json string which I had to convert into a Map. Here’s how you do it:

Type type =
 new TypeToken<Map<String, String>>(){}.getType();
Map<String, String> map =
 gson.fromJson("{'key1':'123','key2':'456'}", type);

Hope that helps you convert a json string into a java Map.