connection to external database: part 2

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

connection to external database: part 2

info@agentur-m3.de
Hi All!

after setting up the connection with an external database
without errors I have two more questions, on which I
could not find some specific information:

(1) after setting up an entity, a delegator and
I datasource, which seem to work together now,
how (or where?) is the exchange of RECORDS with the
external database? ofbiz does not seem to
automatically detect and show the records from the
mysql-database.
Maybe my entity definitions are still wrong,
but then without error messages.
However: no records are imported or displayed
in the view. So: how can I get them from the mysql-database?

Also unexpected to me: when I create new records in ofbiz,
they are displayed in ofbiz after creation (as one would
expect for any regular entity) but they are not transferred to
to the external mysql-database (which I guess could be
the purpose of a entity with associated externally
referenced datasource).

So it seems that ofbiz did recognize the structure of
the external mysql-database, but then ignores to
exchange the data between ofbiz and the database.

So how does ofbiz exchange records between
ofbiz and the external database (in a synchronized way)?

Is there further setup or custom implmentation necessary?

(2) the setup of a datasource is placed in entityengine.xml
in the framework/entity/config folder.
Is there a way to extend it with entries
defined in hot-deploy/.../entitydef/config/entityengine.xml ?

I tried to setup another entityengine.xml there,
but this approach seemed to be ignored by ofbiz.


Thank you!









Reply | Threaded
Open this post in threaded view
|

Re: connection to external database: part 2

Youssef Khaye
I will try to answer, even if i don't understand your use case at 100%

Hi for your second question the answer is no.

For your first question you should show us your entityengine.xml
There is two different cases where  you can use a second database.


Case 1 use a diffrent delegator (from your first post, i think that you
fill in this case), to get record you should instanciate

a  delegator using the name you declared in entityegine.xml
<delegator name="default" entity-model-reader="main"
entity-group-reader="main" entity-eca-reader="main"
distributed-cache-clear-enabled="false">
         <group-map group-name="org.ofbiz" datasource-name="localpostgres"/>
         <group-map group-name="org.ofbiz.olap"
datasource-name="localpostgres"/>
         <group-map group-name="org.ofbiz.tenant"
datasource-name="localpostgres"/>
</delegator>

<delegator name="mysqlDb" entity-model-reader="main"
entity-group-reader="main" entity-eca-reader="main"
distributed-cache-clear-enabled="false">
         <group-map group-name="com.custom datasource-name="sqlDataSource"/>
</delegator>

then in your service
delegator = delagtor.geInstance("mysqlDb")
then use the entity API to get record from your DB.


Case 2
In the same delegator you may assign a diffrent dataSource, that point
to the external DB, to a given package.

<delegator name="default" entity-model-reader="main"
entity-group-reader="main" entity-eca-reader="main"
distributed-cache-clear-enabled="false">
         <group-map group-name="org.ofbiz" datasource-name="localpostgres"/>
         <group-map group-name="com.custom
datasource-name="sqlDataSource"/>
         <group-map group-name="org.ofbiz.olap"
datasource-name="localpostgres"/>
         <group-map group-name="org.ofbiz.tenant"
datasource-name="localpostgres"/>
</delegator>
In this case the defeault delegator you get in a service can fetch
record from any entity in the com.custom package.

Personnaly, I use the first one if I need the external database in
limited area of my OFBiz.

The second one is suitable if you need to access your external db in
many areas of your OFBiz


Le 12/12/2014 09:03, [hidden email] a écrit :

> Hi All!
>
> after setting up the connection with an external database
> without errors I have two more questions, on which I
> could not find some specific information:
>
> (1) after setting up an entity, a delegator and
> I datasource, which seem to work together now,
> how (or where?) is the exchange of RECORDS with the
> external database? ofbiz does not seem to
> automatically detect and show the records from the
> mysql-database.
> Maybe my entity definitions are still wrong,
> but then without error messages.
> However: no records are imported or displayed
> in the view. So: how can I get them from the mysql-database?
>
> Also unexpected to me: when I create new records in ofbiz,
> they are displayed in ofbiz after creation (as one would
> expect for any regular entity) but they are not transferred to
> to the external mysql-database (which I guess could be
> the purpose of a entity with associated externally
> referenced datasource).
>
> So it seems that ofbiz did recognize the structure of
> the external mysql-database, but then ignores to
> exchange the data between ofbiz and the database.
>
> So how does ofbiz exchange records between
> ofbiz and the external database (in a synchronized way)?
>
> Is there further setup or custom implmentation necessary?
>
> (2) the setup of a datasource is placed in entityengine.xml
> in the framework/entity/config folder.
> Is there a way to extend it with entries
> defined in hot-deploy/.../entitydef/config/entityengine.xml ?
>
> I tried to setup another entityengine.xml there,
> but this approach seemed to be ignored by ofbiz.
>
>
> Thank you!
>
>
>
>
>
>
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: connection to external database: part 2

info@agentur-m3.de
Thank you Youssef!

now I understood that the delegator name ="default"
together with the group statements
should cause ofbiz to read of the records
of the external database (what is exactly
what I want to achieve).

With the new datasource definition now there are still (and also some
new) error messages concerning the database driver and about the
connection to the external database:

        at java.lang.Thread.run(Thread.java:745) [?:1.7.0_65]
20141217120652329 |OFBiz-config-0       |DatabaseUtil        |E| Unable
to establish a connection with the database for helperName [platfo]...
Error was: org.ofbiz.entity.GenericEntityException:
com.mysql.jdbc.Driver (com.mysql.jdbc.Driver)
20141217120652329 |OFBiz-config-0       |DatabaseUtil        |E| Unable
to establish a connection with the database, no additional information
available.
20141217120652329 |OFBiz-config-0       |DatabaseUtil        |E| Could
not get table name information from the database, aborting.
20141217120652329 |OFBiz-config-2       |BCPConnectionFactory|E| null
java.lang.ClassNotFoundException: Cached loader got a known bad class
name: com.mysql.jdbc.Driver
        at
org.ofbiz.base.util.CachedClassLoader.loadClass(CachedClassLoader.java:182)
~[ofbiz-base.jar:?]
        at
org.ofbiz.base.util.CachedClassLoader.loadClass(CachedClassLoader.java:162)
~[ofbiz-base.jar:?]
        at java.lang.Class.forName0(Native Method) ~[?:1.7.0_65]
        at java.lang.Class.forName(Class.java:274) ~[?:1.7.0_65]
        at
org.ofbiz.entity.connection.DBCPConnectionFactory.getConnection(DBCPConnectionFactory.java:87)
[ofbiz-entity-test.jar:?]
        at
org.ofbiz.entity.jdbc.ConnectionFactory.getManagedConnection(ConnectionFactory.java:121)
[ofbiz-entity-test.jar:?]
        at
org.ofbiz.geronimo.GeronimoTransactionFactory.getConnection(GeronimoTransactionFactory.java:83)
[ofbiz-geronimo.jar:?]
        at
org.ofbiz.entity.transaction.TransactionFactory.getConnection(TransactionFactory.java:82)
[ofbiz-entity-test.jar:?]
        at
org.ofbiz.entity.jdbc.ConnectionFactory.getConnection(ConnectionFactory.java:97)
[ofbiz-entity-test.jar:?]
        at
org.ofbiz.entity.jdbc.DatabaseUtil.getConnection(DatabaseUtil.java:135)
[ofbiz-entity-test.jar:?]
        at
org.ofbiz.entity.jdbc.DatabaseUtil.getConnectionLogged(DatabaseUtil.java:155)
[ofbiz-entity-test.jar:?]
        at
org.ofbiz.entity.jdbc.DatabaseUtil.getTableNames(DatabaseUtil.java:977)
[ofbiz-entity-test.jar:?]
        at org.ofbiz.entity.jdbc.DatabaseUtil.checkDb(DatabaseUtil.java:189)
[ofbiz-entity-test.jar:?]
        at org.ofbiz.entity.jdbc.DatabaseUtil.checkDb(DatabaseUtil.java:178)
[ofbiz-entity-test.jar:?]
        at org.ofbiz.entity.datasource.GenericDAO.checkDb(GenericDAO.java:1234)
[ofbiz-entity-test.jar:?]
        at
org.ofbiz.entity.datasource.GenericHelperDAO.checkDataSource(GenericHelperDAO.java:200)
[ofbiz-entity-test.jar:?]
        at
org.ofbiz.entity.GenericDelegator.initializeOneGenericHelper(GenericDelegator.java:286)
[ofbiz-entity-test.jar:?]
        at
org.ofbiz.entity.GenericDelegator.access$000(GenericDelegator.java:87)
[ofbiz-entity-test.jar:?]
        at org.ofbiz.entity.GenericDelegator$1.call(GenericDelegator.java:297)
[ofbiz-entity-test.jar:?]
        at org.ofbiz.entity.GenericDelegator$1.call(GenericDelegator.java:295)
[ofbiz-entity-test.jar:?]
        at java.util.concurrent.FutureTask.run(FutureTask.java:262) [?:1.7.0_65]
        at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)
[?:1.7.0_65]
        at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)
[?:1.7.0_65]
        at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
[?:1.7.0_65]
        at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
[?:1.7.0_65]
        at java.lang.Thread.run(Thread.java:745) [?:1.7.0_65]
eadPoolExecutor.java:615) [?:1.7.0_65]
        at java.lang.Thread.run(Thread.java:745) [?:1.7.0_65]

--------------------------------------------------------------------------------

My changeddatasource definition:
<datasource name="platfo"
                            helper-class="org.ofbiz.entity.datasource.GenericHelperDAO"
                            field-type-name="mysql"
                            check-on-start="true"
                            add-missing-on-start="true"
                            check-pks-on-start="false"
                            use-foreign-keys="true"
                            join-style="ansi-no-parenthesis"
                            alias-view-columns="false"
                            drop-fk-use-foreign-key-keyword="true"
                            table-type="InnoDB"
                            character-set="latin1"
                            collate="latin1_general_cs">
                        <read-data reader-name="seed"/>
                        <read-data reader-name="seed-initial"/>
                        <read-data reader-name="demo"/>
                        <read-data reader-name="ext"/>
                        <read-data reader-name="main"/>
                        <inline-jdbc
                                jdbc-driver="com.mysql.jdbc.Driver"
                                jdbc-uri="jdbc:mysql://127.0.0.1:3306/wp_platfo"
                                jdbc-username="test"
                                jdbc-password="test"
                                isolation-level="ReadCommitted"
                                pool-minsize="2"
                                pool-maxsize="250"
                                time-between-eviction-runs-millis="600000" />
                </datasource>    


and delegator:


                <delegator name="default" entity-model-reader="main"
                  entity-group-reader="main" entity-eca-reader="main"
                  distributed-cache-clear-enabled="false">
                  <group-map group-name="org.ofbiz" datasource-name="platfo"/>
                  <group-map group-name="org.ofbiz.olap" datasource-name="platfo"/>
                  <group-map group-name="org.ofbiz.tenant" datasource-name="platfo"/>
                </delegator>



Thanks again!



Am 12.12.2014 um 17:46 schrieb Youssef Khaye:

> I will try to answer, even if i don't understand your use case at 100%
>
> Hi for your second question the answer is no.
>
> For your first question you should show us your entityengine.xml
> There is two different cases where  you can use a second database.
>
>
> Case 1 use a diffrent delegator (from your first post, i think that you
> fill in this case), to get record you should instanciate
>
> a  delegator using the name you declared in entityegine.xml
> <delegator name="default" entity-model-reader="main"
> entity-group-reader="main" entity-eca-reader="main"
> distributed-cache-clear-enabled="false">
>         <group-map group-name="org.ofbiz" datasource-name="localpostgres"/>
>         <group-map group-name="org.ofbiz.olap"
> datasource-name="localpostgres"/>
>         <group-map group-name="org.ofbiz.tenant"
> datasource-name="localpostgres"/>
> </delegator>
>
> <delegator name="mysqlDb" entity-model-reader="main"
> entity-group-reader="main" entity-eca-reader="main"
> distributed-cache-clear-enabled="false">
>         <group-map group-name="com.custom datasource-name="sqlDataSource"/>
> </delegator>
>
> then in your service
> delegator = delagtor.geInstance("mysqlDb")
> then use the entity API to get record from your DB.
>
>
> Case 2
> In the same delegator you may assign a diffrent dataSource, that point
> to the external DB, to a given package.
>
> <delegator name="default" entity-model-reader="main"
> entity-group-reader="main" entity-eca-reader="main"
> distributed-cache-clear-enabled="false">
>         <group-map group-name="org.ofbiz" datasource-name="localpostgres"/>
>         <group-map group-name="com.custom datasource-name="sqlDataSource"/>
>         <group-map group-name="org.ofbiz.olap"
> datasource-name="localpostgres"/>
>         <group-map group-name="org.ofbiz.tenant"
> datasource-name="localpostgres"/>
> </delegator>
> In this case the defeault delegator you get in a service can fetch
> record from any entity in the com.custom package.
>
> Personnaly, I use the first one if I need the external database in
> limited area of my OFBiz.
>
> The second one is suitable if you need to access your external db in
> many areas of your OFBiz
>
>
> Le 12/12/2014 09:03, [hidden email] a écrit :
>> Hi All!
>>
>> after setting up the connection with an external database
>> without errors I have two more questions, on which I
>> could not find some specific information:
>>
>> (1) after setting up an entity, a delegator and
>> I datasource, which seem to work together now,
>> how (or where?) is the exchange of RECORDS with the
>> external database? ofbiz does not seem to
>> automatically detect and show the records from the
>> mysql-database.
>> Maybe my entity definitions are still wrong,
>> but then without error messages.
>> However: no records are imported or displayed
>> in the view. So: how can I get them from the mysql-database?
>>
>> Also unexpected to me: when I create new records in ofbiz,
>> they are displayed in ofbiz after creation (as one would
>> expect for any regular entity) but they are not transferred to
>> to the external mysql-database (which I guess could be
>> the purpose of a entity with associated externally
>> referenced datasource).
>>
>> So it seems that ofbiz did recognize the structure of
>> the external mysql-database, but then ignores to
>> exchange the data between ofbiz and the database.
>>
>> So how does ofbiz exchange records between
>> ofbiz and the external database (in a synchronized way)?
>>
>> Is there further setup or custom implmentation necessary?
>>
>> (2) the setup of a datasource is placed in entityengine.xml
>> in the framework/entity/config folder.
>> Is there a way to extend it with entries
>> defined in hot-deploy/.../entitydef/config/entityengine.xml ?
>>
>> I tried to setup another entityengine.xml there,
>> but this approach seemed to be ignored by ofbiz.
>>
>>
>> Thank you!
>>
>>
>>
>>
>>
>>
>>
>>
>>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: connection to external database: part 2

Deepak Dixit-2
It seems mysql jdbc diver is missing , you need to place mysql jdbc driver at location "framework/entity/lib/jdbc/“
for this simply run following ant target it will download mysql jar and put to to right place:
{code}
./ant download-mySQL-JDBC
{code}

Thanks & Regards

Deepak Dixit

> On Dec 17, 2014, at 4:50 PM, [hidden email] wrote:
>
> Thank you Youssef!
>
> now I understood that the delegator name ="default"
> together with the group statements
> should cause ofbiz to read of the records
> of the external database (what is exactly
> what I want to achieve).
>
> With the new datasource definition now there are still (and also some
> new) error messages concerning the database driver and about the
> connection to the external database:
>
> at java.lang.Thread.run(Thread.java:745) [?:1.7.0_65]
> 20141217120652329 |OFBiz-config-0       |DatabaseUtil        |E| Unable
> to establish a connection with the database for helperName [platfo]...
> Error was: org.ofbiz.entity.GenericEntityException:
> com.mysql.jdbc.Driver (com.mysql.jdbc.Driver)
> 20141217120652329 |OFBiz-config-0       |DatabaseUtil        |E| Unable
> to establish a connection with the database, no additional information
> available.
> 20141217120652329 |OFBiz-config-0       |DatabaseUtil        |E| Could
> not get table name information from the database, aborting.
> 20141217120652329 |OFBiz-config-2       |BCPConnectionFactory|E| null
> java.lang.ClassNotFoundException: Cached loader got a known bad class
> name: com.mysql.jdbc.Driver
> at
> org.ofbiz.base.util.CachedClassLoader.loadClass(CachedClassLoader.java:182)
> ~[ofbiz-base.jar:?]
> at
> org.ofbiz.base.util.CachedClassLoader.loadClass(CachedClassLoader.java:162)
> ~[ofbiz-base.jar:?]
> at java.lang.Class.forName0(Native Method) ~[?:1.7.0_65]
> at java.lang.Class.forName(Class.java:274) ~[?:1.7.0_65]
> at
> org.ofbiz.entity.connection.DBCPConnectionFactory.getConnection(DBCPConnectionFactory.java:87)
> [ofbiz-entity-test.jar:?]
> at
> org.ofbiz.entity.jdbc.ConnectionFactory.getManagedConnection(ConnectionFactory.java:121)
> [ofbiz-entity-test.jar:?]
> at
> org.ofbiz.geronimo.GeronimoTransactionFactory.getConnection(GeronimoTransactionFactory.java:83)
> [ofbiz-geronimo.jar:?]
> at
> org.ofbiz.entity.transaction.TransactionFactory.getConnection(TransactionFactory.java:82)
> [ofbiz-entity-test.jar:?]
> at
> org.ofbiz.entity.jdbc.ConnectionFactory.getConnection(ConnectionFactory.java:97)
> [ofbiz-entity-test.jar:?]
> at
> org.ofbiz.entity.jdbc.DatabaseUtil.getConnection(DatabaseUtil.java:135)
> [ofbiz-entity-test.jar:?]
> at
> org.ofbiz.entity.jdbc.DatabaseUtil.getConnectionLogged(DatabaseUtil.java:155)
> [ofbiz-entity-test.jar:?]
> at
> org.ofbiz.entity.jdbc.DatabaseUtil.getTableNames(DatabaseUtil.java:977)
> [ofbiz-entity-test.jar:?]
> at org.ofbiz.entity.jdbc.DatabaseUtil.checkDb(DatabaseUtil.java:189)
> [ofbiz-entity-test.jar:?]
> at org.ofbiz.entity.jdbc.DatabaseUtil.checkDb(DatabaseUtil.java:178)
> [ofbiz-entity-test.jar:?]
> at org.ofbiz.entity.datasource.GenericDAO.checkDb(GenericDAO.java:1234)
> [ofbiz-entity-test.jar:?]
> at
> org.ofbiz.entity.datasource.GenericHelperDAO.checkDataSource(GenericHelperDAO.java:200)
> [ofbiz-entity-test.jar:?]
> at
> org.ofbiz.entity.GenericDelegator.initializeOneGenericHelper(GenericDelegator.java:286)
> [ofbiz-entity-test.jar:?]
> at
> org.ofbiz.entity.GenericDelegator.access$000(GenericDelegator.java:87)
> [ofbiz-entity-test.jar:?]
> at org.ofbiz.entity.GenericDelegator$1.call(GenericDelegator.java:297)
> [ofbiz-entity-test.jar:?]
> at org.ofbiz.entity.GenericDelegator$1.call(GenericDelegator.java:295)
> [ofbiz-entity-test.jar:?]
> at java.util.concurrent.FutureTask.run(FutureTask.java:262) [?:1.7.0_65]
> at
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)
> [?:1.7.0_65]
> at
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)
> [?:1.7.0_65]
> at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
> [?:1.7.0_65]
> at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
> [?:1.7.0_65]
> at java.lang.Thread.run(Thread.java:745) [?:1.7.0_65]
> eadPoolExecutor.java:615) [?:1.7.0_65]
> at java.lang.Thread.run(Thread.java:745) [?:1.7.0_65]
>
> --------------------------------------------------------------------------------
>
> My changeddatasource definition:
> <datasource name="platfo"
>            helper-class="org.ofbiz.entity.datasource.GenericHelperDAO"
>            field-type-name="mysql"
>            check-on-start="true"
>            add-missing-on-start="true"
>            check-pks-on-start="false"
>            use-foreign-keys="true"
>            join-style="ansi-no-parenthesis"
>            alias-view-columns="false"
>            drop-fk-use-foreign-key-keyword="true"
>            table-type="InnoDB"
>            character-set="latin1"
>            collate="latin1_general_cs">
>        <read-data reader-name="seed"/>
>        <read-data reader-name="seed-initial"/>
>        <read-data reader-name="demo"/>
>        <read-data reader-name="ext"/>
>        <read-data reader-name="main"/>
>        <inline-jdbc
>                jdbc-driver="com.mysql.jdbc.Driver"
>                jdbc-uri="jdbc:mysql://127.0.0.1:3306/wp_platfo"
>                jdbc-username="test"
>                jdbc-password="test"
>                isolation-level="ReadCommitted"
>                pool-minsize="2"
>                pool-maxsize="250"
>                time-between-eviction-runs-millis="600000" />
> </datasource>    
>
>
> and delegator:
>
>
> <delegator name="default" entity-model-reader="main"
>  entity-group-reader="main" entity-eca-reader="main"
>  distributed-cache-clear-enabled="false">
>  <group-map group-name="org.ofbiz" datasource-name="platfo"/>
>  <group-map group-name="org.ofbiz.olap" datasource-name="platfo"/>
>  <group-map group-name="org.ofbiz.tenant" datasource-name="platfo"/>
> </delegator>
>
>
>
> Thanks again!
>
>
>
> Am 12.12.2014 um 17:46 schrieb Youssef Khaye:
>> I will try to answer, even if i don't understand your use case at 100%
>>
>> Hi for your second question the answer is no.
>>
>> For your first question you should show us your entityengine.xml
>> There is two different cases where  you can use a second database.
>>
>>
>> Case 1 use a diffrent delegator (from your first post, i think that you
>> fill in this case), to get record you should instanciate
>>
>> a  delegator using the name you declared in entityegine.xml
>> <delegator name="default" entity-model-reader="main"
>> entity-group-reader="main" entity-eca-reader="main"
>> distributed-cache-clear-enabled="false">
>>        <group-map group-name="org.ofbiz" datasource-name="localpostgres"/>
>>        <group-map group-name="org.ofbiz.olap"
>> datasource-name="localpostgres"/>
>>        <group-map group-name="org.ofbiz.tenant"
>> datasource-name="localpostgres"/>
>> </delegator>
>>
>> <delegator name="mysqlDb" entity-model-reader="main"
>> entity-group-reader="main" entity-eca-reader="main"
>> distributed-cache-clear-enabled="false">
>>        <group-map group-name="com.custom datasource-name="sqlDataSource"/>
>> </delegator>
>>
>> then in your service
>> delegator = delagtor.geInstance("mysqlDb")
>> then use the entity API to get record from your DB.
>>
>>
>> Case 2
>> In the same delegator you may assign a diffrent dataSource, that point
>> to the external DB, to a given package.
>>
>> <delegator name="default" entity-model-reader="main"
>> entity-group-reader="main" entity-eca-reader="main"
>> distributed-cache-clear-enabled="false">
>>        <group-map group-name="org.ofbiz" datasource-name="localpostgres"/>
>>        <group-map group-name="com.custom datasource-name="sqlDataSource"/>
>>        <group-map group-name="org.ofbiz.olap"
>> datasource-name="localpostgres"/>
>>        <group-map group-name="org.ofbiz.tenant"
>> datasource-name="localpostgres"/>
>> </delegator>
>> In this case the defeault delegator you get in a service can fetch
>> record from any entity in the com.custom package.
>>
>> Personnaly, I use the first one if I need the external database in
>> limited area of my OFBiz.
>>
>> The second one is suitable if you need to access your external db in
>> many areas of your OFBiz
>>
>>
>> Le 12/12/2014 09:03, [hidden email] a écrit :
>>> Hi All!
>>>
>>> after setting up the connection with an external database
>>> without errors I have two more questions, on which I
>>> could not find some specific information:
>>>
>>> (1) after setting up an entity, a delegator and
>>> I datasource, which seem to work together now,
>>> how (or where?) is the exchange of RECORDS with the
>>> external database? ofbiz does not seem to
>>> automatically detect and show the records from the
>>> mysql-database.
>>> Maybe my entity definitions are still wrong,
>>> but then without error messages.
>>> However: no records are imported or displayed
>>> in the view. So: how can I get them from the mysql-database?
>>>
>>> Also unexpected to me: when I create new records in ofbiz,
>>> they are displayed in ofbiz after creation (as one would
>>> expect for any regular entity) but they are not transferred to
>>> to the external mysql-database (which I guess could be
>>> the purpose of a entity with associated externally
>>> referenced datasource).
>>>
>>> So it seems that ofbiz did recognize the structure of
>>> the external mysql-database, but then ignores to
>>> exchange the data between ofbiz and the database.
>>>
>>> So how does ofbiz exchange records between
>>> ofbiz and the external database (in a synchronized way)?
>>>
>>> Is there further setup or custom implmentation necessary?
>>>
>>> (2) the setup of a datasource is placed in entityengine.xml
>>> in the framework/entity/config folder.
>>> Is there a way to extend it with entries
>>> defined in hot-deploy/.../entitydef/config/entityengine.xml ?
>>>
>>> I tried to setup another entityengine.xml there,
>>> but this approach seemed to be ignored by ofbiz.
>>>
>>>
>>> Thank you!
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>
>>
>


smime.p7s (6K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: connection to external database: part 2

Adrian Crum-3
In reply to this post by info@agentur-m3.de
This is an advanced topic, but it's worth bringing up here...

Typically, you want to include external data sources in the default
delegator - instead of in a separate delegator.

If you look at the OOTB entityengine.xml file, there are three separate
delegators defined. They all contain the same data sources, but the
difference is in the delegator settings. So, there is one example of WHY
you would want a separate delegator.

The other reason (theoretically) WHY you would have multiple delegators
is when you have multiple data sources that contain table names that
clash (more then one data source contains a table with the same name).
You can use a separate reader and delegator to accommodate that, but
from my perspective, it would be easier to use the default delegator and
use a different entity name - and then utilize the table-name attribute
to specify the clashing table name.

Example:

1. OFBiz Derby data source contains a table named PARTY, mapped to
entity name Party.

2. External data source contains a table named PARTY.

3a. Create a separate delegator to map external PARTY table to entity Party.

3b. Use default delegator to map the external PARTY table to entity
ExtParty (my preference). Both data sources have a table called PARTY,
but one is referenced as Party, and the other is referenced as ExtParty
- using the same delegator.

 From my perspective, the multiple delegator readers are unnecessary
because you have very fine-grained control over how tables are mapped to
entities.


Adrian Crum
Sandglass Software
www.sandglass-software.com

On 12/17/2014 11:20 AM, [hidden email] wrote:

> Thank you Youssef!
>
> now I understood that the delegator name ="default"
> together with the group statements
> should cause ofbiz to read of the records
> of the external database (what is exactly
> what I want to achieve).
>
> With the new datasource definition now there are still (and also some
> new) error messages concerning the database driver and about the
> connection to the external database:
>
> at java.lang.Thread.run(Thread.java:745) [?:1.7.0_65]
> 20141217120652329 |OFBiz-config-0       |DatabaseUtil        |E| Unable
> to establish a connection with the database for helperName [platfo]...
> Error was: org.ofbiz.entity.GenericEntityException:
> com.mysql.jdbc.Driver (com.mysql.jdbc.Driver)
> 20141217120652329 |OFBiz-config-0       |DatabaseUtil        |E| Unable
> to establish a connection with the database, no additional information
> available.
> 20141217120652329 |OFBiz-config-0       |DatabaseUtil        |E| Could
> not get table name information from the database, aborting.
> 20141217120652329 |OFBiz-config-2       |BCPConnectionFactory|E| null
> java.lang.ClassNotFoundException: Cached loader got a known bad class
> name: com.mysql.jdbc.Driver
> at
> org.ofbiz.base.util.CachedClassLoader.loadClass(CachedClassLoader.java:182)
> ~[ofbiz-base.jar:?]
> at
> org.ofbiz.base.util.CachedClassLoader.loadClass(CachedClassLoader.java:162)
> ~[ofbiz-base.jar:?]
> at java.lang.Class.forName0(Native Method) ~[?:1.7.0_65]
> at java.lang.Class.forName(Class.java:274) ~[?:1.7.0_65]
> at
> org.ofbiz.entity.connection.DBCPConnectionFactory.getConnection(DBCPConnectionFactory.java:87)
> [ofbiz-entity-test.jar:?]
> at
> org.ofbiz.entity.jdbc.ConnectionFactory.getManagedConnection(ConnectionFactory.java:121)
> [ofbiz-entity-test.jar:?]
> at
> org.ofbiz.geronimo.GeronimoTransactionFactory.getConnection(GeronimoTransactionFactory.java:83)
> [ofbiz-geronimo.jar:?]
> at
> org.ofbiz.entity.transaction.TransactionFactory.getConnection(TransactionFactory.java:82)
> [ofbiz-entity-test.jar:?]
> at
> org.ofbiz.entity.jdbc.ConnectionFactory.getConnection(ConnectionFactory.java:97)
> [ofbiz-entity-test.jar:?]
> at
> org.ofbiz.entity.jdbc.DatabaseUtil.getConnection(DatabaseUtil.java:135)
> [ofbiz-entity-test.jar:?]
> at
> org.ofbiz.entity.jdbc.DatabaseUtil.getConnectionLogged(DatabaseUtil.java:155)
> [ofbiz-entity-test.jar:?]
> at
> org.ofbiz.entity.jdbc.DatabaseUtil.getTableNames(DatabaseUtil.java:977)
> [ofbiz-entity-test.jar:?]
> at org.ofbiz.entity.jdbc.DatabaseUtil.checkDb(DatabaseUtil.java:189)
> [ofbiz-entity-test.jar:?]
> at org.ofbiz.entity.jdbc.DatabaseUtil.checkDb(DatabaseUtil.java:178)
> [ofbiz-entity-test.jar:?]
> at org.ofbiz.entity.datasource.GenericDAO.checkDb(GenericDAO.java:1234)
> [ofbiz-entity-test.jar:?]
> at
> org.ofbiz.entity.datasource.GenericHelperDAO.checkDataSource(GenericHelperDAO.java:200)
> [ofbiz-entity-test.jar:?]
> at
> org.ofbiz.entity.GenericDelegator.initializeOneGenericHelper(GenericDelegator.java:286)
> [ofbiz-entity-test.jar:?]
> at
> org.ofbiz.entity.GenericDelegator.access$000(GenericDelegator.java:87)
> [ofbiz-entity-test.jar:?]
> at org.ofbiz.entity.GenericDelegator$1.call(GenericDelegator.java:297)
> [ofbiz-entity-test.jar:?]
> at org.ofbiz.entity.GenericDelegator$1.call(GenericDelegator.java:295)
> [ofbiz-entity-test.jar:?]
> at java.util.concurrent.FutureTask.run(FutureTask.java:262) [?:1.7.0_65]
> at
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)
> [?:1.7.0_65]
> at
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)
> [?:1.7.0_65]
> at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
> [?:1.7.0_65]
> at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
> [?:1.7.0_65]
> at java.lang.Thread.run(Thread.java:745) [?:1.7.0_65]
> eadPoolExecutor.java:615) [?:1.7.0_65]
> at java.lang.Thread.run(Thread.java:745) [?:1.7.0_65]
>
> --------------------------------------------------------------------------------
>
> My changeddatasource definition:
> <datasource name="platfo"
>            helper-class="org.ofbiz.entity.datasource.GenericHelperDAO"
>            field-type-name="mysql"
>            check-on-start="true"
>            add-missing-on-start="true"
>            check-pks-on-start="false"
>            use-foreign-keys="true"
>            join-style="ansi-no-parenthesis"
>            alias-view-columns="false"
>            drop-fk-use-foreign-key-keyword="true"
>            table-type="InnoDB"
>            character-set="latin1"
>            collate="latin1_general_cs">
>        <read-data reader-name="seed"/>
>        <read-data reader-name="seed-initial"/>
>        <read-data reader-name="demo"/>
>        <read-data reader-name="ext"/>
>        <read-data reader-name="main"/>
>        <inline-jdbc
>                jdbc-driver="com.mysql.jdbc.Driver"
>                jdbc-uri="jdbc:mysql://127.0.0.1:3306/wp_platfo"
>                jdbc-username="test"
>                jdbc-password="test"
>                isolation-level="ReadCommitted"
>                pool-minsize="2"
>                pool-maxsize="250"
>                time-between-eviction-runs-millis="600000" />
> </datasource>    
>
>
> and delegator:
>
>
> <delegator name="default" entity-model-reader="main"
>  entity-group-reader="main" entity-eca-reader="main"
>  distributed-cache-clear-enabled="false">
>  <group-map group-name="org.ofbiz" datasource-name="platfo"/>
>  <group-map group-name="org.ofbiz.olap" datasource-name="platfo"/>
>  <group-map group-name="org.ofbiz.tenant" datasource-name="platfo"/>
> </delegator>
>
>
>
> Thanks again!
>
>
>
> Am 12.12.2014 um 17:46 schrieb Youssef Khaye:
>> I will try to answer, even if i don't understand your use case at 100%
>>
>> Hi for your second question the answer is no.
>>
>> For your first question you should show us your entityengine.xml
>> There is two different cases where  you can use a second database.
>>
>>
>> Case 1 use a diffrent delegator (from your first post, i think that you
>> fill in this case), to get record you should instanciate
>>
>> a  delegator using the name you declared in entityegine.xml
>> <delegator name="default" entity-model-reader="main"
>> entity-group-reader="main" entity-eca-reader="main"
>> distributed-cache-clear-enabled="false">
>>          <group-map group-name="org.ofbiz" datasource-name="localpostgres"/>
>>          <group-map group-name="org.ofbiz.olap"
>> datasource-name="localpostgres"/>
>>          <group-map group-name="org.ofbiz.tenant"
>> datasource-name="localpostgres"/>
>> </delegator>
>>
>> <delegator name="mysqlDb" entity-model-reader="main"
>> entity-group-reader="main" entity-eca-reader="main"
>> distributed-cache-clear-enabled="false">
>>          <group-map group-name="com.custom datasource-name="sqlDataSource"/>
>> </delegator>
>>
>> then in your service
>> delegator = delagtor.geInstance("mysqlDb")
>> then use the entity API to get record from your DB.
>>
>>
>> Case 2
>> In the same delegator you may assign a diffrent dataSource, that point
>> to the external DB, to a given package.
>>
>> <delegator name="default" entity-model-reader="main"
>> entity-group-reader="main" entity-eca-reader="main"
>> distributed-cache-clear-enabled="false">
>>          <group-map group-name="org.ofbiz" datasource-name="localpostgres"/>
>>          <group-map group-name="com.custom datasource-name="sqlDataSource"/>
>>          <group-map group-name="org.ofbiz.olap"
>> datasource-name="localpostgres"/>
>>          <group-map group-name="org.ofbiz.tenant"
>> datasource-name="localpostgres"/>
>> </delegator>
>> In this case the defeault delegator you get in a service can fetch
>> record from any entity in the com.custom package.
>>
>> Personnaly, I use the first one if I need the external database in
>> limited area of my OFBiz.
>>
>> The second one is suitable if you need to access your external db in
>> many areas of your OFBiz
>>
>>
>> Le 12/12/2014 09:03, [hidden email] a écrit :
>>> Hi All!
>>>
>>> after setting up the connection with an external database
>>> without errors I have two more questions, on which I
>>> could not find some specific information:
>>>
>>> (1) after setting up an entity, a delegator and
>>> I datasource, which seem to work together now,
>>> how (or where?) is the exchange of RECORDS with the
>>> external database? ofbiz does not seem to
>>> automatically detect and show the records from the
>>> mysql-database.
>>> Maybe my entity definitions are still wrong,
>>> but then without error messages.
>>> However: no records are imported or displayed
>>> in the view. So: how can I get them from the mysql-database?
>>>
>>> Also unexpected to me: when I create new records in ofbiz,
>>> they are displayed in ofbiz after creation (as one would
>>> expect for any regular entity) but they are not transferred to
>>> to the external mysql-database (which I guess could be
>>> the purpose of a entity with associated externally
>>> referenced datasource).
>>>
>>> So it seems that ofbiz did recognize the structure of
>>> the external mysql-database, but then ignores to
>>> exchange the data between ofbiz and the database.
>>>
>>> So how does ofbiz exchange records between
>>> ofbiz and the external database (in a synchronized way)?
>>>
>>> Is there further setup or custom implmentation necessary?
>>>
>>> (2) the setup of a datasource is placed in entityengine.xml
>>> in the framework/entity/config folder.
>>> Is there a way to extend it with entries
>>> defined in hot-deploy/.../entitydef/config/entityengine.xml ?
>>>
>>> I tried to setup another entityengine.xml there,
>>> but this approach seemed to be ignored by ofbiz.
>>>
>>>
>>> Thank you!
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>
>>
>
Reply | Threaded
Open this post in threaded view
|

Re: connection to external database: part 2

Jacques Le Roux
Administrator
+1 for the table-name attribute of the entity element.

Jacques

Le 18/12/2014 06:51, Adrian Crum a écrit :

> This is an advanced topic, but it's worth bringing up here...
>
> Typically, you want to include external data sources in the default delegator - instead of in a separate delegator.
>
> If you look at the OOTB entityengine.xml file, there are three separate delegators defined. They all contain the same data sources, but the
> difference is in the delegator settings. So, there is one example of WHY you would want a separate delegator.
>
> The other reason (theoretically) WHY you would have multiple delegators is when you have multiple data sources that contain table names that clash
> (more then one data source contains a table with the same name). You can use a separate reader and delegator to accommodate that, but from my
> perspective, it would be easier to use the default delegator and use a different entity name - and then utilize the table-name attribute to specify
> the clashing table name.
>
> Example:
>
> 1. OFBiz Derby data source contains a table named PARTY, mapped to entity name Party.
>
> 2. External data source contains a table named PARTY.
>
> 3a. Create a separate delegator to map external PARTY table to entity Party.
>
> 3b. Use default delegator to map the external PARTY table to entity ExtParty (my preference). Both data sources have a table called PARTY, but one
> is referenced as Party, and the other is referenced as ExtParty - using the same delegator.
>
> From my perspective, the multiple delegator readers are unnecessary because you have very fine-grained control over how tables are mapped to entities.
>
>
> Adrian Crum
> Sandglass Software
> www.sandglass-software.com
>
> On 12/17/2014 11:20 AM, [hidden email] wrote:
>> Thank you Youssef!
>>
>> now I understood that the delegator name ="default"
>> together with the group statements
>> should cause ofbiz to read of the records
>> of the external database (what is exactly
>> what I want to achieve).
>>
>> With the new datasource definition now there are still (and also some
>> new) error messages concerning the database driver and about the
>> connection to the external database:
>>
>>     at java.lang.Thread.run(Thread.java:745) [?:1.7.0_65]
>> 20141217120652329 |OFBiz-config-0       |DatabaseUtil        |E| Unable
>> to establish a connection with the database for helperName [platfo]...
>> Error was: org.ofbiz.entity.GenericEntityException:
>> com.mysql.jdbc.Driver (com.mysql.jdbc.Driver)
>> 20141217120652329 |OFBiz-config-0       |DatabaseUtil        |E| Unable
>> to establish a connection with the database, no additional information
>> available.
>> 20141217120652329 |OFBiz-config-0       |DatabaseUtil        |E| Could
>> not get table name information from the database, aborting.
>> 20141217120652329 |OFBiz-config-2       |BCPConnectionFactory|E| null
>> java.lang.ClassNotFoundException: Cached loader got a known bad class
>> name: com.mysql.jdbc.Driver
>>     at
>> org.ofbiz.base.util.CachedClassLoader.loadClass(CachedClassLoader.java:182)
>> ~[ofbiz-base.jar:?]
>>     at
>> org.ofbiz.base.util.CachedClassLoader.loadClass(CachedClassLoader.java:162)
>> ~[ofbiz-base.jar:?]
>>     at java.lang.Class.forName0(Native Method) ~[?:1.7.0_65]
>>     at java.lang.Class.forName(Class.java:274) ~[?:1.7.0_65]
>>     at
>> org.ofbiz.entity.connection.DBCPConnectionFactory.getConnection(DBCPConnectionFactory.java:87)
>> [ofbiz-entity-test.jar:?]
>>     at
>> org.ofbiz.entity.jdbc.ConnectionFactory.getManagedConnection(ConnectionFactory.java:121)
>> [ofbiz-entity-test.jar:?]
>>     at
>> org.ofbiz.geronimo.GeronimoTransactionFactory.getConnection(GeronimoTransactionFactory.java:83)
>> [ofbiz-geronimo.jar:?]
>>     at
>> org.ofbiz.entity.transaction.TransactionFactory.getConnection(TransactionFactory.java:82)
>> [ofbiz-entity-test.jar:?]
>>     at
>> org.ofbiz.entity.jdbc.ConnectionFactory.getConnection(ConnectionFactory.java:97)
>> [ofbiz-entity-test.jar:?]
>>     at
>> org.ofbiz.entity.jdbc.DatabaseUtil.getConnection(DatabaseUtil.java:135)
>> [ofbiz-entity-test.jar:?]
>>     at
>> org.ofbiz.entity.jdbc.DatabaseUtil.getConnectionLogged(DatabaseUtil.java:155)
>> [ofbiz-entity-test.jar:?]
>>     at
>> org.ofbiz.entity.jdbc.DatabaseUtil.getTableNames(DatabaseUtil.java:977)
>> [ofbiz-entity-test.jar:?]
>>     at org.ofbiz.entity.jdbc.DatabaseUtil.checkDb(DatabaseUtil.java:189)
>> [ofbiz-entity-test.jar:?]
>>     at org.ofbiz.entity.jdbc.DatabaseUtil.checkDb(DatabaseUtil.java:178)
>> [ofbiz-entity-test.jar:?]
>>     at org.ofbiz.entity.datasource.GenericDAO.checkDb(GenericDAO.java:1234)
>> [ofbiz-entity-test.jar:?]
>>     at
>> org.ofbiz.entity.datasource.GenericHelperDAO.checkDataSource(GenericHelperDAO.java:200)
>> [ofbiz-entity-test.jar:?]
>>     at
>> org.ofbiz.entity.GenericDelegator.initializeOneGenericHelper(GenericDelegator.java:286)
>> [ofbiz-entity-test.jar:?]
>>     at
>> org.ofbiz.entity.GenericDelegator.access$000(GenericDelegator.java:87)
>> [ofbiz-entity-test.jar:?]
>>     at org.ofbiz.entity.GenericDelegator$1.call(GenericDelegator.java:297)
>> [ofbiz-entity-test.jar:?]
>>     at org.ofbiz.entity.GenericDelegator$1.call(GenericDelegator.java:295)
>> [ofbiz-entity-test.jar:?]
>>     at java.util.concurrent.FutureTask.run(FutureTask.java:262) [?:1.7.0_65]
>>     at
>> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)
>> [?:1.7.0_65]
>>     at
>> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)
>> [?:1.7.0_65]
>>     at
>> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
>> [?:1.7.0_65]
>>     at
>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
>> [?:1.7.0_65]
>>     at java.lang.Thread.run(Thread.java:745) [?:1.7.0_65]
>> eadPoolExecutor.java:615) [?:1.7.0_65]
>>     at java.lang.Thread.run(Thread.java:745) [?:1.7.0_65]
>>
>> --------------------------------------------------------------------------------
>>
>> My changeddatasource definition:
>> <datasource name="platfo"
>> helper-class="org.ofbiz.entity.datasource.GenericHelperDAO"
>>                     field-type-name="mysql"
>>                     check-on-start="true"
>>                     add-missing-on-start="true"
>>                     check-pks-on-start="false"
>>                     use-foreign-keys="true"
>>                     join-style="ansi-no-parenthesis"
>>                     alias-view-columns="false"
>>                     drop-fk-use-foreign-key-keyword="true"
>>                     table-type="InnoDB"
>>                     character-set="latin1"
>>                     collate="latin1_general_cs">
>>                 <read-data reader-name="seed"/>
>>                 <read-data reader-name="seed-initial"/>
>>                 <read-data reader-name="demo"/>
>>                 <read-data reader-name="ext"/>
>>                 <read-data reader-name="main"/>
>>                 <inline-jdbc
>>                         jdbc-driver="com.mysql.jdbc.Driver"
>> jdbc-uri="jdbc:mysql://127.0.0.1:3306/wp_platfo"
>>                         jdbc-username="test"
>>                         jdbc-password="test"
>>                         isolation-level="ReadCommitted"
>>                         pool-minsize="2"
>>                         pool-maxsize="250"
>> time-between-eviction-runs-millis="600000" />
>>         </datasource>
>>
>>
>> and delegator:
>>
>>
>>         <delegator name="default" entity-model-reader="main"
>>           entity-group-reader="main" entity-eca-reader="main"
>>           distributed-cache-clear-enabled="false">
>>           <group-map group-name="org.ofbiz" datasource-name="platfo"/>
>>           <group-map group-name="org.ofbiz.olap" datasource-name="platfo"/>
>>           <group-map group-name="org.ofbiz.tenant" datasource-name="platfo"/>
>>         </delegator>
>>
>>
>>
>> Thanks again!
>>
>>
>>
>> Am 12.12.2014 um 17:46 schrieb Youssef Khaye:
>>> I will try to answer, even if i don't understand your use case at 100%
>>>
>>> Hi for your second question the answer is no.
>>>
>>> For your first question you should show us your entityengine.xml
>>> There is two different cases where  you can use a second database.
>>>
>>>
>>> Case 1 use a diffrent delegator (from your first post, i think that you
>>> fill in this case), to get record you should instanciate
>>>
>>> a  delegator using the name you declared in entityegine.xml
>>> <delegator name="default" entity-model-reader="main"
>>> entity-group-reader="main" entity-eca-reader="main"
>>> distributed-cache-clear-enabled="false">
>>>          <group-map group-name="org.ofbiz" datasource-name="localpostgres"/>
>>>          <group-map group-name="org.ofbiz.olap"
>>> datasource-name="localpostgres"/>
>>>          <group-map group-name="org.ofbiz.tenant"
>>> datasource-name="localpostgres"/>
>>> </delegator>
>>>
>>> <delegator name="mysqlDb" entity-model-reader="main"
>>> entity-group-reader="main" entity-eca-reader="main"
>>> distributed-cache-clear-enabled="false">
>>>          <group-map group-name="com.custom datasource-name="sqlDataSource"/>
>>> </delegator>
>>>
>>> then in your service
>>> delegator = delagtor.geInstance("mysqlDb")
>>> then use the entity API to get record from your DB.
>>>
>>>
>>> Case 2
>>> In the same delegator you may assign a diffrent dataSource, that point
>>> to the external DB, to a given package.
>>>
>>> <delegator name="default" entity-model-reader="main"
>>> entity-group-reader="main" entity-eca-reader="main"
>>> distributed-cache-clear-enabled="false">
>>>          <group-map group-name="org.ofbiz" datasource-name="localpostgres"/>
>>>          <group-map group-name="com.custom datasource-name="sqlDataSource"/>
>>>          <group-map group-name="org.ofbiz.olap"
>>> datasource-name="localpostgres"/>
>>>          <group-map group-name="org.ofbiz.tenant"
>>> datasource-name="localpostgres"/>
>>> </delegator>
>>> In this case the defeault delegator you get in a service can fetch
>>> record from any entity in the com.custom package.
>>>
>>> Personnaly, I use the first one if I need the external database in
>>> limited area of my OFBiz.
>>>
>>> The second one is suitable if you need to access your external db in
>>> many areas of your OFBiz
>>>
>>>
>>> Le 12/12/2014 09:03, [hidden email] a écrit :
>>>> Hi All!
>>>>
>>>> after setting up the connection with an external database
>>>> without errors I have two more questions, on which I
>>>> could not find some specific information:
>>>>
>>>> (1) after setting up an entity, a delegator and
>>>> I datasource, which seem to work together now,
>>>> how (or where?) is the exchange of RECORDS with the
>>>> external database? ofbiz does not seem to
>>>> automatically detect and show the records from the
>>>> mysql-database.
>>>> Maybe my entity definitions are still wrong,
>>>> but then without error messages.
>>>> However: no records are imported or displayed
>>>> in the view. So: how can I get them from the mysql-database?
>>>>
>>>> Also unexpected to me: when I create new records in ofbiz,
>>>> they are displayed in ofbiz after creation (as one would
>>>> expect for any regular entity) but they are not transferred to
>>>> to the external mysql-database (which I guess could be
>>>> the purpose of a entity with associated externally
>>>> referenced datasource).
>>>>
>>>> So it seems that ofbiz did recognize the structure of
>>>> the external mysql-database, but then ignores to
>>>> exchange the data between ofbiz and the database.
>>>>
>>>> So how does ofbiz exchange records between
>>>> ofbiz and the external database (in a synchronized way)?
>>>>
>>>> Is there further setup or custom implmentation necessary?
>>>>
>>>> (2) the setup of a datasource is placed in entityengine.xml
>>>> in the framework/entity/config folder.
>>>> Is there a way to extend it with entries
>>>> defined in hot-deploy/.../entitydef/config/entityengine.xml ?
>>>>
>>>> I tried to setup another entityengine.xml there,
>>>> but this approach seemed to be ignored by ofbiz.
>>>>
>>>>
>>>> Thank you!
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>
>
Reply | Threaded
Open this post in threaded view
|

Re: connection to external database: part 2

info@agentur-m3.de
Thank you all for your help with understanding the
datasource and delegator concepts!

There is one additional point to this topic in the
context of automatic importing the entities (it would
be great if this connection would work at the end!):

in ModelInduceFromDb there seems to be a problem
with with the field-names of the mysql definitions.

I work with mysql server version 5.6.20 (as part of xampp).
For some of the field definitions ofbiz does not seem
to have appropriate fieldtypes, so that some of the
results of calling the servlet:

https://localhost:8443/webtools/control/view/ModelInduceFromDb

are like this:
<field name="postParent" type="invalid-BIGINT UNSIGNED:20:0"></field>

So they are invalid and of course they cause errors when using them as
entity-defintions.

Then I took a look at the fieldtype-definitions and to me it seems
that some of the valid mysql-fieldtypes  are not defined in
fieldtypemysql.xml.

Here are the complete fields for a table (wpposts form wordpress) I
would like to import for testing. The reference wordpress schema(1),
the ofbiz fieldtypes(2) and the ModelInduceFromDb-result (3):


(1) This is the reference field list from the mysql table:

  ID bigint(20) unsigned NOT NULL auto_increment,
  post_author bigint(20) unsigned NOT NULL default '0',
  post_date datetime NOT NULL default '0000-00-00 00:00:00',
  post_date_gmt datetime NOT NULL default '0000-00-00 00:00:00',
  post_content longtext NOT NULL,
  post_title text NOT NULL,
  post_excerpt text NOT NULL,
  post_status varchar(20) NOT NULL default 'publish',
  comment_status varchar(20) NOT NULL default 'open',
  ping_status varchar(20) NOT NULL default 'open',
  post_password varchar(20) NOT NULL default '',
  post_name varchar(200) NOT NULL default '',
  to_ping text NOT NULL,
  pinged text NOT NULL,
  post_modified datetime NOT NULL default '0000-00-00 00:00:00',
  post_modified_gmt datetime NOT NULL default '0000-00-00 00:00:00',
  post_content_filtered longtext NOT NULL,
  post_parent bigint(20) unsigned NOT NULL default '0',
  guid varchar(255) NOT NULL default '',
  menu_order int(11) NOT NULL default '0',
  post_type varchar(20) NOT NULL default 'post',
  post_mime_type varchar(100) NOT NULL default '',
  comment_count bigint(20) NOT NULL default '0',
  PRIMARY KEY  (ID),
  KEY post_name (post_name),
  KEY type_status_date (post_type,post_status,post_date,ID),
  KEY post_parent (post_parent),
  KEY post_author (post_author)


(2) This is ofbiz's framework/entity/fieldtype/fieldtypemysql.xml content:


<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->

<fieldtypemodel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/fieldtypemodel.xsd">
  <!-- ===================== field-type-def ==================== -->
    <!-- General Types -->
    <field-type-def type="blob" sql-type="LONGBLOB"
java-type="java.sql.Blob"/>
    <field-type-def type="byte-array" sql-type="LONGBLOB"
java-type="byte[]"/>
    <field-type-def type="object" sql-type="LONGBLOB" java-type="Object"/>

    <field-type-def type="date-time" sql-type="DATETIME"
java-type="java.sql.Timestamp"/>
    <field-type-def type="date" sql-type="DATE" java-type="java.sql.Date"/>
    <field-type-def type="time" sql-type="TIME" java-type="java.sql.Time"/>

    <field-type-def type="currency-amount" sql-type="DECIMAL(18,2)"
java-type="java.math.BigDecimal"/>
    <field-type-def type="currency-precise" sql-type="DECIMAL(18,3)"
java-type="java.math.BigDecimal"/>
    <field-type-def type="fixed-point" sql-type="DECIMAL(18,6)"
java-type="java.math.BigDecimal"/>
    <field-type-def type="floating-point" sql-type="DOUBLE"
java-type="Double"/>
    <field-type-def type="numeric" sql-type="DECIMAL(20,0)"
java-type="Long"/>

    <field-type-def type="id" sql-type="VARCHAR(20)" java-type="String"/>
    <field-type-def type="id-long" sql-type="VARCHAR(60)"
java-type="String"/>
    <field-type-def type="id-vlong" sql-type="VARCHAR(250)"
java-type="String"/>

    <field-type-def type="indicator" sql-type="CHAR(1)" java-type="String"/>
    <field-type-def type="very-short" sql-type="VARCHAR(10)"
java-type="String"/>
    <field-type-def type="short-varchar" sql-type="VARCHAR(60)"
java-type="String"/>
    <field-type-def type="long-varchar" sql-type="VARCHAR(255)"
java-type="String"/>
    <field-type-def type="very-long" sql-type="LONGTEXT"
java-type="String"/>

    <field-type-def type="comment" sql-type="VARCHAR(255)"
java-type="String"/>
    <field-type-def type="description" sql-type="VARCHAR(255)"
java-type="String"/>
    <field-type-def type="name" sql-type="VARCHAR(100)" java-type="String"/>
    <field-type-def type="value" sql-type="VARCHAR(255)"
java-type="String"/>

    <!-- Specialized Types -->
    <field-type-def type="credit-card-number" sql-type="VARCHAR(255)"
java-type="String"/>
    <field-type-def type="credit-card-date" sql-type="VARCHAR(20)"
java-type="String"/>
    <field-type-def type="email" sql-type="VARCHAR(255)"
java-type="String"/>
    <field-type-def type="url" sql-type="VARCHAR(255)" java-type="String"/>
    <field-type-def type="id-ne" sql-type="VARCHAR(20)" java-type="String"/>
    <field-type-def type="id-long-ne" sql-type="VARCHAR(60)"
java-type="String"/>
    <field-type-def type="id-vlong-ne" sql-type="VARCHAR(250)"
java-type="String"/>
    <field-type-def type="tel-number" sql-type="VARCHAR(60)"
java-type="String"/>
</fieldtypemodel>


(3) And this is the induced result (ModelInduceFromDb):

 <entity entity-name="WpPosts"
            package-name=""
            title="None"
            copyright="Copyright 2001-2014 The Apache Software Foundation">
      <field name="menuOrder" type="numeric"></field>
      <field name="postModified" type="date-time"></field>
      <field name="postMimeType" type="long-varchar"></field>
      <field name="guid" type="long-varchar"></field>
      <field name="postAuthor" type="invalid-BIGINT UNSIGNED:20:0"></field>
      <field name="postModifiedGmt" type="date-time"></field>
      <field name="postName" type="long-varchar"></field>
      <field name="commentCount" type="invalid-BIGINT:19:0"></field>
      <field name="postDate" type="date-time"></field>
      <field name="postContentFiltered"
type="invalid-LONGTEXT:2147483647:0"></field>
      <field name="pingStatus" type="short-varchar"></field>
      <field name="postParent" type="invalid-BIGINT UNSIGNED:20:0"></field>
      <field name="toPing" type="very-long"></field>
      <field name="postExcerpt" type="very-long"></field>
      <field name="commentStatus" type="short-varchar"></field>
      <field name="pinged" type="very-long"></field>
      <field name="postStatus" type="short-varchar"></field>
      <field name="id" type="invalid-BIGINT UNSIGNED:20:0"></field>
      <field name="postDateGmt" type="date-time"></field>
      <field name="postTitle" type="very-long"></field>
      <field name="postPassword" type="short-varchar"></field>
      <field name="postContent"
type="invalid-LONGTEXT:2147483647:0"></field>
      <field name="postType" type="short-varchar"></field>
    </entity>

Would it solve the problem  to add the missing fieldtypes to
fieldtypedef.xml ?




Reply | Threaded
Open this post in threaded view
|

Re: connection to external database: part 2

Adrian Crum-3
It would be best to create your own custom field type file, then
reference it in your MySQL data source. Leave the original MySQL field
type file as-is.

I too have noticed problems getting ModelInduceFromDb to work properly
with MySQL. Maybe once you get this working you can create a Jira issue
for it.

Adrian Crum
Sandglass Software
www.sandglass-software.com

On 12/20/2014 8:25 AM, [hidden email] wrote:

> Thank you all for your help with understanding the
> datasource and delegator concepts!
>
> There is one additional point to this topic in the
> context of automatic importing the entities (it would
> be great if this connection would work at the end!):
>
> in ModelInduceFromDb there seems to be a problem
> with with the field-names of the mysql definitions.
>
> I work with mysql server version 5.6.20 (as part of xampp).
> For some of the field definitions ofbiz does not seem
> to have appropriate fieldtypes, so that some of the
> results of calling the servlet:
>
> https://localhost:8443/webtools/control/view/ModelInduceFromDb
>
> are like this:
> <field name="postParent" type="invalid-BIGINT UNSIGNED:20:0"></field>
>
> So they are invalid and of course they cause errors when using them as
> entity-defintions.
>
> Then I took a look at the fieldtype-definitions and to me it seems
> that some of the valid mysql-fieldtypes  are not defined in
> fieldtypemysql.xml.
>
> Here are the complete fields for a table (wpposts form wordpress) I
> would like to import for testing. The reference wordpress schema(1),
> the ofbiz fieldtypes(2) and the ModelInduceFromDb-result (3):
>
>
> (1) This is the reference field list from the mysql table:
>
>    ID bigint(20) unsigned NOT NULL auto_increment,
>    post_author bigint(20) unsigned NOT NULL default '0',
>    post_date datetime NOT NULL default '0000-00-00 00:00:00',
>    post_date_gmt datetime NOT NULL default '0000-00-00 00:00:00',
>    post_content longtext NOT NULL,
>    post_title text NOT NULL,
>    post_excerpt text NOT NULL,
>    post_status varchar(20) NOT NULL default 'publish',
>    comment_status varchar(20) NOT NULL default 'open',
>    ping_status varchar(20) NOT NULL default 'open',
>    post_password varchar(20) NOT NULL default '',
>    post_name varchar(200) NOT NULL default '',
>    to_ping text NOT NULL,
>    pinged text NOT NULL,
>    post_modified datetime NOT NULL default '0000-00-00 00:00:00',
>    post_modified_gmt datetime NOT NULL default '0000-00-00 00:00:00',
>    post_content_filtered longtext NOT NULL,
>    post_parent bigint(20) unsigned NOT NULL default '0',
>    guid varchar(255) NOT NULL default '',
>    menu_order int(11) NOT NULL default '0',
>    post_type varchar(20) NOT NULL default 'post',
>    post_mime_type varchar(100) NOT NULL default '',
>    comment_count bigint(20) NOT NULL default '0',
>    PRIMARY KEY  (ID),
>    KEY post_name (post_name),
>    KEY type_status_date (post_type,post_status,post_date,ID),
>    KEY post_parent (post_parent),
>    KEY post_author (post_author)
>
>
> (2) This is ofbiz's framework/entity/fieldtype/fieldtypemysql.xml content:
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!--
> Licensed to the Apache Software Foundation (ASF) under one
> or more contributor license agreements.  See the NOTICE file
> distributed with this work for additional information
> regarding copyright ownership.  The ASF licenses this file
> to you under the Apache License, Version 2.0 (the
> "License"); you may not use this file except in compliance
> with the License.  You may obtain a copy of the License at
>
> http://www.apache.org/licenses/LICENSE-2.0
>
> Unless required by applicable law or agreed to in writing,
> software distributed under the License is distributed on an
> "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> KIND, either express or implied.  See the License for the
> specific language governing permissions and limitations
> under the License.
> -->
>
> <fieldtypemodel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>
> xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/fieldtypemodel.xsd">
>    <!-- ===================== field-type-def ==================== -->
>      <!-- General Types -->
>      <field-type-def type="blob" sql-type="LONGBLOB"
> java-type="java.sql.Blob"/>
>      <field-type-def type="byte-array" sql-type="LONGBLOB"
> java-type="byte[]"/>
>      <field-type-def type="object" sql-type="LONGBLOB" java-type="Object"/>
>
>      <field-type-def type="date-time" sql-type="DATETIME"
> java-type="java.sql.Timestamp"/>
>      <field-type-def type="date" sql-type="DATE" java-type="java.sql.Date"/>
>      <field-type-def type="time" sql-type="TIME" java-type="java.sql.Time"/>
>
>      <field-type-def type="currency-amount" sql-type="DECIMAL(18,2)"
> java-type="java.math.BigDecimal"/>
>      <field-type-def type="currency-precise" sql-type="DECIMAL(18,3)"
> java-type="java.math.BigDecimal"/>
>      <field-type-def type="fixed-point" sql-type="DECIMAL(18,6)"
> java-type="java.math.BigDecimal"/>
>      <field-type-def type="floating-point" sql-type="DOUBLE"
> java-type="Double"/>
>      <field-type-def type="numeric" sql-type="DECIMAL(20,0)"
> java-type="Long"/>
>
>      <field-type-def type="id" sql-type="VARCHAR(20)" java-type="String"/>
>      <field-type-def type="id-long" sql-type="VARCHAR(60)"
> java-type="String"/>
>      <field-type-def type="id-vlong" sql-type="VARCHAR(250)"
> java-type="String"/>
>
>      <field-type-def type="indicator" sql-type="CHAR(1)" java-type="String"/>
>      <field-type-def type="very-short" sql-type="VARCHAR(10)"
> java-type="String"/>
>      <field-type-def type="short-varchar" sql-type="VARCHAR(60)"
> java-type="String"/>
>      <field-type-def type="long-varchar" sql-type="VARCHAR(255)"
> java-type="String"/>
>      <field-type-def type="very-long" sql-type="LONGTEXT"
> java-type="String"/>
>
>      <field-type-def type="comment" sql-type="VARCHAR(255)"
> java-type="String"/>
>      <field-type-def type="description" sql-type="VARCHAR(255)"
> java-type="String"/>
>      <field-type-def type="name" sql-type="VARCHAR(100)" java-type="String"/>
>      <field-type-def type="value" sql-type="VARCHAR(255)"
> java-type="String"/>
>
>      <!-- Specialized Types -->
>      <field-type-def type="credit-card-number" sql-type="VARCHAR(255)"
> java-type="String"/>
>      <field-type-def type="credit-card-date" sql-type="VARCHAR(20)"
> java-type="String"/>
>      <field-type-def type="email" sql-type="VARCHAR(255)"
> java-type="String"/>
>      <field-type-def type="url" sql-type="VARCHAR(255)" java-type="String"/>
>      <field-type-def type="id-ne" sql-type="VARCHAR(20)" java-type="String"/>
>      <field-type-def type="id-long-ne" sql-type="VARCHAR(60)"
> java-type="String"/>
>      <field-type-def type="id-vlong-ne" sql-type="VARCHAR(250)"
> java-type="String"/>
>      <field-type-def type="tel-number" sql-type="VARCHAR(60)"
> java-type="String"/>
> </fieldtypemodel>
>
>
> (3) And this is the induced result (ModelInduceFromDb):
>
>   <entity entity-name="WpPosts"
>              package-name=""
>              title="None"
>              copyright="Copyright 2001-2014 The Apache Software Foundation">
>        <field name="menuOrder" type="numeric"></field>
>        <field name="postModified" type="date-time"></field>
>        <field name="postMimeType" type="long-varchar"></field>
>        <field name="guid" type="long-varchar"></field>
>        <field name="postAuthor" type="invalid-BIGINT UNSIGNED:20:0"></field>
>        <field name="postModifiedGmt" type="date-time"></field>
>        <field name="postName" type="long-varchar"></field>
>        <field name="commentCount" type="invalid-BIGINT:19:0"></field>
>        <field name="postDate" type="date-time"></field>
>        <field name="postContentFiltered"
> type="invalid-LONGTEXT:2147483647:0"></field>
>        <field name="pingStatus" type="short-varchar"></field>
>        <field name="postParent" type="invalid-BIGINT UNSIGNED:20:0"></field>
>        <field name="toPing" type="very-long"></field>
>        <field name="postExcerpt" type="very-long"></field>
>        <field name="commentStatus" type="short-varchar"></field>
>        <field name="pinged" type="very-long"></field>
>        <field name="postStatus" type="short-varchar"></field>
>        <field name="id" type="invalid-BIGINT UNSIGNED:20:0"></field>
>        <field name="postDateGmt" type="date-time"></field>
>        <field name="postTitle" type="very-long"></field>
>        <field name="postPassword" type="short-varchar"></field>
>        <field name="postContent"
> type="invalid-LONGTEXT:2147483647:0"></field>
>        <field name="postType" type="short-varchar"></field>
>      </entity>
>
> Would it solve the problem  to add the missing fieldtypes to
> fieldtypedef.xml ?
>
>
>
>