Shared EC woes (was: Flattened one-side M:N fails wildly with SharedEC)

2018-09-28 Thread o...@ocs.cz
 in the code for all I know; the Schrödinger EOF 
> behaviour did bit me once or twice already :) it does seem very weird to me 
> that the flattened thing should be the culprit; that's why I am asking 
> whether such kind of behaviour is to be expected, or whether I should try to 
> hunt for the culprit elsewhere.
>  
> Thanks and all the best,
> OC
> 
> 
> 
>  
> From: Webobjects-dev 
>  <mailto:webobjects-dev-bounces+chill=gevityinc@lists.apple.com>> on 
> behalf of "ocs@ocs" mailto:o...@ocs.cz>>
> Date: Wednesday, August 29, 2018 at 8:28 AM
> To: WebObjects-Dev Mailing List  <mailto:webobjects-dev@lists.apple.com>>
> Subject: Flattened one-side M:N fails wildly with SharedEC
>  
> Hi there, 
>  
> just have bumped into another weird (at least to me) behaviour.
>  
> In my model, there used to be a very standard M:N relationship, which 
> exploits an “invisible” intermediate table, flattened “direct” relationships 
> ad both sides.
>  
> One of the sides lately went to the sharedEC; thus I made sure to delete this 
> side's flattened relationship. The other side and the intermediate table both 
> stay outside of the sharedEC, so I thought that is all right.
>  
> It failed miserably with “The shared context recently initialized the object 
>  which is already registered in this context yadda yadda”, 
> i.e., EOF for some godforsaken reason kept loading the non-shared object (the 
> one whose relationship remained intanct) into SEC along with the shared one 
> (whose relationship were removed all right, no traces remained; I have 
> checked about zillion times).
>  
> Out of desperation, I have just tried to remov the flattened relationship 
> from the non-shared side, exposing instead the intermediate table, and 
> replacing the flattened relationship by something like
>  
> ===
> List availablePrototypes { // this is how the original flattened rel has 
> been named
> def mn=this.db_Prototype_DataBlock // 1:N relationship to the 
> intermediate table, exposed
> mn.collect {
> it.valueForKey('prototype') // N:1 relationship from the inmdt 
> table to the shared object
> }
> }
> ===
>  
> and it seems to work all right :-O So, it looks like the culprit was the 
> existence of the flattened rel with definiton 
> “db_Prototype_DataBlock.prototype” at the non-shared side.
>  
> Is that the intended behaviour? Seems pretty weird to me, but as always, I 
> might be overlooking something of importance. Or should that work even with 
> the flattened relationship, and the problems mean I must have done something 
> wrong elsewhere?
>  
> Thanks and all the best,
> OC
>  
> ___
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com 
> <mailto:Webobjects-dev@lists.apple.com>)
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/webobjects-dev/ocs%40ocs.cz 
> <https://lists.apple.com/mailman/options/webobjects-dev/ocs%40ocs.cz>
> 
> This email sent to o...@ocs.cz <mailto:o...@ocs.cz>
 ___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


handleQueryWithUnboundKey override for 3rd party objects?

2018-09-25 Thread o...@ocs.cz
Hi there,

is there any hook WO- or WOnder-side, which would allow me to catch 
handleQueryWithUnboundKey for 3rd party objects?

Something like to be able to set up a (presumably static) method with a 
signature (Object object,String key), which would get called by the framework 
whenever an object which does not conform to NSKeyValueCoding.ErrorHandling 
would normally cause an NSKeyValueCoding.UnknownKeyException, and could either 
raise the exception itself, or return a replacement result object?

Thanks a lot and all the best,
OC

 ___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: SSL and port fun

2017-04-07 Thread o...@ocs.cz
Chuck,

(as always to the rescue, you the man! Thanks!)

> On 7. 4. 2017, at 6:41 PM, Chuck Hill <ch...@gevityinc.com> wrote:
> Is there a SSL terminating proxy or load balancer in front of the new 
> installation?

Absolutely no idea :( Aside of asking the side admin, might I check somehow?

> x-forwarded-port is more standard and dependable in that case.  The other 
> headers are from mod_webobjects.  

Just making sure I am not misunderstanding you, this means I should check the 
x-forwarded-port header first, and if it is 443, can I safely ignore 
server_port (not speaking of x-webobjects-server-port) and assume the access to 
application was SSL-protected, right?

Thanks again a big lot,
OC

> On 2017-04-07, 9:31 AM, "Webobjects-dev on behalf of OC" 
> <webobjects-dev-bounces+chill=gevityinc....@lists.apple.com on behalf of 
> o...@ocs.cz> wrote:
> 
>Hi there,
> 
>my ages-old code to support SSL
> 
>- gets the request
>- checks its server_port and x-webobjects-server-port headers
>- if at least one of them is 443, we were accessed under SSL and all is 
> well and swell. Otherwise, it generates 302 and HTTPS URL to re-direct to the 
> same page under SSL.
> 
>So far it worked like a charm for long long years. Now I am told that on a 
> new installation on a new product server (I believe it is a Mac OS X 10.11) 
> the redirections keep coming. Having added extra logs, I have found that
> 
>(a) the server_port is always 80, even when the application is accessed 
> through HTTPS
>(b) nevertheless, the request contains a header x-forwarded-port with the 
> proper value of 443
> 
>Does someone here understand this stuff?
> 
>Should I check the x-forwarded-port header first, and if it is 443, can I 
> safely ignore server_port and assume the access to application was 
> SSL-protected?
> 
>Or should I tell them they need to fix their Apache settings, or whatever?
> 
>Thanks a lot,
>OC
> 
> ___
>Do not post admin requests to the list. They will be ignored.
>Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
>Help/Unsubscribe/Update your Subscription:
>
> https://lists.apple.com/mailman/options/webobjects-dev/chill%40gevityinc.com
> 
>This email sent to ch...@gevityinc.com
> 
> 

 ___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: using value conversion/factory to encode objects in blobs

2017-02-25 Thread o...@ocs.cz
D'oh. Thanks a lot!

OC

> On 25. 2. 2017, at 7:01 PM, Fabian Peters <lists.fab...@e-lumo.com> wrote:
> 
> Try "blobDictionary"… ;-)
> 
>> Am 25.02.2017 um 17:56 schrieb o...@ocs.cz:
>> 
>> Thanks! But... sorry for me being stupid, but where do I find them? Google 
>> can't find the former at all suggesting I really wanted “blood dictionary”; 
>> as for the latter, there's the opposite problem -- zillions of hits, among 
>> which the proper one _might perhaps_ be hidden somewhere...
>> 
>> All the best,
>> OC
>> 
>>> On 25. 2. 2017, at 6:32 PM, George Domurot <g...@knuckleheads.net> wrote:
>>> 
>>> Use the Prototype of blodDictionary or mutableDictionary to do the heavy 
>>> lifting for you.
>>> 
>>> -G
>>> 
>>> 
>>>> On Feb 25, 2017, at 8:19 AM, o...@ocs.cz wrote:
>>>> 
>>>> Hi there,
>>>> 
>>>> this must be WebObjects 101 and I must be blind as a bat, but ... how on 
>>>> earth does one use the value conversion/factory model support to represent 
>>>> e.g., an attribute containing an NSDictionary (or another custom data 
>>>> object) by a BLOB containing archived data?
>>>> 
>>>> Far as I understand the support, I specify the desired EO-side class, plus 
>>>> an instance method to archive it to NSData, plus a class method (in 
>>>> Javaspeak presumably a static one) to initialise an instance from NSData. 
>>>> But... there are no such methods far as I know for most data classes. 
>>>> E.g., I would need something like
>>>> 
>>>> class NSDictionary ... {
>>>> static NSDictionary theMethodToBeUsedForValueFactory(NSData data) {
>>>> ByteArrayInputStream bis=new ByteArrayInputStream(data.bytes())
>>>> ObjectInputStream is=new ObjectInputStream(bis)
>>>> return objectInputStream.readObject()
>>>> }
>>>> NSData theMethodToBeUsedForValueConversion() {
>>>> ByteArrayOutputStream bos=new ByteArrayOutputStream();
>>>> ObjectOutputStream os=new ObjectOutputStream(bos)
>>>> os.writeObject(this)
>>>> os.flush()
>>>> return new NSData(bos.toByteArray())
>>>> }
>>>> }
>>>> 
>>>> none of which, far as I know, actually exists. In Objective C the solution 
>>>> would be trivial, I would simply add appropriate methods through a 
>>>> category; but the bloody Java thing has no similar support.
>>>> 
>>>> What am I missing and how does one solve this?
>>>> 
>>>> Thanks a lot,
>>>> OC
>>>> 
>>>> 
>>>> ___
>>>> Do not post admin requests to the list. They will be ignored.
>>>> Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
>>>> Help/Unsubscribe/Update your Subscription:
>>>> https://lists.apple.com/mailman/options/webobjects-dev/mastermind%40knuckleheads.net
>>>> 
>>>> This email sent to masterm...@knuckleheads.net
>>> 
>> 
>> 
>> ___
>> Do not post admin requests to the list. They will be ignored.
>> Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
>> Help/Unsubscribe/Update your Subscription:
>> https://lists.apple.com/mailman/options/webobjects-dev/lists.fabian%40e-lumo.com
>> 
>> This email sent to lists.fab...@e-lumo.com
> 


 ___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: using value conversion/factory to encode objects in blobs

2017-02-25 Thread o...@ocs.cz
Thanks! But... sorry for me being stupid, but where do I find them? Google 
can't find the former at all suggesting I really wanted “blood dictionary”; as 
for the latter, there's the opposite problem -- zillions of hits, among which 
the proper one _might perhaps_ be hidden somewhere...

All the best,
OC

> On 25. 2. 2017, at 6:32 PM, George Domurot <g...@knuckleheads.net> wrote:
> 
> Use the Prototype of blodDictionary or mutableDictionary to do the heavy 
> lifting for you.
> 
> -G
> 
> 
>> On Feb 25, 2017, at 8:19 AM, o...@ocs.cz wrote:
>> 
>> Hi there,
>> 
>> this must be WebObjects 101 and I must be blind as a bat, but ... how on 
>> earth does one use the value conversion/factory model support to represent 
>> e.g., an attribute containing an NSDictionary (or another custom data 
>> object) by a BLOB containing archived data?
>> 
>> Far as I understand the support, I specify the desired EO-side class, plus 
>> an instance method to archive it to NSData, plus a class method (in 
>> Javaspeak presumably a static one) to initialise an instance from NSData. 
>> But... there are no such methods far as I know for most data classes. E.g., 
>> I would need something like
>> 
>> class NSDictionary ... {
>> static NSDictionary theMethodToBeUsedForValueFactory(NSData data) {
>>   ByteArrayInputStream bis=new ByteArrayInputStream(data.bytes())
>>   ObjectInputStream is=new ObjectInputStream(bis)
>>   return objectInputStream.readObject()
>> }
>> NSData theMethodToBeUsedForValueConversion() {
>>   ByteArrayOutputStream bos=new ByteArrayOutputStream();
>>   ObjectOutputStream os=new ObjectOutputStream(bos)
>>   os.writeObject(this)
>>   os.flush()
>>   return new NSData(bos.toByteArray())
>> }
>> }
>> 
>> none of which, far as I know, actually exists. In Objective C the solution 
>> would be trivial, I would simply add appropriate methods through a category; 
>> but the bloody Java thing has no similar support.
>> 
>> What am I missing and how does one solve this?
>> 
>> Thanks a lot,
>> OC
>> 
>> 
>> ___
>> Do not post admin requests to the list. They will be ignored.
>> Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
>> Help/Unsubscribe/Update your Subscription:
>> https://lists.apple.com/mailman/options/webobjects-dev/mastermind%40knuckleheads.net
>> 
>> This email sent to masterm...@knuckleheads.net
> 


 ___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

using value conversion/factory to encode objects in blobs

2017-02-25 Thread o...@ocs.cz
Hi there,

this must be WebObjects 101 and I must be blind as a bat, but ... how on earth 
does one use the value conversion/factory model support to represent e.g., an 
attribute containing an NSDictionary (or another custom data object) by a BLOB 
containing archived data?

Far as I understand the support, I specify the desired EO-side class, plus an 
instance method to archive it to NSData, plus a class method (in Javaspeak 
presumably a static one) to initialise an instance from NSData. But... there 
are no such methods far as I know for most data classes. E.g., I would need 
something like

class NSDictionary ... {
  static NSDictionary theMethodToBeUsedForValueFactory(NSData data) {
ByteArrayInputStream bis=new ByteArrayInputStream(data.bytes())
ObjectInputStream is=new ObjectInputStream(bis)
return objectInputStream.readObject()
  }
  NSData theMethodToBeUsedForValueConversion() {
ByteArrayOutputStream bos=new ByteArrayOutputStream();
ObjectOutputStream os=new ObjectOutputStream(bos)
os.writeObject(this)
os.flush()
return new NSData(bos.toByteArray())
  }
}

none of which, far as I know, actually exists. In Objective C the solution 
would be trivial, I would simply add appropriate methods through a category; 
but the bloody Java thing has no similar support.

What am I missing and how does one solve this?

Thanks a lot,
OC


 ___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Raw row fetch returns NSData instead of String for a derived attribute through a relationship?!?

2016-12-02 Thread o...@ocs.cz
Hi there,

I am fetching raw rows. Most time, it works well, but I have bumped into a 
pretty weird behaviour with a derived attribute. The attribute is defined like 
this:

===
{
className = NSString;
definition = "CAST(C_AUCTION_SEQ as VARCHAR(18))";
externalType = "CHAR VARYING";
name = ceboisAuctionId;
valueType = S;
width = 256;
}
===

(the actual definition is much more complex, but the one above sports the 
problem as well; also, I have tried both with valueType=S as shown above and 
without a valueType for String/stream default.)

If I fetch raw rows _directly from the table_ which contains the attribute, it 
works perfectly, I get strings for 'ceboisAuctionId' in the dictionaries -- in 
my raw row dictionaries there are things like e.g., "ceboisAuctionId:28", all 
right.

Nevertheless, if I fetch _another_ table which contains a relationship :1 
'auction' into this table, and if I add 'auction.ceboisAuctionId' to 
fetchSpec.rawRowKeyPaths, I do get the proper value -- but _encoded in NSData_! 
In this case, in my raw row dictionaries there are things like e.g., 
"auction.ceboisAuctionId:" :-O

This does not happen with normal (non-derived) columns of the same type: e.g., 
for a column

===
{
allowsNull = Y;
className = NSString;
columnName = "C_TITLE";
externalType = "CHAR VARYING";
name = title;
width = 256;
}
===

those I get proper strings in both cases, i.e., regardless they are fetched 
directly from the table, or indirectly through a relationship from another 
table, in my raw row dictionaries there are always things like 
"title:Something" or "auction.title:Something".

Does it make any sense? Could I fix something in my model to get the values 
properly converted even if fetched through a relationship and a derived 
attribute?

Thanks and all the best,
OC


 ___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

subEntityForEntity never called?

2016-10-30 Thread o...@ocs.cz
Hello there,

I must be missing something darn obvious, for my subEntityForEntity delegate 
method never gets called. My code looks like this:

===
class ModelGroupDelegate {
EOEntity subEntityForEntity(EOEntity entity,NSDictionary dic) {
println "&& fetching '$entity' $dic"
null
}
}
... ... ...
mdg.delegate=new ModelGroupDelegate()
println "&& MY MDG DELEGATE: ${mdg.delegate()}"
EOEntity rece=mdg.entityNamed('DBRecord')
println "&& subentities of $rece.name: $rece.subEntities.count: 
$rece.subEntities.name"
EOEntity rec2=mdg.entityNamed('DBRecord2')
EOEntity rec3=mdg.entityNamed('DBRecord3')
println "&& r2p($rec2.name) $rec2.parentEntity.name / r3p($rec3.name) 
$rec3.parentEntity.name"
def fs=new EOFetchSpecification('DBRecord',null,null)
fs.fetchLimit=10 // there's a LOT of records, limiting for test
def got=new ERXEC().objectsWithFetchSpecification(fs) // should use 
subEntityForEntity, should it not?!?
println "&& fetched $got.count objects all right in entities 
${got*.entityName()}"
System.exit(0)
===

and it never tries to call subEntityForEntity; instead, for whatever darned 
reason, it forces DBRecord3:

===
&& MY MDG DELEGATE: cz.ocs.model.ModelGroupDelegate@7db534f2
&& subentities of DBRecord: 2: [DBRecord3, DBRecord2]
&& r2p(DBRecord2) DBRecord / r3p(DBRecord3) DBRecord
&& fetched 10 objects all right in entities [DBRecord3, DBRecord3, 
DBRecord3, DBRecord3, DBRecord3, DBRecord3, DBRecord3, DBRecord3, DBRecord3, 
DBRecord3]
APPLICATION SHUTDOWN SEQUENCE COMPLETE


Any idea what might I be doing wrong?

Thanks a lot,
OC


 ___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

direct action URL without a session

2016-10-28 Thread o...@ocs.cz
Hello there,

the subject says it all — is there a decent way to construct a direct action 
URL from a code which has no session (and thus no context)? Note I need a full 
URL, not a relative one (it is to be used in diverse ways like “sent to client 
by an e-mail” etc.)

At the moment, I use

Application app=Application.application()
String 
url=app.cgiAdaptorURL+'/'+app.name+'/'+app.directActionRequestHandlerKey+'/'+directActionName+'?'+directActionAttributeName+'='+directActionAttributeValue

which sort of works, but is not too flexible (e.g., it stops working with 
direct access, where it lacks the port), it is very slightly incorrect (does 
not contain ".woa"; seems harmless, but still weird), and besides, is pretty 
ugly code (and would become far uglier with more attributes than one). Is there 
a better way?

Thanks,
OC


 ___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: log4j bug causes deadlock?!? (was: which sort of application bugs hang wotaskd?)

2016-10-25 Thread o...@ocs.cz
Hmmm, looks like we are not the only one who got bit by that thing in tender 
parts: http://stackoverflow.com/a/7397857

> On 25. 10. 2016, at 10:59 PM, OC <o...@ocs.cz> wrote:
> 
> Chuck,
> 
> On 24. 10. 2016, at 18:23, Chuck Hill <ch...@gevityinc.com> wrote:
> 
>> Running “sudo jstack –F ” should dump a trace of all threads.  
>> Should… 
> 
> Luckily, it did; just it is sort of weird that it identifies threads by name 
> in the deadlock report, but by some unknown ID (perhaps hash of the Thread 
> instance, looks like that) in the traces, which makes for sort of difficult 
> parsing. I guess I'm not the first one to swear :)
> 
>> ... As for the hang, the code in the logging does seem like a likely culprit.
> 
> Actually it looks like the culprit is log4j itself?!? What the heck! Anyroad, 
> here's the deadlock report:
> 
> ===
> "model.ReportPDFTask@5f6ce9a5":
>  waiting to lock Monitor@0x00012c0008a8 (Object@0x0003f7efb980, a 
> org/apache/log4j/spi/RootLogger),
>  which is held by "WorkerThread6"
> "WorkerThread6":
> waiting for ownable synchronizer 0x0003f9538960, (a 
> java/util/concurrent/locks/ReentrantLock$NonfairSync),
> which is held by "model.ReportPDFTask@5f6ce9a5"
> ===
> 
> the WorkerThread6 problem happens in the “log.info("$tch")” part, it looks 
> like this (and although changesFromCommittedSnapshot happens to be part of 
> the culprit, I believe the problem is actually caused by the logger itself): 
> instead of rendering its argument immediately, as soon as it is determined 
> that we should log, it does that self-evidently under a lock:
> 
> === Worker6 (cleaned up considerably) ===
> - er.extensions.eof.ERXEC.lockObjectStore() // the lock W6 [2] hangs on, 
> caused by...
> - er.extensions.eof.ERXGenericRecord.changesFromCommittedSnapshot() // ... 
> changesFromCommittedSnapshot ...
> - cz.ocs.model.OCSEnterpriseObject.toString() // ... which yours truly dumbly 
> uses in toString, alas!
> - org.apache.log4j.or.DefaultRenderer.doRender(java.lang.Object) // ... this 
> thing happens INSIDE of log4j code
> ... lot of frames here; self-evidently, some of them acquires and holds 
> Monitor@0x00012c0008a8 [1] ...
> - org.apache.log4j.Category.info(java.lang.Object) // this is the 
> log.info("$tch") of mine
> ... the loop and the other standard stuff up to dispatchRequest and 
> WOWorkerThread.run() ...
> ===
> 
> The "model.ReportPDFTask" actually does not do anything wrong (far as I can 
> say) -- it just fetches. A fetch presumably (and understandably) would lock 
> the object store. With locked object store, it... logs! (I do not think the 
> stack trace is important here; anyway, I have attached it at the end of this 
> message for reference.)
> 
> Nothing wrong there I believe, it feels right to be able to log with a locked 
> object store; but it causes deadlock, for the log tries to acquire its 
> Monitor@0x00012c0008a8 -- which is held by Worker6.
> 
> Now, although in my case the culprit happens to be unneeded (and generally 
> dangerous) changesFromCommittedSnapshot, I believe that
> 
> (a) whatever which locks object store in the log would cause deadlock just as 
> well
> (b) which can be e.g., a fault fired, or lots of other perfectly valid things 
> to log.
> 
> I do understand why log4j methods accept generic Object and render the result 
> inside -- it is reasonable not to render anything unless we want to log with 
> the current setting.
> 
> What seems to me to be a grave bug though is that this rendering happens 
> under a lock, which causes a deadlock if two threads log concurrently and it 
> so happens that
> 
> (i) one of them logs under object store lock (which I believe is valid and 
> correct)
> (ii) the other's log contents causes an object store lock (which again I 
> believe is valid and correct, see (a) and (b) above).
> 
> So, well, is there indeed a grave bug inside of the ubiquitous log4j, or am I 
> overlooking something of importance?
> 
> And if there is a bug, is there anything better one can do to work around it 
> than using toStrings for all non-trivial logs, like 
> “log.info("non-trivial-contents".toString())”, which would affect efficiency 
> pretty bad?
> 
> Thanks and all the best,
> OC
> 
> === "model.ReportPDFTask@5f6ce9a5" slightly cleaned up ===
> - org.apache.log4j.Category.callAppenders(org.apache.log4j.spi.LoggingEvent) 
> @bci=12, line=204 (Compiled frame) // hangs on Monitor@0x00012c0008a8, 
> which is held by [1] above
> - org.apache.log4j.Category.force

Re: which sort of application bugs hang wotaskd?

2016-10-24 Thread o...@ocs.cz
Thanks a lot both!

(weird, I would have bet wotaskd is designed to survive and detect and 
potentially even relaunch frozen apps, but well, my memory self-evidently plays 
ugly tricks on me.)

Anyway...

> On 24. 10. 2016, at 6:23 PM, Chuck Hill <ch...@gevityinc.com> wrote:
> This should explain the how and why (IIRC) 
> http://www.podcastchart.com/podcasts/webobjects-podcasts/episodes/wotaskd-internals-bringing-sanity-to-deployment

... I would not like to sound ungrateful, but might perhaps there be somewhere 
something similar in a written form? Thing is, English is not my native 
language, and whilst I succeeded to read pretty well, my listening abilities 
are, alas, quite another story :(
 
> And offer some fixes and improvements.  And like most (all?) of my WOWODC 
> presentations, never fully finished. 
> As for the hang, the code in the logging does seem like a likely culprit.  
> Running “sudo jstack –F ” should dump a trace of all threads.  
> Should… 

Thanks a lot, I'll ask the site admit to try, if the darned this happens again.

All the best,
OC

> From: <webobjects-dev-bounces+chill=gevityinc@lists.apple.com> on behalf 
> of OC <o...@ocs.cz>
> Date: Monday, October 24, 2016 at 8:41 AM
> To: WebObjects-Dev <webobjects-dev@lists.apple.com>
> Subject: which sort of application bugs hang wotaskd?
>  
> Hello there,
>  
> there seems to be one pretty rare, ugly and hard-to find lock in my 
> application (I shall get back to it at the end, in hope it might ring a 
> bell), but what's most weird: it seems that when it happens, it's _wotaskd_ 
> what primarily goes down?!?
>  
> Alas, the information is sparse: it is the deployment site, to where the 
> programming team has no access (and so far we were not able to repeat the 
> problem at the test site whatever we try), but due to the site admin and 
> logs, it looks like
>  
> (a) first, one of the worker threads hangs somehow, so far inexplicably (EC 
> locking problem possible but improbable, explained below)
> (b) for some time, other threads run without a glitch, new reqeusts are 
> served, new R/R loop worker threads are spawned and logged (I log out all R/R 
> loops)
> (c) shortly (in minutes) though the adaptor begins to redirect requests to 
> the “Redirection URL”
> (d) now, the site admin is alerted; he runs JavaMonitor **which reports 
> “Failed to contact 127.0.0.1-1085”**!
> (e) he finds which process belongs to *the application instance* (*not* the 
> wotaskd!), and kills it from Terminal
> (f) which causes wotaskd to magically cure and JavaMonitor starts working and 
> stops showing the 1085 fail, allows to re-launch the instance, all is well 
> and swell.
>  
> Does this perhaps ring a bell? To me this behaviour does not make any sense :/
>  
> As for the hang itself, it's rather weird too. There is a loop which goes 
> through a list of EOs; each of them is logged out. Something like this:
>  
> ===
> for (DBTimeChunk tch in session().currentMarket.orderedTimeChunks()) {
> log.info(""+tch)
> if (tch.someTimestamp>fixedTimestamp) continue // happens to be 
> true in our case
> ... therefore some irrelevant code here (it would log if it 
> happened, does not) ...
> }
> ===
>  
> The problem is that
>  
> - this goes through some of the TimeChunks, and _then_ it hangs -- not at the 
> start of R/R loop, where EC locking problems could be expected
> - in the same session, with the same EC, even in the same thread (for the 
> method which contains the loop happens to be used twice in the page template) 
> the loop already run through all the TimeChunks and tested their 
> someTimestamp and ended without a glitch (so, no fault is fired when it hangs)
>  
> So far it happened about thrice; each time on different TimeChunk.
>  
> About the only thing I guess _might_ cause the hang of the thread is the "log 
> tch". TimeChunk's toString() is comparatively complex, it might call, among 
> more mundane things, also
> - this.changesFromCommittedSnapshot()
> - this.attributeKeys()
> - this.primaryKey() (of ERXGenericRecord which it inherits)
>  
> Might one of them hang the thread, if another thread does the same/something 
> other at the wrong moment? (Presumed all of them were already called for the 
> same EO in the same thread all right shortly ago.)
>  
> If it happens again, it would help if the site admin could, before killing 
> the application, to force it somehow to log the stacktracks of all its 
> threads. Is there some trick for that?
>  
> And of course, for any other advice how to hunt for this bloody kind of bug 
> I'll be extremely grateful.
>  
> Thanks a lo

ERXExistsQualifier blocks *all coordinators* even before a SELECT?!?

2016-10-13 Thread o...@ocs.cz
Hello there,

just the very now, I have bumped into a weird problem.

I run some DB-intensive background tasks. So as they do not block the whole 
application, I set up 
er.extensions.ERXObjectStoreCoordinatorPool.maxCoordinators > 1, and my code

(a) gives one of the coordinators to all sessions (through 
sess.defaultEditingContext=ERXEC.newEditingContext(osc))

Since sessions rarely or never do long selects/inserts/whatever, there's no 
harm they share the coordinator.

(b) the background threads each get one of the remaining coordinators

Thus, the background threads (which _do_ _very_ long selects; actually, they do 
ERXEOControlUtilities.objectCountWithQualifier, involving joins) might block 
one another, but never block the sessions.

So far, it worked well. Today, in session, I used the ERXExistsQualifier -- and 
it looks like its usage blocks somehow until the background threads (which use 
different coordinators -- I did check) are done?!?

To me, it does not make any sense, but it works like this -- the following code 
(where qualifiedEOsSVM is just a thin shell over objectsWithFetchSpecification)

=== 1 ===
def me=new 
EOKeyValueQualifier('user',EOQualifier.QualifierOperatorEqual,session.currentUser)
def hasme=new ERXExistsQualifier(me,'userLinks')
Log "FETCH STARTS ..."
all=DBGenGeneratedItem.qualifiedEOsSVM(DBGenGeneratedItem, hasme, 
session.defaultEditingContext())
Log "...FETCH ENDS"
===

logs out something like this -- always the delay betw. the 1st and 2nd log 
(here about 4 seconds) is big, and always it is full of the thread logs:

=== 1 log ===
18:09:42.129 WARN  FETCH STARTS...   //log:NSLog [WorkerThread11]

... lots of “background-thread-did-end” logs here ...

18:09:46.936 DEBUG  === Begin Internal Transaction   //log:NSLog 
[WorkerThread11]
18:09:46.936 DEBUG  evaluateExpression: ... proper one with EXISTS ...  
//log:NSLog [WorkerThread11]
18:09:46.938 DEBUG 5 row(s) processed   //log:NSLog [WorkerThread11]
18:09:46.938 DEBUG  === Commit Internal Transaction   //log:NSLog 
[WorkerThread11]
18:09:46.944 WARN  ... FETCH DID END   //log:NSLog [WorkerThread11]
===

If I do not launch the threads at all, the log is always as expected, i.e., 
something like this (compare the delay)

=== 1 log, no background threads exist ===
18:14:35.079 WARN  FETCH STARTS...   //log:NSLog [WorkerThread4]
18:14:35.080 DEBUG  === Begin Internal Transaction   //log:NSLog 
[WorkerThread4]
===

If, instead of using the ERXExistsQualifier, I simply fetch all the rows and 
filter them programmatically, something like

=== 2 ===
def fs=new EOFetchSpecification('DBGenGeneratedItem',null,null)
NSLog.err.appendln "FETCH STARTS..."
all=session.defaultEditingContext().objectsWithFetchSpecification(fs)
NSLog.err.appendln "... FETCH DID END, FILTERING ..."
all=all.findAll {
it.userLinks.find { sess.currentUser==it.user }
}
NSLog.err.appendln "... FETCH AND FILTER DID END"
===

and run all the background threads as usually, _there is no delay again_, the 
log looks like this:

=== 2 log ===
18:18:49.722 WARN  FETCH STARTS...   //log:NSLog [WorkerThread8]
18:18:49.722 DEBUG  === Begin Internal Transaction   //log:NSLog 
[WorkerThread8]
18:18:49.722 DEBUG  evaluateExpression: ... SIMPLE ONE ...   //log:NSLog 
[WorkerThread8]
18:18:49.723 DEBUG 6 row(s) processed   //log:NSLog [WorkerThread8]
18:18:49.723 DEBUG  === Commit Internal Transaction   //log:NSLog 
[WorkerThread8]
18:18:49.731 WARN  ... FETCH DID END, FILTERING ...   //log:NSLog 
[WorkerThread8]
18:18:49.737 DEBUG  === Begin Internal Transaction   //log:NSLog 
[WorkerThread8]
18:18:49.737 DEBUG  evaluateExpression: ... SELECTing userLinks for 1st item 
...   //log:NSLog [WorkerThread8]
18:18:49.738 DEBUG 0 row(s) processed   //log:NSLog [WorkerThread8]
18:18:49.738 DEBUG  === Commit Internal Transaction   //log:NSLog 
[WorkerThread8]
... etc, other SQL transactions to select userLinks for the other items when 
filtering ...
18:18:49.750 WARN  ... FETCH AND FILTER DID END   //log:NSLog 
[WorkerThread8]

... lots of “background-thread-did-end” logs here ...
===

I must frankly admit I have no idea what the darn happens there -- it looks 
like there is some weird ERXExistsQualifier pre-processing, which waits for all 
the background threads which fetch inside different store coordinators?!?

Does it make any sense?

Thanks for any advice,
OC



 ___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

WORedirect with a known MIME type?

2016-10-09 Thread o...@ocs.cz
Hello there,

at the moment, my application can return a file to the user through

===
WOResponse downloadFile(String mimeType, File path) {
WOResponse wor=new WOResponse()
wor.setHeader("$mimeType; name=\"$path.name\"","content-type")
wor.setContent(path.getText("utf-8"))
wor.disableClientCaching()
wor.removeHeadersForKey("Cache-Control")
wor.removeHeadersForKey("cache-control")
wor.removeHeadersForKey("pragma")
wor
}
===

The 'path' though happens to map to an URL, accessible directly through the 
HTTP server (without a need to go through the application at all). Therefore, I 
would like to replace the code above by something like

===
WORedirect downloadFile(String mimeType, File path) {
WORedirect wor=new WORedirect(context())
wor.setUrl(URLForFile(path))
wor
}
===

to save, especially for bigger files, the memory and CPU. Nevertheless, I can't 
see any way how to set the MIME type; is there any trick to do that?

Thanks,
OC


 ___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

delete deny rule ignored?

2016-10-07 Thread o...@ocs.cz
Hello there,

is that normal that for a :N relationship *which is not a class property* EOF 
ignores EODeleteRuleDeny and deletes the object, happily leaving dangling 
foreign keys in the other table?

(Making the relationship a class property helps. Nevertheless, since the only 
purpose of the relationship is to prevent accidental deletion and it never ever 
is used explicitly in the code, it would be cleaner to keep it „invisible“, if 
it worked.)

Thanks,
OC


 ___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: EOF inserts already existing M:N relationships/empty snapshot?!?

2016-09-21 Thread o...@ocs.cz
Chuck,

> On 21. 9. 2016, at 10:47 PM, Chuck Hill <ch...@gevityinc.com> wrote:
> 
> Ooh.  I had forgotten about that.  Does that qualify as a Heisenbug?

Pretty much, I guess.

Matter of fact, after I found the culprit in one of my test clones, I have 
fixed it in the main application... ... ...and the fix did not work. What?!? 
D'oh: of course, it could not work, for there still were all those snapshot 
logs here and there, through which I have tried to observe the snapshot 
creation progress; only after I have removed *all* committedSnapshotForObject's 
it started to work properly :)

Incidentally, finding the culprit was sort of at the funny side too.

First I have found in one clone that removing an audit call on user login, it 
helps. What?!?

Then, going through the audit code, I found the actual culprit was

===
switch (arg) { // which arg happened to be the user EO
  case 'sometext': ...something...
}
===

WHAT?!? Well ... in Groovy, a switch is a bit more flexible than in Java/C; it 
effectively boils down to

===
if ('sometext'.equals(arg.toString())) ...something...
===

which indeed causes snapshots not to be filled... well W*H*A*T?!? How can 
this... but then, I do override toString for my EOs after all; and eventually I 
found that the overridden method in some cases _would_ call 
committedSnapshotForObject, so that the EO logs out how it differs from the 
saved state. O frabjous day!

Incidentally, is there some simple test which could be used to determine 
whether at the place and moment and particular eo it is safe to call 
committedSnapshotForObject or not?

Thanks and all the best,
OC

> From: "o...@ocs.cz" <o...@ocs.cz>
> Date: Wednesday, September 21, 2016 at 1:42 PM
> To: Chuck Hill <ch...@gevityinc.com>
> Cc: "webobjects-dev@lists.apple.com WebObjects" 
> <webobjects-dev@lists.apple.com>
> Subject: Re: EOF inserts already existing M:N relationships/empty snapshot?!?
>  
> Chuck,
>  
> On 21. 9. 2016, at 6:10 AM, Chuck Hill <ch...@gevityinc.com> wrote:
> I bet Alice was a developer too.
>  
> Beware the EOF, my son!
> The jaws that bite, the claws that catch!
>  
> Looks like I have found the culprit — seems it was the very log of the 
> committed snapshot. It looks like that if one calls e.g.,
>  
> eo.editingContext().committedSnapshotForObject(eo)
>  
> at the wrong moment — which did happen to me originally (solely for the 
> logging purposes, darnit!), and the more logs I have added, the worse it got 
> — one of the not-quite-presumed side-effects of that would be that the 
> snapshots do not get properly recorded anymore for eo. Quadruple weird!
>  
> When I have removed all the committedSnapshotForObject calls, it starts to 
> run properly for all the M:N's, without a glitch. Adding logs immediately 
> pre-saveChanges (it seems to be safe at the moment), the snapshot proved to 
> be right; and saveChanges sends only the inserts it should.
>  
> Matter of fact, we even have bumped to (another presentation of) the very 
> same problem some time ago, to wit:
>  
> On 28. 2. 2015, at 7:54 PM, Chuck Hill <ch...@gevityinc.com> wrote:
> Ah, Schrödinger’s EOF. :-P  Observing some things can materially change the 
> state of EOF.   Calling this method calls ec.committedSnapshotForObject() 
> which causes the EC to record the committed snapshot for the object at that 
> point in time.  Normally this is done only at the point the EO first changes.
>  
> Whew!
>  
> Thanks a very big lot for all the help,
> OC
>  
>  


 ___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: EOF inserts already existing M:N relationships/empty snapshot?!?

2016-09-21 Thread o...@ocs.cz
Chuck,

> On 21. 9. 2016, at 6:10 AM, Chuck Hill  wrote:
> I bet Alice was a developer too.

Beware the EOF, my son!
The jaws that bite, the claws that catch!

Looks like I have found the culprit — seems it was the very log of the 
committed snapshot. It looks like that if one calls e.g.,

> eo.editingContext().committedSnapshotForObject(eo)

at the wrong moment — which did happen to me originally (solely for the logging 
purposes, darnit!), and the more logs I have added, the worse it got — one of 
the not-quite-presumed side-effects of that would be that the snapshots do not 
get properly recorded anymore for eo. Quadruple weird!

When I have removed all the committedSnapshotForObject calls, it starts to run 
properly for all the M:N's, without a glitch. Adding logs immediately 
pre-saveChanges (it seems to be safe at the moment), the snapshot proved to be 
right; and saveChanges sends only the inserts it should.

Matter of fact, we even have bumped to (another presentation of) the very same 
problem some time ago, to wit:

> On 28. 2. 2015, at 7:54 PM, Chuck Hill  wrote:
> 
> Ah, Schrödinger’s EOF. :-P  Observing some things can materially change the 
> state of EOF.   Calling this method calls ec.committedSnapshotForObject() 
> which causes the EC to record the committed snapshot for the object at that 
> point in time.  Normally this is done only at the point the EO first changes.

Whew!

Thanks a very big lot for all the help,
OC


 ___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: EOF inserts already existing M:N relationships/empty snapshot?!?

2016-09-21 Thread o...@ocs.cz
Chuck,

> On 21. 9. 2016, at 6:10 AM, Chuck Hill <ch...@gevityinc.com> wrote:
> I bet Alice was a developer too.

:)
 
> Have you overridden any of the EOF methods, or the generated methods in User 
> or DataBlock and changed the normal behavior?  Or forgotten to call super?

Note please that there's more M:N's in that application, and other ones work 
all right (although, as outlined below, their changes never occur in the 
DatabaseContextDelegate.databaseContextShouldUpdateCurrentSnapshot method; the 
snapshot though is all right).

As for overridden methods, let me see...

- my EO root is an OCSEnterpriseObject (which extends ERXGenericRecord), and 
overrides
-- awakeFromInsertion to set up creation date; calls super
-- validateForSave; calls super (and does not change the eo :))
-- handleQueryWithUnboundKey and handleTakeValueForUnboundKey: these do not 
call super (which is all right I think)
-- toString (does not call super either)
- DataBlock (extends OCSEnterpriseObject) does not override anything (and works 
all right with other M:N's)
- User ditto

No accessors are implemented explicitly in DataBlock or User[*].

That aside, I install a DatabaseContextDelegate. It extends 
ERXDatabaseContextDelegate, and overrides 
databaseContextWillPerformAdaptorOperations to log what is about to happen with 
the database and databaseContextFailedToFetchObject, again to log which 
object/gid did fail. None of them calls super. Temporarily I tried to override 
databaseContextShouldUpdateCurrentSnapshot to log when and how the snapshot is 
updated, but with M:N's it does not seem to work -- I have never got any M:N in 
its new dict (although most M:N's work all right and the appropriate snapshots, 
logged just-before-save, contain the proper eos).

Can I track somehow (e.g., through some delegate methods/notifications) when 
and how exactly the snapshot :N's gets updated? Looks like 
databaseContextShouldUpdateCurrentSnapshot is not the right way to do that. At 
least, my last attempt obtained all the :N names from the entity and would log 
out if any of them is either in the old or in the new dict -- but never logs 
anything (whilst attributes and :1 changes go through here all right).

Thanks and all the best,
OC

[*] There are no generated sources like _User or _DataBlock in my setup; the 
accessor methods are injected launch-time into User/DataBlock/all other EO 
classes based on model contents. In my personal opinion, this approach 
(conceptually copied down from Core Data) is much cleaner and considerably less 
error-prone than generated sources. Should not be relevant to this problem, I 
think.


>  
> From: OC <o...@ocs.cz>
> Date: Tuesday, September 20, 2016 at 6:33 PM
> To: Chuck Hill <ch...@gevityinc.com>
> Cc: "webobjects-dev@lists.apple.com WebObjects" 
> <webobjects-dev@lists.apple.com>
> Subject: Re: EOF inserts already existing M:N relationships/empty snapshot?!?
>  
> Chuck,
>  
> On 21. 9. 2016, at 2:40, o...@ocs.cz wrote:
>  
> Aside of that, I have added a log into the 
> DatabaseContextDelegate.databaseContextShouldUpdateCurrentSnapshot method, 
> and here I *never* get *anything* for the relationships: neither the old 
> (which is presumable) *nor the new* dictionary ever contain the 
> “userDataBlocks” or “dataBlockUsers” key — not once.
>  
> well this one's weird, or I am missing something of importance here.
>  
> Meantime, I have played with another M:N, which works without a glitch (and 
> which is modelled the same way as that one which does not, incidentally). 
> Here, save-time, the snapshot does contain the proper related objects (and 
> thus proper INSERTs are generated).
>  
> The weird thing is that these objects *do not* come into the snapshot through 
> the DatabaseContextDelegate.databaseContextShouldUpdateCurrentSnapshot 
> method! It logs all right when the object is fetched, but the new (nor the 
> old, of course) dictionary does *not* contain the relationship key at all -- 
> precisely the same way it is with that relationship which does not work 
> properly!
>  
> Nevertheless, as mentioned above, save-time, the snapshot is all right. 
> Couriouser and couriouser, Alice would say :-O
>  
> Thanks and all the best,
> OC
>  
>  


 ___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: EOF inserts already existing M:N relationships/empty snapshot?!?

2016-09-20 Thread o...@ocs.cz
Just a quick followup -- sorry, forgot to copy/paste the 2nd part of the log, 
though I fear it would not help much — it just confirms the user's snapshot 
does not get changed either:

> On 21. 9. 2016, at 2:40 AM, o...@ocs.cz wrote:
> 
> Chuck,
> 
>> On 20. 9. 2016, at 10:48 PM, Chuck Hill <ch...@gevityinc.com> wrote:
>> 
>> This is why they are getting inserted again:
>> Well, logging out 
>> "currentUser.editingContext().committedSnapshotForObject(currentUser)['userDataBlock']"
>>  before saveChanges, I get an empty array. I must admit I don't know whether 
>> there should be the relationship objects in this snapshot, but anyway:
>> 
>> It should not be an empty array.  EOF compares this and the relationship on 
>> the EO to determine what database operations are needed.
> 
> I see.
> 
>> I’d start with logging that out just after you fetch/fault currentUser into 
>> ec (you don’t show that below).  If it is empty there, then keep logging to 
>> see where the data disappears.  At this point, I am not ready to guess.
> 
> The thing seems empty all the time. Weird. Here's what I log fetch-time:
> 
> ===
> def cbc= // the business case whose users are about to be fetched
> println "### about to fetch $cbc...\noldSS 
> ${cbc.editingContext().committedSnapshotForObject(cbc).userDataBlocks}"
> def xxx=cbc.userDataBlocks()
> println "### -> did fetch $xxx\nnewSS 
> ${cbc.editingContext().committedSnapshotForObject(cbc).userDataBlocks}"
> xxx.each { println "### user $it\n### rel ${it.dataBlockUsers()}\n###   ss 
> ${it.editingContext().committedSnapshotForObject(it).dataBlockUsers}" }
> ===
> 
> Presumably, the “oldSS” should be empty, but the “newSS” should be a copy of 
> the relationship value (i.e., “cbc.userDataBlocks()”, or “xxx”)?
> 
> It is not; the snapshot consistently stays empty:
> 
> ===
> ### about to fetch <DBDataBlock@d6ff2f9 PK:103 Title:'überblok' 
> /EC:6350cea5>...
> oldSS []
> ### -> did fetch [<DBUser@6f400a99 PK:105 T:'3' Name:'cl' /EC:6350cea5>, 
> <DBUser@5f8a5755 PK:106 T:'3' Name:'c2' /EC:6350cea5>, <DBUser@569a703e 
> PK:109 T:'4' Name:'kl kl kl' /EC:6350cea5>]
> newSS []

### user <DBUser@6f400a99 PK:105 T:'3' Name:'cl' /EC:6350cea5>
### rel [<DBDataBlock@d6ff2f9 PK:103 E:1 Title:'überblok' /EC:6350cea5>, 
<DBDataBlock@1b2d674b PK:116 Title:'test' /EC:6350cea5>, 
<DBDataBlock@50ebf897 PK:119 Title:'pokus' /EC:6350cea5>, 
<DBDataBlock@6d05217d PK:122 Title:'zabit' /EC:6350cea5>, 
<DBDataBlock@53a2ad4c PK:123 Title:'zamazat' /EC:6350cea5>, 
<DBDataBlock@5c02c8ef PK:124 Title:'zavrazdit' /EC:6350cea5>, 
<DBDataBlock@533e7079 PK:129 Title:'and-now' /EC:6350cea5>, 
<DBDataBlock@6310dfc7 PK:133 Title:'???' /EC:6350cea5>]
###   ss []

> ===
> 
> Aside of that, I have added a log into the 
> DatabaseContextDelegate.databaseContextShouldUpdateCurrentSnapshot method, 
> and here I *never* get *anything* for the relationships: neither the old 
> (which is presumable) *nor the new* dictionary ever contain the 
> “userDataBlocks” or “dataBlockUsers” key — not once.
> 
> Well it still might be a wrong model settings as Samuel suggests perhaps? But 
> it is sort of weird I use this settings for years and lots of M:N's, and this 
> is the first time I have bumped into this kind of problems.
> 
> Can you see what to check next?
> 
> Thanks a very big lot,
> OC
> 
>> 
>> Also, this is 100% consistent, right?  This is not a concurrency issue?
>> 
>> Chuck
>> 
>> 
>> From: <webobjects-dev-bounces+chill=gevityinc@lists.apple.com> on behalf 
>> of "o...@ocs.cz" <o...@ocs.cz>
>> Date: Tuesday, September 20, 2016 at 11:50 AM
>> To: "webobjects-dev@lists.apple.com WebObjects" 
>> <webobjects-dev@lists.apple.com>
>> Subject: EOF inserts already existing M:N relationships/empty snapshot?!?
>> 
>> Hello there,
>> 
>> I have a pretty common setup: entities User and DataBlock, an M:N 
>> relationship represented by an intermediate entity containing just the two 
>> keys, flattened on both sides. At both sides the relationships are 
>> appropriately flattened. Set to own destination+delete rule cascade.
>> 
>> The problem is, upon inserting a new DataBlock and its relationship to a 
>> current user, beside the two objects which should be inserted (the new 
>> DataBlock and the new relationship), relationships to other (old) 
>> DataBlocks, which were before simply _fetched_ for the current user (just to 
>> 

Re: EOF inserts already existing M:N relationships/empty snapshot?!?

2016-09-20 Thread o...@ocs.cz
Chuck,

> On 20. 9. 2016, at 10:48 PM, Chuck Hill <ch...@gevityinc.com> wrote:
> 
> This is why they are getting inserted again:
> Well, logging out 
> "currentUser.editingContext().committedSnapshotForObject(currentUser)['userDataBlock']"
>  before saveChanges, I get an empty array. I must admit I don't know whether 
> there should be the relationship objects in this snapshot, but anyway:
>  
> It should not be an empty array.  EOF compares this and the relationship on 
> the EO to determine what database operations are needed.

I see.

> I’d start with logging that out just after you fetch/fault currentUser into 
> ec (you don’t show that below).  If it is empty there, then keep logging to 
> see where the data disappears.  At this point, I am not ready to guess.

The thing seems empty all the time. Weird. Here's what I log fetch-time:

===
def cbc= // the business case whose users are about to be fetched
println "### about to fetch $cbc...\noldSS 
${cbc.editingContext().committedSnapshotForObject(cbc).userDataBlocks}"
def xxx=cbc.userDataBlocks()
println "### -> did fetch $xxx\nnewSS 
${cbc.editingContext().committedSnapshotForObject(cbc).userDataBlocks}"
xxx.each { println "### user $it\n### rel ${it.dataBlockUsers()}\n###   ss 
${it.editingContext().committedSnapshotForObject(it).dataBlockUsers}" }
===

Presumably, the “oldSS” should be empty, but the “newSS” should be a copy of 
the relationship value (i.e., “cbc.userDataBlocks()”, or “xxx”)?

It is not; the snapshot consistently stays empty:

===
### about to fetch <DBDataBlock@d6ff2f9 PK:103 Title:'überblok' 
/EC:6350cea5>...
oldSS []
### -> did fetch [<DBUser@6f400a99 PK:105 T:'3' Name:'cl' /EC:6350cea5>, 
<DBUser@5f8a5755 PK:106 T:'3' Name:'c2' /EC:6350cea5>, <DBUser@569a703e 
PK:109 T:'4' Name:'kl kl kl' /EC:6350cea5>]
newSS []
===

Aside of that, I have added a log into the 
DatabaseContextDelegate.databaseContextShouldUpdateCurrentSnapshot method, and 
here I *never* get *anything* for the relationships: neither the old (which is 
presumable) *nor the new* dictionary ever contain the “userDataBlocks” or 
“dataBlockUsers” key — not once.

Well it still might be a wrong model settings as Samuel suggests perhaps? But 
it is sort of weird I use this settings for years and lots of M:N's, and this 
is the first time I have bumped into this kind of problems.

Can you see what to check next?

Thanks a very big lot,
OC

>  
> Also, this is 100% consistent, right?  This is not a concurrency issue?
>  
> Chuck
>  
>  
> From: <webobjects-dev-bounces+chill=gevityinc@lists.apple.com> on behalf 
> of "o...@ocs.cz" <o...@ocs.cz>
> Date: Tuesday, September 20, 2016 at 11:50 AM
> To: "webobjects-dev@lists.apple.com WebObjects" 
> <webobjects-dev@lists.apple.com>
> Subject: EOF inserts already existing M:N relationships/empty snapshot?!?
>  
> Hello there,
>  
> I have a pretty common setup: entities User and DataBlock, an M:N 
> relationship represented by an intermediate entity containing just the two 
> keys, flattened on both sides. At both sides the relationships are 
> appropriately flattened. Set to own destination+delete rule cascade.
>  
> The problem is, upon inserting a new DataBlock and its relationship to a 
> current user, beside the two objects which should be inserted (the new 
> DataBlock and the new relationship), relationships to other (old) DataBlocks, 
> which were before simply _fetched_ for the current user (just to display the 
> current state), get inserted too — which, of course, causes an integrity 
> constraint violation “this PK already exists“.
>  
> My code looks essentially like this:
>  
> ===
> EOEditingContext ec= ...
> DBDataBlock ndb=new DBDataBlock()
> ec.insertObject(ndb)
> ndb.addObjectToBothSidesOfRelationshipWithKey(currentUser,'dataBlockUsers')
> // logs here, see below
> ec.saveChanges()
> ===
>  
> Immediately before ec.saveChanges(), I log out
>  
> (a) ec.insertedObjects(), which contains only one object (I have overridden 
> toString() to get the PK /and other attributes, removed here for conciseness/ 
> of an EO):
>  
> [<DBDataBlock@79adaefa PK:null>]
>  
> this is all right, null PK means a newly added object, it's the very 'ndb' 
> datablock I just have inserted and which I am now saving.
>  
> (b) contents of the flattened M:N relationship 'ndb.dataBlockUsers' from the 
> DBDataBlock@79adaefa to DBUser, which looks like this:
>  
> [<DBUser@71b29988 PK:105>]
>  
> again, quite all right: only one related user, the currentUser which I have 
> just added to the relationship.
>  
> (c) contents of the flattened M:N inverse relationship fro

EOF inserts already existing M:N relationships/empty snapshot?!?

2016-09-20 Thread o...@ocs.cz
Hello there,

I have a pretty common setup: entities User and DataBlock, an M:N relationship 
represented by an intermediate entity containing just the two keys, flattened 
on both sides. At both sides the relationships are appropriately flattened. Set 
to own destination+delete rule cascade.

The problem is, upon inserting a new DataBlock and its relationship to a 
current user, beside the two objects which should be inserted (the new 
DataBlock and the new relationship), relationships to other (old) DataBlocks, 
which were before simply _fetched_ for the current user (just to display the 
current state), get inserted too — which, of course, causes an integrity 
constraint violation “this PK already exists“.

My code looks essentially like this:

===
EOEditingContext ec= ...
DBDataBlock ndb=new DBDataBlock()
ec.insertObject(ndb)
ndb.addObjectToBothSidesOfRelationshipWithKey(currentUser,'dataBlockUsers')
// logs here, see below
ec.saveChanges()
===

Immediately before ec.saveChanges(), I log out

(a) ec.insertedObjects(), which contains only one object (I have overridden 
toString() to get the PK /and other attributes, removed here for conciseness/ 
of an EO):

[]

this is all right, null PK means a newly added object, it's the very 'ndb' 
datablock I just have inserted and which I am now saving.

(b) contents of the flattened M:N relationship 'ndb.dataBlockUsers' from the 
DBDataBlock@79adaefa to DBUser, which looks like this:

[]

again, quite all right: only one related user, the currentUser which I have 
just added to the relationship.

(c) contents of the flattened M:N inverse relationship from the current user, 
which looks like this:

[, , 
, , 
, , 
, , 
]

for the third time, all right: 8 of them previously fetched, already existing 
relationships to other (old) datablocks for the current user, plus one new 
relationship to the newly added DBDataBlock@79adaefa. Perfect so far.

At this moment, ec.saveChanges is performed. I log the database operations from 
databaseContextWillPerformAdaptorOperations delegate method, and it looks like 
this:

===
-IN-adaptorOps === SPC: about to perform 10 DB operations   |19:54:37.061 
20.9.16|WorkerThread1
   - 1: INSERT on 'DBDataBlock'  1{uid:142}
   - 2: INSERT on 'DB_UserDataBlock'  2{db_id:123, 
user_id:105}
   - 3: INSERT on 'DB_UserDataBlock'  2{db_id:122, 
user_id:105}
   - 4: INSERT on 'DB_UserDataBlock'  2{db_id:103, 
user_id:105}
   - 5: INSERT on 'DB_UserDataBlock'  2{db_id:116, 
user_id:105}
   - 6: INSERT on 'DB_UserDataBlock'  2{db_id:142, 
user_id:105}
   - 7: INSERT on 'DB_UserDataBlock'  2{db_id:119, 
user_id:105}
   - 8: INSERT on 'DB_UserDataBlock'  2{db_id:129, 
user_id:105}
   - 9: INSERT on 'DB_UserDataBlock'  2{db_id:124, 
user_id:105}
   - 10: INSERT on 'DB_UserDataBlock'  2{db_id:133, 
user_id:105}
===

i.e., along with inserting the two new objects (1: the new datablock, 6: the 
new relationship), EOF for some darned reason decides to insert _also_ all 
those relationship objects it _fetched_ before! Of course, since they were 
fetched, they already exist in the database, and thus cause an integrity 
constraint violation “this PK already exists“.

Well, logging out 
"currentUser.editingContext().committedSnapshotForObject(currentUser)['userDataBlock']"
 before saveChanges, I get an empty array. I must admit I don't know whether 
there should be the relationship objects in this snapshot, but anyway:

- if not, I have no idea where to find the culprit;
- if yes, well, the culprit of those inserts is explained, but why on earth the 
snapshot is not properly maintained by EOF?!?

Any idea what might be the culprit, or at least, how to find it? I am afraid I 
am rather out of ideas :/

Thanks a lot,
OC


 ___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: derived attribute to sum a relationship?

2016-08-23 Thread o...@ocs.cz
Thanks a lot (Samuel too).

> On 22. 8. 2016, at 8:29 PM, Chuck Hill <ch...@gevityinc.com> wrote:
...
> I can’t think of a way to do that that isn’t a lot of code and prone to 
> inconsistencies with the relationship data.

Hmmm... is there at least some WO or WOnder trick, which would fetch at 
SQL-level a sum for relationship on-demand, i.e., something like this 
fetchSumForAttributeInRelationsip hypothetical method:

ClassA eo=...; // an enterprise object of entity A
Number sum=eo.fetchSumForAttributeInRelationsip("x","ab")

which would _not_ fire the "ab" relationship fault; instead, it would generate 
and perform an SQL similar to "SELECT SUM(C_X) FROM B_TABLE WHERE ..." (with 
appropriate WHERE to get those rows of B which are in the 1:N relationship "ab" 
from "eo")?

Or do I have do go explicitly create and run the SQL expression 
programmatically?

Thanks,
OC

> From: <webobjects-dev-bounces+chill=gevityinc@lists.apple.com> on behalf 
> of OC <o...@ocs.cz>
> Date: Monday, August 22, 2016 at 6:36 AM
> To: WebObjects-Dev Mailing List <webobjects-dev@lists.apple.com>
> Subject: derived attribute to sum a relationship?
>  
> Hello there,
>  
> is there a way to define a derived attribute to sum a relationship's 
> attribute?
>  
> Presumed I have
>  
> - entity A with PK column C_ID, relationship:N "ab" leading to entity B
> - entity B with FK column C_A_ID (which forms the relationship) and integer 
> column C_X representing attribute "x"
>  
> is it possible to define a derived attribute "abSum" of A, which would sum 
> all "x"'s of those B rows, which are -- through their C_A_ID foreign key -- 
> related to a row in A?
>  
> Normally, of course, I would implement it Java-side, like this
>  
> ===
> class AEntityClass ... {
>   int abSum() {
> int s=0; for (b in ab()) s+=b.x; return s
>   }
> }
> ===
>  
> but this time, I would need to do that SQL-side, for (a) speed, (b) memory 
> (so that all B rows do not need to be fetched), (c) so that the attribute can 
> be used in qualifiers when fetching, e.g.,
>  
> ===
> NSArray objs=ec.objectsWithFetchSpecification(new 
> EOFetchSpecification("A",EOQualifier.qualifierWithQualifierFormat("abSum > 
> 100",null),null))
> ===
>  
> I have tried to define it as the most obvious "select sum(bt.C_X) from 
> B_TABLE bt where bt.C_A_ID = C_ID", but I bumped into numerous problems, from 
> ambiguity of C_ID up to the fact that EOF caches the fetched value and does 
> not recache when the relationship objects change, and thus I am getting 
> obsolete values.
>  
> Is there a way to do that properly?
>  
> Thanks,
> OC
>  
>  
> ___
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/webobjects-dev/chill%40gevityinc.com
>  
> This email sent to ch...@gevityinc.com


 ___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com