留言板

Service Builder - External Database

Lambert Mickael,修改在11 年前。

Service Builder - External Database

Junior Member 帖子: 58 加入日期: 11-12-29 最近的帖子
Hello everyone

I tried to connect an external database to my service builder. For that i follow all of those steps :

1) In my service.xml i add this :
<entity name="EventTracker" local-service="true" remote-service="false" data-source="myDatasource"></entity>


2) I created my file : "ext-spring.xml" :

<!--?xml version="1.0"?-->
<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="myDatasource" lazy-init="true" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://192.168.*.***/mydatabase?useUnicode=true&amp;characterEncoding=UTF-8&amp;useFastDateParsing=false" />
        <property name="username" value="myusername" />
        <property name="password" value="mypassword" />
    </bean>
</beans>


3) After that, i've moved my .jar of my service in the folder /WEB-INF/lib in the /WEB-INF/lib of another project (i want to use my service in a different project that the portlet in which i've created it)

But when i try to add a row in my table, an error tells me that i try to connect at lportal database...

Can anyone help me please ?
thumbnail
David H Nebinger,修改在11 年前。

RE: Service Builder - External Database

Liferay Legend 帖子: 14915 加入日期: 06-9-2 最近的帖子
Is your ext-spring.xml in the META-INF folder of the service providing project?
Lambert Mickael,修改在11 年前。

RE: Service Builder - External Database

Junior Member 帖子: 58 加入日期: 11-12-29 最近的帖子
David H Nebinger:
Is your ext-spring.xml in the META-INF folder of the service providing project?


Yes it is! With the others files :

- base-spring.xml
- cluster-spring.xml
- dynamic-data-source-spring.xml
- hibernate-spring.xml
... etc.
Lambert Mickael,修改在11 年前。

RE: Service Builder - External Database

Junior Member 帖子: 58 加入日期: 11-12-29 最近的帖子
Here is my service.xml file if it can helps anyone.

I really need help! Please ...

?xml version="1.0" encoding="UTF-8"?&gt;

<service-builder package-path="com.events.database">
	<author>mlambert</author>
	<namespace>E</namespace>

	<entity name="EventTracker" local-service="true" remote-service="false" data-source="myDatasource">

		<!-- PK fields -->

		<column name="id" type="long" primary="true" />

		<!-- Audit fields -->

		<column name="company_id" type="long" />
		<column name="user_id" type="long" />
		<column name="group_id" type="long" />
		<column name="organisation_id" type="long" />
		<column name="date" type="Date" />
		<column name="service" type="String" />
		<column name="description" type="String" />
		<column name="type_event" type="String" />
		<column name="info_statut" type="String" />
		
		<order by="asc">
          <order-column name="id"></order-column>
       	</order>
       	
      	<finder return-type="Collection" name="GroupId">
       		<finder-column name="group_id"></finder-column>
       	</finder>
      	<finder return-type="Collection" name="CompanyId">
          	<finder-column name="company_id"></finder-column>
      	</finder>
      	<finder return-type="Collection" name="UserId">
          	<finder-column name="user_id"></finder-column>
      	</finder>
      	<finder return-type="Collection" name="OrganisationId">
          	<finder-column name="organisation_id"></finder-column>
       	</finder>
       	<finder return-type="Collection" name="Service">
          	<finder-column name="service"></finder-column>
       	</finder>
      	<finder return-type="Collection" name="TypeEvent">
          	<finder-column name="type_event"></finder-column>
       	</finder>
       	<finder return-type="Collection" name="UserService">
          	<finder-column name="user_id"></finder-column>
       		<finder-column name="service"></finder-column>
       	</finder>
       	<finder return-type="Collection" name="InfoStatut">
          	<finder-column name="info_statut"></finder-column>
       	</finder>
	</entity>
</service-builder>
thumbnail
David H Nebinger,修改在11 年前。

RE: Service Builder - External Database

Liferay Legend 帖子: 14915 加入日期: 06-9-2 最近的帖子
Lambert Mickael:
3) After that, i've moved my .jar of my service in the folder /WEB-INF/lib in the /WEB-INF/lib of another project (i want to use my service in a different project that the portlet in which i've created it)


You should not be moving the jar. The service jar must be available for both portlets.

In the IDE you add the context for the plugin providing the service as a required deployment context. The IDE will copy (not move) the service jar to the other portlet.
Lambert Mickael,修改在11 年前。

RE: Service Builder - External Database

Junior Member 帖子: 58 加入日期: 11-12-29 最近的帖子
David H Nebinger:
Lambert Mickael:
3) After that, i've moved my .jar of my service in the folder /WEB-INF/lib in the /WEB-INF/lib of another project (i want to use my service in a different project that the portlet in which i've created it)


You should not be moving the jar. The service jar must be available for both portlets.

In the IDE you add the context for the plugin providing the service as a required deployment context. The IDE will copy (not move) the service jar to the other portlet.


The other project is a hook, i did it, but it didn't solve my problem :s
thumbnail
David H Nebinger,修改在11 年前。

RE: Service Builder - External Database

Liferay Legend 帖子: 14915 加入日期: 06-9-2 最近的帖子
Hooks have entirely different issues than portlets...

Hooks typically run within the ROOT context but will not have the service jar available. To make the service jar available to the ROOT context, you should follow the old method of moving the service jar from the portlet providing the service to the global lib directory (lib/ext in tomcat).
thumbnail
Laura Liparulo,修改在11 年前。

RE: Service Builder - External Database

Junior Member 帖子: 38 加入日期: 12-6-30 最近的帖子
You need to launch the ant build-service command, the add the ext-spring.xml in the /docroot/WEB-INF/src/META-INF folder. Then you can deploy your portlet.
Example:

service.xml
------------------

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


<service-builder package-path="it.dicom">
	<author>Laura Liparulo</author>
	<namespace>dicomViewer</namespace>


<entity name="Volume" local-service="true" remote-service="true" table="volume" data-source="dicomViewerDataSource" session-factory="dicomViewerSessionFactory" tx-manager="dicomViewerTransactionManager">
		<!-- PK Fields -->
		<column name="volumeId" type="long" primary="true" />
		<!-- Other Fields -->
		<column name="volumeName" type="String" />
		<column name="overview" type="String" />
		<column name="folderLink" type="String" />
		<!-- Relationships -->
		<column name="caseVolume" type="Collection" entity="CaseArchive" mapping-key="volumeId" />
		<order by="asc">
			<order-column name="volumeName" />
		</order>
		<finder name="Volume_Name" return-type="Collection">
			<finder-column name="volumeName" />
		</finder>
	</entity>



	<entity name="CaseArchive" local-service="true" remote-service="true" table="case_archive" data-source="dicomViewerDataSource" session-factory="dicomViewerSessionFactory" tx-manager="dicomViewerTransactionManager">
		<!-- PK Fields -->
		<column name="caseId" type="long" primary="true" />
		<!-- Other Fields -->
		<column name="caseName" type="String" />
		<column name="volumeId" type="long" />
		<column name="notes" type="String" />
		<!-- Relationships -->
		<column name="image_Case" type="Collection" entity="Image" mapping-key="caseId" />
		<order by="asc">
			<order-column name="caseName" />
		</order>
		<finder name="Case_Name" return-type="Collection">
			<finder-column name="caseName" />
		</finder>
	</entity>


	


</service-builder>





ext-spring.xml
------------------


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

<beans>
  <bean class="
org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  </bean>
  <bean id="dicomViewerDataSourceTarget" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="url" value="jdbc:mysql://localhost:3306/Unicas-Dicom-Viewer" />
    <property name="username" value="root" />
    <property name="password" value="tigertailz" />
  </bean>
  <bean id="dicomViewerDataSource" class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy">
    <property name="targetDataSource">
      <ref bean="dicomViewerDataSourceTarget" />
    </property>
  </bean>
  <bean id="dicomViewerHibernateSessionFactory" class="com.liferay.portal.spring.hibernate.PortletHibernateConfiguration">
    <property name="dataSource">
      <ref bean="dicomViewerDataSource" />
    </property>
  </bean>
  <bean id="dicomViewerSessionFactory" class="com.liferay.portal.dao.orm.hibernate.SessionFactoryImpl">
    <property name="sessionFactoryImplementor">
      <ref bean="dicomViewerHibernateSessionFactory" />
    </property>
  </bean>
  <bean id="dicomViewerTransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">         
    <property name="dataSource">
      <ref bean="dicomViewerDataSource" />
    </property>
    <property name="sessionFactory">
      <ref bean="dicomViewerHibernateSessionFactory" />
    </property>
  </bean>
</beans>