Foren

Liferay 6.1 GA2 - ext-spring failed on external datasource [SOLVED]

thumbnail
Christophe Cariou, geändert vor 11 Jahren.

Liferay 6.1 GA2 - ext-spring failed on external datasource [SOLVED]

Junior Member Beiträge: 57 Beitrittsdatum: 01.10.07 Neueste Beiträge
Hi,

I Have a plugin that combine a Service Builder made API and a Vaadin portlet (in only one war).

The service builder part has an external datasource defined in classe/META-INF/ext-spring.xml by this way :

<!--?xml version="1.0"?-->

<beans default-destroy-method="destroy" default-init-method="afterPropertiesSet" xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> 

   	<!-- Overrides -->
   
   	<bean id="basePersistence" abstract="true">
		<property name="dataSource" ref="oberDataSource" />
		<property name="sessionFactory" ref="oberSessionFactory" />
	</bean>
	
	<bean id="transactionAdvice" class="org.springframework.transaction.interceptor.TransactionInterceptor">
		<property name="transactionManager" ref="oberTransactionManager" />
		<property name="transactionAttributeSource">
			<bean class="org.springframework.transaction.annotation.AnnotationTransactionAttributeSource">
				<constructor-arg>
					<bean class="com.liferay.portal.spring.annotation.PortalTransactionAnnotationParser" />
				</constructor-arg>
			</bean>
		</property>
	</bean>
 	
 	
 	 	
	<!-- Custom beans -->
    <bean id="oberDataSource" class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy">
       <property name="targetDataSource">
           <bean class="com.liferay.portal.dao.jdbc.util.DataSourceFactoryBean">
               <property name="propertyPrefix" value="jdbc.ober." />
           </bean>
       </property>
   	</bean>
    
    <bean id="oberHibernateSessionFactory" class="com.liferay.portal.spring.hibernate.PortalHibernateConfiguration" lazy-init="true">
        <property name="configurationClass">
            <value>org.hibernate.cfg.Configuration</value>
        </property>
        <property name="dataSource">
            <ref bean="oberDataSource" />
        </property>
		 <property name="mappingResources">
            <list>
                <value>./META-INF/portlet-hbm.xml</value>
            </list>
        </property>
    </bean>
    
    <bean id="oberTransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" lazy-init="true">
        <property name="dataSource">
            <ref bean="oberDataSource" />
        </property>
        <property name="sessionFactory">
            <ref bean="oberHibernateSessionFactory" />
        </property>
    </bean>

	<bean id="oberSessionFactory" class="com.liferay.portal.dao.orm.hibernate.SessionFactoryImpl" lazy-init="true">
        <property name="sessionFactoryImplementor">
            <ref bean="oberHibernateSessionFactory" />
        </property>
    </bean>

</beans>


This plugin work fine on a liferay 6.0.6 or even 6.0.5.

As I'm upgrading to 6.1.1 GA2, I've rebuild all the plugin with sdk6.1, with Liferay IDE 1.6.

Now, when I deploy my plugin, or even restart my Liferay 6.1.1 I've this error :

...
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'oberHibernateSessionFactory' defined in ServletContext resource [/WEB-INF/classes/META-INF/ext-spring.xml]: Invocation of init method failed; nested exception is java.io.FileNotFoundException: class path resource [META-INF/portlet-hbm.xml] cannot be opened because it does not exist
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1422)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:518)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
	... 151 more
Caused by: java.io.FileNotFoundException: class path resource [META-INF/portlet-hbm.xml] cannot be opened because it does not exist
	at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:158)
	at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:677)
	at com.liferay.portal.spring.hibernate.PortalHibernateConfiguration.buildSessionFactory(PortalHibernateConfiguration.java:65)
	at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1479)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1419)
	... 158 more
...


The root cause is : java.io.FileNotFoundException: class path resource [META-INF/portlet-hbm.xml] cannot be opened because it does not exist

After some tests, it seems that my META-INF folder is not in the known classpath for my spring context.
I made a test putting portlet-hbm.xml in ROOT/WEB-INF/classe/META-INF, and then I haven't got this error (but others later, due to the lack of all the java classes that are still in my plugin war).

So it looks like there something changed between Liferay 6.0x and 6.1.1, and i suspect this : http://issues.liferay.com/browse/LPS-29103

I tried some changes in the web.xml file of my plugin but without success.

Has anybody encounter this trouble and find a work around ?
thumbnail
David H Nebinger, geändert vor 11 Jahren.

RE: Liferay 6.1 GA2 - ext-spring failed on external datasource

Liferay Legend Beiträge: 14914 Beitrittsdatum: 02.09.06 Neueste Beiträge
I'm using Vaadin and SB, but I keep my Vaadin portlet separate from a standard SB portlet and things seem to work well in that configuration...

I haven't tried doing them in the same war file, but I'd guess that most of the issue is going to be getting the web.xml squared away so all of the appropriate filters and listeners are defined properly.
thumbnail
Christophe Cariou, geändert vor 11 Jahren.

RE: Liferay 6.1 GA2 - ext-spring failed on external datasource

Junior Member Beiträge: 57 Beitrittsdatum: 01.10.07 Neueste Beiträge
Thank you David.

I'm agree : separating Service and GUI is a good practice, and, as you say, merging the two in a single plugin can lead to bad injection in the web.xml listeners declarations.

Just one (or more) things :
- You said that you deploy your Services in a portlet plugin. Not an ext-plugin. Is it right ?
- In that case, are you using external datasource ? or do you manage schemas as you suggest in this post : Support Catalog and Schema...
- Did you deploy on LIferay 6.1.1 GA2?
- Can't I have a sample of your ext-spring.xml ?



Christophe
thumbnail
David H Nebinger, geändert vor 11 Jahren.

RE: Liferay 6.1 GA2 - ext-spring failed on external datasource

Liferay Legend Beiträge: 14914 Beitrittsdatum: 02.09.06 Neueste Beiträge
I have a separate portlet plugin based upon the Liferay MVC portlet type (it's really blank) that I keep my services in. Since it's Liferay MVC (and since I'm not using it), all of the correct things are injected in the right places to make SB happy.

I'm still running 6.0 (EE sp 2, actually, but would still be the same for 6.0.6). We're not going to do the 6.1 upgrade until Liferay goes to 6.1.

I am using an external data source for my SB, but also use the catalog/schema changes I mentioned. The external data source is to my SqlServer database, and the catalog/schema changes allow me to access all of my entities there.

My sample from my ext-spring.xml would be:

    <bean id="mobileC3P0DataSource" lazy-init="true" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close" />
    <bean id="mobileDataSource" lazy-init="true" class="com.csi.util.PropertiesBasedC3P0DataSource">
        <property name="properties" ref="dataServicesProperties" />
        <property name="prefix" value="mobile" />
        <property name="comboPooledDataSource" ref="mobileC3P0DataSource" />
    </bean>
    <bean id="mobileHibernateSessionFactory" class="com.liferay.portal.spring.hibernate.PortletHibernateConfiguration">
        <property name="dataSource" ref="mobileDataSource" />
         <property name="hibernateProperties">
            <bean class="com.csi.util.PropertiesWrapper">
                <property name="typedProperties" ref="dataServicesProperties" />
                <property name="propertyPrefix" value="mobile" />
            </bean>
        </property>
    </bean>
    <bean id="mobileSessionFactory" class="com.liferay.portal.dao.orm.hibernate.PortletSessionFactoryImpl">
        <property name="dataSource" ref="mobileDataSource" />
        <property name="sessionFactoryClassLoader" ref="portletClassLoader" />
        <property name="sessionFactoryImplementor" ref="mobileHibernateSessionFactory" />
    </bean>


This is a basic set of beans for defining your own data source within the ext-spring.xml file. I've got a number of classes extending the Liferay classes so I can inject properties from a properties file (I don't like using EL injection because a missing property causes exceptions to be thrown), but otherwise it's not that different from the other examples you find on the web...
thumbnail
Jack Bakker, geändert vor 11 Jahren.

RE: Liferay 6.1 GA2 - ext-spring failed on external datasource

Liferay Master Beiträge: 978 Beitrittsdatum: 03.01.10 Neueste Beiträge
I use the same approach as David

one MVCPortlet for services ; and then various seperate Vaadin and other MVCPortlets

but now I am curious about Davids use of c3p0 for this and need to try it

David are u able to provide your dataServicesProperties references with the sensitive bits altered for the sake of the innocent ?
thumbnail
Christophe Cariou, geändert vor 11 Jahren.

RE: Liferay 6.1 GA2 - ext-spring failed on external datasource

Junior Member Beiträge: 57 Beitrittsdatum: 01.10.07 Neueste Beiträge
Thanks all.

I'm going to test this by cutting my plugin in two separates ones (portlet SB/MVC and portlet Vaadin)

I'll feedback when done.

Christophe
thumbnail
Jack Bakker, geändert vor 11 Jahren.

RE: Liferay 6.1 GA2 - ext-spring failed on external datasource

Liferay Master Beiträge: 978 Beitrittsdatum: 03.01.10 Neueste Beiträge
ah I see: CSI is Contact Solutions Inc. which is your company

so com.csi.util.PropertiesWrapper is yours ; ok, thanks
thumbnail
David H Nebinger, geändert vor 11 Jahren.

RE: Liferay 6.1 GA2 - ext-spring failed on external datasource

Liferay Legend Beiträge: 14914 Beitrittsdatum: 02.09.06 Neueste Beiträge
Jack Bakker:
ah I see: CSI is Contact Solutions Inc. which is your company

so com.csi.util.PropertiesWrapper is yours ; ok, thanks


Yeah, I actually have a bunch of external data sources that I use in my data services portlet, but only one properties file. I prefix the properties with a fixed string, i.e. "mobile", and my properties wrapper can return a fixed property name, i.e. "jdbc.url" that my standard implementation wants but will actually end up using the "mobile.jdbc.url" from the properties file.

This way I can have "mobile.jdbc.url" and "reporting.jdbc.url" in the properties file but my implementation classes don't specifically need to know about an exact property to look for...

Comes in quite handy, especially in cases like I have locally...
thumbnail
Christophe Cariou, geändert vor 11 Jahren.

RE: Liferay 6.1 GA2 - ext-spring failed on external datasource

Junior Member Beiträge: 57 Beitrittsdatum: 01.10.07 Neueste Beiträge
Yes : "Divide to conquer" was the good stragegy. Thank you.

I splitted my plugin in two separate ones :
- Portlet MVC with Service Builder inside
- Portlet Vaadin with UI.

My ext-spring.xml is shorted right now (will see if it needs some more stuff) and it works :

<!--?xml version="1.0" encoding="UTF-8"?-->

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" default-destroy-method="destroy" default-init-method="afterPropertiesSet" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

	<bean id="oberDataSource" lazy-init="true" class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy">
		<property name="targetDataSource">
			<bean class="com.liferay.portal.dao.jdbc.util.DataSourceFactoryBean">
				<property name="propertyPrefix" value="jdbc.ober." />
			</bean>
		</property>
	</bean>

	<bean id="oberHibernateSessionFactory" class="com.liferay.portal.spring.hibernate.PortletHibernateConfiguration">
		<property name="dataSource" ref="oberDataSource" />
	</bean>
	
	<bean id="oberSessionFactory" class="com.liferay.portal.dao.orm.hibernate.PortletSessionFactoryImpl">
        <property name="dataSource" ref="oberDataSource" />
        <property name="sessionFactoryClassLoader" ref="portletClassLoader" />
        <property name="sessionFactoryImplementor" ref="oberHibernateSessionFactory" />
    </bean>
	
</beans>


I also moved the service.jar of the service builded plugin to tomcat lib/ext.

Deployment of both plugins succeed and I can see that query reach the good datasource.

But, now I encounter some other trouble because my UI/Vaadin code was referencing modelImpl classes that I can reach.

Should I change my logic in order to not using this classes from my UI, and declaring new methods in my Services ?

For example, instead of using :
myLocalService.addObect(beanImpl)
using something like
myLocalService.addObject(property1, property2, ....)

Or can I copy my modelImpl classes from the ServiceBuilder plugin to the UI Plugin ?
thumbnail
Christophe Cariou, geändert vor 11 Jahren.

RE: Liferay 6.1 GA2 - ext-spring failed on external datasource

Junior Member Beiträge: 57 Beitrittsdatum: 01.10.07 Neueste Beiträge
Moreover, all the samples I found (even the one from official Liferay training) use the modelImpl classes... but I don't see how to respect this pattern when service and UI are in separates plugins (unless deploying my services as an ext-plugin perhaps...)
thumbnail
David H Nebinger, geändert vor 11 Jahren.

RE: Liferay 6.1 GA2 - ext-spring failed on external datasource

Liferay Legend Beiträge: 14914 Beitrittsdatum: 02.09.06 Neueste Beiträge
No, from the vaadin side you need to stick to the service jar.

So you'll use the XxxLocalServiceUtil static classes to access your entities.

So if you were using myLocalService.addObject() in your vaadin code, you'd now be using MyLocalServiceUtil.addObject().

This is different from what you'll do inside of your service implementation classes, where you will still use the myLocalService.addObject() just as you did before.
thumbnail
Christophe Cariou, geändert vor 11 Jahren.

RE: Liferay 6.1 GA2 - ext-spring failed on external datasource

Junior Member Beiträge: 57 Beitrittsdatum: 01.10.07 Neueste Beiträge
Excuse me, i mistyped my sample.

I'm agree with you. I use MyLocalServiceUtil service class in the Vaadin portlet (was already like that before I split in two plugins).

Now, my trouble is just that, before the separation, I was using ObjectImpl class as parameter for MyLocalServiceUtil methods. And now this class is no longer available (because not known in service.jar).

example, in some vaadin side code :

ObjectLocalServiceUtil.updateObject(object) where object has been instancied from ObjectImpl, that is a result of the service building for a final database item objectTable.


The way I'm going to solve this is to replace this client service call by a new one :

ObjectLocalServiceUtil.updateObject(arg1, arg2, arg3...) providing the service with all the necesssary datas to build an Object

and so, in ObjectLocalServiceUtilImpl I declare a new method :

updateObject (arg1, arg2.....)
{
  Object object = objectPersistence.create(counterLocalService.increment(Object.class.getName()));
  object.setArg1(arg1);
  object.setArg2(arg2);
   ... 
  objectPersistence.update(object)
}


and after regenerate all the stuff with service builder (Interfaces, service.jar...).

I'm just disappointed that I can't use the ObjectImpl classes. I'm forced to declare some POJOs in my vaadin portlet to transport my datas that are very similar to the ones generated by SBuilder.

But after looking Liferay sources, that's the way Liferay is made itself.... so it seems to be the correct way ...
...unless you have an alternative, giving the ability to reuse the Model stack generated by ServiceBuilder from client Portlet?

Anyway, thanks a lot David for your help.

Christophe
thumbnail
David H Nebinger, geändert vor 11 Jahren.

RE: Liferay 6.1 GA2 - ext-spring failed on external datasource

Liferay Legend Beiträge: 14914 Beitrittsdatum: 02.09.06 Neueste Beiträge
Okay, sorry for the disconnect, but here goes.

Let's start with a simple entity in your service.xml file:


<service-builder package-path="com.example">
    <namespace>TEST</namespace>
    <entity name="MyObject" local-service="true" remote-service="false">
        [...]
        <column name="name" type="String" />
        <column name="value" type="int" />
    </entity>
</service-builder>


When you build your services, you'll have a com.example.service.impl.MyObjectLocalServiceImpl class.

Let's say you want to create a utility function to add a new entity to the database. In the MyObjectLocalServiceImpl class, you'd add the following method:


public MyObject addObject(final String name, final int value) {
    // create a new instance
    MyObject obj = createMyObject(0);

    // set the values
    obj.setName(name);
    obj.setValue(value);

    // save and return the new instance
    return addMyObject(obj);
}


Note there is no MyObjectImpl classes in play here, you only want to stick to the interfaces.

Now you rebuild your services (so the new method is added).

Switching over to your vaadin code, when it comes time to do the add you can invoke the method as such:


    ...

    // find the values for name and value, i.e. from vaadin components you have

    // add the object
    MyObject obj = MyObjectLocalServiceUtil.addObject(name, value);

    // do whatever with the created instance


Again, here you're just coding against the service jar interfaces. You're not doing anything with MyObjectImpl classes in any way, shape, or form.

The key here is that you never use impl classes directly, not in service builder generated code, not in your vaadin code, not anywhere. You are always coding against the interfaces that are defined in the service jar. Period.
thumbnail
Christophe Cariou, geändert vor 11 Jahren.

RE: Liferay 6.1 GA2 - ext-spring failed on external datasource

Junior Member Beiträge: 57 Beitrittsdatum: 01.10.07 Neueste Beiträge
Thanks for the tuto.

We are agree and that's a way I'm going to do it.

Solved for me.

Christophe
thumbnail
Konstantin Chudinov, geändert vor 10 Jahren.

RE: Liferay 6.1 GA2 - ext-spring failed on external datasource

Junior Member Beiträge: 43 Beitrittsdatum: 23.04.13 Neueste Beiträge
fluently looked through this thread, i didn't find the solution... why spring doesn't see META-INF/portlet-hbm.xml?
thumbnail
David H Nebinger, geändert vor 10 Jahren.

RE: Liferay 6.1 GA2 - ext-spring failed on external datasource

Liferay Legend Beiträge: 14914 Beitrittsdatum: 02.09.06 Neueste Beiträge
Sure, Jack, but we have multiple portlets that use their own properties and sometimes the keys overlap.

Plus it's easier to deploy the project w/ properties contained within as we don't always trust our ops folks to correctly type in the values we need emoticon
thumbnail
Jack Bakker, geändert vor 10 Jahren.

RE: Liferay 6.1 GA2 - ext-spring failed on external datasource

Liferay Master Beiträge: 978 Beitrittsdatum: 03.01.10 Neueste Beiträge
woops, accidentally deleted my post..., copying it here from email

David, Have you thought of using something like the below to get from portal-ext.properties? (except for c3p0 properties ?)

String driverClassName = PropsUtil.get("jdbc.mydb.driverClassName");
String url = PropsUtil.get("jdbc.mydb.url");
String userName = PropsUtil.get("jdbc.mydb.username");
String password = PropsUtil.get("jdbc.mydb.password");

Also, where is your com.csi.util. package ? it isn't in a global classpath I hope...
thumbnail
David H Nebinger, geändert vor 10 Jahren.

RE: Liferay 6.1 GA2 - ext-spring failed on external datasource

Liferay Legend Beiträge: 14914 Beitrittsdatum: 02.09.06 Neueste Beiträge
Jack Bakker:
Also, where is your com.csi.util. package ? it isn't in a global classpath I hope...


No, it's not. We have a single jar that has home-made utility classes. The jar is deployed using an EXT plugin and pulled into projects that depend upon it using the liferay-plugin-package.properties file...
thumbnail
Jack Bakker, geändert vor 10 Jahren.

RE: Liferay 6.1 GA2 - ext-spring failed on external datasource

Liferay Master Beiträge: 978 Beitrittsdatum: 03.01.10 Neueste Beiträge
Drawing on several sources, here is an approach connecting to a second database:

ext-spring.xml

<!--?xml version="1.0"?-->
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
 
	<aop:config>
		<aop:pointcut id="transactionOperation" expression="bean(*Service.impl)" />
		<aop:advisor advice-ref="transactionAdvice" pointcut-ref="transactionOperation" />
	</aop:config>
	
	<bean id="basePersistence" abstract="true">
		<property name="dataSource" ref="mydbDataSource" />
		<property name="sessionFactory" ref="mydbSessionFactory" />
	</bean>
	
	<bean id="transactionAdvice" class="com.liferay.portal.kernel.spring.util.SpringFactoryUtil" factory-method="newBean">
		<constructor-arg value="com.liferay.portal.spring.transaction.TransactionInterceptor" />
		<constructor-arg>
			<map>
				<entry key="platformTransactionManager" value-ref="mydbTransactionManager" />
				<entry key="transactionAttributeSource" value-ref="transactionAttributeSource" />
			</map>
		</constructor-arg>
	</bean>
	

	
	<bean id="mydbHibernateSessionFactory" class="com.liferay.portal.kernel.spring.util.SpringFactoryUtil" factory-method="newBean">
		<constructor-arg value="com.liferay.portal.spring.hibernate.PortletHibernateConfiguration" />
		<constructor-arg>
			<map>
				<entry key="dataSource" value-ref="mydbDataSource" />
			</map>
		</constructor-arg>
	</bean>
	<bean id="mydbSessionFactory" class="com.liferay.portal.kernel.spring.util.SpringFactoryUtil" factory-method="newBean">
		<constructor-arg value="com.liferay.portal.dao.orm.hibernate.PortletSessionFactoryImpl" />
		<constructor-arg>
			<map>
				<entry key="dataSource" value-ref="mydbDataSource" />
				<entry key="sessionFactoryClassLoader" value-ref="portletClassLoader" />
				<entry key="sessionFactoryImplementor" value-ref="mydbHibernateSessionFactory" />
			</map>
		</constructor-arg>
	</bean>
	<bean id="mydbTransactionManager" class="com.liferay.portal.kernel.util.InfrastructureUtil" factory-method="getTransactionManager" />
	
	
    <bean id="mydbDataSource" class="ca.iable.util.PropertiesBasedDataSource" factory-method="getDataSource">
    	<constructor-arg value="jdbc.mydb." />  
    </bean>	
    
</beans>


service.xml

<!--?xml version="1.0" encoding="UTF-8"?-->

<service-builder package-path="ca.iable.services">
	<author>jbakker</author>
	<namespace>services</namespace>

	<entity name="Global" table="global" data-source="mydbDataSource" local-service="true" remote-service="true" session-factory="mydbSessionFactory" tx-manager="mydbTransactionManager">

		<!-- PK fields -->

		<column name="global_id" db-name="global_id" type="int" primary="true" id-type="sequence" id-param="global_id_seq" />

		<!-- Other fields -->

		<column name="name" type="String" />
		<column name="value" type="String" />

		<finder name="Name" return-type="Global" unique="true">
			<finder-column name="name" />
		</finder>
	</entity>
	
	<entity name="Subscribe" table="subscribe" data-source="mydbDataSource" local-service="true" remote-service="true" session-factory="mydbSessionFactory" tx-manager="mydbTransactionManager">

		<!-- PK fields -->

		<column name="subscribe_id" db-name="subscribe_id" type="int" primary="true" id-type="sequence" id-param="subscribe_id_seq" />
		
		<column name="crea_ts" db-name="crea_ts" type="Date" />
		<column name="modi_ts" db-name="modi_ts" type="Date" />
		<!-- Other fields -->

		<column name="email" type="String" />
		<column name="source" type="String" />

		<finder name="Email" return-type="Subscribe" unique="true">
			<finder-column name="email" />
		</finder>
	</entity>
	
</service-builder>


PropertiesBasedDataSource.java

package ca.iable.util;

import com.liferay.portal.kernel.dao.jdbc.DataSourceFactoryUtil;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.PropsUtil;
import javax.sql.DataSource;

public class PropertiesBasedDataSource {

	private PropertiesBasedDataSource() {
	};

	public static DataSource getDataSource(String propertyPrefix) {
		String driverClassName = PropsUtil.get(propertyPrefix
				+ "driverClassName");
		String url = PropsUtil.get(propertyPrefix + "url");
		String userName = PropsUtil.get(propertyPrefix + "username");
		String password = PropsUtil.get(propertyPrefix + "password");

		DataSource _dataSource = null;
		try {
			_dataSource = DataSourceFactoryUtil.initDataSource(driverClassName,
					url, userName, password);
		} catch (Exception e) {
			_log.error("unable to get datasource using prefix "
					+ propertyPrefix + " in portal-ext.properties");
		}
		return _dataSource;
	}

	private static Log _log = LogFactoryUtil
			.getLog(PropertiesBasedDataSource.class);

}


portal-ext.properties

jdbc.default.driverClassName=org.postgresql.Driver
jdbc.default.url=jdbc:postgresql://db.iable.ca/lportal_iable61?
useUnicode=true&amp;characterEncoding=UTF-8
jdbc.default.username=lportal_user
jdbc.default.password=mypassword

jdbc.mydb.driverClassName=org.postgresql.Driver
jdbc.mydb.url=jdbc:postgresql://db.iable.ca/mydb?
useUnicode=true&amp;characterEncoding=UTF-8
jdbc.mydb.username=lportal_user
jdbc.mydb.password=mypassword
thumbnail
David H Nebinger, geändert vor 10 Jahren.

RE: Liferay 6.1 GA2 - ext-spring failed on external datasource

Liferay Legend Beiträge: 14914 Beitrittsdatum: 02.09.06 Neueste Beiträge
Jack Bakker:
portal-ext.properties

jdbc.default.driverClassName=org.postgresql.Driver
jdbc.default.url=jdbc:postgresql://db.iable.ca/lportal_iable61?useUnicode=true&amp;characterEncoding=UTF-8
jdbc.default.username=lportal_user
jdbc.default.password=mypassword

jdbc.mydb.driverClassName=org.postgresql.Driver
jdbc.mydb.url=jdbc:postgresql://db.iable.ca/mydb?useUnicode=true&amp;characterEncoding=UTF-8
jdbc.mydb.username=lportal_user
jdbc.mydb.password=mypassword


Okay, this is a general difference that we have, but no big deal...

I prefer to keep the liferay system properties (the ones in portal-ext.properties) just for liferay needs. For our own custom portlets that require properties, I prefer that they are maintained outside of the liferay properties as completely separate entities.

This is probably due to paranoia on my part, but once I have a working portal-ext.properties file I don't want anyone tampering it for any reason. If you get a new developer that creates a new portlet using a 'new' property, say "upgrade.processes" and gets the value put into portal-ext.properties the Liferay environment breaks...

Using isolated properties files, the developer's new portlet just works and the Liferay environment doesn't get a faulty overridden value of "upgrade.processes"...
thumbnail
Jack Bakker, geändert vor 10 Jahren.

RE: Liferay 6.1 GA2 - ext-spring failed on external datasource

Liferay Master Beiträge: 978 Beitrittsdatum: 03.01.10 Neueste Beiträge
I hope my post will help other small-fries like me and I learned a lot digging through Liferay source and the META-INF/*.xml files generated from service builder but still need to look at c3p0 properties like you have already done to introduce

approach to what is global and what is portletLocal or portletSetLocal will be an ongoing I think ; bundles ?