String or Stream in the same persistent property?

I have a persistent class.

I want to store one of the properties there as a stream or a string depending on a size.

99% of values would be strings (less than $$$MaxStringLength characters) so I don't want to store everything as streams.

What do you think of this approach?

What's the best architecture to implement in this situation?

  • 0
  • 0
  • 103
  • 2
  • 2

Answers

Supposed, you have a magical datatype of %StringOrMaybeStream and your property would be something like this:

Property TheText As %StringOrMaybeStream

So the next question is, how would your application use this magical property?
The very first question is, how would you put your data into this magical property?

Give me some (hypothetical) examples of use and I will try to give you a solution, if there is any.

Without offering a solution to develop this magic data type that Julius suggested
You should also define what datatype you plan to present for the SQL side.
And that is always taken from the Compiled Property definition.

All streams typically present themselves a CLOB or BLOB or similar and have no MAXsize
While a String presents itself as a VARCHAR with a MAXSIZE.
I see no way to manipulate this on the fly.

For object access, you may write a Setter and Getter that covers the real nature of your data:
For SQL access I see no chance at the moment.

Indexing is another issue. This would require another piece of magic.

My suggestion:
have a %String
have a %Stream
and have a calculated property of  %String to decide which one to present.

like a centipede with a wooden leg: 99 times tic and 1 toc

the stream is then truncated and still requires extra coding. 
 

"like a centipede with a wooden leg: 99 times tic and 1 toc
the stream is then truncated and still requires extra coding"

That's the whole point!
If we turncate the stream to $$$MaxStringLength, no matter where (in a calculated property or in a GETter method), just to present this (string)value to a variable, a function or whatever, then we can instantly stick to a string.

By the way, it's possible to store $$$MaxStringLength bytes in a local or global variable.
Properties of classes are stored in globals as $listelements, so the maxlength for a single string property depends on things like count and types of other properties in the class and not least, does this class extends %Persistent or extends another class(es) which extends %Persistent - in this case we need some extra bytes for those (extended) class names too.

Hi Julius,
You got my point!
A Stream is a Stream and a String is a String and
they are different things with different handling. 
The fact that they both (can) contain characters is of no importance.