Wednesday, December 15, 2010

Access multiple Databases in JPA

According to JPA specification we can define multiple "persistence-unit" elements (i.e. like below) in persistence.xml file and can easily refer them inside Dao layers as this.

public class PolarDaoImpl {

    @PersistenceContext(unitName="PolarPU")
    protected EntityManager entityManager;

--
}


public class BearDaoImpl {

    @PersistenceContext(unitName="BearPU")
    protected EntityManager entityManager;

--
}




Checkout sample persistence.xml



<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <!-- Database 1 -->
    <persistence-unit name="PolarPU" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <non-jta-data-source/>
        <class>com.cisco.polar.entity.ManagedAcademy</class>
        <class>com.cisco.polar.entity.TeachAcademy</class>
        <exclude-unlisted-classes>true</exclude-unlisted-classes>
        <properties>
            <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
            <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/polar"/>
            <property name="hibernate.connection.username" value="root"/>
            <property name="hibernate.connection.password" value=""/>
        </properties>
    </persistence-unit>
    <!-- Database 2 -->
    <persistence-unit name="BearPU" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <non-jta-data-source/>
        <class>com.cisco.polar.entity.AcademyReportDate</class>
        <exclude-unlisted-classes>true</exclude-unlisted-classes>
        <properties>
            <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
            <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/bear"/>
            <property name="hibernate.connection.username" value="root"/>
            <property name="hibernate.connection.password" value=""/>
        </properties>
    </persistence-unit>
</persistence>

Thursday, December 2, 2010

Two point formula for Apple IPhone to outsell Android ?

  1. Introduce multiple Iphones with a basic one costing around $100 so Carriers can give it for free in US, and in rest of the world most people can afford it, this can be very slim like IPod without any camera and special hardware, so regular user can enjoy web and touch screen.
  2. Introduce and Advertise more Geeky themes which young men would like, this is where Android is making inroad.
  3. This is for free -- Do something about Java on IPhone like how Google cleverly used it. 

Running Liferay in Development Mode

Liferay speeds up rendering UI pages including Portlets by caching CSS, JS and layout files, this make developing portlets little painful, since every time you make js or css changes in your portlet and deploy. you may have to clear temp, work directoires and clear caches from Liferay control panel.

So when using Liferay for development we can switch off the caching by adding few properties to "portal-ext.properties" file, this will save some time and frustation when developing portlets

Solution 1 :
 Copy all values from portal-developer.properties to portal-ext.properties

Solution 2 :
 Copy below values to portal-ext.properties,
portal-ext.properties location - webapps/ROOT/WEB-INF/classes/portal-ext.properties if not present create a new one

theme.css.fast.load=false
theme.images.fast.load=false

javascript.fast.load=true
javascript.log.enabled=true

layout.template.cache.enabled=false

browser.launcher.url=

combo.check.timestamp=true

freemarker.engine.cache.storage=soft:1
freemarker.engine.modification.check.interval=0

openoffice.cache.enabled=false

velocity.engine.resource.manager.cache.enabled=false

com.liferay.portal.servlet.filters.cache.CacheFilter=false

com.liferay.portal.servlet.filters.themepreview.ThemePreviewFilter=true