cancel
Showing results for 
Search instead for 
Did you mean: 

new vocabulary based on external database ?

Ghazi_HAKIM
Confirmed Champ
Confirmed Champ

Hello,

I declared a new data source in my custom bundle which points to an external database :

<extension target="org.nuxeo.runtime.datasource" point="datasources">
	<datasource name="jdbc/custom" driverClassName="${db.driverClassName}">
		<property name="url">${db.url}</property>
		<property name="user">${db.username}</property>
		<property name="password">${db.password}</property>
	</datasource>
</extension>

I want to know if it is possible to use this data source to add a new read only directory (id - value vocabulary) to my Nuxeo ?

May be using the SQLDirectoryFactory extension ?

Regards.

1 ACCEPTED ANSWER

Ghazi_HAKIM
Confirmed Champ
Confirmed Champ

Hello,

I find the solution 🙂

Steps :

1/ add new datasource pointing to your database

<extension target="org.nuxeo.runtime.datasource" point="datasources">
	<datasource name="jdbc/mydb" driverClassName="${db.driverClassName}">
		<property name="url">${db.url}</property>
		<property name="user">${db.username}</property>
		<property name="password">${db.password}</property>
	</datasource>
</extension>

2/ create a VIEW with only columns : id / label / obsolete / ordering based on your table :

CREATE OR REPLACE FORCE VIEW "XXX"."NUXEO_CAR" ("id", "label", "obsolete", "ordering") AS 
SELECT CAR_ID AS "id", CAR_NAME AS "label", 0 AS "obsolete", 10000000 as "ordering"
FROM CAR_TABLE;

3/ add new SQLDirectoryFactory

<extension target="org.nuxeo.ecm.directory.sql.SQLDirectoryFactory" point="directories">
	<directory name="car">
		<schema>vocabulary</schema>
		<dataSource>jdbc/mydb</dataSource>
		<table>NUXEO_CAR</table>
		<readOnly>true</readOnly>
		<idField>id</idField>
		<autoincrementIdField>false</autoincrementIdField>
		<createTablePolicy>never</createTablePolicy>
		<dataLoadingPolicy>never_load</dataLoadingPolicy>
	</directory>
</extension>

4/ enjoy your "car" vocabulary 🙂

View answer in original post

1 REPLY 1

Ghazi_HAKIM
Confirmed Champ
Confirmed Champ

Hello,

I find the solution 🙂

Steps :

1/ add new datasource pointing to your database

<extension target="org.nuxeo.runtime.datasource" point="datasources">
	<datasource name="jdbc/mydb" driverClassName="${db.driverClassName}">
		<property name="url">${db.url}</property>
		<property name="user">${db.username}</property>
		<property name="password">${db.password}</property>
	</datasource>
</extension>

2/ create a VIEW with only columns : id / label / obsolete / ordering based on your table :

CREATE OR REPLACE FORCE VIEW "XXX"."NUXEO_CAR" ("id", "label", "obsolete", "ordering") AS 
SELECT CAR_ID AS "id", CAR_NAME AS "label", 0 AS "obsolete", 10000000 as "ordering"
FROM CAR_TABLE;

3/ add new SQLDirectoryFactory

<extension target="org.nuxeo.ecm.directory.sql.SQLDirectoryFactory" point="directories">
	<directory name="car">
		<schema>vocabulary</schema>
		<dataSource>jdbc/mydb</dataSource>
		<table>NUXEO_CAR</table>
		<readOnly>true</readOnly>
		<idField>id</idField>
		<autoincrementIdField>false</autoincrementIdField>
		<createTablePolicy>never</createTablePolicy>
		<dataLoadingPolicy>never_load</dataLoadingPolicy>
	</directory>
</extension>

4/ enjoy your "car" vocabulary 🙂

Getting started

Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.