You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by 刘波 <10...@qq.com> on 2018/07/22 15:40:44 UTC

回复: is is possible to dynamically create entity in cayenne?

hi Andrus,
thanks very much!


I've watching your video on youtube that introduce the Cayenne framework one hour ago this evening~


I know Apache Cayenne in yesterday, and find it a very exciting framework maybe can fit our business  requirement.


We need dynamically create data table in java code at runtime, the user case is:
1.user define a table in web form, such as table name, columns, columns type.
2.then, we need to create a table according the user definition in mysql database.
3.user then can use CRUD action on that table, for example, save,select,update,delete,pagination,etc...


I want to use cayenne with linkREST to provide a rest data api. Hope there are some advice~


















------------------ 原始邮件 ------------------
发件人: "Andrus Adamchik"<an...@objectstyle.org>;
发送时间: 2018年7月22日(星期天) 晚上11:15
收件人: "user"<us...@cayenne.apache.org>;
抄送: "刘波"<10...@qq.com>; 
主题: Re: is is possible to dynamically create entity in cayenne?



Hi there,

The short answer is that org.apache.cayenne.CayenneDataObject is that Java object that every generic object can be mapped to. Will be happy to expand this answer if you have any follow up questions.

(Also I noticed you are not subscribed to the list, so you may miss some replies that are sent to the list only. Everything will be in the list archives of course).

Andrus



> On Jul 22, 2018, at 3:37 PM, 刘波 <10...@qq.com> wrote:
> 
> Hi users,
> 
> 
> I'm new to cayenne, we face a problem recently. 
> 
> 
> we want to dynamically create the table in mysql, and it's corresponding entity.
> 
> 
> we find the Generic Objects, but it seems need a specified java class before.
> 
> 
> Any ideas, 
> thanks~

Re: is is possible to dynamically create entity in cayenne?

Posted by Andrus Adamchik <an...@objectstyle.org>.
Hi,

Cayenne can help with #3. Generic object functionality is there. As Tony said elsewhere in this thread, this is not the most common way of doing things, so there is a lack of high quality examples, but it can be done. There are a few possible flows. Here is one example:

1. Implement a custom DataMapLoader that dynamically reverse-engineers your DB schema using cayenne-datasync API [1]. You may need to borrow code from DefaultDbImportAction.java [2].
2. Start ServerRuntime instance with the custom DataMapLoader above (can be added via an extension Module):

Now that I think of it, #1 should probably be a part of Cayenne (so we'd gladly accept it as a contribution :)). 

> I want to use cayenne with linkREST to provide a rest data api. Hope there are some advice~

Is that also in the dynamic scenario? Or are we talking a more "classic" approach, when you know the model upfront. 

FWIW I wanted to prototype a Cayenne / LinkRest extension for some time that starts without any ORM mapping, and when you point it to a previously unknown database, it reverse-engineers it and creates a bunch of LinkRest endpoints on the fly. Never got around to doing it, but I still like the idea.

Andrus

[1] https://github.com/apache/cayenne/tree/master/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport
[2] https://github.com/apache/cayenne/blob/master/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/DefaultDbImportAction.java


> On Jul 22, 2018, at 6:40 PM, 刘波 <10...@qq.com> wrote:
> 
> hi Andrus,
> thanks very much!
> 
> I've watching your video on youtube that introduce the Cayenne framework one hour ago this evening~
> 
> I know Apache Cayenne in yesterday, and find it a very exciting framework maybe can fit our business  requirement.
> 
> We need dynamically create data table in java code at runtime, the user case is:
> 1.user define a table in web form, such as table name, columns, columns type.
> 2.then, we need to create a table according the user definition in mysql database.
> 3.user then can use CRUD action on that table, for example, save,select,update,delete,pagination,etc...
> 
> I want to use cayenne with linkREST to provide a rest data api. Hope there are some advice~
> 
> 
> 
> 
> 
> 
> 
> 
> 
> ------------------ 原始邮件 ------------------
> 发件人: "Andrus Adamchik"<an...@objectstyle.org>;
> 发送时间: 2018年7月22日(星期天) 晚上11:15
> 收件人: "user"<us...@cayenne.apache.org>;
> 抄送: "刘波"<10...@qq.com>;
> 主题: Re: is is possible to dynamically create entity in cayenne?
> 
> Hi there,
> 
> The short answer is that org.apache.cayenne.CayenneDataObject is that Java object that every generic object can be mapped to. Will be happy to expand this answer if you have any follow up questions.
> 
> (Also I noticed you are not subscribed to the list, so you may miss some replies that are sent to the list only. Everything will be in the list archives of course).
> 
> Andrus
> 
> 
> 
> > On Jul 22, 2018, at 3:37 PM, 刘波 <10...@qq.com> wrote:
> > 
> > Hi users,
> > 
> > 
> > I'm new to cayenne, we face a problem recently. 
> > 
> > 
> > we want to dynamically create the table in mysql, and it's corresponding entity.
> > 
> > 
> > we find the Generic Objects, but it seems need a specified java class before.
> > 
> > 
> > Any ideas, 
> > thanks~


Re: 回复: is is possible to dynamically create entity in cayenne?

Posted by Tony <to...@giaccone.org>.
Obviously you know your requirements better than anyone and maybe this is the best solution. However, what you are describing seems like a very complicated solution.

It seems like you are going to build the equivalent of the Cayenne Data Modeler as a web app. And then include the cayenne runtime system as well. I’m sure it’s possible but there are many complicated use cases to model. 

For example, if your user describes a table, creates the table, and populates it with data how will you manage the desire of the user after population of data to change a column type? Will you just delete the data in the column in the table? What if the column is mandatory?

Once the table is instantiated in MySQL you will have to create alter table statements to modify it. This is another complicated process.

Are you going to support foreign key relationships??

I’m sure you can get cayenne to do support the features you describe, the modeler does them, but the consequences and complexity of this solution seems quite high.

Tony Giaccone

> On Jul 22, 2018, at 11:40 AM, 刘波 <10...@qq.com> wrote:
> 
> hi Andrus,
> thanks very much!
> 
> 
> I've watching your video on youtube that introduce the Cayenne framework one hour ago this evening~
> 
> 
> I know Apache Cayenne in yesterday, and find it a very exciting framework maybe can fit our business  requirement.
> 
> 
> We need dynamically create data table in java code at runtime, the user case is:
> 1.user define a table in web form, such as table name, columns, columns type.
> 2.then, we need to create a table according the user definition in mysql database.
> 3.user then can use CRUD action on that table, for example, save,select,update,delete,pagination,etc...
> 
> 
> I want to use cayenne with linkREST to provide a rest data api. Hope there are some advice~
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> ------------------ 原始邮件 ------------------
> 发件人: "Andrus Adamchik"<an...@objectstyle.org>;
> 发送时间: 2018年7月22日(星期天) 晚上11:15
> 收件人: "user"<us...@cayenne.apache.org>;
> 抄送: "刘波"<10...@qq.com>; 
> 主题: Re: is is possible to dynamically create entity in cayenne?
> 
> 
> 
> Hi there,
> 
> The short answer is that org.apache.cayenne.CayenneDataObject is that Java object that every generic object can be mapped to. Will be happy to expand this answer if you have any follow up questions.
> 
> (Also I noticed you are not subscribed to the list, so you may miss some replies that are sent to the list only. Everything will be in the list archives of course).
> 
> Andrus
> 
> 
> 
>> On Jul 22, 2018, at 3:37 PM, 刘波 <10...@qq.com> wrote:
>> 
>> Hi users,
>> 
>> 
>> I'm new to cayenne, we face a problem recently. 
>> 
>> 
>> we want to dynamically create the table in mysql, and it's corresponding entity.
>> 
>> 
>> we find the Generic Objects, but it seems need a specified java class before.
>> 
>> 
>> Any ideas, 
>> thanks~