Re: Question about optionality in one-to-one relationships

2024-01-10 Thread Michael Gentry
Hi Riccardo,

There is also a validateForSave() that might be easier (handles inserts and
updates).

mrg


On Wed, Jan 10, 2024 at 8:34 AM Michael Gentry  wrote:

> Hi Riccardo,
>
> The To Dep PK checkbox on the DbEntity isn't really intended to say "this
> relationship is required" (that is a by-product). It is designed to assign
> a PK from one entity to another.
>
> Perhaps use a Pre-Persist Callback (ObjEntity tab) to verify the shipment
> has a shipment number?
>
>
> https://cayenne.apache.org/docs/4.1/cayenne-guide/#types-of-lifecycle-events
>
> You could also use validateForInsert() I think, but you should also maybe
> do a validateForUpdate() if you go down that path.
>
> mrg
>
>
> On Wed, Jan 10, 2024 at 6:50 AM Riccardo De Menna 
> wrote:
>
>> Hi Michael,
>>
>> > Try deselecting the "To Dep PK" checkbox on the relationship
>> > in SHIPMENT_NUMBER -> SHIPMENT.
>>
>> I tryed both ToDep directions but they don’t seem to affect the result.
>> >
>> > I can see how having that checked would make the relationship required
>> > because it ties SHIPMENT_NUMBER's PK to SHIPMENT's PK, therefore a
>> > SHIPMENT_NUMBER shouldn't exist without a corresponding SHIPMENT and it
>> > sounds like you want it to be separate.
>>
>> But I do expect the reverse relationship to be required… As I undrestood
>> it, I would set ToDepPK on the SHIPMENT_NUMBER side and keep it off on the
>> SHIPMENT side. I want to be able to generate numbers before having to link
>> them to shipments but I also expect shipments non to exist without a number.
>>
>> BTW, as I said to Nikita, if I forcefully ignore the flag and manually
>> bypass my validation code depending on it, the ObjectContext does not seem
>> to complain about it and does commit the save.
>>
>> I assume it’s just the flag being marked as mandatory for some other side
>> condition but I still don’t know what to use in the template as a reliable
>> replacement.
>>
>> Riccardo
>>
>> >
>> > mrg
>> >
>> >
>> > On Wed, Jan 10, 2024 at 12:10 AM Riccardo De Menna 
>> > wrote:
>> >
>> >> Hi Michael,
>> >>
>> >> Thank you for helping. Yes… you modeled exactly what I described down
>> to
>> >> the delete rules. I imported your files in modeler and run class
>> generation
>> >> but I still get the relationship (TO_SHIP in your model) to appear as
>> >> mandatory. Could it be an issue in class generation?
>> >>
>> >> This is a little VE snippet I use in my template to output a static
>> list
>> >> of mandatory relationships.
>> >>
>> >> #foreach( $rel in ${object.DeclaredRelationships} )
>> >>  #if (${rel.isMandatory()} && !${rel.ToMany} )
>> >>#set($bar =
>> >>
>> $requiredRelationships.add("${stringUtils.capitalizedAsConstant($rel.Name)}_PROPERTY"))
>> >>  #end
>> >> #end
>> >> public static final List REQUIRED_RELATIONSHIPS = List.of(
>> >>  #foreach( $rel in ${requiredRelationships} )
>> >>${rel}#if(!$foreach.last),#end
>> >>  #end
>> >> );
>> >>
>> >> And contrary to what I would expect, I get this in my superclass:
>> >>
>> >> public static final List REQUIRED_RELATIONSHIPS = List.of(
>> >>  TO_SHIP_PROPERTY
>> >> );
>> >>
>> >> Riccardo De Menna
>> >>
>> >>
>> >>> On 10 Jan 2024, at 01:20, Michael Gentry  wrote:
>> >>>
>> >>> Hi Riccardo,
>> >>>
>> >>> I may have completely misunderstood your intention, but here is my
>> first
>> >>> cut for a model:
>> >>>
>> >>> cayenne-o2o.xml:
>> >>> 
>> >>> http://cayenne.apache.org/schema/10/domain;
>> >>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance;
>> >>> xsi:schemaLocation="http://cayenne.apache.org/schema/10/domain
>> >>> https://cayenne.apache.org/schema/10/domain.xsd;
>> >>> project-version="10">
>> >>> 
>> >>> 
>> >>>
>> >>> datamap.map.xml:
>> >>> 
>> >>> http://cayenne.apache.org/schema/10/modelMap;
>> >>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance;
>> >>> xsi:schemaLocation="http://cayenne.apache.org/sc

Re: Question about optionality in one-to-one relationships

2024-01-10 Thread Michael Gentry
Hi Riccardo,

The To Dep PK checkbox on the DbEntity isn't really intended to say "this
relationship is required" (that is a by-product). It is designed to assign
a PK from one entity to another.

Perhaps use a Pre-Persist Callback (ObjEntity tab) to verify the shipment
has a shipment number?

https://cayenne.apache.org/docs/4.1/cayenne-guide/#types-of-lifecycle-events

You could also use validateForInsert() I think, but you should also maybe
do a validateForUpdate() if you go down that path.

mrg


On Wed, Jan 10, 2024 at 6:50 AM Riccardo De Menna 
wrote:

> Hi Michael,
>
> > Try deselecting the "To Dep PK" checkbox on the relationship
> > in SHIPMENT_NUMBER -> SHIPMENT.
>
> I tryed both ToDep directions but they don’t seem to affect the result.
> >
> > I can see how having that checked would make the relationship required
> > because it ties SHIPMENT_NUMBER's PK to SHIPMENT's PK, therefore a
> > SHIPMENT_NUMBER shouldn't exist without a corresponding SHIPMENT and it
> > sounds like you want it to be separate.
>
> But I do expect the reverse relationship to be required… As I undrestood
> it, I would set ToDepPK on the SHIPMENT_NUMBER side and keep it off on the
> SHIPMENT side. I want to be able to generate numbers before having to link
> them to shipments but I also expect shipments non to exist without a number.
>
> BTW, as I said to Nikita, if I forcefully ignore the flag and manually
> bypass my validation code depending on it, the ObjectContext does not seem
> to complain about it and does commit the save.
>
> I assume it’s just the flag being marked as mandatory for some other side
> condition but I still don’t know what to use in the template as a reliable
> replacement.
>
> Riccardo
>
> >
> > mrg
> >
> >
> > On Wed, Jan 10, 2024 at 12:10 AM Riccardo De Menna 
> > wrote:
> >
> >> Hi Michael,
> >>
> >> Thank you for helping. Yes… you modeled exactly what I described down to
> >> the delete rules. I imported your files in modeler and run class
> generation
> >> but I still get the relationship (TO_SHIP in your model) to appear as
> >> mandatory. Could it be an issue in class generation?
> >>
> >> This is a little VE snippet I use in my template to output a static list
> >> of mandatory relationships.
> >>
> >> #foreach( $rel in ${object.DeclaredRelationships} )
> >>  #if (${rel.isMandatory()} && !${rel.ToMany} )
> >>#set($bar =
> >>
> $requiredRelationships.add("${stringUtils.capitalizedAsConstant($rel.Name)}_PROPERTY"))
> >>  #end
> >> #end
> >> public static final List REQUIRED_RELATIONSHIPS = List.of(
> >>  #foreach( $rel in ${requiredRelationships} )
> >>${rel}#if(!$foreach.last),#end
> >>  #end
> >> );
> >>
> >> And contrary to what I would expect, I get this in my superclass:
> >>
> >> public static final List REQUIRED_RELATIONSHIPS = List.of(
> >>  TO_SHIP_PROPERTY
> >> );
> >>
> >> Riccardo De Menna
> >>
> >>
> >>> On 10 Jan 2024, at 01:20, Michael Gentry  wrote:
> >>>
> >>> Hi Riccardo,
> >>>
> >>> I may have completely misunderstood your intention, but here is my
> first
> >>> cut for a model:
> >>>
> >>> cayenne-o2o.xml:
> >>> 
> >>> http://cayenne.apache.org/schema/10/domain;
> >>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance;
> >>> xsi:schemaLocation="http://cayenne.apache.org/schema/10/domain
> >>> https://cayenne.apache.org/schema/10/domain.xsd;
> >>> project-version="10">
> >>> 
> >>> 
> >>>
> >>> datamap.map.xml:
> >>> 
> >>> http://cayenne.apache.org/schema/10/modelMap;
> >>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance;
> >>> xsi:schemaLocation="http://cayenne.apache.org/schema/10/modelMap
> >>> https://cayenne.apache.org/schema/10/modelMap.xsd;
> >>> project-version="10">
> >>> 
> >>> 
> >>> 
> >>>  >> isMandatory="true"
> >>> />
> >>> 
> >>> 
> >>>  >> isMandatory="true"
> >>>>
> >>> http://cayenne.apache.org/schema/10/info;
> >> name=
> >>> "comment" value="This ID is the same as SHIPMENTs ID."/>
> >>> 
> >>> 
> >>> http://cayen

Re: Question about optionality in one-to-one relationships

2024-01-10 Thread Michael Gentry
Hi Riccardo,

Try deselecting the "To Dep PK" checkbox on the relationship
in SHIPMENT_NUMBER -> SHIPMENT.

I can see how having that checked would make the relationship required
because it ties SHIPMENT_NUMBER's PK to SHIPMENT's PK, therefore a
SHIPMENT_NUMBER shouldn't exist without a corresponding SHIPMENT and it
sounds like you want it to be separate.

mrg


On Wed, Jan 10, 2024 at 12:10 AM Riccardo De Menna 
wrote:

> Hi Michael,
>
> Thank you for helping. Yes… you modeled exactly what I described down to
> the delete rules. I imported your files in modeler and run class generation
> but I still get the relationship (TO_SHIP in your model) to appear as
> mandatory. Could it be an issue in class generation?
>
> This is a little VE snippet I use in my template to output a static list
> of mandatory relationships.
>
> #foreach( $rel in ${object.DeclaredRelationships} )
>   #if (${rel.isMandatory()} && !${rel.ToMany} )
> #set($bar =
> $requiredRelationships.add("${stringUtils.capitalizedAsConstant($rel.Name)}_PROPERTY"))
>   #end
> #end
> public static final List REQUIRED_RELATIONSHIPS = List.of(
>   #foreach( $rel in ${requiredRelationships} )
> ${rel}#if(!$foreach.last),#end
>   #end
> );
>
> And contrary to what I would expect, I get this in my superclass:
>
> public static final List REQUIRED_RELATIONSHIPS = List.of(
>   TO_SHIP_PROPERTY
> );
>
> Riccardo De Menna
>
>
> > On 10 Jan 2024, at 01:20, Michael Gentry  wrote:
> >
> > Hi Riccardo,
> >
> > I may have completely misunderstood your intention, but here is my first
> > cut for a model:
> >
> > cayenne-o2o.xml:
> > 
> > http://cayenne.apache.org/schema/10/domain;
> > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance;
> > xsi:schemaLocation="http://cayenne.apache.org/schema/10/domain
> > https://cayenne.apache.org/schema/10/domain.xsd;
> > project-version="10">
> > 
> > 
> >
> > datamap.map.xml:
> > 
> > http://cayenne.apache.org/schema/10/modelMap;
> > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance;
> > xsi:schemaLocation="http://cayenne.apache.org/schema/10/modelMap
> > https://cayenne.apache.org/schema/10/modelMap.xsd;
> > project-version="10">
> > 
> > 
> > 
> >  isMandatory="true"
> > />
> > 
> > 
> >  isMandatory="true"
> >>
> > http://cayenne.apache.org/schema/10/info;
> name=
> > "comment" value="This ID is the same as SHIPMENTs ID."/>
> > 
> > 
> > http://cayenne.apache.org/schema/10/info;
> name=
> > "comment" value="This is the shipment number."/>
> > 
> > 
> >  > "optimistic" dbEntityName="SHIPMENT"/>
> >  > lock-type="optimistic" dbEntityName="SHIPMENT_NUMBER">
> >  db-attribute-path="NUM"/>
> > 
> >  target="SHIPMENT_NUMBER"
> >>
> > 
> > 
> >  > toDependentPK="true">
> > 
> > 
> >  target="ShipmentNumber"
> > deleteRule="Cascade" db-relationship-path="toShipNum"/>
> >  > deleteRule="Deny" db-relationship-path="toShip"/>
> > 
> >
> > Copy/Paste these files somewhere, then try loading them up into your 4.2
> > Modeler and see if it is close.
> >
> > mrg
> >
> >
> > On Tue, Jan 9, 2024 at 9:54 AM Riccardo De Menna 
> wrote:
> >
> >> Hi,
> >>
> >> Can someone help me understand something?
> >>
> >> I’m trying to model a one-to-one relationship between two entities but I
> >> can’t seem to get the relationship to be optional.
> >>
> >> In my specific case I need to model an entity representing shipments
> with
> >> a postal service. Each shipment needs to have a number taken from a
> >> range/group that is pre-assigned by the postal service.
> >>
> >> Thus I created a SHIPMENT_NUMBER entity with just an INTEGER attribute
> and
> >> then used that attribute to build the relationship with the SHIPMENT
> >> entity. Possibly with “To dep PK” as well.
> >>
> >> I want the relationship to be optional so that I can generate
> >> SHIPMENT_NUMBER as many as I want and populate them with the numbers
> >> assigned by the postal service and only later, when the real SHIPMENT is
> >> actually needed/created, link it with the number in a one-to-one
> fashion.
> >>
> >> I’m not sure why, but my class generated content always shows the
> >> relationship as mandatory.
> >>
> >> Coming from the WebObjects world, I'm used to a modeler that explicitly
> >> shows checkboxes for isMandatory on relationships like with the
> attributes.
> >> Here in Cayenne it seems that optionality is implicitly determined
> based on
> >> the design.
> >>
> >> Have I misunderstood something? Is my design flawed?
> >>
> >> Any tip is appreciated.
> >>
> >> Regards,
> >> Riccardo
>
>


Re: Question about optionality in one-to-one relationships

2024-01-09 Thread Michael Gentry
Hi Riccardo,

I may have completely misunderstood your intention, but here is my first
cut for a model:

cayenne-o2o.xml:

http://cayenne.apache.org/schema/10/domain;
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance;
xsi:schemaLocation="http://cayenne.apache.org/schema/10/domain
https://cayenne.apache.org/schema/10/domain.xsd;
project-version="10">



datamap.map.xml:

http://cayenne.apache.org/schema/10/modelMap;
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance;
xsi:schemaLocation="http://cayenne.apache.org/schema/10/modelMap
https://cayenne.apache.org/schema/10/modelMap.xsd;
project-version="10">







http://cayenne.apache.org/schema/10/info; name=
"comment" value="This ID is the same as SHIPMENTs ID."/>


http://cayenne.apache.org/schema/10/info; name=
"comment" value="This is the shipment number."/>
















Copy/Paste these files somewhere, then try loading them up into your 4.2
Modeler and see if it is close.

mrg


On Tue, Jan 9, 2024 at 9:54 AM Riccardo De Menna  wrote:

> Hi,
>
> Can someone help me understand something?
>
> I’m trying to model a one-to-one relationship between two entities but I
> can’t seem to get the relationship to be optional.
>
> In my specific case I need to model an entity representing shipments with
> a postal service. Each shipment needs to have a number taken from a
> range/group that is pre-assigned by the postal service.
>
> Thus I created a SHIPMENT_NUMBER entity with just an INTEGER attribute and
> then used that attribute to build the relationship with the SHIPMENT
> entity. Possibly with “To dep PK” as well.
>
> I want the relationship to be optional so that I can generate
> SHIPMENT_NUMBER as many as I want and populate them with the numbers
> assigned by the postal service and only later, when the real SHIPMENT is
> actually needed/created, link it with the number in a one-to-one fashion.
>
> I’m not sure why, but my class generated content always shows the
> relationship as mandatory.
>
> Coming from the WebObjects world, I'm used to a modeler that explicitly
> shows checkboxes for isMandatory on relationships like with the attributes.
> Here in Cayenne it seems that optionality is implicitly determined based on
> the design.
>
> Have I misunderstood something? Is my design flawed?
>
> Any tip is appreciated.
>
> Regards,
> Riccardo


Re: Cayenne and GraalVM

2023-01-12 Thread Michael Gentry
Is that due to reflection?

On Wed, Jan 11, 2023 at 8:09 AM Andrus Adamchik  wrote:

> And per the latest comments in that task, Cayenne actually works with
> Graal, just not the module auto-loading part:
>
> ServerRuntime.builder()
>
>   // no autoloading, each module will need to be explicitly added below
>   .disableModulesAutoLoading()
>
>   // add the main Cayenne module
>   .addModule(new ServerModule())
>
>// ...
>   .build();
> Andrus
>
> > On Jan 10, 2023, at 9:57 AM, Andrus Adamchik 
> wrote:
> >
> > FYI: https://github.com/oracle/graal/issues/5716
> >
> > A discussion on how to package a Cayenne app to a native executable with
> Graal. If anyone tried doing that before and has some experience, feel free
> to chime in.
> >
> > Andrus
>
>


Re: Using Cayenne without Maven

2022-07-21 Thread Michael Gentry
Hi Ali,

What tooling are you using?

Cayenne should be looking for that file at the root/top of one of the
classpaths. Maven will package src/main/resource up and make it available
at the root, but you can specify other classpath values yourself. Like if
you are using a barebones java command, try adding a -cp entry, etc.


On Thu, Jul 21, 2022 at 5:04 PM Ali Baharev  wrote:

> Hi,
>
> I am trying to integrate Cayenne into a project that must not use
> Maven. The application – not too surprisingly – crashes on this line:
>
> ServerRuntime cayenneRuntime = ServerRuntime.builder()
> .addConfig("cayenne-project.xml")
> .build();
>
> Exception in thread "main"
> org.apache.cayenne.configuration.server.DataDomainLoadException:
> [v.4.1.1 Dec 20 2021 16:33:19] Configuration resource
> "cayenne-project.xml" is not found.
>
> It looks like Cayenne is assuming the Maven project folder structure,
> which of course is not there, since I am not using Maven.
>
> I tried the full absolute path, but that did not work either, I get
> the same Exception.
>
> Where exactly is Cayenne looking for the configuration file?
>
> How can I specify the location of the configuration file?
>
> Are there more stumbling blocks if I must not use Maven?
>
> Thank you in advance!
>
> Ali
>


Re: DI container has no binding for key

2022-03-23 Thread Michael Gentry
If you aren't using a shaded JAR (which merges all JARs into a single JAR),
then you'll need more JARs listed on your Java command.


On Wed, Mar 23, 2022 at 12:16 PM Stefan Stegic 
wrote:

> PS: I'm not using maven-shade (just opened the link you sent)
>
> On Wed, Mar 23, 2022 at 5:10 PM Stefan Stegic 
> wrote:
>
>> My knowledge of Java is not so deep, so excuse stupid questions - if any.
>> I believe I am using shading because I'm exporting dependencies into my
>> JAR. IntelliJ does this for me in the build process by publishing the JAR
>> as an artifact. All I did was specify which dependencies I want to package
>> in there like this:
>>
>> [image: image.png]
>>
>> So, I build the project, grab the published JAR artifact and put the file
>> in the plugins folder of the Spigot server. I then run the Server and it
>> tries to load each plugin JAR that's in there. That's when each of the
>> onEnable methods are called, including that of my plugin
>> (FirstSpigotPlugin). The example code that creates the CayenneRuntime is in
>> my onEnable method.
>>
>> Should I be packaging these dependencies differently then?
>>
>> On Wed, Mar 23, 2022 at 4:56 PM Andrus Adamchik 
>> wrote:
>>
>>> This is not a common problem with Cayenne. In fact this is the first
>>> time I see it happen in any environment. So Spigot is special in this
>>> respect. I found this link:
>>> https://bukkit.fandom.com/wiki/Using_External_Libraries_with_Plugins <
>>> https://bukkit.fandom.com/wiki/Using_External_Libraries_with_Plugins>
>>> It doesn't answer the question, but provides some hints. So how do you
>>> package your own code and third-party dependencies like Cayenne for
>>> Spigot/Bukkit? Do you use "shading"?
>>>
>>> Andrus
>>>
>>> > On Mar 23, 2022, at 4:51 PM, Stefan Stegic 
>>> wrote:
>>> >
>>> > Hi,
>>> >
>>> > Thanks for your quick responses! I'm using version 4.1.1.
>>> > Right, so you're saying Spigot is somehow blocking the execution of
>>> said
>>> > code, or it's circumventing it somehow so that those steps of
>>> > initialization are never actually executed? Also, you mean that it's a
>>> > common problem with Cayenne or with Spigot and other jars?
>>> >
>>> > How would we go about understanding how the Spigot classpath works? It
>>> > might help to know that the plugin API is called Bukkit, so Spigot is
>>> kind
>>> > of the parent entity (it's a customized Minecraft server, while Bukkit
>>> is
>>> > the interface for plugins, as I've come to understand). It's source
>>> code
>>> > should be here:
>>> > https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/browse .
>>> >
>>> > On Wed, Mar 23, 2022 at 4:33 PM Andrus Adamchik 
>>> wrote:
>>> >
>>> >> The bootstrap code is as vanilla as it can get:
>>> >>
>>>  ServerRuntime cayenneRuntime = ServerRuntime.builder()
>>>  .addConfig("cayenne-project.xml")
>>>  .build();
>>> >>
>>> >> Missing ObjectContextFactory means ServerModule is not loaded in the
>>> >> environment. Since 4.1 (BTW, which version of Cayenne are we talking
>>> >> about?), ServerModule is loaded by processing
>>> >>
>>> "META-INF/services/org.apache.cayenne.configuration.server.CayenneServerModuleProvider"
>>> >> files from the classpath jars. So there's something about Spigot's
>>> >> classpath that prevents this code in ModuleLoader from returning
>>> proper
>>> >> resources:
>>> >>
>>> >> for (ModuleProvider provider : ServiceLoader.load(providerClass)) {
>>> ... }
>>> >>
>>> >> We need to understand how Spigot classpath works. Cursory Googling
>>> shows
>>> >> that this is a common problem, just don't immediately see a solution.
>>> >>
>>> >> Andrus
>>> >>
>>> >>
>>> >>> On Mar 23, 2022, at 4:03 PM, Andrus Adamchik 
>>> >> wrote:
>>> >>>
>>> >>> Actually the stack shows that there's already an instance of Cayenne
>>> >> runtime available to the code, but the runtime is in a bad state (not
>>> clear
>>> >> why). So thread binding should not be required.
>>> >>>
>>> >>> Andrus
>>> >>>
>>> >>>
>>>  On Mar 23, 2022, at 4:00 PM, John Huss  wrote:
>>> 
>>>  You have to bind the DI injector to the thread (and unbind it
>>> later):
>>> 
>>>  CayenneRuntime.*bindThreadInjector*(cayenneRuntime.getInjector());
>>> 
>>>  If you are using servlets, then CayenneFilter will do this for you.
>>>  Otherwise you can bind it at the start of a request and unbind it
>>> at the
>>>  end.
>>> 
>>>  On Wed, Mar 23, 2022 at 9:10 AM Stefan Stegic <
>>> stefanste...@gmail.com>
>>>  wrote:
>>> 
>>> > Hi Andrus,
>>> >
>>> > Of course:
>>> >
>>> > org.apache.cayenne.di.DIRuntimeException: DI container has no
>>> binding
>>> >> for
>>> > key >> org.apache.cayenne.configuration.ObjectContextFactory>
>>> >  at
>>> >
>>> >
>>> >>
>>> org.apache.cayenne.di.spi.DefaultInjector.getProvider(DefaultInjector.java:158)
>>> > ~[?:?]
>>> >  at
>>> >
>>> >
>>> >>
>>> 

Re: DI container has no binding for key

2022-03-23 Thread Michael Gentry
Hi Stefan,

Attachments, such as images, don't work on the mailing list. You can try
uploading to imgur.com or similar and send the link to it.

Have you tried updating your "java -cp myPlugin.jar path.to.Main" command
to have more classpaths?

mrg


On Wed, Mar 23, 2022 at 12:10 PM Stefan Stegic 
wrote:

> My knowledge of Java is not so deep, so excuse stupid questions - if any.
> I believe I am using shading because I'm exporting dependencies into my
> JAR. IntelliJ does this for me in the build process by publishing the JAR
> as an artifact. All I did was specify which dependencies I want to package
> in there like this:
>
> [image: image.png]
>
> So, I build the project, grab the published JAR artifact and put the file
> in the plugins folder of the Spigot server. I then run the Server and it
> tries to load each plugin JAR that's in there. That's when each of the
> onEnable methods are called, including that of my plugin
> (FirstSpigotPlugin). The example code that creates the CayenneRuntime is in
> my onEnable method.
>
> Should I be packaging these dependencies differently then?
>
> On Wed, Mar 23, 2022 at 4:56 PM Andrus Adamchik 
> wrote:
>
>> This is not a common problem with Cayenne. In fact this is the first time
>> I see it happen in any environment. So Spigot is special in this respect. I
>> found this link:
>> https://bukkit.fandom.com/wiki/Using_External_Libraries_with_Plugins <
>> https://bukkit.fandom.com/wiki/Using_External_Libraries_with_Plugins>
>> It doesn't answer the question, but provides some hints. So how do you
>> package your own code and third-party dependencies like Cayenne for
>> Spigot/Bukkit? Do you use "shading"?
>>
>> Andrus
>>
>> > On Mar 23, 2022, at 4:51 PM, Stefan Stegic 
>> wrote:
>> >
>> > Hi,
>> >
>> > Thanks for your quick responses! I'm using version 4.1.1.
>> > Right, so you're saying Spigot is somehow blocking the execution of said
>> > code, or it's circumventing it somehow so that those steps of
>> > initialization are never actually executed? Also, you mean that it's a
>> > common problem with Cayenne or with Spigot and other jars?
>> >
>> > How would we go about understanding how the Spigot classpath works? It
>> > might help to know that the plugin API is called Bukkit, so Spigot is
>> kind
>> > of the parent entity (it's a customized Minecraft server, while Bukkit
>> is
>> > the interface for plugins, as I've come to understand). It's source code
>> > should be here:
>> > https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/browse .
>> >
>> > On Wed, Mar 23, 2022 at 4:33 PM Andrus Adamchik 
>> wrote:
>> >
>> >> The bootstrap code is as vanilla as it can get:
>> >>
>>  ServerRuntime cayenneRuntime = ServerRuntime.builder()
>>  .addConfig("cayenne-project.xml")
>>  .build();
>> >>
>> >> Missing ObjectContextFactory means ServerModule is not loaded in the
>> >> environment. Since 4.1 (BTW, which version of Cayenne are we talking
>> >> about?), ServerModule is loaded by processing
>> >>
>> "META-INF/services/org.apache.cayenne.configuration.server.CayenneServerModuleProvider"
>> >> files from the classpath jars. So there's something about Spigot's
>> >> classpath that prevents this code in ModuleLoader from returning proper
>> >> resources:
>> >>
>> >> for (ModuleProvider provider : ServiceLoader.load(providerClass)) {
>> ... }
>> >>
>> >> We need to understand how Spigot classpath works. Cursory Googling
>> shows
>> >> that this is a common problem, just don't immediately see a solution.
>> >>
>> >> Andrus
>> >>
>> >>
>> >>> On Mar 23, 2022, at 4:03 PM, Andrus Adamchik 
>> >> wrote:
>> >>>
>> >>> Actually the stack shows that there's already an instance of Cayenne
>> >> runtime available to the code, but the runtime is in a bad state (not
>> clear
>> >> why). So thread binding should not be required.
>> >>>
>> >>> Andrus
>> >>>
>> >>>
>>  On Mar 23, 2022, at 4:00 PM, John Huss  wrote:
>> 
>>  You have to bind the DI injector to the thread (and unbind it later):
>> 
>>  CayenneRuntime.*bindThreadInjector*(cayenneRuntime.getInjector());
>> 
>>  If you are using servlets, then CayenneFilter will do this for you.
>>  Otherwise you can bind it at the start of a request and unbind it at
>> the
>>  end.
>> 
>>  On Wed, Mar 23, 2022 at 9:10 AM Stefan Stegic <
>> stefanste...@gmail.com>
>>  wrote:
>> 
>> > Hi Andrus,
>> >
>> > Of course:
>> >
>> > org.apache.cayenne.di.DIRuntimeException: DI container has no
>> binding
>> >> for
>> > key > org.apache.cayenne.configuration.ObjectContextFactory>
>> >  at
>> >
>> >
>> >>
>> org.apache.cayenne.di.spi.DefaultInjector.getProvider(DefaultInjector.java:158)
>> > ~[?:?]
>> >  at
>> >
>> >
>> >>
>> org.apache.cayenne.di.spi.DefaultInjector.getProvider(DefaultInjector.java:144)
>> > ~[?:?]
>> >  at
>> >
>> >
>> >>
>> 

Re: Natural keys

2022-03-10 Thread Michael Gentry
Hi Tony,

It has been a while since I've mapped natural primary keys, but Cayenne
absolutely supports it.

If my memory cells are working, you will map your natural key as a Java
attribute (in the ObjEntity section). Normally, Cayenne excludes the PK
from your Java/ObjEntity, but you can manually add it and Cayenne is happy.

You //might// also need to fiddle with the PK generation section on the
DbEntity side. For some reason, I'm remembering that specifying Cayenne
Generated keys works better (or maybe not), even if you aren't generating
keys. This is only if you are creating new records. Cayenne won't try to
generate a key for an object that already has a key -- just make sure your
new objects have a key before you commit changes.

mrg


On Thu, Mar 10, 2022 at 6:10 PM Tony Giaccone  wrote:

> I'm writing an application where the primary key for a table is a natural
> key and comes in as part of a data payload after making a call to a remote
> system. I can be certain that this value is unique.  So I've modeled it in
> the database and have it in the data model. Of course this means that in
> the java object this field is absent.
>
> I'm going to want to do selects on it, and comparisons to other fields. So
> I really need it to be part of the model.  So is it best to just add it
> into the java object.  So that it's part of the mapping or is there another
> technique that is a better choice.
>
> Just as an aside, let's not devolve into a discussion of should the key be
> visible. I understand the pluses and minuses of that decision and for this
> case, its really the right thing to do.
>
>
>
> Tony Giaccone
>


Re: Problem with optional to-one deletion

2021-11-17 Thread Michael Gentry
OK, nice to know. I won't dive into it more this evening, then.

Thanks!


On Wed, Nov 17, 2021 at 1:04 PM Andrus Adamchik  wrote:

> Hi Mike,
>
> Nikita mentioned a few hours ago that he was able to reproduce. Appears to
> be a bug in the 4.2 stack.
>
> Andrus
>
> > On Nov 17, 2021, at 7:44 PM, Michael Gentry  wrote:
> >
> > Hi Lon,
> >
> > I didn't have a lot of time to look into it, but I suspect it may be in
> > your PK/FK mapping on the DbEntities.
> >
> > For example, in order_header, you have order_header ->>
> order_detail_sales,
> > but you've mapped that as To-Many AND To-Dependent PK, which doesn't make
> > sense.
> >
> >
> > On Tue, Nov 16, 2021 at 6:14 PM Lon Varscsak 
> wrote:
> >
> >> I forgot to mention that I'm running 4.2.M4-SNAPSHOT (updated from
> github
> >> as of an hour ago).
> >>
> >> On Tue, Nov 16, 2021 at 4:06 PM Lon Varscsak 
> >> wrote:
> >>
> >>> Hey all,
> >>>
> >>> I have a setup where I have an optional to-one relationship, but when I
> >>> try to clear the relationship and commitChanges, I get a low-level
> >> Cayenne
> >>> error along with some in appropriate sql generated.
> >>>
> >>> where it's doing an UPDATE to order_detail_costs should be a no-op,
> >>> because the object was removed from it's parent (order_detail_sales)
> with
> >>> setOrderDetailCost(null) along with a
> >>> objectContext.deleteObject(orderDetailCost).  This is probably a
> problem
> >>> for Nikita to look at, but I figured someone else may have run into
> this
> >> as
> >>> well.  It's unusual for me to have optional to-one relationships, but
> it
> >>> does happen.
> >>>
> >>> Here is a sample project (Debug As -> Java Application) to try (link to
> >> my
> >>> Synology):
> >>>
> >>
> https://varscsak.synology.me:5001/d/s/mI7SBS6fApoUMNT1K5lfpaCXHKEkHkgd/jIy5Ug64Hjp2ieZzOceknc39sjBasJLE-T74gPgqKEgk
> >>>
> >>> ...snip...
> >>>
> >>> Nov 16 15:27:55 INFO  org.apache.cayenne.log.JdbcEventLogger  - INSERT
> >>> INTO "order_header"( "attribute_1", "attribute_2", "order_number")
> >> VALUES(
> >>> ?, ?, ?)
> >>>
> >>> Nov 16 15:27:55 INFO  org.apache.cayenne.log.JdbcEventLogger  - [bind:
> >>> 1->attribute_1:'TEST1', 2->attribute_2:1, 3->order_number:1]
> >>>
> >>> Nov 16 15:27:55 INFO  org.apache.cayenne.log.JdbcEventLogger  - ===
> >>> updated 1 row.
> >>>
> >>> Nov 16 15:27:55 INFO  org.apache.cayenne.log.JdbcEventLogger  - INSERT
> >>> INTO "order_detail_sales"( "detail_attr_1", "detail_attr_2",
> >>> "order_line_number", "order_number") VALUES( ?, ?, ?, ?)
> >>>
> >>> Nov 16 15:27:55 INFO  org.apache.cayenne.log.JdbcEventLogger  - [bind:
> >>> 1->detail_attr_1:'TEST1', 2->detail_attr_2:1, 3->order_line_number:1,
> >>> 4->order_number:1]
> >>>
> >>> Nov 16 15:27:55 INFO  org.apache.cayenne.log.JdbcEventLogger  - ===
> >>> updated 1 row.
> >>>
> >>> Nov 16 15:27:55 INFO  org.apache.cayenne.log.JdbcEventLogger  - UPDATE
> >>> "order_detail_costs" SET "order_number" = ?, "order_line_number" = ?
> >> WHERE
> >>> ( "order_line_number" = ? ) AND ( "order_number" = ? )
> >>>
> >>> Nov 16 15:27:55 INFO  org.apache.cayenne.log.JdbcEventLogger  - ***
> >> error.
> >>>
> >>> java.lang.UnsupportedOperationException
> >>>
> >>> at java.util.Collections$UnmodifiableMap.put(Collections.java:1459)
> >>>
> >>> at
> org.apache.cayenne.query.BatchQueryRow.getValue(BatchQueryRow.java:80)
> >>>
> >>> at org.apache.cayenne.query.UpdateBatchQuery$1.getValue(
> >>> UpdateBatchQuery.java:124)
> >>>
> >>> at
> >>>
> >>
> org.apache.cayenne.access.translator.batch.UpdateBatchTranslator.updateBindings(
> >>> UpdateBatchTranslator.java:80)
> >>>
> >>> at org.apache.cayenne.access.jdbc.BatchAction.runAsIndividualQueries(
> >>> BatchAction.java:191)
> >>>
> >>> at org.apache.cayenne.access.jdbc.BatchAction.perform

Re: Problem with optional to-one deletion

2021-11-17 Thread Michael Gentry
Hi Lon,

I didn't have a lot of time to look into it, but I suspect it may be in
your PK/FK mapping on the DbEntities.

For example, in order_header, you have order_header ->> order_detail_sales,
but you've mapped that as To-Many AND To-Dependent PK, which doesn't make
sense.


On Tue, Nov 16, 2021 at 6:14 PM Lon Varscsak  wrote:

> I forgot to mention that I'm running 4.2.M4-SNAPSHOT (updated from github
> as of an hour ago).
>
> On Tue, Nov 16, 2021 at 4:06 PM Lon Varscsak 
> wrote:
>
> > Hey all,
> >
> > I have a setup where I have an optional to-one relationship, but when I
> > try to clear the relationship and commitChanges, I get a low-level
> Cayenne
> > error along with some in appropriate sql generated.
> >
> > where it's doing an UPDATE to order_detail_costs should be a no-op,
> > because the object was removed from it's parent (order_detail_sales) with
> > setOrderDetailCost(null) along with a
> > objectContext.deleteObject(orderDetailCost).  This is probably a problem
> > for Nikita to look at, but I figured someone else may have run into this
> as
> > well.  It's unusual for me to have optional to-one relationships, but it
> > does happen.
> >
> > Here is a sample project (Debug As -> Java Application) to try (link to
> my
> > Synology):
> >
> https://varscsak.synology.me:5001/d/s/mI7SBS6fApoUMNT1K5lfpaCXHKEkHkgd/jIy5Ug64Hjp2ieZzOceknc39sjBasJLE-T74gPgqKEgk
> >
> > ...snip...
> >
> > Nov 16 15:27:55 INFO  org.apache.cayenne.log.JdbcEventLogger  - INSERT
> > INTO "order_header"( "attribute_1", "attribute_2", "order_number")
> VALUES(
> > ?, ?, ?)
> >
> > Nov 16 15:27:55 INFO  org.apache.cayenne.log.JdbcEventLogger  - [bind:
> > 1->attribute_1:'TEST1', 2->attribute_2:1, 3->order_number:1]
> >
> > Nov 16 15:27:55 INFO  org.apache.cayenne.log.JdbcEventLogger  - ===
> > updated 1 row.
> >
> > Nov 16 15:27:55 INFO  org.apache.cayenne.log.JdbcEventLogger  - INSERT
> > INTO "order_detail_sales"( "detail_attr_1", "detail_attr_2",
> > "order_line_number", "order_number") VALUES( ?, ?, ?, ?)
> >
> > Nov 16 15:27:55 INFO  org.apache.cayenne.log.JdbcEventLogger  - [bind:
> > 1->detail_attr_1:'TEST1', 2->detail_attr_2:1, 3->order_line_number:1,
> > 4->order_number:1]
> >
> > Nov 16 15:27:55 INFO  org.apache.cayenne.log.JdbcEventLogger  - ===
> > updated 1 row.
> >
> > Nov 16 15:27:55 INFO  org.apache.cayenne.log.JdbcEventLogger  - UPDATE
> > "order_detail_costs" SET "order_number" = ?, "order_line_number" = ?
> WHERE
> > ( "order_line_number" = ? ) AND ( "order_number" = ? )
> >
> > Nov 16 15:27:55 INFO  org.apache.cayenne.log.JdbcEventLogger  - ***
> error.
> >
> > java.lang.UnsupportedOperationException
> >
> > at java.util.Collections$UnmodifiableMap.put(Collections.java:1459)
> >
> > at org.apache.cayenne.query.BatchQueryRow.getValue(BatchQueryRow.java:80)
> >
> > at org.apache.cayenne.query.UpdateBatchQuery$1.getValue(
> > UpdateBatchQuery.java:124)
> >
> > at
> >
> org.apache.cayenne.access.translator.batch.UpdateBatchTranslator.updateBindings(
> > UpdateBatchTranslator.java:80)
> >
> > at org.apache.cayenne.access.jdbc.BatchAction.runAsIndividualQueries(
> > BatchAction.java:191)
> >
> > at org.apache.cayenne.access.jdbc.BatchAction.performAction(
> > BatchAction.java:93)
> >
> > at org.apache.cayenne.access.DataNodeQueryAction.runQuery(
> > DataNodeQueryAction.java:97)
> >
> > at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:273)
> >
> > at
> >
> org.apache.cayenne.access.flush.DefaultDataDomainFlushAction.lambda$executeQueries$6(
> > DefaultDataDomainFlushAction.java:177)
> >
> > at java.util.HashMap.forEach(HashMap.java:1290)
> >
> > at
> >
> org.apache.cayenne.access.flush.DefaultDataDomainFlushAction.executeQueries(
> > DefaultDataDomainFlushAction.java:176)
> >
> > at org.apache.cayenne.access.flush.DefaultDataDomainFlushAction.flush(
> > DefaultDataDomainFlushAction.java:89)
> >
> > at org.apache.cayenne.access.DataDomain.onSyncFlush(DataDomain.java:637)
> >
> > at org.apache.cayenne.access.DataDomain.onSyncNoFilters(
> > DataDomain.java:609)
> >
> > at org.apache.cayenne.access.DataDomain$DataDomainSyncFilterChain.onSync(
> > DataDomain.java:835)
> >
> > at org.apache.cayenne.tx.TransactionFilter.lambda$onSync$0(
> > TransactionFilter.java:61)
> >
> > at
> >
> org.apache.cayenne.tx.DefaultTransactionManager$BaseTransactionHandler.performInTransaction(
> > DefaultTransactionManager.java:180)
> >
> > at
> >
> org.apache.cayenne.tx.DefaultTransactionManager$BaseTransactionHandler.performInNewTransaction(
> > DefaultTransactionManager.java:152)
> >
> > at
> >
> org.apache.cayenne.tx.DefaultTransactionManager$NestedTransactionHandler.handle(
> > DefaultTransactionManager.java:95)
> >
> > at org.apache.cayenne.tx.DefaultTransactionManager.performInTransaction(
> > DefaultTransactionManager.java:62)
> >
> > at org.apache.cayenne.tx.DefaultTransactionManager.performInTransaction(
> > DefaultTransactionManager.java:40)
> >
> > at org.apache.cayenne.tx.TransactionFilter.onSync(
> > 

Re: Insertion order issue

2021-11-05 Thread Michael Gentry
Hi Anthonin,

A) If my memory hasn't failed me, a DEFERRABLE/INITIALLY DEFERRED
constraint is checked at the END (commit) of the transaction instead of
each statement as it happens. The constraint check still happens...just
deferred. If there is a constraint error at the end, Oracle will roll back
the transaction and you'll get an error/exception in your code.

B) I don't think your custom PK generator will cause your current issue.
Unless, of course, there is a bug. :-) It certainly can be annoying to set
the sequence name/size for each entity, so I understand wanting to avoid
that.

mrg


On Fri, Nov 5, 2021 at 11:09 AM Lize Anthonin (OceanOPS) 
wrote:

> Hi Michael,
>
> A) I'll look into that, I have to check the potential implications first.
> I wanted to find an applicative work around before touching the DB. But
> thanks, that would solve it indeed.
> B) Just to define the sequence pattern. The default Oracle PK generator
> uses sequence like 'PK_'. All my sequences are like
> '_SEQ'. Since my model contains a lot of entities, I extended
> the OraclePkGenerator to modify the sequence naming, it was faster to
> implement. Do you think that could impact this? If so, I'll spend some time
> defining the custom sequences. I'll try on the few entities I'm working on.
>
> anthonin
>
> -Original Message-
> From: Michael Gentry 
> Sent: Friday, November 5, 2021 2:25 PM
> To: Cayenne Users 
> Subject: Re: Insertion order issue
>
> CAUTION: This message comes from an external server, do not click on links
> or open attachments unless you know the sender and are sure the content is
> safe.
>
>
> Hi Anthonin,
>
> A) Since you are using Oracle, you may need to use a DEFERRABLE constraint
> (INITIALLY DEFERRED).
>
> B) Any reason you are using a custom PK generator instead of using the
> standard sequence generator supported by Cayenne? (Cayenne Modeler ->
> select DB Entity -> PK Generation Strategy -> Custom Sequence -> enter
> Sequence Name and Cache Size -- looks like you are using 1).
>
> mrg
>
>
> On Fri, Nov 5, 2021 at 5:44 AM Lize Anthonin (OceanOPS) <
> al...@groupcls.com>
> wrote:
>
> > Hi Michael,
> >
> > Thanks for your answer.
> > I tried, but does not seem to make any difference. I added
> > WeightedAshwoodEntitySorter (amongst other things) in a module loaded
> > as init-param for the CayenneFilter, as follows:
> > @Override
> > public void configure(Binder binder) {
> > binder.bind(RequestHandler.class)
> > .to(StatelessContextRequestHandler.class)
> > .withoutScope();
> >
> > OraclePkGeneratorCustom pkgen = new
> OraclePkGeneratorCustom();
> > pkgen.setPkCacheSize(1);
> > binder.bind(PkGenerator.class).toInstance(pkgen);
> >
> >
> > binder.bind(EntitySorter.class).to(WeightedAshwoodEntitySorter.class);
> > }
> >
> > And then the annotation as you mentioned on the child entity. It still
> > stays rather random...
> >
> >
> > Here is the stack trace, as you can see I use Cayenne 4.2.M3. That
> > would have been smarter of me to share it initially!
> > java.sql.SQLIntegrityConstraintViolationException: ORA-02291:
> > integrity constraint (JCOMMOPS_B.PTF_HARDWARE_FK) violated - parent
> > key not found
> >
> > at
> > oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:509)
> > ~[ojdbc10-19.12.0.0.jar:19.12.0.0.0]
> > at
> > oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:461)
> > ~[ojdbc10-19.12.0.0.jar:19.12.0.0.0]
> > at
> > oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:1104)
> > ~[ojdbc10-19.12.0.0.jar:19.12.0.0.0]
> > at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:553)
> > ~[ojdbc10-19.12.0.0.jar:19.12.0.0.0]
> > at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:269)
> > ~[ojdbc10-19.12.0.0.jar:19.12.0.0.0]
> > at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:655)
> > ~[ojdbc10-19.12.0.0.jar:19.12.0.0.0]
> > at
> > oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.j
> > ava:270)
> > ~[ojdbc10-19.12.0.0.jar:19.12.0.0.0]
> > at
> > oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.j
> > ava:91)
> > ~[ojdbc10-19.12.0.0.jar:19.12.0.0.0]
> > at
> > oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStat
> > ement.java:970)
> > ~[ojdbc10-19.12.0.0.jar:19.12.0.0.0]
> > at
> > oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatemen
>

Re: Insertion order issue

2021-11-05 Thread Michael Gentry
rsey.internal.Errors.process(Errors.java:244)
> [jersey-common-2.35.jar:?]
> at
> org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:265)
> [jersey-common-2.35.jar:?]
> at
> org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:234)
> [jersey-server-2.35.jar:?]
> at
> org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:684)
> [jersey-server-2.35.jar:?]
> at
> org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:394)
> [jersey-container-servlet-core-2.35.jar:?]
> at
> org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:346)
> [jersey-container-servlet-core-2.35.jar:?]
> at
> org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:366)
> [jersey-contain[apache-tomcat-9.0.40]: er-servlet-core-2.35.jar:?]
> at
> org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:319)
> [jersey-container-servlet-core-2.35.jar:?]
> at
> org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:205)
> [jersey-container-servlet-core-2.35.jar:?]
> at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
> [catalina.jar:9.0.40]
> at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
> [catalina.jar:9.0.40]
> at
> org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
> [tomcat-websocket.jar:9.0.40]
> at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
> [catalina.jar:9.0.40]
> at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
> [catalina.jar:9.0.40]
> at
> org.oceanops.api.filters.AuthFilter.doFilter(AuthFilter.java:40)
> [api-1.3-SNAPSHOT-classes.jar:?]
> at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
> [catalina.jar:9.0.40]
> at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
> [catalina.jar:9.0.40]
> at
> org.apache.cayenne.configuration.web.CayenneFilter.doFilter(CayenneFilter.java:127)
> [cayenne-web-4.2.M3.jar:4.2.M3]
> at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
> [catalina.jar:9.0.40]
> at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
> [catalina.jar:9.0.40]
> at
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
> [catalina.jar:9.0.40]
> at
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
> [catalina.jar:9.0.40]
> at
> org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542)
> [catalina.jar:9.0.40]
> at
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143)
> [catalina.jar:9.0.40]
> at
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
> [catalina.jar:9.0.40]
> at
> org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690)
> [catalina.jar:9.0.40]
> at
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
> [catalina.jar:9.0.40]
> at
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
> [catalina.jar:9.0.40]
> at
> org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374)
> [tomcat-coyote.jar:9.0.40]
> at
> org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
> [tomcat-coyote.jar:9.0.40]
> at
> org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:880)
> [tomcat-coyote.jar:9.0.40]
> at 
> org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1601)
> [tomcat-coyote.jar:9.0.40]
> at 
> org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
> [tomcat-coyote.jar:9.0.40]
> at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
> [?:?]
> at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
> [?:?]
> at
> org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
> [tomcat-util.jar:9.0.40]
> at java.lang.Thread.run(Thread.java:832) [?:?]
> Caused by: oracle.jdbc.OracleDatabaseException: ORA-02291: integrity
> constraint (JCOMMOPS_B.PTF_HARDWARE_FK) vio

Re: Insertion order issue

2021-11-04 Thread Michael Gentry
Hi Anthonin,

Perhaps put a @SortWeight(2) annotation [1] on your child entity? Also, you
need to configure a different entity sorter:

// Need WeightedAshwoodEntitySorter for @SortWeight to work.
ModuleentitySorterModule = (binder) ->
binder.bind(EntitySorter.class).to(WeightedAshwoodEntitySorter.class);
ServerRuntime runtime=
ServerRuntimeBuilder.builder().addModule(myModule)

If this doesn't help, please provide a stack track and Cayenne version
information.

Thanks!

mrg


[1]
https://cayenne.apache.org/docs/4.0/api/org/apache/cayenne/ashwood/SortWeight.html


On Thu, Nov 4, 2021 at 10:38 AM Lize Anthonin (OceanOPS) 
wrote:

> Hi,
>
> I am using Cayenne in a web app (through AgRest, but this is purely
> cayenne related, well I think so) that contains one service through a POST
> method.
> Basically, I submit a JSON body with multiple object in it, pass it
> through the service method defined below, process each object and for each
> ones doing some insert into an Oracle DB.
> @POST
> @Consumes(MediaType.APPLICATION_JSON)
> @Path("getid")
> @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
> public List getID(final List inputs)
> {
> There I loop over this list, process the object IdInput
> and make the necessary insertions
> }
>
> My issue there is that when I commit the changes, the order of the inserts
> seems to fail randomly, from one request to another. I have relationships
> set in those modifications, and through the logs I can see the PK being
> fetched from the sequences, but then sometimes (most of the times) the
> referencing entity is inserted before the referenced entity. And of course
> the commit fail for violation of parent key.
>
> I've tried to secure as much as possible the context, through different
> ways:
>
>   *   stateless thread context through the provided cayenne filter
> (stateless because the session one would be committed via another commit
> made in another filter, weird, but I send only one request, this filter
> commit should happen prior to the 'service' commit)
>   *   per method context
>   *   custom stateless context through a filter that I made myself.
> I thought I got it with he per method context, but it failed after a while.
> And I tried committing after each processing in the loop, or after the
> loop, but same results.
>
> I'm probably missing something, but I'm not getting why it happen
> sometimes, not always(or never!). A threading issue maybe? But I'm
> processing only one request, so I'm a bit lost.
> Any thoughts? (before I commit after each insertion of entities haha)
> How the order of inserts are defined? Maybe I miss-configured some
> relationships in the modeler, but they come from a reverse engineering and
> look ok...
>
> Many thanks in advance
> Anthonin
> 
>
> Ce message et toutes les pi?ces jointes (ci-apr?s le "message") sont
> ?tablis ? l'intention exclusive de ses destinataires et sont confidentiels.
> Si vous recevez ce message par erreur ou s'il ne vous est pas destin?,
> merci de le d?truire ainsi que toute copie de votre syst?me et d'en avertir
> imm?diatement l'exp?diteur. Toute lecture non autoris?e, toute utilisation
> de ce message qui n'est pas conforme ? sa destination, toute diffusion ou
> toute publication, totale ou partielle, est interdite. L'Internet ne
> permettant pas d'assurer l'int?grit? de ce message ?lectronique susceptible
> d'alt?ration, l'exp?diteur (et ses filiales) d?cline(nt) toute
> responsabilit? au titre de ce message dans l'hypoth?se o? il aurait ?t?
> modifi? ou falsifi?.
>
> This message and any attachments (the "message") is intended solely for
> the intended recipient(s) and is confidential. If you receive this message
> in error, or are not the intended recipient(s), please delete it and any
> copies from your systems and immediately notify the sender. Any
> unauthorized view, use that does not comply with its purpose, dissemination
> or disclosure, either whole or partial, is prohibited. Since the internet
> cannot guarantee the integrity of this message which may not be reliable,
> the sender (and its subsidiaries) shall not be liable for the message if
> modified or falsified.
>


Re: Ordering objects by primary keys

2021-10-30 Thread Michael Gentry
I had 100% forgotten about MarkMail -- thanks for the reminder!


On Sat, Oct 30, 2021 at 4:09 AM Aristedes Maniatis 
wrote:

> Its old, but still fast and works well:
> https://markmail.org/search/?q=list%3Aorg.apache.cayenne.user+%22db%3A%22
>
> Ari
>
>
> On 30/10/21 1:01am, Michael Gentry wrote:
> > Fun fact: I have years worth of Cayenne mailing list content in GMail,
> but
> > you can't search for db: in it because GMail uses prefix:term as an
> > advanced search option and it doesn't know what to do with db: ...
> >
> >
> > On Thu, Oct 28, 2021 at 2:38 AM giulio.ces...@gmail.com <
> > giulio.ces...@gmail.com> wrote:
> >
> >> Is there any point in the documentation where this "db:" prefix has been
> >> documented?
> >>
> >> Cheers,
> >> Giulio Cesare
> >>
> >> On Wed, Oct 27, 2021 at 11:23 PM giulio.ces...@gmail.com <
> >> giulio.ces...@gmail.com> wrote:
> >>
> >>> It did work! 朗
> >>>
> >>> Thanks Nikita. 
> >>>
> >>> Cheers,
> >>>
> >>> Giulio Cesare
> >>>
> >>>
> >>> On Wed, Oct 27, 2021 at 7:46 PM Nikita Timofeev <
> >> ntimof...@objectstyle.com>
> >>> wrote:
> >>>
> >>>> Hi!
> >>>>
> >>>> You could try to add "db:" prefix to the primary key name.
> >>>> Something like this: orderBy("db:ARTIST_ID")
> >>>>
> >>>> On Wed, Oct 27, 2021 at 8:14 PM giulio.ces...@gmail.com
> >>>>  wrote:
> >>>>> Hello,
> >>>>>
> >>>>> I am try to run some BBD tests integrated with Cayenne (succesfully,
> >> so
> >>>>> far).
> >>>>> I am at the point where I can not fully specify the record/object to
> >>>> select
> >>>>> in the test script, and so I am trying to select the latest object
> >>>>> inserted, matching some lose criteria.
> >>>>>
> >>>>> Unfortunately, I don't have a generic "insertion date" in all my
> >>>> entities;
> >>>>> so the next best think I could think of, is to use the value of the
> PK
> >>>>> (generated using Postgres sequences) to sort the selected objects
> >> (DESC)
> >>>>> and picking the first match.
> >>>>>
> >>>>> To achieve this, I have tried with this code:
> >>>>>
> >>>>> String dbEntityName =
> >>>>>
> >> context.getEntityResolver().getObjEntity(entityName).getDbEntityName();
> >>>>> ImmutableList orderBy =
> >>>>>
> >>
> context.getEntityResolver().getDbEntity(dbEntityName).getPrimaryKeys().stream()
> >>>>> .map(attribute -> new Ordering(attribute.getName(),
> >>>> SortOrder.DESCENDING))
> >>>>> .collect(ImmutableList.toImmutableList())
> >>>>> ;
> >>>>> BaseDataObject latestInstance =
> >>>>> ObjectSelect.query(clazz).orderBy(orderBy).selectFirst(context);
> >>>>>
> >>>>> but I get the following error:
> >>>>> - Can't resolve path component: [{EntityName}.{primaryKeyFieldName}]
> >>>>>
> >>>>> I realize that {EntityName} and {primaryKeyFieldName} live in two
> >>>> separate
> >>>>> contexts (Entities vs DB); but I have no more ideas on how to
> >> progress.
> >>>>> Does anyone have any suggestions on how to do this stunt?
> >>>>>
> >>>>> Cheers,
> >>>>> Giulio Cesare
> >>>>
> >>>>
> >>>> --
> >>>> Best regards,
> >>>> Nikita Timofeev
> >>>>
>
>


Re: Ordering objects by primary keys

2021-10-29 Thread Michael Gentry
Fun fact: I have years worth of Cayenne mailing list content in GMail, but
you can't search for db: in it because GMail uses prefix:term as an
advanced search option and it doesn't know what to do with db: ...


On Thu, Oct 28, 2021 at 2:38 AM giulio.ces...@gmail.com <
giulio.ces...@gmail.com> wrote:

> Is there any point in the documentation where this "db:" prefix has been
> documented?
>
> Cheers,
> Giulio Cesare
>
> On Wed, Oct 27, 2021 at 11:23 PM giulio.ces...@gmail.com <
> giulio.ces...@gmail.com> wrote:
>
> > It did work! 朗
> >
> > Thanks Nikita. 
> >
> > Cheers,
> >
> > Giulio Cesare
> >
> >
> > On Wed, Oct 27, 2021 at 7:46 PM Nikita Timofeev <
> ntimof...@objectstyle.com>
> > wrote:
> >
> >> Hi!
> >>
> >> You could try to add "db:" prefix to the primary key name.
> >> Something like this: orderBy("db:ARTIST_ID")
> >>
> >> On Wed, Oct 27, 2021 at 8:14 PM giulio.ces...@gmail.com
> >>  wrote:
> >> >
> >> > Hello,
> >> >
> >> > I am try to run some BBD tests integrated with Cayenne (succesfully,
> so
> >> > far).
> >> > I am at the point where I can not fully specify the record/object to
> >> select
> >> > in the test script, and so I am trying to select the latest object
> >> > inserted, matching some lose criteria.
> >> >
> >> > Unfortunately, I don't have a generic "insertion date" in all my
> >> entities;
> >> > so the next best think I could think of, is to use the value of the PK
> >> > (generated using Postgres sequences) to sort the selected objects
> (DESC)
> >> > and picking the first match.
> >> >
> >> > To achieve this, I have tried with this code:
> >> >
> >> > String dbEntityName =
> >> >
> context.getEntityResolver().getObjEntity(entityName).getDbEntityName();
> >> > ImmutableList orderBy =
> >> >
> >>
> context.getEntityResolver().getDbEntity(dbEntityName).getPrimaryKeys().stream()
> >> > .map(attribute -> new Ordering(attribute.getName(),
> >> SortOrder.DESCENDING))
> >> > .collect(ImmutableList.toImmutableList())
> >> > ;
> >> > BaseDataObject latestInstance =
> >> > ObjectSelect.query(clazz).orderBy(orderBy).selectFirst(context);
> >> >
> >> > but I get the following error:
> >> > - Can't resolve path component: [{EntityName}.{primaryKeyFieldName}]
> >> >
> >> > I realize that {EntityName} and {primaryKeyFieldName} live in two
> >> separate
> >> > contexts (Entities vs DB); but I have no more ideas on how to
> progress.
> >> >
> >> > Does anyone have any suggestions on how to do this stunt?
> >> >
> >> > Cheers,
> >> > Giulio Cesare
> >>
> >>
> >>
> >> --
> >> Best regards,
> >> Nikita Timofeev
> >>
> >
>


Re: Cayenne Version 4.0 Logging

2021-09-20 Thread Michael Gentry
Hi Keena,

At some point you may want to consider switching to HikariCP [1]. I don't
remember the exact numbers, but a couple years ago I switched a Cayenne
application from DBCP to HikariCP and the speed increase was noticeable.
The more faults (lazy loads) your application does fetching in
relationships, the more noticeable it'll be. Of course, if your application
is low-volume or doesn't have a lot of relationships, it might not be worth
the effort. HikariCP would be my first choice today for any non-trivial
application. Also, frameworks like Spring Boot default to using HikariCP
now, too, so it has become more popular.

mrg

[1] https://github.com/brettwooldridge/HikariCP


On Wed, Sep 8, 2021 at 10:36 PM Keena Grepo 
wrote:

> Hi,
>
> Is there any documentation that may serve as a reference on how to log the
> connection pool status/information for cayenne version 4.0?
>
> Here are the only information that is being logged once the web
> application has started to run on the server :
>
> 2021-09-09 09:22:58.288  INFO 25112 --- [   main]
> c.m.a.t.ServletInitializer   : Starting ServletInitializer
> v2.1.1.3 on CAVLT018 with PID 25112
> (C:\sts-bundle\pivotal-tc-server\instances\base-instance\wtpwebapps\MonitoringSystem\WEB-INF\classes
> started by Dev.User in C:\sts-bundle\sts-3.9.9.RELEASE)
> 2021-09-09 09:22:58.294  INFO 25112 --- [   main]
> c.m.a.t.ServletInitializer   : The following profiles are
> active: default
> 2021-09-09 09:23:01.851  INFO 25112 --- [   main]
> o.s.web.context.ContextLoader: Root WebApplicationContext:
> initialization completed in 3351 ms
> 2021-09-09 09:23:03.651  INFO 25112 --- [   main]
> o.a.c.c.XMLDataChannelDescriptorLoader   : Loading XML configuration
> resource from
> file:/C:/sts-bundle/pivotal-tc-server/instances/base-instance/wtpwebapps/MonitoringSystem/WEB-INF/classes/cayenne-project.xml
> 2021-09-09 09:23:03.682  INFO 25112 --- [   main]
> o.a.c.c.XMLDataChannelDescriptorLoader   : Loading XML DataMap resource
> from
> file:/C:/sts-bundle/pivotal-tc-server/instances/base-instance/wtpwebapps/MonitoringSystem/WEB-INF/classes/datamap.map.xml
> 2021-09-09 09:23:04.107  INFO 25112 --- [   main]
> o.a.c.c.server.DataDomainProvider: setting DataNode 'datanode' as
> default, used by all unlinked DataMaps
> 2021-09-09 09:23:10.374  INFO 25112 --- [   main]
> org.apache.cayenne.log.JdbcEventLogger   : Detected and installed adapter:
> org.apache.cayenne.dba.mysql.MySQLAdapter
>
> Our goal is to get the number of active connections in the pool.
>
> Btw, the applciation is using
> factory="org.apache.cayenne.configuration.server.DBCPDataSourceFactory" in
> the cayene-project.xml file.
>


Re: Dealing with a commit exception....

2021-06-24 Thread Michael Gentry
10 is a rather small batch size. I'd suggest at least 100, perhaps even
1000, unless you are expecting tons of problem records.

For your hashing concerns, could you maybe store that in an H2 DB you use
for this migration?

On Wed, Jun 23, 2021 at 12:54 PM Tony Giaccone  wrote:

> Yeah, that's not a solution that's going to work. I need to move about a
> million records from one database to a second, and the delay associated
> with querying the database for every record would take a problem that's
> already going to take more than a day to complete and turn it into several
> days.  That's why I'm batching them into groups of 10 at a time.  The
> problem is there are duplicate records, they hash to the same value, and
> when that happens the insert on the other side is going to fail the Hash is
> a way to identify uniqueness.   I'm sure you're thinking, well keep a
> record of the hash values and only insert ones that you haven't seen. The
> problem with this solution is that I have to be able to restart the
> application and pick up where the process ended. If I had an in memory
> cache of the hash values, on restart I'd have to read all the previously
> transferred records and inflate the cache.  Another process that really is
> going to be too odious and time consuming.
>
>
>
> On Wed, Jun 23, 2021 at 12:45 PM John Huss  wrote:
>
> > I think it would be better to figure out the "problem" objects before
> > committing by querying the DB and the object context.
> >
> > On Wed, Jun 23, 2021 at 9:47 AM Tony Giaccone  wrote:
> >
> > > I have a list of 10 new objects that I've inserted into the
> objectcontex
> > > and am about to do a commit changes on the object context.
> > >
> > > One, or more, of those entries violates a constraint and causes the
> > commit
> > > changes to throw an exception.
> > >
> > > Now most of them are  probably ok, so I want to make sure they get
> > > inserted. How do I handle this?
> > >
> > > My first thought was to invalidate the 10 items.. then individually add
> > > each one back into the context and do a commit changes after each add.
> > Is
> > > that a reasonable path? Obviously the one that failed before will fail
> > > again, and then I can just log that, invalidate it again and keep
> going.
> > >
> > > Is there a better faster way to do this?
> > >
> > >
> > >
> > > Tony Giaccone
> > >
> >
>


Re: SSL connections to postgresql in Azure

2021-06-10 Thread Michael Gentry
I almost suggested adding parameters to the jdbc: URL to see if that might
work. Looks like it does and you found it.

Cheers!

mrg


On Wed, Jun 9, 2021 at 2:53 PM Rick Bonnett 
wrote:

> Since I didn't have to worry about cert validations, it was dead simple.
> Pretty much just copied my psql connection string into my java code:
>
>
> Module m1 = new Module() {
> public void configure(Binder binder) {
> binder.bindMap(Constants.PROPERTIES_MAP).put(Constants.JDBC_DRIVER_PROPERTY,
> "org.postgresql.Driver")
> .put(Constants.JDBC_URL_PROPERTY,
>  
> "jdbc:postgresql://<>:5432/are?user=<>=<>=true=org.postgresql.ssl.NonValidatingFactory");
> }
> };
>
> *Rick Bonnett*
>
> *Programmer Analyst*
>
> Ascent Global Logistics
>
> PO Box 1039, Augusta, ME, 04332
>
> Office: 207.620.8670
>
> *ascentgl.com* <http://ascentgl.com/>
>
>
>
>
> --
> *From:* Michael Gentry 
> *Sent:* Wednesday, June 9, 2021 1:37 PM
> *To:* Cayenne Users 
> *Subject:* Re: SSL connections to postgresql in Azure
>
>
> *EXTERNAL EMAIL:* Be extra careful around links and attachments.
> Sweet! What was the solution (in case anyone else searches for it)?
>
>
> On Wed, Jun 9, 2021 at 12:49 PM Rick Bonnett  >
> wrote:
>
> > Thanks. That got me on the path to success
> >
> > *Rick Bonnett*
> >
> > *Programmer Analyst*
> >
> > Ascent Global Logistics
> >
> > PO Box 1039, Augusta, ME, 04332
> >
> > Office: 207.620.8670
> >
> > *ascentgl.com* <http://ascentgl.com/>
> >
> >
> >
> >
> > --
> > *From:* Michael Gentry 
> > *Sent:* Wednesday, June 9, 2021 12:26 PM
> > *To:* Cayenne Users 
> > *Subject:* Re: SSL connections to postgresql in Azure
> >
> >
> > *EXTERNAL EMAIL:* Be extra careful around links and attachments.
> > Hi Rick,
> >
> > Are you connecting:
> >
> > a) local development system -> Azure Postgres
> > b) Azure server -> Azure Postgres?
> >
> > If "a", are there SSL certificates from Azure you need to load into your
> > local Java environment. Or you could try turning off SSL verification.
> See
> > more (for both options) here:
> >
> > https://jdbc.postgresql.org/documentation/head/ssl-client.html
> >
> > Also, maybe try adding:
> >
> > .put("ssl", "true"); // Or some other combo from above link...
> >
> >
> > On Wed, Jun 9, 2021 at 10:59 AM Rick Bonnett <
> richard.bonn...@ascentgl.com
> > >
> > wrote:
> >
> > >
> > > Having issues connecting to postgres in Azure - because by default SSL
> > > connections are required. I am using:
> > >
> > > - cayenne 3.1 - yes I know it's old but it's what I'm stuck with
> > > - latest postgres JDBC driver
> > >
> > > Code snippets below.
> > >
> > > On the JDBC_URLPROPERTY I have tried every flavor of ssslmode=required
> or
> > > usessl=true that I've been able to dredge up, but consistenyly getting:
> > >
> > > Unable to connect to server: FATAL: SSL connection is required. Please
> > > specify SSL options and retry.
> > >
> > > Hopefully I am just overlooking something simple and obvious. Any
> > insights?
> > >
> > > Module m1 = new Module() {
> > > public void configure(Binder binder) {
> > >
> >
> binder.bindMap(Constants.PROPERTIES_MAP).put(Constants.JDBC_DRIVER_PROPERTY,
> > > "org.postgresql.Driver")
> > > .put(Constants.JDBC_URL_PROPERTY, "jdbc:postgresql://
> > > http://mypostgres.postgres.database.azure.com:5432/are;)
> > > .put(Constants.JDBC_USERNAME_PROPERTY, "")
> > > .put(Constants.JDBC_PASSWORD_PROPERTY, "");
> > > }
> > > };
> > >
> > > cayenneRuntime = new ServerRuntime("cayenne-ARETariffDomain.xml", m1);
> > > DataDomain dd = cayenneRuntime.getDataDomain();
> > > Collection dmaps = dd.getDataMaps();
> > > for (DataMap dm: dmaps) {
> > > for (DbEntity entity: dm.getDbEntities()) {
> > > entity.setSchema("p");
> > > }
> > > }
> > > ObjectContext ORMContext = cayenneRuntime.getContext();
> > >
> > >
> > >
> > > *Rick Bonnett*
> > >
> > > *Programmer Analyst*
> > >
> > > Ascent Global Logistics
> > >
> > > PO Box 1039, Augusta, ME, 04332
> &g

Re: SSL connections to postgresql in Azure

2021-06-09 Thread Michael Gentry
Sweet! What was the solution (in case anyone else searches for it)?


On Wed, Jun 9, 2021 at 12:49 PM Rick Bonnett 
wrote:

> Thanks. That got me on the path to success
>
> *Rick Bonnett*
>
> *Programmer Analyst*
>
> Ascent Global Logistics
>
> PO Box 1039, Augusta, ME, 04332
>
> Office: 207.620.8670
>
> *ascentgl.com* <http://ascentgl.com/>
>
>
>
>
> --
> *From:* Michael Gentry 
> *Sent:* Wednesday, June 9, 2021 12:26 PM
> *To:* Cayenne Users 
> *Subject:* Re: SSL connections to postgresql in Azure
>
>
> *EXTERNAL EMAIL:* Be extra careful around links and attachments.
> Hi Rick,
>
> Are you connecting:
>
> a) local development system -> Azure Postgres
> b) Azure server -> Azure Postgres?
>
> If "a", are there SSL certificates from Azure you need to load into your
> local Java environment. Or you could try turning off SSL verification. See
> more (for both options) here:
>
> https://jdbc.postgresql.org/documentation/head/ssl-client.html
>
> Also, maybe try adding:
>
> .put("ssl", "true"); // Or some other combo from above link...
>
>
> On Wed, Jun 9, 2021 at 10:59 AM Rick Bonnett  >
> wrote:
>
> >
> > Having issues connecting to postgres in Azure - because by default SSL
> > connections are required. I am using:
> >
> > - cayenne 3.1 - yes I know it's old but it's what I'm stuck with
> > - latest postgres JDBC driver
> >
> > Code snippets below.
> >
> > On the JDBC_URLPROPERTY I have tried every flavor of ssslmode=required or
> > usessl=true that I've been able to dredge up, but consistenyly getting:
> >
> > Unable to connect to server: FATAL: SSL connection is required. Please
> > specify SSL options and retry.
> >
> > Hopefully I am just overlooking something simple and obvious. Any
> insights?
> >
> > Module m1 = new Module() {
> > public void configure(Binder binder) {
> >
> binder.bindMap(Constants.PROPERTIES_MAP).put(Constants.JDBC_DRIVER_PROPERTY,
> > "org.postgresql.Driver")
> > .put(Constants.JDBC_URL_PROPERTY, "jdbc:postgresql://
> > http://mypostgres.postgres.database.azure.com:5432/are;)
> > .put(Constants.JDBC_USERNAME_PROPERTY, "")
> > .put(Constants.JDBC_PASSWORD_PROPERTY, "");
> > }
> > };
> >
> > cayenneRuntime = new ServerRuntime("cayenne-ARETariffDomain.xml", m1);
> > DataDomain dd = cayenneRuntime.getDataDomain();
> > Collection dmaps = dd.getDataMaps();
> > for (DataMap dm: dmaps) {
> > for (DbEntity entity: dm.getDbEntities()) {
> > entity.setSchema("p");
> > }
> > }
> > ObjectContext ORMContext = cayenneRuntime.getContext();
> >
> >
> >
> > *Rick Bonnett*
> >
> > *Programmer Analyst*
> >
> > Ascent Global Logistics
> >
> > PO Box 1039, Augusta, ME, 04332
> >
> > Office: 207.620.8670
> >
> > *ascentgl.com* <http://ascentgl.com/>
> >
> >
> >
> >
> > The information transmitted is intended only for the person or entity to
> > which it is addressed and may contain proprietary, business-confidential
> > and/or privileged material. If you are not the intended recipient of this
> > message you are hereby notified that any use, review, retransmission,
> > dissemination, distribution, reproduction or any action taken in reliance
> > upon this message is prohibited. If you received this in error, please
> > contact the sender and delete the material from any computer.
> >
>
> The information transmitted is intended only for the person or entity to
> which it is addressed and may contain proprietary, business-confidential
> and/or privileged material. If you are not the intended recipient of this
> message you are hereby notified that any use, review, retransmission,
> dissemination, distribution, reproduction or any action taken in reliance
> upon this message is prohibited. If you received this in error, please
> contact the sender and delete the material from any computer.
>


Re: SSL connections to postgresql in Azure

2021-06-09 Thread Michael Gentry
Hi Rick,

Are you connecting:

a) local development system -> Azure Postgres
b) Azure server -> Azure Postgres?

If "a", are there SSL certificates from Azure you need to load into your
local Java environment. Or you could try turning off SSL verification. See
more (for both options) here:

https://jdbc.postgresql.org/documentation/head/ssl-client.html

Also, maybe try adding:

.put("ssl", "true"); // Or some other combo from above link...


On Wed, Jun 9, 2021 at 10:59 AM Rick Bonnett 
wrote:

>
> Having issues connecting to postgres in Azure - because by default SSL
> connections are required. I am using:
>
>- cayenne 3.1 - yes I know it's old but it's what I'm stuck with
>- latest postgres JDBC driver
>
> Code snippets below.
>
> On the JDBC_URLPROPERTY I have tried every flavor of ssslmode=required or
> usessl=true that I've been able to dredge up, but consistenyly getting:
>
> Unable to connect to server: FATAL: SSL connection is required. Please
> specify SSL options and retry.
>
> Hopefully I am just overlooking something simple and obvious. Any insights?
>
> Module m1 = new Module() {
> public void configure(Binder binder) {
> binder.bindMap(Constants.PROPERTIES_MAP).put(Constants.JDBC_DRIVER_PROPERTY,
> "org.postgresql.Driver")
> .put(Constants.JDBC_URL_PROPERTY, "jdbc:postgresql://
> mypostgres.postgres.database.azure.com:5432/are")
> .put(Constants.JDBC_USERNAME_PROPERTY, "")
> .put(Constants.JDBC_PASSWORD_PROPERTY, "");
> }
> };
>
> cayenneRuntime = new ServerRuntime("cayenne-ARETariffDomain.xml", m1);
> DataDomain dd = cayenneRuntime.getDataDomain();
> Collection dmaps =  dd.getDataMaps();
> for (DataMap dm: dmaps) {
> for (DbEntity entity: dm.getDbEntities()) {
> entity.setSchema("p");
> }
> }
> ObjectContext ORMContext = cayenneRuntime.getContext();
>
>
>
> *Rick Bonnett*
>
> *Programmer Analyst*
>
> Ascent Global Logistics
>
> PO Box 1039, Augusta, ME, 04332
>
> Office: 207.620.8670
>
> *ascentgl.com* 
>
>
>
>
> The information transmitted is intended only for the person or entity to
> which it is addressed and may contain proprietary, business-confidential
> and/or privileged material. If you are not the intended recipient of this
> message you are hereby notified that any use, review, retransmission,
> dissemination, distribution, reproduction or any action taken in reliance
> upon this message is prohibited. If you received this in error, please
> contact the sender and delete the material from any computer.
>


Re: Examples of Cayenne Tapestry apps

2021-06-09 Thread Michael Gentry
Using Spring/Thymeleaf+JPA currently...really missing
Tapestry+Cayenne--much more elegant, IMO.


On Tue, Jun 8, 2021 at 11:32 PM Robert Zeigler 
wrote:

> I haven't really been involved in java for a long time (primarily python
> these days), but nice to see that someone else picked up what Kevin and I
> started ages ago. Odd thing is, I thought I had officially ported
> tapestry5-cayenne over to github a long while ago; I have a t5cayenne repo
> in my account... but it's empty. Might just have to look for an excuse to
> pick up java, Tapestry, Cayenne again.
>
> On Tue, Jun 8, 2021 at 10:01 AM Richard Frovarp 
> wrote:
>
> > There is an integration library that was developed by a group of people
> > once upon a time. It was abandoned, but was Apache License 2. So I've
> > picked up a fork, and have it updated.
> >
> > https://code.google.com/archive/p/tapestry5-cayenne/
> >
> > https://github.com/NDSU-Information-Technology/tapestry5-cayenne
> >
> > I've released the artifacts to Maven Central using my namesspace over at
> > edu.ndsu. Works the same as the archived version, just updated some.
> > What I have up is for internal use, as I don't have the time to fully
> > bring our fork up to snuff with respect to documentation, etc at the
> > moment. But others are obviously free to use it.
> >
> > And you're looking for an example:
> >
> >
> >
> https://github.com/NDSU-Information-Technology/international-capstone-exchange
> >
> > That uses the integration service. Versions are kind of old, but the
> > idea is the same.
> >
> >
> > On 5/12/21 5:50 AM, D Tim Cummings wrote:
> > > Does anyone know of any good open-source Cayenne Tapestry apps that
> show
> > > best practice and latest features for using these two frameworks
> > > together? Most of the Tapestry examples use Hibernate.
> > >
> > > Tim
> > >
> > >
> > >
> >
>


Re: Examples of Cayenne Tapestry apps

2021-05-12 Thread Michael Gentry
Hi Tim!

The Tapestry+Cayenne apps I worked on weren't open source, but the
combination worked amazingly well for us.

In the largest one, we had a small user base, but the object graph being
edited could be 100s or for a few, over 1000 records [1]. Because the
number of records could take a while to load in from the database and
because our validations had to traverse the entire object graph every time,
we chose to make the app session-based. Didn't have any issues with the
object graph being in session and Tapestry did a great job reading the data
from the Cayenne object graph to edit in the UI and pushing all the data
back to the Cayenne object graph on submit where we could re-validate.

Our save button was essentially dataContext.commitChanges(), with a
try/catch block around it to handle errors. This was a HUGE advantage over
having to micromanage each individual record like you'd do with
Hibernate/JPA -- plus no LazyInitializationExceptions ever.

My memory is a little fuzzy here, but I believe we had custom encoders for
Tapestry to tell it how to identify Cayenne objects, especially when you
were iterating over them. We had a common Cayenne superclass for all of our
objects that implemented this to make it simpler and allow us to re-use a
generic encoder. I believe this identifier (t5id) was simply a dynamic UUID
we'd generate for every Cayenne object when needed. No need to persist it
and it didn't have to be the same ID across sessions as it was only for
Tapestry to identify objects when doing a submit.

mrg

[1] We learned the hard way that Tomcat has a default limit of 10k form
inputs because one of our users was reporting data wasn't saving at the
BOTTOM of the page, but was saving at the TOP. To make it worse, Tomcat
just silently ignores anything after 10k inputs -- no error/exception/etc.
Had to adjust Tomcat to accept an unlimited number of inputs to get their
data saving again.


On Wed, May 12, 2021 at 6:50 AM D Tim Cummings 
wrote:

> Does anyone know of any good open-source Cayenne Tapestry apps that show
> best practice and latest features for using these two frameworks
> together? Most of the Tapestry examples use Hibernate.
>
> Tim
>
>
>
>


Re: PK Generation and FrontBase

2021-04-16 Thread Michael Gentry
Hi Jérémy,

I've never used it, but Andrus (and others) have a project called LinkMove
which may work:

https://github.com/nhl/link-move

I don't see a way to re-use a Cayenne model as the source AND the target,
but perhaps that is also an option (instead of the XML source), too.


On Fri, Apr 16, 2021 at 4:14 AM Jérémy DE ROYER 
wrote:

> Sorry, please read
>
> « Migrate from FrontbaseSQL to PostgreSQL »  
>
> Jérémy
>
> > Le 16 avr. 2021 à 10:04, Jérémy DE ROYER 
> a écrit :
> >
> > Hi Hugi,
> >
> > Unfortunately, I think you’re right.
> >
> > I wanted to leave FrontbaseSQL too but as Andrus say, the meeting in
> Frankfurt help me to resolve some cases and finally we keep our softwares
> using FrontbaseSQL.
> >
> > According to your experience, is there an easy way to migrate/transfert
> from PostgreSQL to FrontBaseSQL ?
> >
> > It could respond to the request from developers to have access to
> programming tools with the database, not offered by FrontbaseSQL.
> >
> > Thank’s for this highlight,
> >
> > Jérémy
> >
> >> Le 16 avr. 2021 à 09:53, Hugi Thordarson  a écrit :
> >>
> >> Hi Jérémy,
> >>
> >> I believe you hit a bug in the FrontBase JDBC driver:
> >> https://issues.apache.org/jira/browse/CAY-2574 <
> https://issues.apache.org/jira/browse/CAY-2574>
> >>
> >> Andrus wrote to FrontBase about this after our Frankfurt meetup:
> >>
> https://mail-archives.apache.org/mod_mbox/cayenne-dev/201905.mbox/%3C52EC2486-4736-4854-AE49-A7CF77904E52%40objectstyle.org%3E
>  >
> >>
> >> I haven't seen anything from FB about this since this thread, perhaps
> you should give their support a check?
> >> I also wrote to them last year about their JDBC driver not working on
> more recent Java versions, but don't think they've fixed it. I ended up
> migrating that one last FrontBase app to Postgres.
> >>
> >> Cheers,
> >> - hugi
> >>
> >>
> >>
> >>> On 15 Apr 2021, at 20:59, Jérémy DE ROYER 
> wrote:
> >>>
> >>> Hi John,
> >>>
> >>> I know that FrontbaseSQL is not commonly used but our all apps are
> based on.
> >>>
> >>> I’ve just :
> >>> - created the model explained on the doc
> https://cayenne.apache.org/docs/3.0/modeling-single-table-inheritance.html
> >>> - wrote the code below inside the ‘Application’ class of a simple woapp
> >>>
> >>> But yes, maybe Cayenne is not done to work with FrontbaseSQL… as it
> works well with PostregSQL.
> >>>
> >>> Thank’s for your answer and have a nice day,
> >>>
> >>> Jérémy
> >>>
> >>> Le 15 avr. 2021 à 22:50, John Huss  johnth...@gmail.com>> a écrit :
> >>>
> >>> I don't think FrontBase is very commonly used. I would recommend
> submitting
> >>> a minimal example of the problem and someone should be able to fix the
> >>> issue then.
> >>>
> >>> On Thu, Apr 15, 2021 at 3:44 PM Jérémy DE ROYER <
> jeremy.dero...@ingencys.net>
> >>> wrote:
> >>>
> >>> Hello,
> >>>
> >>> I switched my model from FrontBase to PostgreSQL and it works great.
> >>>
> >>> Does someone use Cayenne 4.1 with FrontbaseSQL successfully ?
> >>>
> >>> Is there something specific to know ?
> >>>
> >>> Thank’s for any tip,
> >>>
> >>> Jérémy
> >>>
> >>> Le 14 avr. 2021 à 23:05, Jérémy DE ROYER  >
> >>> a écrit :
> >>>
> >>> Hi all,
> >>>
> >>> I’m trying to find a solution for the (temporary ?) lack of horizontal
> >>> inheritance so I did model vertical inheritance following :
> >>>
> >>> https://cayenne.apache.org/docs/3.0/modeling-vertical-inheritance.html
> >>>
> >>> using a Frontbase database.
> >>>
> >>> I did :
> >>> - create the model,
> >>> - generate the database,
> >>> - fix lack of jars and other things like username, password, jdbc
> driver
> >>>
> >>> The demo code below starts well and connects to database...
> >>>
> >>> try {
> >>> ServerRuntime cayenneRuntime = ServerRuntime.builder()
> >>> .addConfig("cayenne-CayenneTest.xml")
> >>> .build();
> >>>
> >>> ObjectContext context = cayenneRuntime.newContext();
> >>>
> >>> Book _newBook = context.newObject(Book.class);
> >>> _newBook.setTitle("Nouveau Book");
> >>> _newBook.setCreated(new Date());
> >>>
> >>> context.commitChanges();
> >>>
> >>> EBook _newEBook = context.newObject(EBook.class);
> >>> _newEBook.setTitle("Nouveau EBook");
> >>> _newEBook.setCreated(new Date());
> >>> _newEBook.setDownloadUrl("https://www.google.fr/;);
> >>>
> >>> context.commitChanges();
> >>>
> >>> PaperBook _newPaperBook = context.newObject(PaperBook.class);
> >>> _newPaperBook.setTitle("Nouveau PaperBook");
> >>> _newPaperBook.setCreated(new Date());
> >>> _newPaperBook.setShippingWeight(1000);
> >>>
> >>> context.commitChanges();
> >>>
> >>> List _books = ObjectSelect.query(Book.class).select(context);
> >>>
> >>> System.out.println("** ALL **");
> >>>
> >>> for (Book currentBook : _books)
> >>> {
> >>> System.out.println(currentBook.getTitle() + " created on " +
> >>> currentBook.getCreated());
> >>> }
> >>> }
> >>> 

Re: 4.1 informix jdbc issue

2020-09-11 Thread Michael Gentry
Hugi...you need to save that story for Halloween...


On Thu, Sep 10, 2020 at 3:00 PM Hugi Thordarson  wrote:

> Hi Sébastien,
>
> Do you have the option of upgrading the Informix JDBC-driver? I seem to
> recall that their more recent drivers *do* support
> prepareStatement(String,int) but to use a newer JDBC driver you need a
> compatible version of Informix (can't use the new JDBC-drivers to connect
> to older versions of the DB). We couldn't do that—all the people that knew
> the DB server were either dead or retired—but if that's possible in your
> case, that would probably be the best solution.
>
>  Story of an ugly workaround starts. Do not read if you are young,
> impersonable or mentally unstable. In fact, probably just don't read this
> at all.
>
> But yes, I encountered this issue a couple of years ago and I didn't
> really solve it. Cayenne 4.1+ will use prepareStatement( String, int ) if
> the table has a DB-generated PK column. In my case, the non-solution I
> ended with was make the generated PK "Cayenne generated". Then I
> implemented a PKGenerator that just returned "null" for the PK. Then I
> excluded the PK-column from insert statements using an
> InsertBatchTranslator (because Informix would not populate the PK/serial's
> value if it was set to null in the insert statement). Then I just threw
> away the poor ObjectContext that did all these horrible things and
> re-fetched the inserted objects in a new context, now with DB generated PKs.
> This is obviously horrid. But it worked as a temporary workaround while we
> were in the process of migrating to Postgres.
>
>  Ugly workaround ends
>
> So in short: I hope you can upgrade the JDBC driver. Or that I am in the
> wrong and someone has a better solution for you.
>
> - hugi
>
>
>
> > On 10 Sep 2020, at 10:24, Sébastien Pérès-Labourdette <
> sebastien.peres-labourde...@omerin.com> wrote:
> >
> > Hi there.
> >
> > While integrating 4.1 we found that the informix jdbc driver from ibm
> > does not support
> > IfxSqliConnection:prepareStatement(String,int)
> >
> > Invoked from
> > connection.prepareStatement(compiled.getSql(), generatedKeys); in
> > SQLTemplateAction.execute
> >
> > FYI,4.0.2 sqltemplates are fine with this jdbc driver.
> >
> > Is there anything we can do (replacing informix with any other rdbms not
> > being an option) to get 4.1 sqltemplates running as smooth as the 4.0.2
> > ones ?
> >
> > --
> > Sébastien
> >
>
>


Re: Expression to compare a property against another property

2020-09-10 Thread Michael Gentry
Hi Faizel,

What version of Cayenne are you using?  That will influence the feedback we
can provide.


On Thu, Sep 10, 2020 at 5:00 PM Faizel Dakri  wrote:

> Is there a facility in Cayenne to create an expression that would compare
> a property of one object against another property (maybe via a relationship
> path rooted at the same object) rather than against a scalar value?
>
> I’m trying to port over some old EOF code and we used to have a
> EOKeyComparisonQualifier which would allow you to create a qualifier to
> compare a property’s value with that of another property (or property key
> path).
>
> For example, given a model consisting of employees, where each employee
> can have a relationship to a manager and each employee has a salary
> property, you could use a key comparison qualifier to find those employees
> that are making more than their manager:
>
> salary > manager.salary
>
> I’ve looked in ExpressionFactory and through some of the source, but to me
> it looks like all comparison nodes in an expression operate on a key and a
> scalar. Am I missing something?
>
> Thanks for any help or pointers,
>
> F
>
> --
> Faizel Dakri
>
>
>


Re: Programmatically adding (db/obj) attributes to a model and saving

2020-09-05 Thread Michael Gentry
I'm naive enough that I'd just use a macro in Emacs to modify the mapping...


On Sat, Sep 5, 2020 at 5:14 AM Hugi Thordarson  wrote:

> Hi all,
> I'm adding some standard attributes to a few dozen tables. Since they all
> look more or less the same, I'd like to do it programmatically.
> That's easy enough, but I'm wondering what the best way would be for me to
> write out the project after adding the attributes.
>
> I've currently got something like:
>
> XMLEncoder encoder = new XMLEncoder( new PrintWriter( new File(
> "new.map.xml" ) ) );
> map.encodeAsXML( encoder, new EmptyConfigurationNodeVisitor() );
>
> …which works kinda-sorta. But I imagine there's a better or more idiomatic
> way using something like ProjectLoader or ProjectSaver?
>
> Cheers,
> - hugi


Re: springboot and cayenne

2020-08-10 Thread Michael Gentry
+1 for Hikari.

I don't remember the numbers off the top of my head, but I switched from
DBCP to Hikari a few years ago and the speed improvement was pretty
noticeable.  The gains seemed to largely come from relationship faults as
you could get and return your DB connection faster with Hikari.


On Mon, Aug 10, 2020 at 1:49 AM Andrew Lindesay  wrote:

> Hello Tony;
>
> I have a hobby Spring (not SpringBoot) application that uses Cayenne.
>
> https://github.com/haiku/haikudepotserver
>
> The configuration class `PersistenceConfig` shows how an instance of
> `ServerRuntime` is created and is then able to be injected where it is
> required.
>
> Hope this helps.
>
> Regards.
>
> --
> Andrew Lindesay
>
> On Fri, 31 Jul 2020, at 01:03, Tony Giaccone wrote:
> > Yes, I know I asked this question before, and there were some answers
> > previously, one of them has led me to a solution I think works, haven't
> > quite got it functional yet, but it's close.  I asked again because it's
> > been a while since the first time and I thought maybe someone else had an
> > easily available solution.
> >
> >
> > Tony
> >
> > On Thu, Jul 30, 2020 at 1:51 AM Andrus Adamchik 
> > wrote:
> >
> > > Hi Tony,
> > >
> > > I haven't used Cayenne with SpringBoot for obvious reasons, but it
> should
> > > be no different from using it in any other env:
> > >
> > > * Create a ServerRuntime singleton
> > > * Get ObjectContext from it when you need it.
> > >
> > > Andrus
> > >
> > > > On Jul 29, 2020, at 5:33 PM, Tony Giaccone 
> wrote:
> > > >
> > > > I see there's a cayenne spring boot starter project, has anyone used
> > > this?
> > > > What's the state of using Cayenne with springboot?
> > > >
> > > >
> > > >
> > > > Tony Giaccone
> > >
> > >
> >
>


Re: Check for certain changes in @PreUpdate listener class

2020-07-16 Thread Michael Gentry
Hi Hugi,

I think you can use similar mechanics to examine relationship data, too.  I
just didn't do that there.


On Thu, Jul 16, 2020 at 3:46 AM Hugi Thordarson  wrote:

> Thanks Michael! This works excellently for attributes on the entity, but
> I've yet to find a good solution when dealing with FKs (when to-one
> relationships are modified).
>
> I've opted to just don't update modificationDate when relationships are
> touched for now so… At least halfway there :).
>
> Thanks,
> - hugi
>
>
>
> > On 13 Jul 2020, at 13:23, Michael Gentry  wrote:
> >
> > Hi Hugi,
> >
> > You might have to compare everything to be certain.  Here is something
> I've
> > used in the past (for Cayenne 3.x) which might be helpful:
> >
> >
> https://gist.github.com/mrg/4dce22b67175c27f4047#file-cayenneutils-java-L105
> >
> >
> > On Mon, Jul 13, 2020 at 9:11 AM Hugi Thordarson 
> wrote:
> >
> >> Hi all.
> >> Almost all of my objects have attributes called creationDate() and
> >> modificationDate(), these are populated in a listener attached to the
> >> DataDomain:
> >>
> >> https://gist.github.com/hugith/a40faae5529a1826d601515a9e8c5206
> >>
> >> Relatively simple and has served me well for the past few years. One
> thing
> >> has always irritated me though. This method of doing things means that
> if
> >> the only change to an object is to a to-many relationship,
> >> "modificationDate" will get updated (for example: User has a
> relationship
> >> user<-->>invoices, the user creates an invoice which is then added to
> his
> >> "invoices" relationship. modificationDate is then updated even if there
> was
> >> no logical change to the user itself).
> >>
> >> So, I'm wondering… Is there any good way in the listener to check what
> >> attributes have changed, so I can skip the update to modificationDate if
> >> the only changed properties are to-many relationships?
> >> I know I could implement a CommitLogListener and use the ChangeMap from
> >> there, but as you see I'm doing these updates before committing, making
> >> these changes a part of the same commit (which I'd much prefer to keep
> that
> >> way).
> >>
> >> Cheers,
> >> - hugi
>
>


Re: Check for certain changes in @PreUpdate listener class

2020-07-13 Thread Michael Gentry
Hi Hugi,

You might have to compare everything to be certain.  Here is something I've
used in the past (for Cayenne 3.x) which might be helpful:

https://gist.github.com/mrg/4dce22b67175c27f4047#file-cayenneutils-java-L105


On Mon, Jul 13, 2020 at 9:11 AM Hugi Thordarson  wrote:

> Hi all.
> Almost all of my objects have attributes called creationDate() and
> modificationDate(), these are populated in a listener attached to the
> DataDomain:
>
> https://gist.github.com/hugith/a40faae5529a1826d601515a9e8c5206
>
> Relatively simple and has served me well for the past few years. One thing
> has always irritated me though. This method of doing things means that if
> the only change to an object is to a to-many relationship,
> "modificationDate" will get updated (for example: User has a relationship
> user<-->>invoices, the user creates an invoice which is then added to his
> "invoices" relationship. modificationDate is then updated even if there was
> no logical change to the user itself).
>
> So, I'm wondering… Is there any good way in the listener to check what
> attributes have changed, so I can skip the update to modificationDate if
> the only changed properties are to-many relationships?
> I know I could implement a CommitLogListener and use the ChangeMap from
> there, but as you see I'm doing these updates before committing, making
> these changes a part of the same commit (which I'd much prefer to keep that
> way).
>
> Cheers,
> - hugi


Re: [OT] I demand change

2020-07-13 Thread Michael Gentry
Clearly The Google doesn't know enough about you.  Try DuckDuckGo and see
if it is better! :-)


On Mon, Jul 13, 2020 at 5:16 AM Hugi Thordarson  wrote:

> That's it. I'm sick and tired of Porsche polluting my search results.
>
> http://chng.it/ySkvT5DK7z 
>
> Cheers,
> - hugi


Re: Automatically deleting objects from a to-many relationship when removed?

2020-07-13 Thread Michael Gentry
Hi Faizel,

If you don't have many entities where deleting is important, you could put
"delete" type methods in your subclasses.  For example, if you have
LineItem and a to-many to Order, in LineItem.java add a
deleteFromOrders(Order order) { ... } method which will remove and delete
the Order object.  If you have many entities, it might be easier to create
your own Velicity template (using the current Velocity template as a guide)
and add new code for a deleteFromX(X x) { ... } type method for each
to-many relationship.  If you go that route and need help, please ask.

The reason Cayenne doesn't automatically delete objects is you might be
moving them.  For example, if your LineItem has both fulfilledOrders and
unfulfilledOrders to-many relationships, you can remove an Order from the
unfulfilled relationship and add it to the fulfilled relationship.  When
you commit, Cayenne updates the FKs for you and no delete/insert is done.

mrg


On Sun, Jul 12, 2020 at 5:35 PM Faizel Dakri  wrote:

> Is there a facility in Cayenne to automatically delete an object when it
> is removed from an “owning” object’s to-many relationship (and not added to
> another owning object)?
>
> I’m migrating a project from EOF to Cayenne. In the EOF world, there was
> the concept of a relationship owning its destination, meaning that removing
> a destination object from that relationship in the source object would also
> cause that destination object to be deleted from the database on commit
> without having to explicitly call deleteObject() on it (provided it wasn’t
> subsequently added to another source object). This automatic deletion would
> happen during saveChanges() on the editing context.
>
> Maybe it’s just too obvious and I haven’t been able to recognize it, but I
> have not been able to find anything similar in Cayenne. Is there such a
> feature?
>
> Thanks,
>
> F
>
> --
> Faizel Dakri
>
>
>


Re: Migrating from exposed, compund PKs to single-column db generated keys

2020-07-09 Thread Michael Gentry
Hi Hugi,

Are the legacy systems that are accessing this DB doing inserts?  If so,
check if the DB has a way to do an automatic generated PK for that column's
value if it is null upon insert.  If the inserts are only done from the
Cayenne-based system, you'll be OK there.  Not sure if there'd be
update/delete implications from the legacy system, but I suspect these may
be OK.


On Thu, Jul 9, 2020 at 9:17 AM Hugi Thordarson  wrote:

> Hi all,
>
> I'm currently in the progress of migrating an old DB schema from using
> exposed meaningful PKs to using db generated (serial) surrogate PKs.
> However, some legacy systems still use the same DB, so my new PKs will
> have to coexist alongside the older ones for a while.
>
> My current plan:
> - Each table gains a new column named "id" of the type serial, with a
> unique constraint applied to it.
> - The corresponding Cayenne DbEntity is changed to use the new "id" column
> as the PK with a PK-generation strategy of "Database generated".
> - Every table with relationships to this entity gets appropriate FKs that
> reference the new "id" column instead of the old columns (and their
> corresponding DbRelationships get changed as well)
>
> Note that the tables will keep their old PK as the real, defined PK — the
> "id" column is a plain addition.
>
> So, my question is: Does anyone see a problem with this? What this
> essentially means is that for a while, Cayenne will be using a "fake"
> primary key to identify objects, i.e. not the table's actual defined PK but
> just a regular unique integer column.
>
> Initial testing seems to suggest that this works well, but I just wanted
> to check if I could expect something horrid to happen down the line :).
>
> Cheers,
> - hugi


Re: Building Master Branch

2020-05-26 Thread Michael Gentry
Hi Malcolm,

Did you use mvn verify or mvn install?  I seem to recall having a problem
using install instead of verify.


On Tue, May 26, 2020 at 6:17 AM Malcolm Edgar 
wrote:

> Hi All,
>
> I am wanting to build the Cayenne master branch to explore adding support
> for Postgres JSON, JSONB data types.  I am getting the following build
> error resolving the cayenne-maven-plugin when building on Windows or Linux
> / WSL.
>
> Does anyone have suggestions for how to resolve this?
>
> Thanks for your help.
>
> regards Malcolm
>
> [INFO]
> 
> [INFO] BUILD FAILURE
> [INFO]
> 
> [INFO] Total time:  5.206 s
> [INFO] Finished at: 2020-05-26T11:16:12+10:00
> [INFO]
> 
> [ERROR] Plugin
> org.apache.cayenne.plugins:cayenne-maven-plugin:4.2.M2-SNAPSHOT or one of
> its dependencies could not be resolved: Could not find artifact
> org.apache.cayenne.plugins:cayenne-maven-plugin:jar:4.2.M2-SNAPSHOT ->
> [Help 1]
> org.apache.maven.plugin.PluginResolutionException: Plugin
> org.apache.cayenne.plugins:cayenne-maven-plugin:4.2.M2-SNAPSHOT or one of
> its dependencies could not be resolved: Could not find artifact
> org.apache.cayenne.plugins:cayenne-maven-plugin:jar:4.2.M2-SNAPSHOT
> at
> org.apache.maven.plugin.internal.DefaultPluginDependenciesResolver.resolve
> (DefaultPluginDependenciesResolver.java:131)
> at
>
> org.apache.maven.plugin.internal.DefaultMavenPluginManager.getPluginDescriptor
> (DefaultMavenPluginManager.java:182)
> at
>
> org.apache.maven.plugin.internal.DefaultMavenPluginManager.getMojoDescriptor
> (DefaultMavenPluginManager.java:286)
> at org.apache.maven.plugin.DefaultBuildPluginManager.getMojoDescriptor
> (DefaultBuildPluginManager.java:244)
>


Re: likeIgnoreCase

2020-04-16 Thread Michael Gentry
I've never used "?s" personally, but I'd try at the beginning of your
expression string first.  It is supposed to tell the Pattern to treat the
string as a single line...


On Thu, Apr 16, 2020 at 11:24 AM Lon Varscsak 
wrote:

> It's simply %string%.  I can try that.
>
> On Thu, Apr 16, 2020 at 7:21 AM Michael Gentry 
> wrote:
>
> > Hi Lon,
> >
> > What does your pattern look like?  Did you try adding a "?s" to your
> > expression?
> >
> >
> > On Wed, Apr 15, 2020 at 11:05 PM Lon Varscsak 
> > wrote:
> >
> > > Hey all, trying to use likeIgnoreCase on an in-memory list and it
> appears
> > > not to work if there is a new line in the text.  The Pattern would need
> > > Pattern.DOTALL as a flat to work properly. Would you consider this a
> bug?
> > >
> > > -Lon
> > >
> >
>


Re: likeIgnoreCase

2020-04-16 Thread Michael Gentry
Hi Lon,

What does your pattern look like?  Did you try adding a "?s" to your
expression?


On Wed, Apr 15, 2020 at 11:05 PM Lon Varscsak 
wrote:

> Hey all, trying to use likeIgnoreCase on an in-memory list and it appears
> not to work if there is a new line in the text.  The Pattern would need
> Pattern.DOTALL as a flat to work properly. Would you consider this a bug?
>
> -Lon
>


Re: MySQL + Iterated/Streamed Query

2020-03-18 Thread Michael Gentry
That worked perfectly.  Used a much higher fetch size for performance,
though.  The memory usage held steady and was able to process all 30M
records.

Thanks!


On Tue, Mar 17, 2020 at 10:50 AM Andrus Adamchik 
wrote:

> This translates to java.sql.Statement#setFetchSize(), i.e. the number of
> records to retrieve at once from the DB, so it has to be positive. E.g.
> 1000 or something.
>
> From java.sql.Statement#setFetchSize javadocs:
>
> "Gives the JDBC driver a hint as to the number of rows that should be
> fetched from the database when more rows are needed for ResultSet objects
> generated by this Statement. If the value specified is zero, then the hint
> is ignored. The default value is zero."
>
> Andrus
>
>
>
> > On Mar 17, 2020, at 4:54 PM, Michael Gentry  wrote:
> >
> > Do you use Integer.MIN_VALUE for the ObjectSelect.statementFetchSize()?
> >
> >
> > On Tue, Mar 17, 2020 at 2:14 AM Andrus Adamchik 
> > wrote:
> >
> >> Yeah, had to deal with this before. While there's no API to directly
> >> access the Statement (I think we should introduce it just in case),
> there
> >> is an alternative: add "useCursorFetch=true" URL parameter and use
> >> "ObjectSelect.statementFetchSize(..)".
> >>
> >> Andrus
> >>
> >>
> >>> On Mar 14, 2020, at 5:31 PM, Michael Gentry 
> wrote:
> >>>
> >>> I'm trying to do an iterated query (using the 4.1 RC) against MySQL and
> >> it
> >>> appears that the MySQL JDBC driver loads everything into memory first
> >>> instead of streaming results.  This results in memory-related
> exceptions
> >>> for larger results.
> >>>
> >>> From searching, it appears that the MySQL JDBC driver needs the
> following
> >>> hint to stream results:
> >>>
> >>> statement =
> >>> connection.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY,
> >>> java.sql.ResultSet.CONCUR_READ_ONLY);
> >>> statement.setFetchSize(Integer.MIN_VALUE);
> >>>
> >>> Is there an easy way to get the iterated query to provide that hint
> when
> >>> getting a connection?  I've not found a way yet.  Best I've found so
> far
> >> is
> >>> to swap out a whole slew of classes to change the DataSource that's
> >>> actually returned.
> >>>
> >>> Thanks,
> >>>
> >>> mrg
> >>
> >>
>
>


Re: MySQL + Iterated/Streamed Query

2020-03-17 Thread Michael Gentry
Do you use Integer.MIN_VALUE for the ObjectSelect.statementFetchSize()?


On Tue, Mar 17, 2020 at 2:14 AM Andrus Adamchik 
wrote:

> Yeah, had to deal with this before. While there's no API to directly
> access the Statement (I think we should introduce it just in case), there
> is an alternative: add "useCursorFetch=true" URL parameter and use
> "ObjectSelect.statementFetchSize(..)".
>
> Andrus
>
>
> > On Mar 14, 2020, at 5:31 PM, Michael Gentry  wrote:
> >
> > I'm trying to do an iterated query (using the 4.1 RC) against MySQL and
> it
> > appears that the MySQL JDBC driver loads everything into memory first
> > instead of streaming results.  This results in memory-related exceptions
> > for larger results.
> >
> > From searching, it appears that the MySQL JDBC driver needs the following
> > hint to stream results:
> >
> > statement =
> > connection.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY,
> > java.sql.ResultSet.CONCUR_READ_ONLY);
> > statement.setFetchSize(Integer.MIN_VALUE);
> >
> > Is there an easy way to get the iterated query to provide that hint when
> > getting a connection?  I've not found a way yet.  Best I've found so far
> is
> > to swap out a whole slew of classes to change the DataSource that's
> > actually returned.
> >
> > Thanks,
> >
> > mrg
>
>


MySQL + Iterated/Streamed Query

2020-03-14 Thread Michael Gentry
I'm trying to do an iterated query (using the 4.1 RC) against MySQL and it
appears that the MySQL JDBC driver loads everything into memory first
instead of streaming results.  This results in memory-related exceptions
for larger results.

>From searching, it appears that the MySQL JDBC driver needs the following
hint to stream results:

statement =
connection.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY,
java.sql.ResultSet.CONCUR_READ_ONLY);
statement.setFetchSize(Integer.MIN_VALUE);

Is there an easy way to get the iterated query to provide that hint when
getting a connection?  I've not found a way yet.  Best I've found so far is
to swap out a whole slew of classes to change the DataSource that's
actually returned.

Thanks,

mrg


Re: Using Cayenne with unsupported relational databases

2020-02-12 Thread Michael Gentry
Hi Salman,

The Altibase website says "Altibase is a relational DBMS and is compatible
and interoperable with Oracle."  Please try using the Oracle JDBC driver
and Cayenne will treat the DB (and SQL generation) as Oracle.

If that doesn't work and you need to use an Altibase JDBC driver, let us
know and we'll give you a few more pointers.  (There'll be a bit more work
involved, but you can base a new Altibase DB adapter upon the existing
Oracle DB adapter.)

mrg


On Tue, Feb 11, 2020 at 11:40 PM Salman Hussain <
salman.hussain@gmail.com> wrote:

> Hi Andrus Adamchik,
>
> The supported databases by Cayenne listed at
> https://cayenne.apache.org/database-support.html are
> DB2, Derby, FrontBase, HSQLDB, H2, Ingres, MySQL, OpenBase, Oracle,
> PostgreSQL, SQLite, SQLServer, Sybase.
>
> But I wish to use Cayenne with Altibase (http://www.altibase.com/), a
> database not supported by Cayenne.
> Could you please let me know if it is possible to use Cayenne with Altibase
> and the steps to acheive the same?
>
> Thanks
> Salman Hussain
>
>
>
> --
> Sent from: http://cayenne.195.n3.nabble.com/Cayenne-User-f196.html
>


Re: Cayenne and Mysql 8.x

2019-12-16 Thread Michael Gentry
Try going into Cayenne Modeler's preferences and adding the MySQL 8.x
driver JAR to the CLASSPATH preference and see if it works for you.  After
adding, you may need to restart CM in order for the JAR to be utilized.


On Mon, Dec 16, 2019 at 5:25 AM Feliks_Wang王祺童(PE) <
feliks_w...@ks.gemteks.com> wrote:

> hello
>
> I want to import the MySQL database tables in the Cayenne modeler, but
> my MySQL is 8.x version, the JDBC Driver in the modeler is the 5.x driver,
> and the Database Support given at https://cayenne.apache.org/ is also a
> 5.x
> driver. Is there any solution for this?
> Thanks for any help you can provide.
>
> Best Regards!
>
>
>
>
>
>
>
> ssevvenn
>
> --
> *CONFIDENTIALITY NOTICE :* Please be advised that this e-mail and any
> files
> transmitted therewith are privileged or confidential and are intended
> solely for the individual or entity to whom they are addressed. If you are
> not the intended recipient, please do not read, copy or retransmit this
> communication but destroy it immediately. Any unauthorized dissemination,
> distribution or copying of this communication is strictly prohibited.
>


Re: Long primary keys

2019-11-13 Thread Michael Gentry
Hi Andrus,

I was basing my response due to the "Numeric Overflow" exception, which
sounds like a number too big to fit into a Long.  If a BIGINT/BigInteger
will work, that's the easiest solution.


On Wed, Nov 13, 2019 at 8:35 AM Andrus Adamchik 
wrote:

> This still does not invalidate the original question though - why wouldn't
> Cayenne choose a Long here?
>
> My suggestion is to map this column as BIGINT in Cayenne, and it will do
> the right thing.
>
> Andrus
>
>
> > On Nov 13, 2019, at 4:29 PM, Michael Gentry  wrote:
> >
> > Hi Vemund!
> >
> > Long.MAX_VALUE is 9,223,372,036,854,775,807.  NUMBER(38) is a lot more
> > digits.
> >
> > Does your DB really have primary keys that large?  To play Devil's
> Advocate:
> >
> > 9223372036854775807 / 1000 inserts/second / 60 seconds/minute / 60
> > minutes/hour / 24 hours/day / 365 days/year = 292,471,208 years before
> your
> > primary keys are exhausted assuming you can actually insert 1000
> > records/second non-stop for nearly 300 million years.  If so, you'll need
> > to consider a different approach.  Perhaps using BigInteger, although
> I've
> > not personally tried that with Cayenne's mapping so it may not work.  If
> it
> > doesn't, you can try creating a class that will work with Cayenne's
> mapping
> > (right API) which wraps a BigInteger holding the actual value.
> >
> > Also, I just looked at the Oracle documentation for the NUMBER data type
> > and it says "up to 38 digits of precision" ... perhaps whomever created
> the
> > schema just chose the maximum precision to be safe?
> >
> > mrg
> >
> >
> > On Wed, Nov 13, 2019 at 6:13 AM Vemund Jakobsen  wrote:
> >
> >> Hi,
> >>
> >> I'm running a Oracle database and trying to get Cayenne to work when
> >> having primary keys that should be mapped to Long in Java. The data
> type in
> >> Oracle is NUMBER(38), but when I create a SelectQuery and use DlpObject
> >> object= (DlpObject) Cayenne.objectForQuery(ctx, this); to get the
> object, I
> >> get the exception below. I'm using Cayenne version 4.0.2. Why does
> Cayenne
> >> think that the type is Integer,  and how can the issue be resolved?
> >>
> >> 10:59:36,285 WARN  [com.dataloy.rest.exception.CayenneExceptionMapper]
> >> (default task-1) : java.sql.SQLException: Numeric Overflow
> >>at
> >>
> oracle.jdbc.driver.NumberCommonAccessor.throwOverflow(NumberCommonAccessor.java:4136)
> >> [ojdbc8.jar:12.2.0.1.0]
> >>at
> >>
> oracle.jdbc.driver.NumberCommonAccessor.getInt(NumberCommonAccessor.java:123)
> >> [ojdbc8.jar:12.2.0.1.0]
> >>at
> >>
> oracle.jdbc.driver.GeneratedStatement.getInt(GeneratedStatement.java:197)
> >> [ojdbc8.jar:12.2.0.1.0]
> >>at
> >>
> oracle.jdbc.driver.GeneratedScrollableResultSet.getInt(GeneratedScrollableResultSet.java:244)
> >> [ojdbc8.jar:12.2.0.1.0]
> >>at
> >>
> org.jboss.jca.adapters.jdbc.WrappedResultSet.getInt(WrappedResultSet.java:1052)
> >>at
> >>
> org.apache.cayenne.access.types.IntegerType.materializeObject(IntegerType.java:38)
> >> [cayenne-server-4.0.2.jar:4.0.2]
> >>at
> >>
> org.apache.cayenne.access.types.IntegerType.materializeObject(IntegerType.java:28)
> >> [cayenne-server-4.0.2.jar:4.0.2]
> >>at
> >>
> org.apache.cayenne.access.jdbc.reader.FullRowReader.readRow(FullRowReader.java:52)
> >> [cayenne-server-4.0.2.jar:4.0.2]
> >>at
> >>
> org.apache.cayenne.access.jdbc.reader.FullRowReader.readRow(FullRowReader.java:32)
> >> [cayenne-server-4.0.2.jar:4.0.2]
> >>at
> >>
> org.apache.cayenne.access.jdbc.JDBCResultIterator.nextRow(JDBCResultIterator.java:104)
> >> [cayenne-server-4.0.2.jar:4.0.2]
> >>at
> >>
> org.apache.cayenne.access.jdbc.JDBCResultIterator.allRows(JDBCResultIterator.java:80)
> >> [cayenne-server-4.0.2.jar:4.0.2]
> >>at
> >>
> org.apache.cayenne.access.jdbc.SelectAction.performAction(SelectAction.java:138)
> >> [cayenne-server-4.0.2.jar:4.0.2]
> >>at
> >>
> org.apache.cayenne.access.DataNodeQueryAction.runQuery(DataNodeQueryAction.java:97)
> >> [cayenne-server-4.0.2.jar:4.0.2]
> >>at
> >> org.apache.cayenne.access.DataNode.performQueries(DataNode.java:293)
> >> [cayenne-server-4.0.2.jar:4.0.2]
> >>at
> >>

Re: Long primary keys

2019-11-13 Thread Michael Gentry
Hi Vemund!

Long.MAX_VALUE is 9,223,372,036,854,775,807.  NUMBER(38) is a lot more
digits.

Does your DB really have primary keys that large?  To play Devil's Advocate:

9223372036854775807 / 1000 inserts/second / 60 seconds/minute / 60
minutes/hour / 24 hours/day / 365 days/year = 292,471,208 years before your
primary keys are exhausted assuming you can actually insert 1000
records/second non-stop for nearly 300 million years.  If so, you'll need
to consider a different approach.  Perhaps using BigInteger, although I've
not personally tried that with Cayenne's mapping so it may not work.  If it
doesn't, you can try creating a class that will work with Cayenne's mapping
(right API) which wraps a BigInteger holding the actual value.

Also, I just looked at the Oracle documentation for the NUMBER data type
and it says "up to 38 digits of precision" ... perhaps whomever created the
schema just chose the maximum precision to be safe?

mrg


On Wed, Nov 13, 2019 at 6:13 AM Vemund Jakobsen  wrote:

> Hi,
>
> I'm running a Oracle database and trying to get Cayenne to work when
> having primary keys that should be mapped to Long in Java. The data type in
> Oracle is NUMBER(38), but when I create a SelectQuery and use DlpObject
> object= (DlpObject) Cayenne.objectForQuery(ctx, this); to get the object, I
> get the exception below. I'm using Cayenne version 4.0.2. Why does Cayenne
> think that the type is Integer,  and how can the issue be resolved?
>
> 10:59:36,285 WARN  [com.dataloy.rest.exception.CayenneExceptionMapper]
> (default task-1) : java.sql.SQLException: Numeric Overflow
> at
> oracle.jdbc.driver.NumberCommonAccessor.throwOverflow(NumberCommonAccessor.java:4136)
> [ojdbc8.jar:12.2.0.1.0]
> at
> oracle.jdbc.driver.NumberCommonAccessor.getInt(NumberCommonAccessor.java:123)
> [ojdbc8.jar:12.2.0.1.0]
> at
> oracle.jdbc.driver.GeneratedStatement.getInt(GeneratedStatement.java:197)
> [ojdbc8.jar:12.2.0.1.0]
> at
> oracle.jdbc.driver.GeneratedScrollableResultSet.getInt(GeneratedScrollableResultSet.java:244)
> [ojdbc8.jar:12.2.0.1.0]
> at
> org.jboss.jca.adapters.jdbc.WrappedResultSet.getInt(WrappedResultSet.java:1052)
> at
> org.apache.cayenne.access.types.IntegerType.materializeObject(IntegerType.java:38)
> [cayenne-server-4.0.2.jar:4.0.2]
> at
> org.apache.cayenne.access.types.IntegerType.materializeObject(IntegerType.java:28)
> [cayenne-server-4.0.2.jar:4.0.2]
> at
> org.apache.cayenne.access.jdbc.reader.FullRowReader.readRow(FullRowReader.java:52)
> [cayenne-server-4.0.2.jar:4.0.2]
> at
> org.apache.cayenne.access.jdbc.reader.FullRowReader.readRow(FullRowReader.java:32)
> [cayenne-server-4.0.2.jar:4.0.2]
> at
> org.apache.cayenne.access.jdbc.JDBCResultIterator.nextRow(JDBCResultIterator.java:104)
> [cayenne-server-4.0.2.jar:4.0.2]
> at
> org.apache.cayenne.access.jdbc.JDBCResultIterator.allRows(JDBCResultIterator.java:80)
> [cayenne-server-4.0.2.jar:4.0.2]
> at
> org.apache.cayenne.access.jdbc.SelectAction.performAction(SelectAction.java:138)
> [cayenne-server-4.0.2.jar:4.0.2]
> at
> org.apache.cayenne.access.DataNodeQueryAction.runQuery(DataNodeQueryAction.java:97)
> [cayenne-server-4.0.2.jar:4.0.2]
> at
> org.apache.cayenne.access.DataNode.performQueries(DataNode.java:293)
> [cayenne-server-4.0.2.jar:4.0.2]
> at
> org.apache.cayenne.access.DataDomainQueryAction.runQuery(DataDomainQueryAction.java:471)
> [cayenne-server-4.0.2.jar:4.0.2]
> at
> org.apache.cayenne.access.DataDomainQueryAction.access$000(DataDomainQueryAction.java:72)
> [cayenne-server-4.0.2.jar:4.0.2]
> at
> org.apache.cayenne.access.DataDomainQueryAction$2.perform(DataDomainQueryAction.java:446)
> [cayenne-server-4.0.2.jar:4.0.2]
> at
> org.apache.cayenne.tx.DefaultTransactionManager.performInTransaction(DefaultTransactionManager.java:87)
> [cayenne-server-4.0.2.jar:4.0.2]
> at
> org.apache.cayenne.tx.DefaultTransactionManager.performInLocalTransaction(DefaultTransactionManager.java:59)
> [cayenne-server-4.0.2.jar:4.0.2]
> at
> org.apache.cayenne.tx.DefaultTransactionManager.performInTransaction(DefaultTransactionManager.java:52)
> [cayenne-server-4.0.2.jar:4.0.2]
> at
> org.apache.cayenne.tx.DefaultTransactionManager.performInTransaction(DefaultTransactionManager.java:40)
> [cayenne-server-4.0.2.jar:4.0.2]
> at
> org.apache.cayenne.access.DataDomainQueryAction.runQueryInTransaction(DataDomainQueryAction.java:443)
> [cayenne-server-4.0.2.jar:4.0.2]
> at
> org.apache.cayenne.access.DataDomainQueryAction.execute(DataDomainQueryAction.java:122)
> [cayenne-server-4.0.2.jar:4.0.2]
> at
> org.apache.cayenne.access.DataDomain.onQueryNoFilters(DataDomain.java:564)
> [cayenne-server-4.0.2.jar:4.0.2]
> at
> org.apache.cayenne.access.DataDomain$DataDomainQueryFilterChain.onQuery(DataDomain.java:748)
> [cayenne-server-4.0.2.jar:4.0.2]
> at
> 

Re: Compound PK/FK fun

2019-10-21 Thread Michael Gentry
Hi Hugi,

I have no idea if this will work, but try the following:

* in Cayenne Modeler, add companyNumber (company_number) as an attribute
for Company.
* Regenerate classes.
* In Company.java, override the setCompanyNumber method to check for
nulls.  If non-null, call the super; if null, ignore it.


On Mon, Oct 21, 2019 at 7:19 AM Hugi Thordarson  wrote:

> Hi all.
>
> I'm currently in the progress of cleaning up an older system and I have a
> bit of a conundrum that I would love some input on.
>
> Almost all data in the DB belongs to/is related to a "Company" object. The
> PK of that company object forms part of a compound PK for the other objects.
> For example; here "Customer" and "Invoice" are related to "Company" on the
> "company_number" attribute, "Invoice" has a related "Customer" joined on
> "company_number" and "customer_number".
>
> Company
> 
> * company_number (pk)
>
> Customer
> 
> * company_number (pk)
> * customer_number (pk
>
> Invoice
> 
> * company_number (pk)
> * invoice_number (pk)
> * customer_number
>
>
> Now, I've modeled all of this in Cayenne and it's been working very well
> for years for reporting purposes. However, we're now moving the "writing"
> part of the system to Cayenne as well, and that's caused a small problem.
>
> For the most part it works very well. An object will never change
> companies once created, so if I set a "Customer" on an an "Invoice", it
> doesn't have any undesired side effects, it's essentially just setting the
> same company number again—no harm in that.
> However, a problem occurs when I set an Invoice's customer to null. In
> that case, Cayenne will nullify both the invoice's customer_number AND
> company_number, which is obviously problematic.
>
> I'm now wondering how I can solve this problem, i.e. how can I set an
> invoice's customer to "null" without blowing up the system.
>
> I'm open to "dirty" solutions since this is a temporary situation. The
> Cayenne version of the system just has to work alongside an older system
> for a couple of months, but once that's been closed, I have full control of
> the DB and these tables will be getting their own shiny new unique PKs.
>
> About the only thing I don't want to do is expose the FKs and/or handle
> relationships using manual fetching, since the relatiosnhips are already
> modeled and I have thousands of lines of logic that depend on the modeled
> relationships.
>
> Any ideas?
>
> Cheers,
> - hugi


Re: Cayenne and classpath question and help

2019-10-17 Thread Michael Gentry
Hi Andrew,

Are you using JRebel?  I seem to recall someone posting a solution here
about using JRebel during development and getting the Cayenne stack to
reload properly.


On Wed, Oct 16, 2019 at 11:24 PM Andrew Willerding 
wrote:

> Hi,
>
> I have an application that dynamically loads jar files and reloads them
> when they are changed.  Unfortunately I'm have an issue getting Cayenne
> to see the classes inside one of these dynamically loaded jar files. I
> have some test code that looks roughly like this.
>
> import com.dbclientbase.Database.Account;
> public class blah
>
>public testMethod(){
>
>  Account ac = new Account();  // This object instantiates
> without an error so it's visible to app outside of Cayenne
>
>  ObjectContext oc = DBClientBase.getObjectContext(); // This
> method generates the ServerRuntime and fails to get an ObjectContext to
> work with (error below)
>
>   }
> }
>
> The error output below seems to suggest that Cayenne cannot access the
> Account class although I can successfully instantiate a non-Cayenne
> object.  What can I do to ensure that Cayenne also has access to the
> contents of a dynamically loaded and reloaded jar file?  I have found
> references to AdhocObjectFactory.getClassLoader()  but I can't find any
> examples on how to use it and I'm quite at a loss on how to even begin
> use it.
>
> Thanks,
>
> Andrew
>
>
> Exception==>org.apache.cayenne.configuration.server.DataDomainLoadException:
>
> [v.4.1.B2 May 04 2019 09:30:14] DataDomain startup failed: Invalid
> class: com.dbclientbase.Database$Account
>  at
>
> org.apache.cayenne.configuration.server.DataDomainProvider.get(DataDomainProvider.java:123)
>  at
>
> org.apache.cayenne.configuration.server.DataDomainProvider.get(DataDomainProvider.java:60)
>  at
>
> org.apache.cayenne.di.spi.CustomProvidersProvider.get(CustomProvidersProvider.java:39)
>  at
>
> org.apache.cayenne.di.spi.FieldInjectingProvider.get(FieldInjectingProvider.java:43)
>  at
>
> org.apache.cayenne.di.spi.DefaultScopeProvider.get(DefaultScopeProvider.java:50)
>  at
>
> org.apache.cayenne.di.spi.DefaultInjector.getInstance(DefaultInjector.java:139)
>  at
>
> org.apache.cayenne.di.spi.FieldInjectingProvider.value(FieldInjectingProvider.java:103)
>  at
>
> org.apache.cayenne.di.spi.FieldInjectingProvider.injectMember(FieldInjectingProvider.java:68)
>  at
>
> org.apache.cayenne.di.spi.FieldInjectingProvider.injectMembers(FieldInjectingProvider.java:59)
>  at
>
> org.apache.cayenne.di.spi.FieldInjectingProvider.get(FieldInjectingProvider.java:44)
>  at
>
> org.apache.cayenne.di.spi.DefaultScopeProvider.get(DefaultScopeProvider.java:50)
>  at
>
> org.apache.cayenne.di.spi.DefaultInjector.getInstance(DefaultInjector.java:134)
>  at
>
> org.apache.cayenne.configuration.CayenneRuntime.newContext(CayenneRuntime.java:124)
>  at
> com.dbclientbase.DBClientBase.getObjectContext(DBClientBase.java:100)
>  at java.base/java.lang.Thread.run(Thread.java:834)
> Caused by: org.apache.cayenne.di.DIRuntimeException: Invalid class:
> com.Database$Account
>  at
>
> org.apache.cayenne.di.spi.DefaultAdhocObjectFactory.getJavaClass(DefaultAdhocObjectFactory.java:128)
>  at org.apache.cayenne.util.Util.getJavaClass(Util.java:632)
>  at org.apache.cayenne.map.ObjEntity.getJavaClass(ObjEntity.java:265)
>  at
>
> org.apache.cayenne.map.EntityResolver.initCallbacks(EntityResolver.java:141)
>  at
>
> org.apache.cayenne.map.EntityResolver.getCallbackRegistry(EntityResolver.java:163)
>  at
> org.apache.cayenne.access.DataDomain.addListener(DataDomain.java:791)
>  at
> org.apache.cayenne.access.DataDomain.addSyncFilter(DataDomain.java:748)
>  at
>
> org.apache.cayenne.configuration.server.DataDomainProvider.createAndInitDataDomain(DataDomainProvider.java:188)
>  at
>
> org.apache.cayenne.configuration.server.DataDomainProvider.get(DataDomainProvider.java:117)
>  ... 16 more
> Caused by: java.lang.ClassNotFoundException:
> com.dbclientbase.Database.Account
>  at
>
> java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
>  at
>
> java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
>  at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
>  at java.base/java.lang.Class.forName0(Native Method)
>  at java.base/java.lang.Class.forName(Class.java:398)
>  at
>
> org.apache.cayenne.di.spi.DefaultAdhocObjectFactory.getJavaClass(DefaultAdhocObjectFactory.java:93)
>  ... 24 more
>
>


Re: Best Practice for blobs

2019-10-03 Thread Michael Gentry
I've always used a secondary table (1:1 relationship) which contained just
the blob data.  The parent table would have the metadata for the blob, and
possibly other data as required.  That way you can fetch in the name, file
size, type, etc without fetching in the blob until needed.


On Wed, Oct 2, 2019 at 8:02 PM Lon Varscsak  wrote:

> Hey all,
>
> I have a blob column in an entity, but I don't want to always actually load
> the blob, just on demand (but I still want to be able to see the other
> attributes in the entity).  Any best practice here to have the blob be
> lazy?
>
> Thanks,
>
> Lon
>


Re: 4.2 modeler change

2019-10-02 Thread Michael Gentry
On Wed, Oct 2, 2019 at 11:10 AM Andrus Adamchik 
wrote:

> As for the JS backend, the concern (at least from me) was that our
> community is mostly Java developers, so it may be hard to support if a
> primary author becomes unavailable. FWIW, it is less of a concern for me
> these days, as JS world had matured significantly since the last time we
> had this discussion.
>

I wouldn't do the backend in Node/JS with an Electron application if I
could avoid it.  I'd bundle a Java-based microservice that the Electron UI
starts up and uses to read/write Cayenne models, communicate with DBs via
JDBC, etc.  With JavaFX I was just using the Cayenne JARs natively (no
client/server architecture).


Re: 4.2 modeler change

2019-10-02 Thread Michael Gentry
Hi Emerson,

The reason I started playing around with JavaFX instead of Electron is
because I could re-use some of the Cayenne JARs.  An advantage of Electron,
though, is I feel it has more momentum than JavaFX, but you'd have to
duplicate data structures and end up with a more complex client/server
architecture.  Both approaches would produce a cross-platform "native"
solution for the 3 major OSes, which is a win.


On Wed, Oct 2, 2019 at 11:01 AM Emerson Castañeda  wrote:

> @Ari, Completely agree with you, and since we're still on Swing's parallel
> reality :) I will be working on that PR and any UI testing in general for
> the modeler.  For some reason, that I don't know yet, my builds are failing
> in a totally different module (cayenne-rop-server).
>
>
> @Michael  I don't have any experience with Electron, but any approach for a
> web-modeler will be interesting to discuss.
>
>
> @John maybe we can start introducing that MVC pattern in order to uncouple
> the modeler's layers. Actually that is one of the keys factors for a
> testable app.
>
> @Lon do you have a specific JIRA ticket(s) were you are following the new
> bugs?
>
> Thanks
>
> EmeCas
>
>
>
>
> On Wed, Oct 2, 2019 at 7:42 AM Michael Gentry  wrote:
>
> > I started a JavaFX prototype, but got bogged down (with other things) and
> > haven't picked it back up again.  Kind of hoping to do that again within
> > the coming year...
> >
> > As to Ari's HTML/JS/CSS comment, if we went that route, it would likely
> be
> > an Electron-based application, I think, with HTML/JS/CSS for the UI and a
> > Java backend.
> >
> >
> > On Tue, Oct 1, 2019 at 7:34 PM Aristedes Maniatis 
> > wrote:
> >
> > > JavaFX would be a huge amount of work since almost the entire app would
> > > be rewritten from scratch. And if there was a reason to do it, that
> > > reason would probably point toward an html/js front end. There are just
> > > so many more html/js widgets for object graphs, table views, etc than
> > > any other UI kit.
> > >
> > > And then we'd have Cayenne modeler SaaS!  \s
> > >
> > > Back in reality, Swing is going to be here a long time. If you are able
> > > to submit a PR to run even a basic set of tests on the UI that would be
> > > great and provide a guide on how to add more over time.
> > >
> > >
> > > Ari
> > >
> > > On 2/10/19 5:36am, Emerson Castañeda wrote:
> > > > Last year a got some progresses testing Swing UI using
> > > assertj-swing-junit
> > > > dependency
> > > >
> > > > Also, I got to run TravisCI successfully, by including  xvfb In order
> > to
> > > > run the tests that require a GUI.
> > > >
> > > > Finally, it required 2 additional changes:
> > > >
> > > > 1. Modifying Main class on modeler to expose Injector object
> > > > 2. Include some modifications to the CayenneModelerFrame to set names
> > for
> > > > the GUI components to test, since assertj cannot test anonymous
> > > instances.
> > > >
> > > > If Swing still being an option, I can open a PR with a full
> functional
> > > use
> > > > case of GUI testing using the mentioned stack..
> > > >
> > > > Other way, what would be the desires/goals for diving into JavaFX? so
> > we
> > > > could think about at GUI testing strategy covering that path.
> > > >
> > > > Thanks
> > > >
> > > > EmeCas
> > > >
> > > >
> > > >
> > > >
> > > > On Tue, Oct 1, 2019 at 2:51 PM John Huss 
> wrote:
> > > >
> > > >> The way to handle testing for the UI is to write the app in an MVP
> > > style,
> > > >> sort of like this:
> > > >>
> > >
> >
> https://stackoverflow.com/questions/11367250/concrete-code-example-of-mvp
> > > >>
> > > >> The gist is to define an interface contract for the view so that you
> > can
> > > >> replace the actual Swing UI View with a mock while testing.
> > > >> But that doesn't help much with an existing application that wasn't
> > > written
> > > >> in that style.
> > > >>
> > > >>
> > > >> On Tue, Oct 1, 2019 at 1:00 AM Andrus Adamchik <
> > and...@objectstyle.org>
> > > >> wrote:
> > > >>
> > > >>> Yeah, I was thinking how do w

Re: 4.2 modeler change

2019-10-02 Thread Michael Gentry
I started a JavaFX prototype, but got bogged down (with other things) and
haven't picked it back up again.  Kind of hoping to do that again within
the coming year...

As to Ari's HTML/JS/CSS comment, if we went that route, it would likely be
an Electron-based application, I think, with HTML/JS/CSS for the UI and a
Java backend.


On Tue, Oct 1, 2019 at 7:34 PM Aristedes Maniatis  wrote:

> JavaFX would be a huge amount of work since almost the entire app would
> be rewritten from scratch. And if there was a reason to do it, that
> reason would probably point toward an html/js front end. There are just
> so many more html/js widgets for object graphs, table views, etc than
> any other UI kit.
>
> And then we'd have Cayenne modeler SaaS!  \s
>
> Back in reality, Swing is going to be here a long time. If you are able
> to submit a PR to run even a basic set of tests on the UI that would be
> great and provide a guide on how to add more over time.
>
>
> Ari
>
> On 2/10/19 5:36am, Emerson Castañeda wrote:
> > Last year a got some progresses testing Swing UI using
> assertj-swing-junit
> > dependency
> >
> > Also, I got to run TravisCI successfully, by including  xvfb In order to
> > run the tests that require a GUI.
> >
> > Finally, it required 2 additional changes:
> >
> > 1. Modifying Main class on modeler to expose Injector object
> > 2. Include some modifications to the CayenneModelerFrame to set names for
> > the GUI components to test, since assertj cannot test anonymous
> instances.
> >
> > If Swing still being an option, I can open a PR with a full functional
> use
> > case of GUI testing using the mentioned stack..
> >
> > Other way, what would be the desires/goals for diving into JavaFX? so we
> > could think about at GUI testing strategy covering that path.
> >
> > Thanks
> >
> > EmeCas
> >
> >
> >
> >
> > On Tue, Oct 1, 2019 at 2:51 PM John Huss  wrote:
> >
> >> The way to handle testing for the UI is to write the app in an MVP
> style,
> >> sort of like this:
> >>
> https://stackoverflow.com/questions/11367250/concrete-code-example-of-mvp
> >>
> >> The gist is to define an interface contract for the view so that you can
> >> replace the actual Swing UI View with a mock while testing.
> >> But that doesn't help much with an existing application that wasn't
> written
> >> in that style.
> >>
> >>
> >> On Tue, Oct 1, 2019 at 1:00 AM Andrus Adamchik 
> >> wrote:
> >>
> >>> Yeah, I was thinking how do we even approach testing of Java UI. Any
> >>> suggestions are welcome.
> >>>
> >>> And to complicate things we've been postponing a dive into JavaFX,
> while
> >>> the Swing app keeps adding functionality. So investing effort in a test
> >>> framework should take this pending decision into account.
> >>>
> >>> Andrus
> >>>
>  On Oct 1, 2019, at 7:11 AM, Aristedes Maniatis 
> >> wrote:
>  I've been down that path before, trying to test Swing and JavaFX. Its
> >>> not easy to do. The best tool I found (and that was about 8 years ago)
> >> was
> >>> https://www.froglogic.com/squish/editions/automated-java-gui-testing/
> >> but
> >>> I don't know if they have any licensing available for open source
> >> projects.
>  Emerson, if you have any experience with this, let us know what has
> >>> worked for you.
> 
>  Ari
> 
> 
>  On 30/9/19 12:21am, Emerson Castañeda wrote:
> > Wonder if these bugs would be into the kind of things that a good GUI
> >>> test
> > suite for the modeler could prevent.
> >
> > EmeCas
> >
> > On Thu, Sep 26, 2019 at 12:08 PM Lon Varscsak <
> lon.varsc...@gmail.com
> > wrote:
> >
> >> Okay, cool.  Another bug (I just found) is on the add relationship
> >>> dialog
> >> (on object entity) is that it seems to ignore the "delete" rule and
> >>> just is
> >> always the default.  Easily worked around by just editing the added
> >> relationship after the fact.
> >>
> >> On Thu, Sep 26, 2019 at 12:22 AM Andrus Adamchik <
> >>> and...@objectstyle.org>
> >> wrote:
> >>
> >>> Screenshots are stripped by the list management software, but the
> >>> description is pretty clear. I am not using 4.2 myself, but we do
> >>> need to
> >>> fix it before we release 4.2.M1.
> >>>
> >>> Andrus
> >>>
>  On Sep 26, 2019, at 1:08 AM, Lon Varscsak  >
> >>> wrote:
>  Hey all,
> 
>  It looks like when adding a db-relationship in the Modeler
> >>> (4.2.M1-SNAPSHOT from today) the potential target entities is not
> >>> sorted
> >>> (which is only mildly annoying), but doesn't contain any target
> >>> entities
> >>> outside of the current data map (blocker).  Am i missing something?
>  Thanks!
> 
>  -Lon
> 
>  Here's a screenshot for reference:
> 
> >>>
>


Re: Sending data across the wire.

2019-09-18 Thread Michael Gentry
Jackson allows you to define custom un/marshalling mechanisms when needed
so you can control what gets included.

Years ago we had some code which allowed you to include/exclude
properties/paths to build up a JSON object to return
using read[Nested]Property().  Basically you'd explicitly define what you
wanted to include and it would build the JSON for you.  No idea if I still
have that code lying around somewhere, but the idea is fairly simple, I
think.

mrg


On Wed, Sep 18, 2019 at 2:21 AM Andrus Adamchik 
wrote:

> Ignoring serialization mechanics (and even the presence of Cayenne) for a
> moment, I was always wondering how do people even approach this problem.
> Every persistent object is potentially an entry point to a near-infinite
> graph of objects coming from DB. So you need to have a set of clear rules
> of how deep and wide you want to go when you start serializing.
>
> DTO is one way to define such rules. But unless your rules are very simple
> ("send the attributes, don't send the relationships"), if you start
> generating DTOs, they will have the same set of relationships. And you'd
> end up with the same issue as you had with serializing the original
> DataObjects.
>
> So what parts of the graph do you need to serialize?
>
> And if this needs to be flexible, I would probably write a small library
> that allows a user to define a subset of model to serialize, and then
> applies that "submodel" to DataObjects directly (this is the Agrest.io
> approach on a smaller scale). But as with any generic solution, this will
> require a bit of effort, dealing with edge cases, etc.
>
> Andrus
>
>
>
> > On Sep 18, 2019, at 12:29 AM, John Huss  wrote:
> >
> > It's a small effort to create a custom entity template to generate any
> kind
> > of entity class you want, for instance for a DTO. You can copy a lot of
> > stuff right out of the regular templates if you want.
> >
> > Then you can use maven or ant to easily regenerate those classes the same
> > way CayenneModeler does without having to change the custom template
> > selections all the time.
> >
> > On Tue, Sep 17, 2019 at 1:49 PM Tony Giaccone  wrote:
> >
> >> So typically I create a Data Transfer Object to return values across the
> >> wire that I have fetched and copy attributes from my model object to the
> >> DTO.  This gets tedious quickly.  I wondered if there's not another way
> >> that people are doing this, because this seems entirely too painful.
> >>
> >> However, if* this is* what most people do, then perhaps a change could
> be
> >> made to the modeler, that would all you to create automatically a set of
> >> DTO objects with when you generate the model objects.  I recognize that
> >> this would be a rather significant effort and I'm guessing that there's
> >> probably a better way, but I'm not aware of what it is.
> >>
> >> Any suggestions?
> >>
> >>
> >> Tony Giaccone
> >>
>
>


Re: Sending data across the wire.

2019-09-17 Thread Michael Gentry
Hi Tony,

Have you tried using Jackson?

https://github.com/FasterXML/jackson

https://www.baeldung.com/jackson


On Tue, Sep 17, 2019 at 2:49 PM Tony Giaccone  wrote:

> So typically I create a Data Transfer Object to return values across the
> wire that I have fetched and copy attributes from my model object to the
> DTO.  This gets tedious quickly.  I wondered if there's not another way
> that people are doing this, because this seems entirely too painful.
>
> However, if* this is* what most people do, then perhaps a change could be
> made to the modeler, that would all you to create automatically a set of
> DTO objects with when you generate the model objects.  I recognize that
> this would be a rather significant effort and I'm guessing that there's
> probably a better way, but I'm not aware of what it is.
>
> Any suggestions?
>
>
> Tony Giaccone
>


Re: Connection over SSH tunnel without password not working

2019-09-03 Thread Michael Gentry
Hi Rafael,

Wouldn't you still need to provide the credentials?  Your SSH tunnel is
forwarding the bits to/from PostgreSQL, but your connection still needs to
login to the database.

Does Cayenne Modeler or IntelliJ have the password cached somewhere?


On Mon, Sep 2, 2019 at 1:34 AM Rafael Bugajewski 
wrote:

> Hello,
>
> I recently upgraded to Cayenne 4.1.B2 and I have the strange issue that my
> cayenne-project.xml isn’t working anymore. In my development environment I
> create a SSH tunnel to a machine inside the intranet. JDBC is configured to
> connect to localhost. The relevant parts from cayenne-project.xml in the
> JAR look like this:
>
> 
>
>
>
>
> 
>
> This used to work without issues. The strange thing is that exactly the
> same connection still works in the Cayenne Modeler, and it also works in my
> IDE (IntelliJ).
>
> A workaround for me was to add a password and configure it in Cayenne. But
> I’m wondering why the configuration suddenly stopped working and why it
> still works in Cayenne Modeler / IntelliJ. Any ideas?
>
> Best,
> Rafael
>
>


Re: Deleting a bunch of interrelated objects

2019-05-30 Thread Michael Gentry
I'm a fan of well-named things ... deleteWithoutMercy and
horribleMutantRuntimeWithoutRelationships are fabulous!


On Thu, May 30, 2019 at 6:44 AM Hugi Thordarson  wrote:

> Hi Jurgen,
>
> thanks for the suggestions :). I made a horrible hack just now, based on
> the idea of having a different model, but instead of modifying files, I
> remove the relationships in memory. This actually works but it would be
> interesting to hear the point of view of others—am I potentially shooting
> myself in the foot by firing up a copy of my ServerRuntime within the same
> JVM, based on the same (but modified in memory) model? Any potential
> conflicts?
>
> public void deleteWithoutMercy( final List objectsToDelete ) {
> final ServerRuntime horribleMutantRuntimeWithoutRelationships =
> NBCore.createServerRuntime( Props.defaultProps() );
>
> horribleMutantRuntimeWithoutRelationships
> .getDataDomain()
> .getEntityResolver()
> .getObjEntities()
> .forEach( objEntity -> {
> new ArrayList<>(
> objEntity.getRelationships() ).forEach( relationship -> {
> objEntity.removeRelationship(
> relationship.getName() );
> } );
> } );
>
> final ObjectContext localOC =
> horribleMutantRuntimeWithoutRelationships.newContext();
> final List localObjects = new ArrayList<>();
>
> for( final DataObject objectFromAnotherRuntime : objectsToDelete )
> {
> localObjects.add( localOC.localObject(
> objectFromAnotherRuntime ) );
> }
>
> localOC.deleteObjects( localObjects );
> localOC.commitChanges();
> }
>
>
> *shudder*
>
> - hugi
>
>
> > On 30 May 2019, at 07:13, Jurgen  wrote:
> >
> > Hi Hugi
> >
> > So crazy idea number one is to maybe duplicate your model and revise the
> delete rules, then use this DeleteModel to nuke the customer. The downside
> of this is having to maintain two models, maybe not such a good idea ?
> >
> > Idea number two is to add a delete method to each of the classes that
> first deletes the children. So you have:
> >
> > Customer ->> Invoice ->> InvoiceLine ->> InvoiceLineSums
> >
> > Then add deleteLineSums() to InvoiceLine that deletes its
> InvoiceLineSums with something like:  getObjectContext().deleteObjects(
> getLineSums() );
> >
> > Do the same in Invoice where deleteLines() is something like:
> >
> >   for ( InvoiceLine line : getLines() )  line.deleteLineSums();
> >   getObjectContext().commitChanges();
> >   getObjectContext().invalidateObjects( this );
> >   getObjectContext().deleteObjects( getLines() );
> >
> > Then the same for Customer  The downside of all this is that it's
> not very efficient in terms of DB calls, but then you won't have to go all
> caveman like and "write out damn joins like our ancestors did" :-)
> >
> > Cheers
> > Jurgen
> >
>
>


Re: ExpressionFactory help

2019-02-04 Thread Michael Gentry
https://cayenne.apache.org/docs/3.1/cayenne-guide/#expressions


On Mon, Feb 4, 2019 at 5:24 AM Amedeo Mantica 
wrote:

> oh, cool, thank you !
> btw, where I can find docs for these ?
>
> > On 4 Feb 2019, at 11:20, Andrus Adamchik  wrote:
> >
> > Sorry, forgot plus sign for outer join:
> >
> > ExpressionFactory.matchExp("paintings+", null)
> >
> >
> >> On Feb 4, 2019, at 1:19 PM, Andrus Adamchik 
> wrote:
> >>
> >> In 3.x the idea is the same, though Property API is not available of
> course. So you can do this instead:
> >>
> >> ExpressionFactory.matchExp("paintings", null)
> >>
> >> Andrus
> >>
> >>
> >>> On Feb 4, 2019, at 12:29 PM, Amedeo Mantica
>  wrote:
> >>>
> >>> in Cayenne 3.x ?
> >>>
>  On 4 Feb 2019, at 09:17, Arseni Bulatski 
> wrote:
> 
>  Hi
>  You can do it in that way:
>  Artist.PAINTINGS.outer().isNull()
> 
> 
> 
>  On Sun, Feb 3, 2019 at 10:19 PM Amedeo Mantica
> 
>  wrote:
> 
> > Hi all,
> >
> > Which is the correct Expression to use in order to select objects
> thats
> > have an 1:many relationship empty ?
> >
> > Thank you
> > Amedeo
> >>>
> >>
> >
>
>


Re: Large Results sets..

2018-10-23 Thread Michael Gentry
Hi Tony,

I think you are looking for an Iterated Query:

https://cayenne.apache.org/docs/4.0/cayenne-guide/#performance-tuning

I'm not sure what version you are using, but it is similar in the 3.x
releases, too (change the documentation pulldown if needed).

mrg


On Mon, Oct 22, 2018 at 11:43 AM Tony Giaccone  wrote:

> I asked this question once before, and I've looked but cant' find the
> answer.
>
> We're going to be using queries that would normally bring back large
> numbers of objects, 100's of thousand potentially.
>
> I know there's a facility in Cayenne to essentially use a "cursor" like
> fetch. But I can't remember the exact details and I wasn't able to find
> something that matched up with what I remember.
>
> I thought there was a query that let you bring back an Iterator, that
> returned a set of objects, not data rows, or maps, and let you iterate
> across the objects from the entire result set.
>
> Am I remembering correctly? Is the solution something like an iterated
> query.
>
> Just looking for the best possible solution.
>
>
> Tony Giaccone
>


Re: Commit Exception

2018-09-29 Thread Michael Gentry
I'm a little late to this party, but here is the approach I'd take:

1. Use a batch size of N (in your case, this is 500, but it is really
DB-specific as to what can be handled with an IN clause).

2. Read in N (or whatever is remaining) records from your data file and
call your inserter method with these records (unless finished reading the
file, of course).

3. In your inserter method, put together a SelectQuery using an IN
expression (ExpressionFactory.inExp or ExpressionFactory.inDbExp) based
upon your unique constraint values.

4. Perform that query in a new DataContext.  If you get back ANY results,
those are your duplicates.  Handle the duplicates right there (you have a
List of them now -- no need to parse exception strings, etc).

5. After handling the duplicates, do your batch insert.

6. Continue at step 2 until finished.

I'd expect this approach to be pretty quick as it gives you the advantage
of working with larger batches of data and also makes it easy to find the
problem records.

mrg


On Fri, Sep 28, 2018 at 12:40 PM Tony Giaccone  wrote:

> This answer is probably way off topic for this group as it's not really
> Cayenne related. But I want to give some closure to the solution so that
> anyone else who ends up reading this can see the totality of the problem
> and solution.
>
> My original through was, I don't have to test for uniqueness because the
> database will tell me if I violate the unique key constraint. The problem
> with doing it on the java code side of persistence is that as the number of
> inserted records grows so does the time a query takes to test for
> uniqueness. If you're inserting a million records that starts to
> accumulate.  The database has to enforce this constraint so putting in your
> java code is just a duplication of effort.
>
> That process works fine as long as you're inserting one record at a time.
> In that case the lack of identifying information isn't a problem, because
> you can know that the object your inserting caused the error. The solution
> is log the offending row and off you go, to the next record. Simple and
> direct.
>
> Where that ability fails is when you start "batching" your objects and
> commit multiple objects at once. At that point relying on the database
> becomes problematic in a few ways. First the transaction fails on the first
> failure. Which is fine the DB only cares about the transaction and it
> failed. What to do about it, from the DB perspective, is someone eles's
> problem.   From the java app perspective its possible there are more
> problems in that batch and the way you solve that problem is going to be
> difficult and/or time consuming. The second issue is that short of parsing
> this error string there's not an easy way to figure out which insert caused
> the problem. All these inserts are to the same table so just finding the ID
> that caused the problem would be enough. If I had to do this.. I could. But
> change the database and I need a new implementation. I hate that idea.
>
> In the end this was a case of premature optimization.  Running a sample job
> of one million lines show that without batching the app only takes about 4
> minutes to insert those rows. Would I like that to be faster, I would, but
> is it acceptable, yes.
>
> Tony Giaccone
>
> On Fri, Sep 28, 2018 at 11:17 AM Bob Schellink  wrote:
>
> > Would be nice if Cayenne could pinpoint the problematic record, but I
> think
> > that will depend on what error info the database provides.
> >
> > Thinking of a strategy to get speed and correctness, how about an
> > optimistic strategy:
> >
> > Process a batch of 500 records and if commit fails only then process that
> > batch records one by one ( or chunk the 500 batch into smaller batches )
> > until you find the guilty object, then continue with the 500 batches
> again.
> >
> > You pay a price through with more complex code. ;-)
> >
> > Kind regards
> >
> > Bob
> >
> >
> > On Fri, Sep 28, 2018 at 4:28 PM Tony Giaccone  wrote:
> >
> > > Yeah, that's pretty much what I ended up doing. Even reading the file
> > line
> > > by line and doing an insert after each object is created only made the
> > run
> > > time go to 4 minutes and I can live with that. What I really wanted to
> do
> > > was find a way to recover from a larger commit. It seems that's not
> > really
> > > possible. The one feature that would make that failure easier to deal
> > with
> > > would be some kind of data value in commit error that would identify
> the
> > > class and key value of the object that caused the commit exception. I
> > > recognize that the value is there in the text, but parsing through that
> > > text message to find the value is a serious hack. It would be better if
> > the
> > > framework included in the commit exception, the class type and the key
> > > value of the entity that caused the problem.
> > >
> > > Now maybe in the larger scheme of things, it doesn't make sense to
> > identify
> > > which item in the set 

Re: DataObject changes - before commit

2018-09-11 Thread Michael Gentry
Hi Matt,

Cayenne already keeps track of the original values for you.  This is needed
in order to do optimistic locking, plus it allows Cayenne to only send over
changes in a record instead of the entire record when you are doing an
UPDATE.

I haven't tried this approach on the field-based version of Cayenne yet,
but these two utility methods are similar and illustrate how to find the
underlying values and detect the changes, at least in 3.x:

https://gist.github.com/mrg/4dce22b67175c27f4047#file-cayenneutils-java-L124

https://gist.github.com/mrg/4dce22b67175c27f4047#file-cayenneutils-java-L184

I believe you could adapt for your purposes/needs pretty readily.

mrg


On Mon, Sep 10, 2018 at 8:04 PM Matt R Watson  wrote:

> Now that the DataObject classes are “field based”, I would like to find a
> way to replace the heavy Map we have placed on all of our DataObject
> classes.
>
> We extend Cayenne’s default class and added a HashMap to keep track of the
> original values (as it changes) since the object has been loaded and before
> committing. (see our class below)
>
> This allows us to check if something is modified (
> inventoryAdjustment.isPropertyModified(“date”), or
> inventoryAdjustment.getOriginalProperty(“date”) )
>
> I’d like to find a Cayenne friendly way of doing this. Any suggestions?
>
> Thanks,
> Matt
>
> 
>
>
> public class CayenneBaseDataObject extends CayenneDataObject {
>
> /**
>  * Stores the original values for this object's properties. Uses
> the
>  * property name string as the key for each entry. Its purpose is
> to keep
>  * track of any original values since the object was initialized
> or last
>  * committed.
>  */
> private final Map originalPropertyMap = New.map();
>
> /**
>  * Initializes the originalPropertyMap. Used as a callback during
> the
>  */
> public void initializeOriginalPropertyMap() {
> originalPropertyMap.clear();
> }
>
> @Override
> protected void beforePropertyWrite(String propName, Object oldValue,
> Object newValue) {
> if (!originalPropertyMap.containsKey(propName)) {
> originalPropertyMap.put(propName, oldValue);
> }
>
> super.beforePropertyWrite(propName, oldValue, newValue);
> }
>
> /**
>  * Overrides
>  * {@link org.apache.cayenne.DataObject#writeProperty(String,
> Object)} by
>  * saving a {@link CayenneBaseDataObject}'s existing property
> value, if any,
>  * to the {@link #originalPropertyMap} prior to updating the
>  * {@link CayenneBaseDataObject}'s property with a new value.
>  *
>  * @param relationship
>  *  the name of the to-one-relationship
>  * @param value
>  *  the value used to set the to-one-relationship
>  * @param reverse
>  *  a boolean indicating whether to set the reverse
> relationship as well
>  */
> @Override
> public void setToOneTarget(final String relationship, final
> org.apache.cayenne.DataObject value, final boolean reverse) {
> if (!originalPropertyMap.containsKey(relationship)) {
> originalPropertyMap.put(relationship,
> this.readProperty(relationship));
> }
>
> super.setToOneTarget(relationship, value, reverse);
> }
>
>
> @Override
> public Object getOriginalProperty(final String property) {
> if (!originalPropertyMap.containsKey(property)) {
> return this.readProperty(property);
> }
>
> return originalPropertyMap.get(property);
> }
>
> @Override
> public Boolean isPropertyModified(final String property) {
> final Object original = this.getOriginalProperty(property);
> final Object current = this.readProperty(property);
>
> return !Objects.equals(original, current);
> }
>
> }
>
>


Re: [ANN] Cayenne 3.1.3 and 4.1.M2 releases

2018-07-25 Thread Michael Gentry
Thanks for putting the release together, Nikita!


On Wed, Jul 25, 2018 at 1:04 PM Nikita Timofeev 
wrote:

> I'm glad to announce two releases of Apache Cayenne.
>
> 3.1.3 - is a maintenance release with a couple of bug fixes [1]
>
> 4.1.M2 - is a much more interesting one, with cool new features. With
> this release 4.1 version should be stable enough to try it in your
> projects (remember to check upgrade notes [2] first).
> It introduces completely new Reverse Engineering UI in Modeler,
> improved transaction control, minor API additions (like prefetch API
> for SQLTemplate and SQLSelect) and numerous other fixes and
> improvements.
> See release notes [3] for full change list.
>
> Thanks everyone for using Cayenne and making it better!
>
> [1]
> https://github.com/apache/cayenne/blob/3.1.2/docs/doc/src/main/resources/RELEASE-NOTES.txt
> [2] https://github.com/apache/cayenne/blob/4.1.M2/UPGRADE.txt
> [3] https://github.com/apache/cayenne/blob/4.1.M2/RELEASE-NOTES.txt
>
> --
> Best regards,
> Nikita Timofeev
>


Re: In memory DB for unit testing

2018-05-02 Thread Michael Gentry
Hi Ken,

To add to what Mike said, I've used H2 in the past with pretty good
results.  You can either let Cayenne create your schema or use something
like Flyway/Liquibase if you have that integrated into your application
already.

One thing I do differently, though, is I create a temporary on-disk DB
instead of in-memory DB.  I've found that when a test fails, I can use the
H2Console utility to examine the leftover on-disk DB to see what it looks
like.  On successful tests, though, I close the DB connection and delete
it, ready to start over with a clean slate after that.

mrg


On Wed, May 2, 2018 at 3:59 PM Ken Anderson 
wrote:

> All,
>
> We’re thinking about setting up an in-memory database in place of SQL
> Server for doing unit tests.  Does anyone have any experience doing this
> with Cayenne?  Any recommendations or warnings?
>
> Thanks,
> Ken
> Confidentiality Notice: This e-mail and accompanying documents contain
> confidential information intended for a specific individual and purpose.
> This e-mailed information is private and protected by law. If you are not
> the intended recipient, you are hereby notified that any disclosure,
> copying, or distribution, or the taking of any action based on the contents
> of this information, is strictly prohibited.
>


Re: Check dirty before write?

2018-04-27 Thread Michael Gentry
On Fri, Apr 27, 2018 at 11:52 AM, Michael Gentry <blackn...@gmail.com>
wrote:

> Hi Ken,
>
> If you really need to know, I made some utility methods a while back which
> determine true object dirty status:
>

Correction: True **context** dirty status.


Re: Check dirty before write?

2018-04-27 Thread Michael Gentry
Hi Ken,

If you really need to know, I made some utility methods a while back which
determine true object dirty status:

https://gist.github.com/mrg/4dce22b67175c27f4047#file-cayenneutils-java-L124

mrg


On Fri, Apr 27, 2018 at 11:40 AM, Ken Anderson 
wrote:

> Makes sense Andrus - thanks.
>
> On 4/27/18, 11:40 AM, "Andrus Adamchik"  wrote:
>
> Hi Ken,
>
> We never performed such check, and 4.0 is no exception. The reason is
> performance. We defer it until commit, hoping it will be fewer checks to do
> if say the same object is modified multiple times.
>
> It is easy to redefine this behavior by overriding
> "DataObject.writeProperty(..)" and friends in your own superclass.
>
> Andrus
>
>
> > On Apr 27, 2018, at 6:31 PM, Ken Anderson <
> ken.ander...@amphorainc.com> wrote:
> >
> > It *seems* like Cayenne (4.0) doesn’t check to see if a property
> being set is different from the prior value before making the object
> dirty.  Is that a correct observation?  If so, is there a reason it doesn’t?
> >
> > Thanks,
> > Ken
> > Confidentiality Notice: This e-mail and accompanying documents
> contain confidential information intended for a specific individual and
> purpose. This e-mailed information is private and protected by law. If you
> are not the intended recipient, you are hereby notified that any
> disclosure, copying, or distribution, or the taking of any action based on
> the contents of this information, is strictly prohibited.
>
>
>
> Confidentiality Notice: This e-mail and accompanying documents contain
> confidential information intended for a specific individual and purpose.
> This e-mailed information is private and protected by law. If you are not
> the intended recipient, you are hereby notified that any disclosure,
> copying, or distribution, or the taking of any action based on the contents
> of this information, is strictly prohibited.
>


Re: Bad data…trying to compensate

2018-04-23 Thread Michael Gentry
Hi Lon,

Can you update all of your current "0" values to null?  Or set a PostLoad
handler on your Java class and set "0" to null when you load it from the DB?


On Mon, Apr 23, 2018 at 3:31 PM, Lon Varscsak 
wrote:

> I have a foreign key id that is 0 (zero).  Our old system would interpret
> this the same as it would for null.
>
> I'm trying to see where I could hook into the system so the Cayenne can
> convert these to null on the fly.  Any ideas?
>
> -Lon
>


Re: New Modeler icons

2018-03-20 Thread Michael Gentry
Hi Ken,

Such things are on my agenda, I've just been very lax at development
recently:

https://camo.githubusercontent.com/83c4ec936ec7b08144b87bbf81cde4f819960e09/68747470733a2f2f70656f706c652e6170616368652e6f72672f2537456d67656e7472792f4f626a656374456e74697479322e706e67


On Tue, Mar 20, 2018 at 9:06 AM, Ken Anderson  wrote:

> This is beautiful!  One question - are we ever going to get the ability to
> add userInfo like in EOF?  I would really like to annotate entities,
> attributes, and relationships.  Is there another way people are doing it?
>
> Thanks,
> Ken
>
> > On Mar 20, 2018, at 3:01 AM, Nikita Timofeev 
> wrote:
> >
> > Hi all,
> >
> > Wanted to share with you screenshot of Cayenne Modeler with new icons
> [1].
> > Everyone agreed earlier that we need some colors back, so here they are.
> > Any thoughts?
> >
> > [1] https://drive.google.com/file/d/1RiSbuRogij4OkQfyCZRFVjmX4Vj1J
> 68r/view?usp=sharing
> >
> > --
> > Best regards,
> > Nikita Timofeev
>
>


Re: Fetching a to-many DbRelationship

2018-03-19 Thread Michael Gentry
I wouldn't think having company->>employees modeled would cause a
performance issue.  Did you try it first and then remove it?


On Mon, Mar 19, 2018 at 8:39 AM, Hugi Thordarson <h...@karlmenn.is> wrote:

> No, I only have a DbRelationship so no code gets generated. The
> ObjRelationship is only modeled in one direction for performance reasons.
>
> Imagine a relationship Company <->> Employees where both
> DbRelationships are modeled but only "Emploee" has a "company"
> relationship, "Company" has no "employees" relationship—but now I want to
> get a company's employees.
>
> Conceptually, something along the lines of company.readProperty(
> "db:employees" ) but obviously that doesn't work.
>
> I know I can manually extract the PK from the Company and perform a brute
> force search on Employees, but since I have a modeled DbRelationship I
> imagined there's something a bit higher level.
>
> - hugi
>
>
>
>
> > On 19 Mar 2018, at 12:32, Michael Gentry <blackn...@gmail.com> wrote:
> >
> > Hi Hugi,
> >
> > Do you mean something like lineItem.getOrders(); ?
> >
> >
> > On Mon, Mar 19, 2018 at 7:06 AM, Hugi Thordarson <h...@karlmenn.is>
> wrote:
> >
> >> Hi all,
> >> I feel like this is something I should know so I'm almost hesitant to
> ask.
> >> But…
> >>
> >> I have a DataObject - how do I read the value of a ToMany DbRelationship
> >> it has?
> >>
> >> Cheers,
> >> - hugi
>
>


Re: Fetching a to-many DbRelationship

2018-03-19 Thread Michael Gentry
Hi Hugi,

Do you mean something like lineItem.getOrders(); ?


On Mon, Mar 19, 2018 at 7:06 AM, Hugi Thordarson  wrote:

> Hi all,
> I feel like this is something I should know so I'm almost hesitant to ask.
> But…
>
> I have a DataObject - how do I read the value of a ToMany DbRelationship
> it has?
>
> Cheers,
> - hugi


Re: Truncating a table

2017-12-21 Thread Michael Gentry
Hi Maik,

Raw SQL would certainly be the most efficient way.  Even if you didn't use
raw SQL, though, how were you planning on dealing with Cayenne's caches?  I
think this issue would, regardless of how you truncated the table.  There
are various options, I'm just trying to get a feel for your use can and
thoughts.

Thanks,

mrg


On Thu, Dec 21, 2017 at 5:10 AM, Musall, Maik  wrote:

> Hi,
>
> I have a lookup table with >400k rows that I want to periodically refill
> from external sources. Since it also contains precomputed values that are
> not part of the external source, my plan is to read the external data and
> batch-insert it all into the table.
>
> How can I truncate the entire table to prepare it for new inserts? The
> only thing that comes to mind is raw SQL, but that would obviously leave
> stale data in Cayenne's various caches.
>
> Thanks
> Maik
>
>


Re: Redacting db user name and password from XML

2017-12-18 Thread Michael Gentry
A disadvantage of this approach, though, is it puts the username/password
on the command-line and/or the process list, plus potentially exposes it in
command-line history, too.

mrg


On Mon, Dec 18, 2017 at 11:49 AM, Andrus Adamchik 
wrote:

> Hi Mark,
>
> We've done quite a bit of work in Cayenne to avoid complex things like
> PasswordEncoding or custom DataSourceFactories. If all that is needed is to
> change / define login credentials, the simplest way is via properties [1].
> [2] shows an example with a single DataNode. If you have more than one, you
> will need to add the project name and the DataNode name to the base
> property name. E.g.:
>
> export MY_USER=user
> export MY_PASSWORD=secret
>
> java -Dcayenne.jdbc.username.project.mynode=$MY_USER \
>  -Dcayenne.jdbc.password.project.mynode=$MY_PASSWORD \
>  -jar myapp.jar
>
>
> Hope this helps,
> Andrus
>
> [1] http://cayenne.apache.org/docs/4.0/cayenne-guide/
> configuration-properties.html
> [2] https://stackoverflow.com/questions/45781378/best-
> practice-to-manage-apache-cayenne-project-xml-file
>
>
>
> > On Dec 17, 2017, at 4:23 AM, Mark Hull  wrote:
> >
> > I apologize if this question has been asked and answered before but:
> What is the best-practices solution to redact the database user name and
> password from an XML file created and used by Cayenne Modeler? The
> ServerRuntime build statement is simply:
> >
> > cayenneRuntime = ServerRuntime.builder()
> > .addConfig("com/hulles/a1icia/cayenne/cayenne-a1icia.xml")
> > .build();
> >
> > It works just fine as long as the db user name and password are in the
> XML file, but I don't believe in leaving clear-text artifacts like that
> laying around in the code, so I want to add the user and password data at
> runtime from a Java method (not from an external file or an 'executable',
> whatever that means in the content of PasswordEncoding). Adding
> .user("xyz") and .password("zyx") to the build statement don't work,
> presumably because the DataNode is not the default and those statements
> just set their respective fields for the default DataNode.
> >
> > If I have to, I can create either a Module to change those properties
> somehow at runtime (though the documentation for doing so is, to be kind,
> sparse), somehow implement the PasswordEncoding (even less documentation,
> because I don't know where it's used), or just edit the XML at runtime
> (horrible choice but looking like the best of a bad lot at this point).
> >
> > All this seems like a lot of effort when I imagine this need must crop
> up fairly often among Cayenne users (it should, for security reasons IMO).
> Is there a simple standard way to do what I want? Or at least a standard
> way? I don't want to invent a new wheel here. I feel like I'm missing
> something obvious that everyone else knows about and that I just missed.
> Oh, by the way, whatever the solution is should still allow Cayenne Modeler
> to function normally.
> >
> > I promise I searched for the answer everywhere I could think of.
> StackOverflow had a couple answers that used deprecated methods and didn't
> work when I tried them.
> >
> > Thanks in advance for any help. I hope there's a really simple answer so
> I feel stupid but don't have to spend any more time on this than I have
> already. :)
> >
> > - Mark Hull
> >
> > /People say nothing is impossible, but I do nothing every day. - A. A.
> Milne/
>
>


Re: Redacting db user name and password from XML

2017-12-18 Thread Michael Gentry
Hi Mark,

What type of application are you developing?  For web applications, which
I'd imagine are the most common cases, using a JNDI DataSource is the way
to go.  Your container (Tomcat, Jetty, etc) will provide database
connection services to Cayenne through a JNDI lookup.  If you aren't
developing a web application, we can guide you toward a different solution.

Thanks,

mrg


On Sat, Dec 16, 2017 at 8:23 PM, Mark Hull  wrote:

> I apologize if this question has been asked and answered before but: What
> is the best-practices solution to redact the database user name and
> password from an XML file created and used by Cayenne Modeler? The
> ServerRuntime build statement is simply:
>
> cayenneRuntime = ServerRuntime.builder()
> .addConfig("com/hulles/a1icia/cayenne/cayenne-a1icia.xml")
> .build();
>
> It works just fine as long as the db user name and password are in the XML
> file, but I don't believe in leaving clear-text artifacts like that laying
> around in the code, so I want to add the user and password data at runtime
> from a Java method (not from an external file or an 'executable', whatever
> that means in the content of PasswordEncoding). Adding .user("xyz") and
> .password("zyx") to the build statement don't work, presumably because the
> DataNode is not the default and those statements just set their respective
> fields for the default DataNode.
>
> If I have to, I can create either a Module to change those properties
> somehow at runtime (though the documentation for doing so is, to be kind,
> sparse), somehow implement the PasswordEncoding (even less documentation,
> because I don't know where it's used), or just edit the XML at runtime
> (horrible choice but looking like the best of a bad lot at this point).
>
> All this seems like a lot of effort when I imagine this need must crop up
> fairly often among Cayenne users (it should, for security reasons IMO). Is
> there a simple standard way to do what I want? Or at least a standard way?
> I don't want to invent a new wheel here. I feel like I'm missing something
> obvious that everyone else knows about and that I just missed. Oh, by the
> way, whatever the solution is should still allow Cayenne Modeler to
> function normally.
>
> I promise I searched for the answer everywhere I could think of.
> StackOverflow had a couple answers that used deprecated methods and didn't
> work when I tried them.
>
> Thanks in advance for any help. I hope there's a really simple answer so I
> feel stupid but don't have to spend any more time on this than I have
> already. :)
>
> - Mark Hull
>
> /People say nothing is impossible, but I do nothing every day. - A. A.
> Milne/
>


Re: Multiple data sources

2017-12-12 Thread Michael Gentry
Hey Tony,

"Do they belong in separate data models?"

Belong?  No.  You could use two separate models, but it is likely easier to
use one model depending upon your requirements.


"Or two nodes in the same model?"

You can have multiple data nodes and data maps in the same model.  Each
data map would point to a different data node.  That's how Cayenne figures
out the routing, by having your entities associated with a given data map
which is assigned to a given data node.


"Do you run two separate cayenne stacks, with different contexts?"

Again, you could, but likely is easier to use just one.  A single data
context can handle multiple data nodes and data maps.


mrg


On Tue, Dec 12, 2017 at 10:45 AM, t...@giaccone.org <t...@giaccone.org>
wrote:

> MRG,
>
> I'm using the most recent version of Cayenne. My question is more about
> how you instantiate the two data stacks in the application. Do they belong
> in separate data models? Or two nodes in the same model?  Do you run two
> separate cayenne stacks, with different contexts?
>
> But with your answer I think I understand how to get started.
>
>
> Tony
>
> On 2017-12-07 14:36, Michael Gentry <blackn...@gmail.com> wrote:
> > Hi Tony,
> >
> > I've not done this before, but pretty sure you'll need two DataNodes (to
> > manage the two DB connections, one DB per node) and two DataMaps (one
> > attached to each DataNode).  Put the relevant Java classes/etc in the
> > proper DataMap and Cayenne will then handle the routing for you.
> (Cayenne
> > determines which DataNode to use based upon the Java class/package that
> is
> > contained in each DataMap.)
> >
> > BTW, which version of Cayenne are you using?
> >
> > mrg
> >
> >
> > On Thu, Dec 7, 2017 at 1:50 PM, Tony Giaccone <t...@giaccone.org> wrote:
> >
> > > What's the general technique for using multiple data sources with a
> cayenne
> > > project?
> > >
> > > I want to read from one table, and then use that data to collect data
> from
> > > a second database, and validate certain values.
> > >
> > > Anyone have a specific example of this kind of work?
> > >
> > >
> > >
> > > Tony Giaccone
> > >
> >
>


Re: URI for data object?

2017-12-12 Thread Michael Gentry
Hi Ken,

I had some code somewhere that did this, but can't find it offhand.

Nutshell version, I was storing the information in this format:

EntityName:KeyName:KeyValue

You can get that information from the Cayenne[1] (or DataObjectUtils if on
3.0) helper class.  That format requires a single PK and likewise a single
integer PK value.

When I needed the object back, I split on the colons and used the parts to
construct a new ObjectId(entityName, key, value) and passed that to
Cayenne.objectForPK(context, objectId).

mrg

[1] http://cayenne.apache.org/docs/3.1/api/org/apache/cayenne/Cayenne.html



On Tue, Dec 12, 2017 at 1:44 PM, Ken Anderson 
wrote:

> Everyone,
>
> I’ve been looking around the Cayenne API, but have not been able to find a
> way to serialize an object ID into a string, and then turn that string back
> into an object ID or object.  What’s the best/right way to do this?  For
> instance, if you want to store a reference to a database object in a text
> file…
>
> Thanks,
> Ken
> Confidentiality Notice: This e-mail and accompanying documents contain
> confidential information intended for a specific individual and purpose.
> This e-mailed information is private and protected by law. If you are not
> the intended recipient, you are hereby notified that any disclosure,
> copying, or distribution, or the taking of any action based on the contents
> of this information, is strictly prohibited.
>


Re: Multiple data sources

2017-12-07 Thread Michael Gentry
Hi Tony,

I've not done this before, but pretty sure you'll need two DataNodes (to
manage the two DB connections, one DB per node) and two DataMaps (one
attached to each DataNode).  Put the relevant Java classes/etc in the
proper DataMap and Cayenne will then handle the routing for you.  (Cayenne
determines which DataNode to use based upon the Java class/package that is
contained in each DataMap.)

BTW, which version of Cayenne are you using?

mrg


On Thu, Dec 7, 2017 at 1:50 PM, Tony Giaccone  wrote:

> What's the general technique for using multiple data sources with a cayenne
> project?
>
> I want to read from one table, and then use that data to collect data from
> a second database, and validate certain values.
>
> Anyone have a specific example of this kind of work?
>
>
>
> Tony Giaccone
>


Re: 4.1.M1 on Maven Central

2017-10-25 Thread Michael Gentry
Ninja'd by Andrus!


On Wed, Oct 25, 2017 at 7:03 AM, Michael Gentry <blackn...@gmail.com> wrote:

> Hmm, I'm not seeing it:
>
> http://repo1.maven.org/maven2/org/apache/cayenne/cayenne-server/
>
>
>
> On Wed, Oct 25, 2017 at 6:43 AM, Hugi Thordarson <h...@karlmenn.is> wrote:
>
>> Hi all,
>> not entirely familiar with how the release phase works—has Cayenne 4.1.M1
>> already been submitted to Maven Central?
>>
>> - hugi
>
>
>


Re: 4.1.M1 on Maven Central

2017-10-25 Thread Michael Gentry
Hmm, I'm not seeing it:

http://repo1.maven.org/maven2/org/apache/cayenne/cayenne-server/



On Wed, Oct 25, 2017 at 6:43 AM, Hugi Thordarson  wrote:

> Hi all,
> not entirely familiar with how the release phase works—has Cayenne 4.1.M1
> already been submitted to Maven Central?
>
> - hugi


Re: Cayenne-Tapestry integration problem

2017-10-12 Thread Michael Gentry
Hi Juan,

In your Data Domain configuration (highest level item) in Cayenne Modeler,
do you have Use Shared Cache checked?


On Thu, Oct 12, 2017 at 2:14 PM, Juan Manuel Diaz Lara <
jmdia...@yahoo.com.invalid> wrote:

> I devoloped a module to integrate cayenne into apache-tapestry, using
> cayenne 4.0.M5 and tapestry 5.4.3...
> I the module I create a single ServerRuntime for mi web app, then, on each
> request I call serverRuntime.newContext(); to get a new fresh
> ObjectContext, but some way I get the same results in my queries all the
> time, even if i change my data outsise de app (in a external sql tool, by
> instance, and commiting of course)... this seems like cayenne is caching
> database results and not going to DB for each query, but I am not
> configuring any caching.
> The only way I can get fresh results calling invalidateObjects() on
> returned results, but this is a workround.
> I am sure I am creating new context on each request.
> Any insight would be appreciated.
>
>
>
> Atte. Juan Manuel Díaz Lara


Re: Cayenne advantages

2017-10-10 Thread Michael Gentry
Actually, let me add a 3rd:

3) Great community.  Everyone tries to be helpful and respectful here.


On Tue, Oct 10, 2017 at 9:08 AM, Michael Gentry <blackn...@gmail.com> wrote:

> Hi Ari,
>
> For me it is two primary things:
>
> 1) The ObjectContext.  Our data has a top-level item which faults in up-to
> tens of thousands of child records throughout a complex object graph.  The
> UI allows editing of the entire object graph and navigating around the
> various levels.  At the end, a single objectContext.commitChanges()
> persists everything that has changed.  This works amazingly well and
> requires no additional code on our part to manage the object graph changes,
> re-attach objects to sessions, etc.
>
> 2) Cayenne Modeler.  I have it open most of the time I'm doing work that
> touches the Cayenne graph.  It is much easier for me to visualize Cayenne
> objects in CM than Eclipse/etc.  It is also quite easy for novice Cayenne
> developers to run CM and get a gentle introduction in a nice visual format
> without having to learn annotations or XML.  This greatly improves real
> productivity while they are becoming familiar with the framework.
>
> mrg
>
>
> On Mon, Oct 9, 2017 at 3:32 AM, Aristedes Maniatis <a...@maniatis.org>
> wrote:
>
>> We are currently rebuilding the Cayenne website and would like to refresh
>> its unique selling points. What is it that brought you to Cayenne and kept
>> you here? I know there are some EOF escapees who are here because EOF is no
>> longer supported, but what positive reasons keep you here rather than
>> moving to a JPA or other library?
>>
>> This is not about denigrating the alternatives but highlighting what
>> Cayenne does well and showing new developers why they should try it.
>>
>> 1. If you made a bullet list of your key features (even with only one
>> item!) what would it be?
>>
>> 2. If you met a developer at a conference and suggest they try Cayenne,
>> what would convince them to try it?
>>
>>
>> Ari
>>
>>
>>
>> --
>> -->
>> Aristedes Maniatis
>> GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A
>>
>
>


Re: For those who upgraded to Java 9

2017-09-23 Thread Michael Gentry
It seems like the Mac version is always the one breaking...


On Sat, Sep 23, 2017 at 8:25 AM, Andrus Adamchik 
wrote:

> Public service announcement for those who rushed to upgrade their dev
> machines to the recently released JDK 9 as I did. If CayenneModeler no
> longer starts, follow these instructions:
>
>https://twitter.com/andrus_a/status/911565910003068928
>
> In short, you can keep JDK9 (and run your Cayenne and other apps on it),
> but the desktop JRE must be downgraded to 8 for the time being per links in
> the twit above. We will work on a 9-compatible Modeler in the meantime.
>
> Cheers,
> Andrus


Re: Question on how to properly create parent-child nested dependent objects?

2017-09-20 Thread Michael Gentry
PS. I did mention you might want to change the last line...


On Wed, Sep 20, 2017 at 10:36 AM, Michael Gentry <blackn...@gmail.com>
wrote:

> Hi Mike,
>
> This is 3-4 year old 3.0 code which is working and I haven't updated it
> yet.  That's mainly it...not enough cycles.
>
> mrg
>
>
> On Wed, Sep 20, 2017 at 10:28 AM, Mike Kienenberger <mkien...@gmail.com>
> wrote:
>
>> Michael,
>>
>> Why do you suggest
>>
>> DataObjectUtils.objectForPK(destinationContext,
>> contractDesignation.getObjectId());
>>
>> instead of
>>
>> destinationContext.localObject(contractDesignation);
>>
>>
>> ?
>>
>


Re: Question on how to properly create parent-child nested dependent objects?

2017-09-20 Thread Michael Gentry
Hi Mike,

This is 3-4 year old 3.0 code which is working and I haven't updated it
yet.  That's mainly it...not enough cycles.

mrg


On Wed, Sep 20, 2017 at 10:28 AM, Mike Kienenberger 
wrote:

> Michael,
>
> Why do you suggest
>
> DataObjectUtils.objectForPK(destinationContext,
> contractDesignation.getObjectId());
>
> instead of
>
> destinationContext.localObject(contractDesignation);
>
>
> ?
>


Re: Question on how to properly create parent-child nested dependent objects?

2017-09-20 Thread Michael Gentry
Hi Andrew,

I'm jumping in late here, but I did something very similar to what you are
trying to do with CommunicationType.find().  I create (auto-populate) a
reference table record based upon some enum values if missing, or just
return the reference table record if I find it.  I do this in a completely
separate (not a child) DataContext and copy the result into the main
destination context passed into the method.

This is from 3.1, so might vary a bit on the last line if you are on 4.x
(I'm using a deprecated method there and haven't updated yet):

public static ContractDesignation fetch(ObjectContext
destinationContext,
ContractMethodType
contractMethod,
ContractType   contractType,
FundingVehicleType
fundingVehicle)
{
ContractDesignation contractDesignation = null;
DataContext dataContext =
CayenneUtils.createDataContext();
Expression  exp1=
ExpressionFactory.matchExp(CONTRACT_METHOD_PROPERTY, contractMethod);
Expression  exp2=
ExpressionFactory.matchExp(CONTRACT_TYPE_PROPERTY, contractType);
Expression  exp3=
ExpressionFactory.matchExp(FUNDING_VEHICLE_PROPERTY, fundingVehicle);
Expression  exp =
exp1.andExp(exp2).andExp(exp3);
SelectQuery query   = new
SelectQuery(ContractDesignation.class, exp);

@SuppressWarnings("unchecked")
List contractDesignations =
dataContext.performQuery(query);

// If no contract designation is found, create a new one, else use
the
// one that was found (throwing an exception if too many are found).
if (contractDesignations.isEmpty())
{
contractDesignation =
dataContext.newObject(ContractDesignation.class);

contractDesignation.setContractMethod(contractMethod);
contractDesignation.setContractType(contractType);
contractDesignation.setFundingVehicle(fundingVehicle);

dataContext.commitChanges();
}
else if (contractDesignations.size() == 1)
{
contractDesignation = contractDesignations.get(0);
}
else
{
// There can be only one!
throw new TooManyResultsException("There can be at most one
match for ContractDesignation contractMethod='" + contractMethod +
  "' / contractType='" +
contractType +
  "' / fundingVehicle='" +
fundingVehicle + "'");
}

// Pull the fetched ContractDesignation into the destination
ObjectContext.
return (ContractDesignation)
DataObjectUtils.objectForPK(destinationContext,
contractDesignation.getObjectId());
}




On Wed, Sep 20, 2017 at 9:16 AM, Andrew Willerding  wrote:

> I thought of this too but I'm trying to create the child object
> dynamically without having any impact on the parent object or making the
> coder of the parent object worry about creating child objects first.
>
>
>
> On 20/09/17 08:45 AM, Nikita Timofeev wrote:
>
>> Other option is to create CommunicationType first and then just use it:
>>
>> CommunicationType type = CommunicationType.find("Email");
>>
>> CommunicationLog cl = oc.newObject(CommunicationLog.class);
>> cl.setCommunicationDT(LocalDateTime.now());
>> cl.setCommunicationType(type);
>> oc.commitChanges();
>>
>> In this case everything will be in one context, and you can freely
>> commit CommunicationType to DB.
>>
>> On Wed, Sep 20, 2017 at 3:37 PM, Mike Kienenberger 
>> wrote:
>>
>>> I haven't followed the details, so I don't know if using a separate
>>> object context is necessary, but all you need to do to move a data
>>> object (in your case "child") to a different context is to call
>>> parentContext.localObject(childDataObject) which will return
>>> childDataObjectInParentContext.   Note that this requires either a
>>> hollow or committed childDataObject as a modified (uncommitted) or new
>>> (uncommitted) data object's changes only exist in the
>>> childObjectContext.
>>>
>>> I may also have the syntax for localObject() wrong as I'm probably
>>> using an older version of Cayenne than you are.
>>>
>>>
>>>
>>> On Wed, Sep 20, 2017 at 8:30 AM, Andrew Willerding
>>>  wrote:
>>>
 I guess my issue is with how independent the commits can be.  Now that I
 better understand this, my code example works as Nikita suggested (with
 the
 fix for my problem with the PrimaryKey table) and if I drop the commit
 during the creation of the child object otherwise the commit during the
 child creation will fail because the parent has not yet been assigned
 with
 the child object.

 My objective is 

Re: Quotes for 4.0 press release

2017-06-26 Thread Michael Gentry
The quote from us is still pretty valid.  Just upgraded to 3.1 ...


On Wed, Jun 21, 2017 at 7:32 AM, Andrus Adamchik 
wrote:

> @ Cayenne Community --
>
> We are preparing an ASF press release about Cayenne 4.0 Beta. If you are
> using Cayenne (4.0 or older versions), I'd appreciate if you could share
> your experiences in a few sentences for PR inclusion. It will help us a lot
> in spreading the word. Here is an example of 3.1 press release [1].
>
> Please contact me off-list if you'd like to participate.
>
> Thanks,
> Andrus
>
>
> [1] https://blogs.apache.org/foundation/entry/the_apache_
> software_foundation_announces63


Re: Cayenne Modeler Inheritance Warning

2017-06-09 Thread Michael Gentry
You were very close!  Exhibit has relationships to subclasses of Facility,
but not Facility itself.  I'll bet that is what is triggering it.

Thanks for the insight,

mrg


On Fri, Jun 9, 2017 at 1:48 AM, Andrus Adamchik <and...@objectstyle.org>
wrote:

> Does Facility.exhibit point to a sublcass of Exhibit?
>
> Some background:
>
> https://issues.apache.org/jira/browse/CAY-1600
> https://lists.apache.org/thread.html/01f69b73b99651f6ecf96fc24176b0
> e2d4f63d5af08e2f764e6f12bf@1332798063@%3Cuser.cayenne.apache.org%3E
>
> Andrus
>
>
> > On Jun 8, 2017, at 6:30 PM, Michael Gentry <blackn...@gmail.com> wrote:
> >
> > In converting an application from 3.0 to 3.1, have a validation warning
> in
> > CM regarding a "Facility" abstract superclass which defines an "exhibit"
> > relationship which is used by the subclasses.  The warning is:
> >
> > Usage of super entity's relationships 'Facility.exhibit' as reversed
> > relationships for sub entity is discouraged
> >
> > The concrete subclasses have qualifiers similar to:
> >
> > exhibit.itemExhibit.code = "foo"
> >
> > They all utilize the "exhibit" relationship defined in the superclass to
> > identify the correct subclass.  Why is inheriting and using an abstract
> > superclass relationship a warning and discouraged, but inheriting and
> using
> > the abstract superclass attributes are OK and no warning?  I could, of
> > course, re-define these relationships in each subclass, but I'm wondering
> > why this warning is in place and if I'm overlooking something.
> >
> > Thanks,
> >
> > mrg
>
>


Re: Best method to fetch a lot of objects

2017-05-19 Thread Michael Gentry
Hi Andrus,

In your example, wouldn't "context" continue growing and possibly
exhausting memory as more Artists are brought into it?  (And this would
also slow down the commitChanges() call as it has more evaluation to do as
the context grows.)

mrg


On Fri, May 19, 2017 at 9:49 AM, Andrus Adamchik <and...@objectstyle.org>
wrote:

> I concur with Mike on the suggestion. Though I would recommend using
> vastly improved 4.0 API:
>
> http://cayenne.apache.org/docs/4.0/cayenne-guide/performance-tuning.html#
> iterated-queries
>
> > As you iterate over your entire record set, you can convert the DataRows
> > into Cayenne objects
>
> In 4.0 you can iterate over objects.
>
> > Gather up 50 or 100 or 1000
>
> In 4.0 you can use batch iterator to receive the stream already split in
> batches. Docs example actually has a typo. Batch iterator looks like this:
>
> try(ResultBatchIterator it =
> ObjectSelect.query(Artist.class).batchIterator(context, batchSize)) {
>
> for(List list : it) {
>...
>    context.commitChanges();
> }
> }
>
> Andrus
>
>
> > On May 19, 2017, at 4:39 PM, Michael Gentry <blackn...@gmail.com> wrote:
> >
> > Hi Pascal,
> >
> > I suspect you need to utilize an iterated query:
> >
> > http://cayenne.apache.org/docs/3.1/cayenne-guide/
> performance-tuning.html#iterated-queries
> >
> > As you iterate over your entire record set, you can convert the DataRows
> > into Cayenne objects (see the section in the documentation above the
> > iterated queries documentation) in a *different* DataContext.  Gather up
> 50
> > or 100 or 1000 (whatever number feels good to you) in that second
> > DataContext and then commit them, throw away that DataContext and create
> a
> > new one.  Repeat.  This should keep your memory usage fairly constant and
> > allow you to process arbitrarily large record sizes.
> >
> > mrg
> >
> >
> > On Fri, May 19, 2017 at 9:27 AM, Pascal Robert <prob...@druide.com>
> wrote:
> >
> >> Hi,
> >>
> >> I’m still in my FileMaker -> MySQL migration project. This time, I want
> to
> >> migrate a FileMaker table who have 445 244 records in it. If I fetch
> >> everything into an object entity for each row, I’m getting a Java heap
> >> space problem, which is somewhat expected by the size of the result set.
> >>
> >> If I call setFetchLimit() with a 10 000 limit, works fine. FileMaker
> >> doesn’t support fetch limits, so I can’t do something on that side.
> >>
> >> Any tips?
>
>


Re: Best method to fetch a lot of objects

2017-05-19 Thread Michael Gentry
Hi Pascal,

I suspect you need to utilize an iterated query:

http://cayenne.apache.org/docs/3.1/cayenne-guide/performance-tuning.html#iterated-queries

As you iterate over your entire record set, you can convert the DataRows
into Cayenne objects (see the section in the documentation above the
iterated queries documentation) in a *different* DataContext.  Gather up 50
or 100 or 1000 (whatever number feels good to you) in that second
DataContext and then commit them, throw away that DataContext and create a
new one.  Repeat.  This should keep your memory usage fairly constant and
allow you to process arbitrarily large record sizes.

mrg


On Fri, May 19, 2017 at 9:27 AM, Pascal Robert  wrote:

> Hi,
>
> I’m still in my FileMaker -> MySQL migration project. This time, I want to
> migrate a FileMaker table who have 445 244 records in it. If I fetch
> everything into an object entity for each row, I’m getting a Java heap
> space problem, which is somewhat expected by the size of the result set.
>
> If I call setFetchLimit() with a 10 000 limit, works fine. FileMaker
> doesn’t support fetch limits, so I can’t do something on that side.
>
> Any tips?


Re: Read-only contexts?

2017-05-05 Thread Michael Gentry
Hi Alexander,

Those are also good suggestions for implementing this feature.

Thanks,

mrg


On Fri, May 5, 2017 at 9:19 AM, Alexander <lex.f...@gmail.com> wrote:

> Hi,
>
> thank you and Maik for answering so fast. You saved me a lot of time
> searching around for nothing.
>
> Your suggestion seems to be the right approach.
> I’d consider making the read-only flag in the ObjectContext final, as to
> prevent unintended changes. Therefore it has to be set in the
> ObjectContext’s constructor.
>
> A fail fast behavior should be considered for nested ObjectContexts, i.e.
> commitChangesToParent() should check the parent’s read-only flag, unless
> the nested context’s read-only flag is copied from the parent on
> instantiation (in this case ObjectContextFactory class has to be changed
> too)..
>
> Let’s hope this feature will be added before 4.0 final.
>
> For now subclassing is a good option.
>
> Thanks again
> Alexander
>
>
> On 2017-05-05 13:08 (+0200), Michael Gentry <blackn...@gmail.com> wrote:
> > #2 should've read:
> >
> > 2. Alter CayenneDataObject to check the entity's read-only status AND the
> > context's read-only status.  (Change writeProperty(), etc.)  If either is
> > read-only and you are trying to sneak a change in, throw an exception.
> >
> > mrg
> >
> >
> > On Fri, May 5, 2017 at 7:04 AM, Michael Gentry <blackn...@gmail.com>
> wrote:
> >
> > > Hi Alexander,
> > >
> > > I don't believe what you are asking for is currently doable, even in
> the
> > > latest 4.0 milestone release.
> > >
> > > An ObjectContext doesn't know anything about read-only.  You can make a
> > > Cayenne object read-only in Cayenne Modeler, however this just omits
> > > setter-type methods.  CayenneDataObject, which all Cayenne database
> objects
> > > inherit from, doesn't actually restrict setting values if you flag it
> as
> > > read-only in the modeler.  You can directly call writeProperty(),
> > > writePropertyDirectly(), removeToManyTarget(), etc on the objects.
> > >
> > > I think this feature would be fairly easy to add (the information is
> > > already in the model's XML files [1]), so perhaps it could be added
> before
> > > 4.0 final.
> > >
> > > I'd suggest:
> > >
> > > 1. Add a read-only flag to DataContext and friends.  If you call
> > > commitChanges() on a read-only context, throw an exception.
> > > 2. Alter each CayenneDataObject which modifies data (writeProperty(),
> etc)
> > > to check the entity's read-only status AND the context's read-only
> status.
> > > If either is read-only and you are trying to sneak a change in, throw
> an
> > > exception.
> > >
> > > Does this sound like the right approach (to you and other Cayenne
> users)?
> > >
> > > As to your localObject() question, I think it should adhere to the 1/2
> > > semantics I just mentioned.
> > > Thanks,
> > >
> > > mrg
> > >
> > > [1]  > > dbEntityName="..." superClassName="...">
> > >
> > >
> > >
> > > On Fri, May 5, 2017 at 6:29 AM, Alexander <lex.f...@gmail.com> wrote:
> > >
> > >> Hi,
> > >>
> > >> I searched for a while, but wasn’t able to find a solution to make an
> > >> ObjectContext “read-only”.
> > >> Maybe I'm missing something.
> > >>
> > >> The point is:
> > >> As suggested many times, there are situations where it makes sense to
> > >> have a shared read-only ObjectContext and other ObjectContexts to
> commit
> > >> changes.
> > >> I can certainly handle two and more ObjectContexts, but I need to lock
> > >> out other users / applications which can somehow gain access to
> persistent
> > >> objects instantiated through the assumed read-only shared context,
> since
> > >> any application that has access to such objects (maybe obtained from a
> > >> service class that is expected to return read-only objects) could
> simply
> > >> call object.getObjectContext().commitChanges(). By the way, this
> would
> > >> also commit unwanted temporary changes that happen elsewhere in the
> main
> > >> application or in the service class.
> > >>
> > >> Is there a method like CONTEXT.makeReadOnly() to make sure that any
> > >> objects that resides in this specific ObjectContext cannot be changed?
> > >> Even better, is there a way to let persistent objects, that are bound
> to
> > >> a read-only context, throw an exception?
> > >>
> > >> Should this be possible, there is only one question left: would it
> still
> > >> be possible to transfer objects retrieved through a read-only
> > >> ObjectContext  to a read-write ObjectContext, by calling
> > >> localObject(readWriteContext)?
> > >>
> > >> Any help would be greatly appreciated.
> > >> Alexander
> > >>
> > >>
> > >
> >
>


Re: Read-only contexts?

2017-05-05 Thread Michael Gentry
#2 should've read:

2. Alter CayenneDataObject to check the entity's read-only status AND the
context's read-only status.  (Change writeProperty(), etc.)  If either is
read-only and you are trying to sneak a change in, throw an exception.

mrg


On Fri, May 5, 2017 at 7:04 AM, Michael Gentry <blackn...@gmail.com> wrote:

> Hi Alexander,
>
> I don't believe what you are asking for is currently doable, even in the
> latest 4.0 milestone release.
>
> An ObjectContext doesn't know anything about read-only.  You can make a
> Cayenne object read-only in Cayenne Modeler, however this just omits
> setter-type methods.  CayenneDataObject, which all Cayenne database objects
> inherit from, doesn't actually restrict setting values if you flag it as
> read-only in the modeler.  You can directly call writeProperty(),
> writePropertyDirectly(), removeToManyTarget(), etc on the objects.
>
> I think this feature would be fairly easy to add (the information is
> already in the model's XML files [1]), so perhaps it could be added before
> 4.0 final.
>
> I'd suggest:
>
> 1. Add a read-only flag to DataContext and friends.  If you call
> commitChanges() on a read-only context, throw an exception.
> 2. Alter each CayenneDataObject which modifies data (writeProperty(), etc)
> to check the entity's read-only status AND the context's read-only status.
> If either is read-only and you are trying to sneak a change in, throw an
> exception.
>
> Does this sound like the right approach (to you and other Cayenne users)?
>
> As to your localObject() question, I think it should adhere to the 1/2
> semantics I just mentioned.
> Thanks,
>
> mrg
>
> [1]  dbEntityName="..." superClassName="...">
>
>
>
> On Fri, May 5, 2017 at 6:29 AM, Alexander <lex.f...@gmail.com> wrote:
>
>> Hi,
>>
>> I searched for a while, but wasn’t able to find a solution to make an
>> ObjectContext “read-only”.
>> Maybe I'm missing something.
>>
>> The point is:
>> As suggested many times, there are situations where it makes sense to
>> have a shared read-only ObjectContext and other ObjectContexts to commit
>> changes.
>> I can certainly handle two and more ObjectContexts, but I need to lock
>> out other users / applications which can somehow gain access to persistent
>> objects instantiated through the assumed read-only shared context, since
>> any application that has access to such objects (maybe obtained from a
>> service class that is expected to return read-only objects) could simply
>> call object.getObjectContext().commitChanges(). By the way, this would
>> also commit unwanted temporary changes that happen elsewhere in the main
>> application or in the service class.
>>
>> Is there a method like CONTEXT.makeReadOnly() to make sure that any
>> objects that resides in this specific ObjectContext cannot be changed?
>> Even better, is there a way to let persistent objects, that are bound to
>> a read-only context, throw an exception?
>>
>> Should this be possible, there is only one question left: would it still
>> be possible to transfer objects retrieved through a read-only
>> ObjectContext  to a read-write ObjectContext, by calling
>> localObject(readWriteContext)?
>>
>> Any help would be greatly appreciated.
>> Alexander
>>
>>
>


Re: Raw query

2017-05-01 Thread Michael Gentry
Hi Amedeo,

Another option for 3.1 is to use my AggregateUtils:

https://github.com/mrg/cbe/tree/master/FetchingObjects/Aggregates/src/main/java/cbe/fetching/utilities

(You'd need both of the files there.)

With it you get count, min, max, avg, and sum functions.

For your example, this is how you would do a count:

SelectQuery query = new SelectQuery(MyEntity.class);
long count = AggregateUtils.count(dataContext, query);

An example of all 5 aggregate functions in use can be found here:

https://github.com/mrg/cbe/blob/master/FetchingObjects/Aggregates/src/main/java/cbe/fetching/Aggregates.java

mrg


On Mon, May 1, 2017 at 3:55 AM, Andrus Adamchik 
wrote:

> SQLTemplate it is then.
>
> > On Apr 30, 2017, at 9:02 PM, Amedeo Mantica 
> wrote:
> >
> > Cool.
> > However I'm using the 3.1.2 yet
> > Amedeo
> >
> >> On 30 Apr 2017, at 10:21, Andrus Adamchik 
> wrote:
> >>
> >>> SQLTemplate query = new SQLTemplate(MyEntity.class, "SELECT COUNT(1)
> >>> FROM MY_ENTITY");
> >>> query.setFetchingDataRows(true);
> >>> List rows = (List) context.performQuery(query);
> >>
> >> Or you can use SQLSelect as a type-safe and more user-friendly flavor
> doing the same thing:
> >>
> >> List rows = SQLSelect.dataRowQuery("SELECT COUNT(1) FROM
> MY_ENTITY").select(context);
> >>
> >>> You can also use aggregate functions directly with Cayenne API (since
> >>> version 4.0.M5):
> >>>
> >>> long count = ObjectSelect.query(MyEntity.class).selectCount(context);
> >>
> >> Yep, this one is the best option.
> >>
> >> Andrus
> >>
> >>
> >>> On Apr 29, 2017, at 5:22 PM, Nikita Timofeev <
> ntimof...@objectstyle.com> wrote:
> >>>
> >>> Hi Amedeo,
> >>>
> >>> For raw queries you can use SQLTemplate, like this:
> >>>
> >>> SQLTemplate query = new SQLTemplate(MyEntity.class, "SELECT COUNT(1)
> >>> FROM MY_ENTITY");
> >>> query.setFetchingDataRows(true);
> >>> List rows = (List) context.performQuery(query);
> >>>
> >>> You can also use aggregate functions directly with Cayenne API (since
> >>> version 4.0.M5):
> >>>
> >>> long count = ObjectSelect.query(MyEntity.class).selectCount(context);
> >>>
> >>> Hope this helps!
> >>>
> >>> On Sat, Apr 29, 2017 at 4:49 PM, Amedeo Mantica 
> wrote:
>  Hi all,
> 
>  Ho to execute a simple raw query with cayenne ?
> 
>  let say: SELECT COUNT(1) FROM MY_ENTITY;
> 
>  Thank you
>  Amedeo
> >>>
> >>>
> >>>
> >>> --
> >>> Best regards,
> >>> Nikita Timofeev
> >>
> >
>
>


Re: Detached Cayenne Objects

2017-04-20 Thread Michael Gentry
Ah, I can see that being a bit slower.  Keep in mind the "directly" methods
won't resolve faults and there are different methods for dealing with
relationships.



On Thu, Apr 20, 2017 at 8:00 AM, Markus Reich <markus.re...@markusreich.at>
wrote:

> Hi Michael,
>
> I checked the stacktrace again, it's my fault, the expensive operation was
> the reflection on the getter and setter :-/
> The coding was pretty old, so I don't need reflection in my case ;-)
>
> Here the old approach
> Object value = Reflect.on(source).call("get" +
> StringUtils.capitalize(objAttribute.getName())).get();
> Reflect.on(target).call("set" +
> StringUtils.capitalize(objAttribute.getName()), value);
>
> Now I switch to
> Object value = source.readPropertyDirectly(objAttribute.getName());
> target.writePropertyDirectly(objAttribute.getName(), value);
>
> I think this will give my application a real kick :-)
>
> br
> Markus
>
>
>
> Michael Gentry <blackn...@gmail.com> schrieb am Do., 20. Apr. 2017 um
> 13:28 Uhr:
>
> > Hi Markus,
> >
> > As you have discovered, Cayenne objects need to be in a context when
> > relationships are involved.  I'm curious why you think creating a context
> > is very expensive, though?  It should actually be pretty cheap
> > memory/cpu-wise.
> >
> > As for copying objects, are you copying committed objects or copying
> > new/modified objects and you need the new values?
> >
> > mrg
> >
> >
> > On Thu, Apr 20, 2017 at 7:12 AM, Markus Reich <
> markus.re...@markusreich.at
> > >
> > wrote:
> >
> > > Hi,
> > >
> > > I have a very special problem :-/
> > > We want to use a cayenne object as detached object, for a simple object
> > > this works fine, as the attribute values are hosted in a value map, but
> > we
> > > need a context when we want to use  the relations too :-/
> > >
> > > What would be the best approach?
> > > At the moment we create the object in a second context and copy the
> > > attributes / relations with reflection (deep copy) as we have a lot of
> > this
> > > objects, creating context is very expensive and we want to reduce costs
> > :-)
> > >
> > > br
> > > Markus
> > >
> >
>


Re: Detached Cayenne Objects

2017-04-20 Thread Michael Gentry
Hi Markus,

As you have discovered, Cayenne objects need to be in a context when
relationships are involved.  I'm curious why you think creating a context
is very expensive, though?  It should actually be pretty cheap
memory/cpu-wise.

As for copying objects, are you copying committed objects or copying
new/modified objects and you need the new values?

mrg


On Thu, Apr 20, 2017 at 7:12 AM, Markus Reich 
wrote:

> Hi,
>
> I have a very special problem :-/
> We want to use a cayenne object as detached object, for a simple object
> this works fine, as the attribute values are hosted in a value map, but we
> need a context when we want to use  the relations too :-/
>
> What would be the best approach?
> At the moment we create the object in a second context and copy the
> attributes / relations with reflection (deep copy) as we have a lot of this
> objects, creating context is very expensive and we want to reduce costs :-)
>
> br
> Markus
>


Re: Committed snapshot

2017-04-18 Thread Michael Gentry
Hi Mark,

I haven't done it for a specific property, but I did it for a DataObject.
Perhaps you can get inspiration from:

https://gist.github.com/mrg/4dce22b67175c27f4047#file-cayenneutils-java-L73

Note: This was written for Cayenne 3.0, so 3.1/4.0 might be slightly
different.

mrg


On Tue, Apr 18, 2017 at 10:52 AM, Mark Wardle  wrote:

> Is there a simple way of getting the value of a property as committed
> rather than the current property value?
>
> Many thanks,
>
> Mark
>
>


Re: Validation and @PrePersist

2017-03-01 Thread Michael Gentry
Hi Maik,

I've historically done data manipulations in the lifecycle events
(pre-persist, post-add, post-load, etc) and not the validate methods.  I
kind of agree with you that validate shouldn't be modifying data.  I'm
hoping someone else explains the change now.  :-)

mrg


On Wed, Mar 1, 2017 at 11:43 AM, Musall, Maik  wrote:

> Hi all,
>
> but isn't hte purpose of validation to check if the object to be saved is
> in a valid state? That would imply that validation has a positive (pass) or
> negative (ValidationException) result, and no side effects. Modifying the
> object during validation would defeat the purpose, wouldn't it?
>
> Maik
>
> > Am 01.03.2017 um 17:12 schrieb Matt Watson :
> >
> > When I ran into this same scenario I realized that “validateForInsert”
> was the hook I needed, instead of @PrePersist.
> >
> > @Override
> > public void validateForInsert(ValidationResult validationResult) {
> >   if (getReference() == null || getReference().isEmpty()) {
> >   setReference(System.getNextPurchaseOrderReference());
> >   }
> >   super.validateForInsert(validationResult);
> > }
> >
> >
> >
> >> On Mar 1, 2017, at 5:51 AM, Hugi Thordarson  wrote:
> >>
> >> Hi Jurgen,
> >> fine suggestion but unfortunately not the part of the lifecycle I need
> to catch—the action needs to be performed before committing, not after
> adding (so basically I need @PrePersist—but I need it before validation
> happens).
> >>
> >> Cheers,
> >> - hugi
> >>
> >>
> >>> On 1. mar. 2017, at 13:14,  
> wrote:
> >>>
> >>> Hi Hugi
> >>>
> >>> For this kind of thing use @PostAdd instead.
> >>>
> >>> Regards
> >>> Jurgen
> >>>
> >>>
> >>> -Original Message- From: Hugi Thordarson
> >>> Sent: Wednesday, March 1, 2017 1:18 PM
> >>> To: user@cayenne.apache.org
> >>> Subject: Validation and @PrePersist
> >>>
> >>> Hi all,
> >>> I have some logic in a Listener that uses @PrePersist to populate the
> value of a required attribute before committing changes. Turns out this
> doesn’t work, since Cayenne invokes validateForInsert() before running
> @PrePersist.
> >>>
> >>> Any suggestions for where I can invoke logic populates required values
> before validation?
> >>>
> >>> Cheers,
> >>> - hugi
> >>
> >
>
>


Re: Validation and @PrePersist

2017-03-01 Thread Michael Gentry
Hi Hugi,

I was indeed looking at < 4.  No idea why the change was made.  Perhaps
someone else can answer that one...

Thanks,

mrg


On Wed, Mar 1, 2017 at 10:03 AM, Hugi Thordarson <h...@godurkodi.is> wrote:

> Hi Michael,
> the documentation was apparently changed for 4.0 in 2015 to reflect the
> current behaviour:
>
> https://github.com/apache/cayenne/commit/5bb12cd36f0d87e3b217cdc20c22a0
> f6dc9613f3#diff-5b9a57288e30ef9855d80a63a812ec4f
>
> Cheers,
> - hugi
>
>
> > On 1. mar. 2017, at 14:59, Michael Gentry <blackn...@gmail.com> wrote:
> >
> > Hi Hugi,
> >
> > If validateForInsert() is being called before PrePersist, we have a
> > disconnect between the documentation and the behavior you are seeing:
> >
> > "PrePersist: right before a new object is committed, inside
> > ObjectContext.commitChanges() and ObjectContext.commitChangesToParent()
> > (and prior to validateForInsert())."
> >
> > What version of Cayenne are you using?  I wonder if something has changed
> > or if the documentation is just wrong.
> >
> > Thanks,
> >
> > mrg
> >
> >
> >
> > On Wed, Mar 1, 2017 at 6:18 AM, Hugi Thordarson <h...@godurkodi.is>
> wrote:
> >
> >> Hi all,
> >> I have some logic in a Listener that uses @PrePersist to populate the
> >> value of a required attribute before committing changes. Turns out this
> >> doesn’t work, since Cayenne invokes validateForInsert() before running
> >> @PrePersist.
> >>
> >> Any suggestions for where I can invoke logic populates required values
> >> before validation?
> >>
> >> Cheers,
> >> - hugi
>
>


Re: Validation and @PrePersist

2017-03-01 Thread Michael Gentry
Hi Hugi,

If validateForInsert() is being called before PrePersist, we have a
disconnect between the documentation and the behavior you are seeing:

"PrePersist: right before a new object is committed, inside
ObjectContext.commitChanges() and ObjectContext.commitChangesToParent()
(and prior to validateForInsert())."

What version of Cayenne are you using?  I wonder if something has changed
or if the documentation is just wrong.

Thanks,

mrg



On Wed, Mar 1, 2017 at 6:18 AM, Hugi Thordarson  wrote:

> Hi all,
> I have some logic in a Listener that uses @PrePersist to populate the
> value of a required attribute before committing changes. Turns out this
> doesn’t work, since Cayenne invokes validateForInsert() before running
> @PrePersist.
>
> Any suggestions for where I can invoke logic populates required values
> before validation?
>
> Cheers,
> - hugi


Re: Switching SQL logging on/off at runtime

2017-02-17 Thread Michael Gentry
Ours allows us to specify an arbitrary string, too, in case we forget a
logger or need to fine-tune it more.  Just a suggestion.  :-)


On Fri, Feb 17, 2017 at 9:29 AM, Musall, Maik <m...@selbstdenker.ag> wrote:

> Hi Michael,
>
> I have a similar thing in mine, but somehow the Cayenne loggers weren't
> included in that list yet.
>
> Maik
>
>
> > Am 17.02.2017 um 14:39 schrieb Michael Gentry <blackn...@gmail.com>:
> >
> > Hi Maik,
> >
> > One thing we put in the administrative pages for all of our applications
> is
> > the ability to set logger levels at runtime (not just Cayenne, but any of
> > them).  Allows us to have a "reasonable" default most of the time,
> > especially in production, but then be able to change dynamically if we
> need
> > to troubleshoot.
> >
> > mrg
> >
> >
> > On Thu, Feb 16, 2017 at 4:53 PM, Musall, Maik <m...@selbstdenker.ag>
> wrote:
> >
> >> Of course, thanks. Works!
> >>
> >>> Am 16.02.2017 um 21:22 schrieb John Huss <johnth...@gmail.com>:
> >>>
> >>> Use the log4j api.  Something like RootLogger.getLogger("org.
> >> apache.cayenn
> >>> e.access.QueryLogger").setLevel(Level.INFO)
> >>>
> >>> On Thu, Feb 16, 2017 at 2:53 PM Musall, Maik <m...@selbstdenker.ag>
> >> wrote:
> >>>
> >>>> Hi all,
> >>>>
> >>>> like recommended in
> >>>> https://cayenne.apache.org/docs/3.0/configuring-logging.html, I use
> >> these
> >>>> properties to control the logging of SQL:
> >>>>
> >>>> log4j.logger.org.apache.cayenne.access.QueryLogger = WARN
> >>>> log4j.logger.org.apache.cayenne = WARN
> >>>>
> >>>> How would I switch SQL logging on from within the application at
> >> runtime?
> >>>>
> >>>> Thanks
> >>>> Maik
> >>>>
> >>>>
> >>
> >>
>
>


Re: Switching SQL logging on/off at runtime

2017-02-17 Thread Michael Gentry
Hi Maik,

One thing we put in the administrative pages for all of our applications is
the ability to set logger levels at runtime (not just Cayenne, but any of
them).  Allows us to have a "reasonable" default most of the time,
especially in production, but then be able to change dynamically if we need
to troubleshoot.

mrg


On Thu, Feb 16, 2017 at 4:53 PM, Musall, Maik  wrote:

> Of course, thanks. Works!
>
> > Am 16.02.2017 um 21:22 schrieb John Huss :
> >
> > Use the log4j api.  Something like RootLogger.getLogger("org.
> apache.cayenn
> > e.access.QueryLogger").setLevel(Level.INFO)
> >
> > On Thu, Feb 16, 2017 at 2:53 PM Musall, Maik 
> wrote:
> >
> >> Hi all,
> >>
> >> like recommended in
> >> https://cayenne.apache.org/docs/3.0/configuring-logging.html, I use
> these
> >> properties to control the logging of SQL:
> >>
> >> log4j.logger.org.apache.cayenne.access.QueryLogger = WARN
> >> log4j.logger.org.apache.cayenne = WARN
> >>
> >> How would I switch SQL logging on from within the application at
> runtime?
> >>
> >> Thanks
> >> Maik
> >>
> >>
>
>


Re: Creating a fault for an ObjectId

2017-02-15 Thread Michael Gentry
Hi Maik,

Would it be possible to use child DataContexts and then push the changes up
to the parent?


On Wed, Feb 15, 2017 at 11:17 AM, Musall, Maik  wrote:

> The use case is as follows.
>
> I have a large collection of objects which I want some function to be
> executed on. I want to use multiple threads to do this, so AFAIK I have to
> use separate ObjectContexts per thread like in EOF. So, I will then
> instantiate those objects in the per-thread contexts, do the processing,
> but then the wrapper function should return the entire collection of
> processed objects in the original context that they were in at the
> beginning.
>
> With EOF, I have a snapshot cache that will contain the changed
> attributes, but the EO instances in the original context have their
> original values. So, I will then call ec.faultForGlobalID() to have them
> refaulted from the snapshot cache, avoiding to refetch 100.000 objects from
> db.
>
> I suppose using a shared cache would make the problem obsolete, as those
> objects would receive changed attributes automatically, but I'm still on
> the fence whether or not to use a shared cache, because it's a major
> behavioural difference to EOF and I still have to think about that while
> migrating my project.
>
> Maik
>
>
> > Am 15.02.2017 um 15:49 schrieb Ken Anderson  >:
> >
> > Yes, use the objectID to pass around, but on the receiving end, you
> should turn it into a fault and release it into the wild.  Then, if some
> code needs it, the fault fires, otherwise – no DB activity.
> >
> > Ken Anderson
> > CTO Amphora, Inc.
> > Mobile:   +1 914 262 8540
> >
> >
> >
> > www.amphorainc.com 
> >
> >
> >
> >
> > On 2/15/17, 10:47 AM, "Amedeo Mantica"  wrote:
> >
> >I would just use the ObjectId
> >
> >> On 15 Feb 2017, at 16:45, Hugi Thordarson  wrote:
> >>
> >> It can be useful in some cases—one example is if you want to be able to
> pass objects around in an API without triggering a DB fetch unless they are
> actually used.
> >>
> >> Cheers,
> >> - hugi
> >>
> >>
> >>> On 15. feb. 2017, at 15:28, Amedeo Mantica 
> wrote:
> >>>
> >>> no worries, but I cannot understand your goal, why do you want to get
> the fault ?
> >>>
>  On 15 Feb 2017, at 16:25, Hugi Thordarson  wrote:
> 
>  Thanks Ken, but the immediate fetch performed by Cayenne.objectForPk
> is precisely what I’d like to avoid.
> 
>  Cheers,
>  - hugi
> 
>  S: Amedeo, sorry about calling you “Amadeo” in my last post. I have
> been properly lambasted.
> 
> 
> > On 15. feb. 2017, at 15:20, Ken Anderson <
> ken.ander...@amphorainc.com> wrote:
> >
> > I do this:
> >
> > dataObject = (DataObject) Cayenne.objectForPK(getObjectContext(),
> MyEntity.class, oid);
> >
> > But it will do the fetch if it’s not already in cache.
> >
> > Ken
> >
> > Ken Anderson
> > CTO Amphora, Inc.
> > Mobile:   +1 914 262 8540
> >
> >
> >
> > www.amphorainc.com 
> >
> >
> >
> >
> > On 2/15/17, 9:59 AM, "Hugi Thordarson"  wrote:
> >
> > Thanks Amadeo, but I ended up creating a method that looks like
> this. It would be nice to get some feedback on it, if I’m violating any
> Cayenne Commandments.
> >
> > /**
> > * @return An existing object or fault if registered with the OC,
> otherwise creates a new hollow object based on the given ObjectId.
> > */
> > public static Persistent faultForObjectId( ObjectContext oc,
> ObjectId objectId ) {
> > Persistent object = (Persistent) oc.getGraphManager().getNode(
> objectId );
> >
> > if( object == null ) {
> > ClassDescriptor descriptor = oc.getEntityResolver().
> getClassDescriptor(objectId.getEntityName());
> >
> > object = (Persistent) descriptor.createObject();
> >
> > object.setPersistenceState(PersistenceState.HOLLOW);
> > object.setObjectContext(oc);
> > object.setObjectId(objectId);
> >
> > oc.getGraphManager().registerNode(objectId, object);
> > }
> >
> > return object;
> > }
> >
> > Cheers,
> > - hugi
> >
> >
> >> On 15. feb. 2017, at 14:41, Amedeo Mantica 
> wrote:
> >>
> >> may be you want invalidateObject ?
> >>
> >>> On 15 Feb 2017, at 14:15, Hugi Thordarson 
> wrote:
> >>>
> >>> Hi all,
> >>> I need to get a fault for an ObjectId from an ObjectContext. How
> would I do this?
> >>>
> >>> I don’t see any public API for this—the implementation of
> createFault in CayenneContext seems to get me halfway there, but it will
> not return an existing fault, only create new ones.
> >>>
> >>> Cheers,
> >>> - hugi
> >>
> >
> >
> >
> > Confidentiality 

Re: Checking what attributes have changed in a DataObject

2017-02-14 Thread Michael Gentry
Oh, I guess that version uses a logger.  I have several versions lying
around.  Still, same mechanics apply.

mrg


On Tue, Feb 14, 2017 at 11:18 AM, Michael Gentry <mgen...@masslight.net>
wrote:

> Something similar to this?
>
> https://gist.github.com/mrg/4dce22b67175c27f4047#file-
> cayenneutils-java-L149
>
> It uses stdout since I was mainly using it as a debugging tool.
>
>
> On Tue, Feb 14, 2017 at 11:04 AM, Hugi Thordarson <h...@karlmenn.is>
> wrote:
>
>> Hi all,
>> is there some easy way for me in Cayenne to get information (for example
>> a Map) about changes that have been made to a DataObject since it was
>> fetched?
>>
>> Cheers,
>> - hugi
>
>
>


Re: Checking what attributes have changed in a DataObject

2017-02-14 Thread Michael Gentry
Something similar to this?

https://gist.github.com/mrg/4dce22b67175c27f4047#file-cayenneutils-java-L149

It uses stdout since I was mainly using it as a debugging tool.


On Tue, Feb 14, 2017 at 11:04 AM, Hugi Thordarson  wrote:

> Hi all,
> is there some easy way for me in Cayenne to get information (for example a
> Map) about changes that have been made to a DataObject since it was fetched?
>
> Cheers,
> - hugi


Re: Generic dictionary data with entities?

2017-02-10 Thread Michael Gentry
On Fri, Feb 10, 2017 at 3:08 PM, John Huss  wrote:

> Another option is to create a separate file and put things there, like a
> properties file or a json document or something.  It's not a bad solution.
>

Yeah, I was just answering the question about the CM file itself.  Either
create or own properties or YAML or similar.

mrg


Re: Generic dictionary data with entities?

2017-02-10 Thread Michael Gentry
Hi Ken,

This isn't doable in CM currently, but is a future goal (at least of mine):

https://github.com/apache/cayenne-modeler

Just haven't gotten there yet.

mrg


On Fri, Feb 10, 2017 at 2:09 PM, Ken Anderson 
wrote:

> All,
>
>
>
> In EOF, I used to decorate entities with additional data in the uerInfo of
> the entities.  Right now, I would like to add the entity name of the alias
> entity to the model, so I can access it in the apps.
>
>
>
> Is there an equivalent function in Cayenne?  I couldn’t find any way to
> add user info to an entity in the modeler.
>
>
>
> For example, we have an entity Location, and there’s an entity called
> LocationAlias.  Rather than put a static string in Location for
> LocationAlias, I’d rather put something in the model so a generic method
> could find entities based on alias values.
>
>
>
> Thanks,
>
> Ken
>
>
>
>
>
> *Ken Anderson*
>
> CTO Amphora, Inc.
>
> Mobile:   +1 914 262 8540 <(914)%20262-8540>
>
>
>
> [image: id:image001.png@01CE8142.D18AEB10]
>
>
> www.amphorainc.com
>
>
> Confidentiality Notice: This e-mail and accompanying documents contain
> confidential information intended for a specific individual and purpose.
> This e-mailed information is private and protected by law. If you are not
> the intended recipient, you are hereby notified that any disclosure,
> copying, or distribution, or the taking of any action based on the contents
> of this information, is strictly prohibited.
>


Re: Cayenne and migrations

2017-02-09 Thread Michael Gentry
Yeah, all of our migration scripts are hand-coded SQL that we let Flyway
then manage.  We don't have the option of having the application run the
migration scripts.  We have to get one of our DBAs to do it using an admin
account so they can create/drop/etc anything required, so we have set them
up to be able to run Flyway migrations for us.



On Thu, Feb 9, 2017 at 10:36 AM, John Huss <johnth...@gmail.com> wrote:

> I'm developing and using cayenne-migrations. It works fine for me and has a
> very similar approach to ERXMigrations.  I don't think others are using it
> though.  It has the advantage of being able to auto-generate the migration
> code from your cayenne model (DataMap), where I think the others require
> hand coding.  On the other hand, sometimes having all pure SQL statements
> instead of mostly java code is useful.  Good luck!
>
> John
>
> On Thu, Feb 9, 2017 at 9:15 AM Michael Gentry <mgen...@masslight.net>
> wrote:
>
> > Hi Hugi,
> >
> > We manage schema changes outside of Cayenne using Flyway (could also use
> > Liquibase).  Any schema changes we make are updated by hand in Cayenne
> > Modeler.  This works fairly well for us and fits in with our automated
> > builds/etc.  Perhaps not the answer you were looking for, though!
> >
> > mrg
> >
> >
> > On Thu, Feb 9, 2017 at 9:21 AM, Hugi Thordarson <h...@karlmenn.is>
> wrote:
> >
> > > Hi all.
> > > In EOF/WOnder we have the most swesome ERXMigrations to manage changes
> in
> > > the data model between versions, i.e. upgrades of the schema (and
> > > downgrades, if applicable).
> > >
> > > I see that some years ago there was discussion of an API to handle this
> > in
> > > Cayenne ( http://svn.apache.org/repos/asf/cayenne/sandbox/cayenne-
> > > migrations/ ). but how’s the situation today? Is there something in/for
> > > Cayenne to do this, and if not, what tools are people using to manage
> > > versioning of their DB schemas?
> > >
> > > Cheers,
> > > - hugi
> >
>


  1   2   3   4   5   6   7   >