Kombinierte Ansicht Flache Ansicht Baumansicht
Threads [ Zurück | Nächste ]
toggle
Using Service-Builder Entities without creating Database Tables Prakash Khanchandani 13. Januar 2012 03:04
RE: Using Service-Builder Entities without creating Database Tables Prakash Khanchandani 16. Januar 2012 02:24
RE: Using Service-Builder Entities without creating Database Tables Gerald Rubin 16. Januar 2012 04:48
RE: Using Service-Builder Entities without creating Database Tables Prakash Khanchandani 16. Januar 2012 20:58
RE: Using Service-Builder Entities without creating Database Tables Gerald Rubin 17. Januar 2012 02:45
RE: Using Service-Builder Entities without creating Database Tables Remis Lima Baima 14. September 2012 05:17
RE: Using Service-Builder Entities without creating Database Tables David H Nebinger 28. November 2012 19:02
RE: Using Service-Builder Entities without creating Database Tables Riccardo Rotondo 14. Mai 2013 10:33
RE: Using Service-Builder Entities without creating Database Tables David H Nebinger 14. Mai 2013 10:39
RE: Using Service-Builder Entities without creating Database Tables Riccardo Rotondo 15. Mai 2013 09:44
RE: Using Service-Builder Entities without creating Database Tables David H Nebinger 15. Mai 2013 09:45
RE: Using Service-Builder Entities without creating Database Tables Jack Bakker 24. September 2013 11:33
RE: Using Service-Builder Entities without creating Database Tables David H Nebinger 24. September 2013 12:06
RE: Using Service-Builder Entities without creating Database Tables Jack Bakker 1. Oktober 2013 21:12
RE: Using Service-Builder Entities without creating Database Tables David H Nebinger 25. September 2013 08:11
RE: Using Service-Builder Entities without creating Database Tables Jack Bakker 25. September 2013 11:12
RE: Using Service-Builder Entities without creating Database Tables David H Nebinger 26. September 2013 19:38
RE: Using Service-Builder Entities without creating Database Tables Jack Bakker 28. September 2013 11:41
RE: Using Service-Builder Entities without creating Database Tables David H Nebinger 29. September 2013 07:48
RE: Using Service-Builder Entities without creating Database Tables Jack Bakker 29. September 2013 17:18
RE: Using Service-Builder Entities without creating Database Tables David H Nebinger 30. September 2013 05:20
RE: Using Service-Builder Entities without creating Database Tables Jack Bakker 1. Oktober 2013 21:11
RE: Using Service-Builder Entities without creating Database Tables David H Nebinger 1. Oktober 2013 19:11
RE: Using Service-Builder Entities without creating Database Tables Jack Bakker 2. Oktober 2013 16:54
RE: Using Service-Builder Entities without creating Database Tables David H Nebinger 2. Oktober 2013 19:12
RE: Using Service-Builder Entities without creating Database Tables Jack Bakker 3. Oktober 2013 12:07
RE: Using Service-Builder Entities without creating Database Tables Riccardo Rotondo 22. November 2013 04:37
RE: Using Service-Builder Entities without creating Database Tables David H Nebinger 22. November 2013 06:01
RE: Using Service-Builder Entities without creating Database Tables Marco Fargetta 25. November 2013 03:17
Prakash Khanchandani
Using Service-Builder Entities without creating Database Tables
13. Januar 2012 03:04
Antwort

Prakash Khanchandani

Rang: Expert

Nachrichten: 258

Eintrittsdatum: 10. Februar 2011

Neue Beiträge

The subject may sound like the thread here: Service Builder with non-DB data source , but its not the same.

Here is how it differs:
When I create the entities in service.xml without any <column> tag, it generates all the localService and service classes but it does not generate any model.

My question is how do I generate an entity with all the properties specified in the service.xml but not create a database table when I deploy the portlet.

I want to use the entity as a return type to my method calls, and also will use it as a web-service returning the entity.

Is it possible?

So in short the question could be asked like this:
Can I build a web-service using service-builder which returns a custom object/entity instead of the model entity?
or
Can I build a web-service using service-builder which returns the model entity but does not create a Database table for the entity?

Your help will be very much appreciated.

Thanks for helping.
Prakash Khanchandani
RE: Using Service-Builder Entities without creating Database Tables
16. Januar 2012 02:24
Antwort

Prakash Khanchandani

Rang: Expert

Nachrichten: 258

Eintrittsdatum: 10. Februar 2011

Neue Beiträge

Will this be possible?

Any suggestions or any hints in this direction?

Thank you
Gerald Rubin
RE: Using Service-Builder Entities without creating Database Tables
16. Januar 2012 04:48
Antwort

Gerald Rubin

Rang: Junior Member

Nachrichten: 59

Eintrittsdatum: 23. Oktober 2011

Neue Beiträge

You may have to build the table once, but you can delete them and avoid re-building them when you update service.xml.

After the first deploy, look at the servicecomponent table in your database. You will find a row for your service's namespace and a buildNumber. It will most likely be 1.

Open service.properties under docroot/WEB-INF/src and make sure that this is at the top
1    #
2    # Specify where to get the overridden properties. Updates should not be made
3    # on this file but on the overridden version of this file.
4    #
5    include-and-override=${base.path}/service-ext.properties


It might be there already. If you don't have a service-ext.properties file just above service.properties in Package Explorer (Eclipse assumed), create one. Put in one line:
1    build.number=1


Never increment it and, for good measure, keep build.number=1 in service.properties.

You should be good.
Prakash Khanchandani
RE: Using Service-Builder Entities without creating Database Tables
16. Januar 2012 20:58
Antwort

Prakash Khanchandani

Rang: Expert

Nachrichten: 258

Eintrittsdatum: 10. Februar 2011

Neue Beiträge

Thanks a lot Gerald.

It works.

It seems the right way to go, but just a little question: For the deployments after this, would the updates work correctly? (I suppose they should, not encountered any problems till now, but still just to confirm)

Thanks again.
Gerald Rubin
RE: Using Service-Builder Entities without creating Database Tables
17. Januar 2012 02:45
Antwort

Gerald Rubin

Rang: Junior Member

Nachrichten: 59

Eintrittsdatum: 23. Oktober 2011

Neue Beiträge

Yes, the updates would work correctly. If you're using the service.jar from any other portlets, you'll want to deploy, stop Tomcat, move the xxx-service.jar from the /lib folder in your portlet to tomcat/lib/ext and add it in that location to all build classpaths from other portlets. Then, of course, restart Tomcat.

See, one Junior Member can help another!
Remis Lima Baima
RE: Using Service-Builder Entities without creating Database Tables
14. September 2012 05:17
Antwort

Remis Lima Baima

Rang: New Member

Nachrichten: 8

Eintrittsdatum: 5. November 2010

Neue Beiträge

We have a similar use case:
- We have N plugins that need the same POJO (e.g. Foo).
- So we simply created the POJO and copy-and-paste to all N plugins.
- But we thought: "hey... this is a lot of duplicated code" (i.e. very bad :-)
- We had the idea to use the ServiceBuilder (SB ) to create this POJO in a base plugin and reference it in all other N plugins that needed to use this POJO (similar to what we do with SB shared services).
- So we defined the POJO in service.xml and let SB auto-generate the POJO for us.
- The problem is that SB always generates a DB table and we do not need/want one.
- This is why we need a way to avoid the SB to generate the DB tables.

Then we found a way to trick SB in not creating the DB tables, but we decided to not use it as it is not an official feature supported by Liferay (we use the EE version) and we want to avoid problems in a future migration.
But anyway, the trick is:
- In service.xml specify a data-source for your entity e.g.:
<entity name="Foo" local-service="false" remote-service="false" data-source="no_data_source">
<column name="fooId" type="long" primary="true" />
<column name="companyId" type="long" />
<column name="userId" type="long" />
<column name="userName" type="String" />
</entity>

-In your ext-spring.xml add:
<bean id="no_data_source" class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy">
<property name="targetDataSource">
<ref bean="liferayDataSource" />
</property>
</bean>
David H Nebinger
RE: Using Service-Builder Entities without creating Database Tables
28. November 2012 19:02
Antwort

David H Nebinger

Rang: Liferay Legend

Nachrichten: 7238

Eintrittsdatum: 1. September 2006

Neue Beiträge

Actually, I think another alternative (aside from the lazy data source), would be to set up a datasource using HSQL or some other in-memory-only data source.

That way, in case some unknowning developer actually calls one of the CRUD routines, you wouldn't have to worry about the table actually getting created. And if the table wasn't created, you're still able to use your entities as you had started.
Riccardo Rotondo
RE: Using Service-Builder Entities without creating Database Tables
14. Mai 2013 10:33
Antwort

Riccardo Rotondo

Rang: Junior Member

Nachrichten: 28

Eintrittsdatum: 11. Juni 2010

Neue Beiträge

Dear all,

the problem I'm facing is similar. I'm trying to write a method returning a complex object. For complex object I mean an object that represents two entities. For this reasons I created a fake entity referring to the existing one.

 1
 2<entity name="File"  local-service="true" remote-service="false">
 3        <column name="fileId" type="long" primary="true" id-type="increment"/>
 4        <column name="name" type="String" />
 5        <column name="userId" type="long" />
 6        <column name="size" type="long" />
 7        <column name="date" type="Date" /> 
 8        <column name="virtualPaths" type="Collection" entity="VirtualPath"
 9                mapping-table="Files_VirtualPaths" /> 
10        <column name="storageURLs" type="Collection" entity="StorageURLs"
11                mapping-key="fileId" /> 
12        <column name="tags" type="Collection" entity="Tag"
13                mapping-table="Files_Tags" />
14        <order by="asc">
15            <order-column name="name" />
16        </order>
17    </entity>
18
19<entity name="VirtualPath"  local-service="true" remote-service="false">
20        <column name="vpId" type="long" primary="true" id-type="increment"/>
21        <column name="vp" type="String" />
22        <column name="userId" type="long" />
23        <column name="date" type="Date" /> 
24        <column name="files" type="Collection" entity="File"
25                mapping-table="Files_VirtualPaths" />
26        <order by="asc">
27            <order-column name="userId" />
28            <order-column name="vp" />
29        </order>   
30        <finder name="VP_userId" return-type="VirtualPath">
31            <finder-column name="vp" />
32            <finder-column name="userId" />
33        </finder>
34    </entity>
35
36<entity name="DirectoryElement" local-service="true" remote-service="false"
37            data-source="noDataSource">
38        <column name="id" type="long" primary="true"/>
39        <column name="VirutalPathElement" type="Collection" entity="VirtualPath"
40                mapping-key="vpId"/>
41    <column name="FileElement" type="Collection" entity="File"
42                mapping-table="VirtualPath_DirectoryElement_noDataSource"/>
43    </entity>


That's becuase I want File and VirtualPath mapped on the database, DirectoryElement not. The build services works properly. The deploy no. Probably because I didn't define any "noDataSource" in the ext-spring.xml. By the way where I should create it? In the same folder of service.xml??

Plus, I liked so much David suggestion of use a memory-only-data source. Please could you be more explicit about that? How should I define it?

Thank you very much for your precious help.

Regards,

Riccardo
David H Nebinger
RE: Using Service-Builder Entities without creating Database Tables
14. Mai 2013 10:39
Antwort

David H Nebinger

Rang: Liferay Legend

Nachrichten: 7238

Eintrittsdatum: 1. September 2006

Neue Beiträge

Riccardo Rotondo:
Probably because I didn't define any "noDataSource" in the ext-spring.xml. By the way where I should create it? In the same folder of service.xml??


Nope, it goes into the META-INF\ext-spring.xml and follows the following pattern:

1<bean id="noDataSource" class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy">
2  <property name="targetDataSource" ref="liferayDataSource" />
3</bean>


Plus, I liked so much David suggestion of use a memory-only-data source. Please could you be more explicit about that? How should I define it?


Just like you'd define any datasource. You can use HSQL for the driver, an appropriate jdbc url, etc. These would also be defined in META-INF/ext-spring.xml, but along with the data source definition you also need to define a com.liferay.portal.spring.hibernate.PortletHibernateConfiguration bean and a com.liferay.portal.dao.orm.hibernate.PortletSessionFactoryImpl bean.
Riccardo Rotondo
RE: Using Service-Builder Entities without creating Database Tables
15. Mai 2013 09:44
Antwort

Riccardo Rotondo

Rang: Junior Member

Nachrichten: 28

Eintrittsdatum: 11. Juni 2010

Neue Beiträge

Dear David,

thank you for your quick helpful reply.

Right now I'm facing another issue. Despite fake-entities works file with "simple" type (such as long or string) I got sever errors in building the service once I specify a collection as follows:

1
2<column name="VirutalPathElement" type="Collection" entity="VirtualPath"
3                mapping-table="VirtualPath_DirectoryElement_noDataSource"/>


Once I specify type Collection the built of the VirtualPath and other entities fail.

 1
 2Method public java.util.List com.liferay.portal.tools.servicebuilder.ServiceBuilder.getMappingEntities(java.lang.String) throws java.io.IOException threw an exception when invoked on com.liferay.portal.tools.servicebuilder.ServiceBuilder@5b09062e
 3The problematic instruction:
 4----------
 5==> list serviceBuilder.getMappingEntities(column.mappingTable) as mapColumn [on line 260, column 41 in com/liferay/portal/tools/servicebuilder/dependencies/model_impl.ftl]
 6----------
 7
 8Java backtrace for programmers:
 9----------
10freemarker.template.TemplateModelException: Method public java.util.List com.liferay.portal.tools.servicebuilder.ServiceBuilder.getMappingEntities(java.lang.String) throws java.io.IOException threw an exception when invoked on com.liferay.portal.tools.servicebuilder.ServiceBuilder@5b09062e
11    at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:130)
12    at freemarker.core.MethodCall._getAsTemplateModel(MethodCall.java:93)
13    at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
14    at freemarker.core.IteratorBlock.accept(IteratorBlock.java:94)
15    at freemarker.core.Environment.visit(Environment.java:221)
16    at freemarker.core.MixedContent.accept(MixedContent.java:92)
17    at freemarker.core.Environment.visit(Environment.java:221)
18    at freemarker.core.Environment.visit(Environment.java:310)
19    at freemarker.core.CompressedBlock.accept(CompressedBlock.java:73)
20    at freemarker.core.Environment.visit(Environment.java:221)
21    at freemarker.core.MixedContent.accept(MixedContent.java:92)
22    at freemarker.core.Environment.visit(Environment.java:221)
23    at freemarker.core.ConditionalBlock.accept(ConditionalBlock.java:79)
24    at freemarker.core.Environment.visit(Environment.java:221)
25    at freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:179)
26    at freemarker.core.Environment.visit(Environment.java:428)
27    at freemarker.core.IteratorBlock.accept(IteratorBlock.java:102)
28    at freemarker.core.Environment.visit(Environment.java:221)
29    at freemarker.core.MixedContent.accept(MixedContent.java:92)
30    at freemarker.core.Environment.visit(Environment.java:221)
31    at freemarker.core.Environment.process(Environment.java:199)
32    at freemarker.template.Template.process(Template.java:237)
33    at com.liferay.portal.freemarker.FreeMarkerUtil.process(FreeMarkerUtil.java:47)
34    at com.liferay.portal.freemarker.FreeMarkerUtil.process(FreeMarkerUtil.java:37)
35    at com.liferay.portal.tools.servicebuilder.ServiceBuilder._processTemplate(ServiceBuilder.java:4983)
36    at com.liferay.portal.tools.servicebuilder.ServiceBuilder._createModelImpl(ServiceBuilder.java:2293)
37    at com.liferay.portal.tools.servicebuilder.ServiceBuilder.<init>(ServiceBuilder.java:671)
38    at com.liferay.portal.tools.servicebuilder.ServiceBuilder.main(ServiceBuilder.java:151)
39Caused by: java.lang.NullPointerException
40    at com.liferay.portal.tools.servicebuilder.ServiceBuilder.getMappingEntities(ServiceBuilder.java:1048)
41    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
42    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
43    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
44    at java.lang.reflect.Method.invoke(Method.java:597)
45    at freemarker.ext.beans.BeansWrapper.invokeMethod(BeansWrapper.java:866)
46    at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:106)
47    ... 27 more


Is there any way to use collection with noDataSource entities? Maybe a list or an array?

Thanks in advance for helping.

Regards,

Riccardo
David H Nebinger
RE: Using Service-Builder Entities without creating Database Tables
15. Mai 2013 09:45
Antwort

David H Nebinger

Rang: Liferay Legend

Nachrichten: 7238

Eintrittsdatum: 1. September 2006

Neue Beiträge

The fake entities are still constrained by the types supported by SB, and Collection is not one of those.
David H Nebinger
RE: Using Service-Builder Entities without creating Database Tables
27. Mai 2013 20:41
Antwort

David H Nebinger

Rang: Liferay Legend

Nachrichten: 7238

Eintrittsdatum: 1. September 2006

Neue Beiträge

You can define all of the connections in ext-spring.xml, then each entity would include the appropriate datasource in it's definition.

You can edit the hints file to make the change to use different types/sizes within the constraints of what hibernate will support.
Jack Bakker
RE: Using Service-Builder Entities without creating Database Tables
24. September 2013 11:33
Antwort

Jack Bakker

Rang: Liferay Master

Nachrichten: 630

Eintrittsdatum: 3. Januar 2010

Neue Beiträge

in v6.1 I get a

Caused by: java.lang.ClassNotFoundException: org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy

when using in ext-spring.xml

<bean id="noDataSource" class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy">
<property name="targetDataSource" ref="liferayDataSource" />
</bean>
David H Nebinger
RE: Using Service-Builder Entities without creating Database Tables
24. September 2013 12:06
Antwort

David H Nebinger

Rang: Liferay Legend

Nachrichten: 7238

Eintrittsdatum: 1. September 2006

Neue Beiträge

Be sure to include spring-jdbc.jar as a dependent jar for your project.
Jack Bakker
RE: Using Service-Builder Entities without creating Database Tables
1. Oktober 2013 21:12
Antwort

Jack Bakker

Rang: Liferay Master

Nachrichten: 630

Eintrittsdatum: 3. Januar 2010

Neue Beiträge

I previously posted the below in another forum post ; not sure if it is ethical to repost like this, but I thought I'd save people lookup time. As per below, I'd like to avoid including any spring jars and use built in liferay utils to create a nodatasource.



Drawing on several sources, here is an approach connecting to a second database:

ext-spring.xml
 1
 2<?xml version="1.0"?>
 3<beans xmlns="http://www.springframework.org/schema/beans"
 4    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
 5    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 6    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">
 7
 8    <aop:config>
 9        <aop:pointcut id="transactionOperation" expression="bean(*Service.impl)" />
10        <aop:advisor advice-ref="transactionAdvice" pointcut-ref="transactionOperation" />
11    </aop:config>
12   
13    <bean id="basePersistence" abstract="true">
14        <property name="dataSource" ref="mydbDataSource" />
15        <property name="sessionFactory" ref="mydbSessionFactory" />
16    </bean>
17   
18    <bean id="transactionAdvice" class="com.liferay.portal.kernel.spring.util.SpringFactoryUtil" factory-method="newBean">
19        <constructor-arg value="com.liferay.portal.spring.transaction.TransactionInterceptor" />
20        <constructor-arg>
21            <map>
22                <entry key="platformTransactionManager" value-ref="mydbTransactionManager" />
23                <entry key="transactionAttributeSource" value-ref="transactionAttributeSource" />
24            </map>
25        </constructor-arg>
26    </bean>
27   
28
29   
30    <bean id="mydbHibernateSessionFactory" class="com.liferay.portal.kernel.spring.util.SpringFactoryUtil" factory-method="newBean">
31        <constructor-arg value="com.liferay.portal.spring.hibernate.PortletHibernateConfiguration" />
32        <constructor-arg>
33            <map>
34                <entry key="dataSource" value-ref="mydbDataSource" />
35            </map>
36        </constructor-arg>
37    </bean>
38    <bean id="mydbSessionFactory" class="com.liferay.portal.kernel.spring.util.SpringFactoryUtil" factory-method="newBean">
39        <constructor-arg value="com.liferay.portal.dao.orm.hibernate.PortletSessionFactoryImpl" />
40        <constructor-arg>
41            <map>
42                <entry key="dataSource" value-ref="mydbDataSource" />
43                <entry key="sessionFactoryClassLoader" value-ref="portletClassLoader" />
44                <entry key="sessionFactoryImplementor" value-ref="mydbHibernateSessionFactory" />
45            </map>
46        </constructor-arg>
47    </bean>
48    <bean id="mydbTransactionManager" class="com.liferay.portal.kernel.util.InfrastructureUtil" factory-method="getTransactionManager" />
49   
50   
51    <bean id="mydbDataSource" class="ca.iable.util.PropertiesBasedDataSource" factory-method="getDataSource">
52        <constructor-arg value="jdbc.mydb."/> 
53    </bean>   
54   
55</beans>


service.xml
 1
 2<?xml version="1.0" encoding="UTF-8"?>
 3<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.1.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_1_0.dtd">
 4<service-builder package-path="ca.iable.services">
 5    <author>jbakker</author>
 6    <namespace>services</namespace>
 7
 8    <entity name="Global" table="global" data-source="mydbDataSource"
 9        local-service="true" remote-service="true" session-factory="mydbSessionFactory"
10        tx-manager="mydbTransactionManager">
11
12        <!-- PK fields -->
13
14        <column name="global_id" db-name="global_id" type="int"
15            primary="true" id-type="sequence" id-param="global_id_seq" />
16
17        <!-- Other fields -->
18
19        <column name="name" type="String" />
20        <column name="value" type="String" />
21
22        <finder name="Name" return-type="Global" unique="true">
23            <finder-column name="name" />
24        </finder>
25    </entity>
26   
27    <entity name="Subscribe" table="subscribe" data-source="mydbDataSource"
28        local-service="true" remote-service="true" session-factory="mydbSessionFactory"
29        tx-manager="mydbTransactionManager">
30
31        <!-- PK fields -->
32
33        <column name="subscribe_id" db-name="subscribe_id" type="int"
34            primary="true" id-type="sequence" id-param="subscribe_id_seq" />
35       
36        <column name="crea_ts" db-name="crea_ts" type="Date" />
37        <column name="modi_ts" db-name="modi_ts" type="Date" />
38        <!-- Other fields -->
39
40        <column name="email" type="String" />
41        <column name="source" type="String" />
42
43        <finder name="Email" return-type="Subscribe" unique="true">
44            <finder-column name="email" />
45        </finder>
46    </entity>
47   
48</service-builder>


PropertiesBasedDataSource.java
 1
 2package ca.iable.util;
 3
 4import com.liferay.portal.kernel.dao.jdbc.DataSourceFactoryUtil;
 5import com.liferay.portal.kernel.log.Log;
 6import com.liferay.portal.kernel.log.LogFactoryUtil;
 7import com.liferay.portal.kernel.util.PropsUtil;
 8import javax.sql.DataSource;
 9
10public class PropertiesBasedDataSource {
11
12    public PropertiesBasedDataSource() {
13    };
14
15    public static DataSource getDataSource(String propertyPrefix) {
16        String driverClassName = PropsUtil.get(propertyPrefix
17                + "driverClassName");
18        String url = PropsUtil.get(propertyPrefix + "url");
19        String userName = PropsUtil.get(propertyPrefix + "username");
20        String password = PropsUtil.get(propertyPrefix + "password");
21
22        DataSource _dataSource = null;
23        try {
24            _dataSource = DataSourceFactoryUtil.initDataSource(driverClassName,
25                    url, userName, password);
26        } catch (Exception e) {
27            _log.error("unable to get datasource using prefix "
28                    + propertyPrefix + " in portal-ext.properties");
29        }
30        return _dataSource;
31    }
32
33    private static Log _log = LogFactoryUtil
34            .getLog(PropertiesBasedDataSource.class);
35
36}


portal-ext.properties
 1
 2jdbc.default.driverClassName=org.postgresql.Driver
 3jdbc.default.url=jdbc:postgresql://db.iable.ca/lportal_iable61?
 4useUnicode=true&amp;characterEncoding=UTF-8
 5jdbc.default.username=lportal_user
 6jdbc.default.password=mypassword
 7
 8jdbc.mydb.driverClassName=org.postgresql.Driver
 9jdbc.mydb.url=jdbc:postgresql://db.iable.ca/mydb?
10useUnicode=true&amp;characterEncoding=UTF-8
11jdbc.mydb.username=lportal_user
12jdbc.mydb.password=mypassword
David H Nebinger
RE: Using Service-Builder Entities without creating Database Tables
25. September 2013 08:11
Antwort

David H Nebinger

Rang: Liferay Legend

Nachrichten: 7238

Eintrittsdatum: 1. September 2006

Neue Beiträge

I think reposting is fine, Jack.

Seems like so much extra work to get a fake db connection, where the lazy connection and a spring-jdbc jar is much lighter weight...
Jack Bakker
RE: Using Service-Builder Entities without creating Database Tables
25. September 2013 11:12
Antwort

Jack Bakker

Rang: Liferay Master

Nachrichten: 630

Eintrittsdatum: 3. Januar 2010

Neue Beiträge

my post for 2nd database works like a charm

adding only spring-jdbc.jar throws additional spring errors in v6.1
David H Nebinger
RE: Using Service-Builder Entities without creating Database Tables
26. September 2013 19:38
Antwort

David H Nebinger

Rang: Liferay Legend

Nachrichten: 7238

Eintrittsdatum: 1. September 2006

Neue Beiträge

Eh, additional dependencies may be necessary. But I'm glad it's working either way.

The fake entity approach is a good one and any solution is one worth trying!
Jack Bakker
RE: Using Service-Builder Entities without creating Database Tables
28. September 2013 11:41
Antwort

Jack Bakker

Rang: Liferay Master

Nachrichten: 630

Eintrittsdatum: 3. Januar 2010

Neue Beiträge

just to be clear, while I do have a 2nd database working per my repost here in this thread, I still am attempting ... for a fake data source ... to avoid direct references to Spring in ext-spring.xml ... as I follow what I see Liferay doing via the other META-INF/*.xml files
David H Nebinger
RE: Using Service-Builder Entities without creating Database Tables
29. September 2013 07:48
Antwort

David H Nebinger

Rang: Liferay Legend

Nachrichten: 7238

Eintrittsdatum: 1. September 2006

Neue Beiträge

Sorry? Didn't really follow you there, "avoid direct references to Spring in ext-spring.xml"? As a Spring config file, how can you avoid direct references?
Jack Bakker
RE: Using Service-Builder Entities without creating Database Tables
29. September 2013 17:18
Antwort

Jack Bakker

Rang: Liferay Master

Nachrichten: 630

Eintrittsdatum: 3. Januar 2010

Neue Beiträge

I should have been more clear..

In v6.1.1, if you look at the various xml files in /src/META-INF for a service portlet, you'll see beans with classes in com.liferay.* packages like:

class="com.liferay.portal.kernel.spring.util.SpringFactoryUtil"

not with classes directly referencing org.springframework.* packages like:

class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy"

my example in this thread shows how I avoid org.springframework.* references while still accessing a 2nd database
David H Nebinger
RE: Using Service-Builder Entities without creating Database Tables
30. September 2013 05:20
Antwort

David H Nebinger

Rang: Liferay Legend

Nachrichten: 7238

Eintrittsdatum: 1. September 2006

Neue Beiträge

Hmm, I've never shared that concern. For me, a LazyConnectionDataSourceProxy is an ideal class to use.

Frankly, Liferay has so many classes w/ so little (if any) documentation, I'd almost rather use a non-Liferay class where I can.

Then there's the update thing - the Spring classes never seem to go away. I've been bitten a couple of times using a Liferay class that gets deprecated or dropped or significantly changed when the next release comes out; with a Spring implementation, I don't have to worry about this issue.

At the end of the day, it's all wired together using Spring so using a Spring class or a Liferay class doesn't seem to matter so much.
Jack Bakker
RE: Using Service-Builder Entities without creating Database Tables
1. Oktober 2013 21:11
Antwort

Jack Bakker

Rang: Liferay Master

Nachrichten: 630

Eintrittsdatum: 3. Januar 2010

Neue Beiträge

this seems to work:

-- in ext-spring.xml ---

1<bean id="noDataSource" class="my.util.NoDataSource" factory-method="getDataSource">
2</bean>


-- add to service portlet src: my.util.NoDataSource.java --

 1
 2package my.util;
 3import com.liferay.portal.kernel.log.Log;
 4import com.liferay.portal.kernel.log.LogFactoryUtil;
 5import javax.sql.DataSource;
 6
 7public class NoDataSource {
 8    public NoDataSource() {
 9    };
10    public static DataSource getDataSource() {   
11        return null;
12    }
13    private static Log _log = LogFactoryUtil
14            .getLog(NoDataSource.class);
15}


(note the need for suitable logging, as returning null might go wrong emoticon

-- add to service.xml something like the following fake entity --

1<entity name="FakeEntity"  local-service="true" remote-service="false" data-source="noDataSource">
2        <column name="fakeEntityId" type="long" primary="true" id-type="increment"/>
3        <column name="value" type="String" />
4    </entity>
David H Nebinger
RE: Using Service-Builder Entities without creating Database Tables
1. Oktober 2013 19:11
Antwort

David H Nebinger

Rang: Liferay Legend

Nachrichten: 7238

Eintrittsdatum: 1. September 2006

Neue Beiträge

Hmm, I would have thought you'd have to have an implementation of the DataSource interface...

After a re-read, I see you're just using as a factory class to return a null DS. Looks like a great solution to me, Jack, and it also solves the problem if you were to use the lazy datasource proxy and actually called one of the database-bound methods (i.e. addXxx()) would actually get through to the datasource. Using null would end in an NPE, but that's better than a DB attempt...
Jack Bakker
RE: Using Service-Builder Entities without creating Database Tables
2. Oktober 2013 16:54
Antwort

Jack Bakker

Rang: Liferay Master

Nachrichten: 630

Eintrittsdatum: 3. Januar 2010

Neue Beiträge

Looks like a great solution to me, Jack

Thanks man !

Now I have an ext-spring.xml that references no spring classes directly...
Be cool if there was a 'persistence' attribute to a service.xml entity reference that by default is true but when set to false the persistence related don't get generated.

I started with this as I have my eye on a NoDatasource-backed MyServiceImpl to be the main local service which in turn consumes local or remote RESTful services... however getting the httpclient, gson (or whatever) down there in the belly of a service is awkward... but I digress and am off topic again...
David H Nebinger
RE: Using Service-Builder Entities without creating Database Tables
2. Oktober 2013 19:12
Antwort

David H Nebinger

Rang: Liferay Legend

Nachrichten: 7238

Eintrittsdatum: 1. September 2006

Neue Beiträge

I'd take it even farther; allow the definition of a datasource within service.xml. Let SB generate the necessary spring definitions rather than placing within ext-spring.xml...

That on top of the persistence flag would make service.xml a 'more complete' service definition.

however getting the httpclient, gson (or whatever) down there in the belly of a service is awkward


Yep, it's a pain, especially if you don't want to mess with the spring beans which implement a service layer. Personally I don't want to mess with the generated service beans either.

I've taken to using singletons (as either the holder of an instance or as a the implementation itself) which you can then reference using the singleton pattern. Alternatively you can make your service object implement ApplicationContextAware (to be given a copy of the app context instance) and look up beans manually.

I do like the singleton approach; define your beans in ext-spring.xml that you need (the httpclient, etc.), then have your own MyServiceUtil class to return the instance that can be used in your XxxLocalServiceImpl as necessary...
Jack Bakker
RE: Using Service-Builder Entities without creating Database Tables
3. Oktober 2013 12:07
Antwort

Jack Bakker

Rang: Liferay Master

Nachrichten: 630

Eintrittsdatum: 3. Januar 2010

Neue Beiträge


I do like the singleton approach; define your beans in ext-spring.xml that you need (the httpclient, etc.), then have your own MyServiceUtil class to return the instance that can be used in your XxxLocalServiceImpl as necessary...


Thanks for the lead, I'll give that a smack
Riccardo Rotondo
RE: Using Service-Builder Entities without creating Database Tables
22. November 2013 04:37
Antwort

Riccardo Rotondo

Rang: Junior Member

Nachrichten: 28

Eintrittsdatum: 11. Juni 2010

Neue Beiträge

What if I want to create a table not accessible by third users. The idea is to create an entity where interface methods are private or simply not be exposed to the developers who will interact with the services. This because I want to force them to use other calls.

I tried to achieve that creating an entity with both local and remote service to false but then I have no way to access the database.

Is there any way to do that?

Thank you so much for your help.

Regards,

Riccardo
David H Nebinger
RE: Using Service-Builder Entities without creating Database Tables
22. November 2013 06:01
Antwort

David H Nebinger

Rang: Liferay Legend

Nachrichten: 7238

Eintrittsdatum: 1. September 2006

Neue Beiträge

Okay, since some time in the later 6.0 releases, the XxxLocalServiceImpl classes have access to all of the other service objects as well as the persistence objects directly.

So if you really needed to hide an implementation, I would create your entity with the local service flag set to true. Then in the HiddenLocalServiceImpl class, override all of the base methods to throw an unsupported method exception or something. In your other XxxLocalServiceImpl classes that use the new entity, have them go to the persistence class directly to hit the table.
Marco Fargetta
RE: Using Service-Builder Entities without creating Database Tables
25. November 2013 03:17
Antwort

Marco Fargetta

Rang: New Member

Nachrichten: 2

Eintrittsdatum: 30. Januar 2012

Neue Beiträge

Actually, it the local and remote options are set to false the service builder still create the persistent layer to interact with the entity from the service.
So you can access the entity from other XXXLocalServiceImpl