Book a Demo

Author Topic: Where to put length for string attribute?  (Read 4732 times)

jlavery

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Where to put length for string attribute?
« on: July 24, 2006, 12:31:10 am »
Hi all,
I'm using EA to model a VB.NET system which will use NHibernate for its OR modelling into a database.

Ultimately I would like to generate NHibernate mapping templates from my model (but that's a separate thread!). For now, I'd like to get the max length of String attributes into the model.

Can someone point me in the right direction, please?

Thanks,

James

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Where to put length for string attribute?
« Reply #1 on: July 24, 2006, 04:35:59 am »
Hi James,

The real problem here is that VB.Net (or .Net itself for that matter) does not have an native String variant with a fixed (or maximum) length. You need to find some way around this to support your OR requirement, while not severely breaking the model's integrety.

You might be in a bit of a bind, depending on exactly how you want to model this. If you really need to model an OR situation in an implementation language - VB.Net in your case - you'll have to 'invent' something along the way. We'll come back to that. You might be stuck with this approach due to your mapping requirement.

If you can use EA's data modelling profile - by choosing the Table entity from the Class toolbox instead of the Class entity, and then allowing EA to present you with the Column dialog for attributes - you can gracefully handle  strings with fixed or maximum lengths, but you lose the ability to work with implementation languages - you need to choose a DBMS and stick with its data types.

Here's what I'd suggest, remembering that whatever you choose to do must support your requirements...

If you can determine the target DBMS, or if one the EA DBMS definitions will work as a 'generic' language for you, then use the data modelling profile and you're home free.

If EA does not provide a suitable DBMS, you may be able to define one that covers your requirements. This would likely include a variety of common data types patterned on VB.Net (or native .Net) types, and would have fixed or bounded String lengths. You can then proceed with the data modelling profile as above.

If these don't work, or if the other requirements of the data modelling profile (using operations to define keys, how relations are defined, etc.) preclude this approach you will have to find a way to handle String lengths.

My best guess would be to use either a stereotype or a tagged value to indicate the length of the string. In the former case the stereotype would likely mark the String as fixed or bounded length, and there would still have to be a tag to show the length. The possible advantage would be that the stereotype would immediately draw attention to the fact that this was not a 'normal' String. If that is not practical you can always simply test or inspect the tagged values for something like 'length=50' or perhaps 'maxLength=50' or whatever, but you'll need to find a way of differentiating between fixed and variable String types.

Another approach would be to add a data type to EA's VB.Net definition. Or, you could create a slightly customized language based on the VB.Net definition. In either case you would extend or modify the 'given' data types to include your fixed or bounded String types.

Both the above solutions involve changes that somehow have to be carried over into your mapping transformation, which might mean a bit of script modification. There's some work here, and some careful testing and debugging, but you stand a good chance of getting the results you need and want, rather than a close approximation becuase "that's how the tool does it." With luck it will all pay off.

BTW, take a look at the EA User Group and Wiki. There's a link to the UG at the top of the Automation section of this forum, and the Wiki is easy to find via a quick search here. If you do some scripting and your organization allows it, please consider posting your approach and scripts to either or both of the above communities, so that others might benefit. Who knows, you might even get some good enhancements in response.

David
No, you can't have it!

jlavery

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Where to put length for string attribute?
« Reply #2 on: July 25, 2006, 01:48:50 am »
Hi David,
Thanks for the very comprehensive reply.

I don't need to carry the length through to the generated code, (unless we can generate NHibernate mapping files from EA).

I want it in there for the Engineer to be able to see when doing his/her coding of the NHibernate mappings.

So it looks like your idea of using a tagged value will be fine - it's not a problem if the generated code does not have the length.

Thanks,

James

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Where to put length for string attribute?
« Reply #3 on: July 25, 2006, 04:07:20 am »
And you can always write a custom transformation or generation script, or even an application, to automate the NHibernate mappings in future. At that time you can test the tagged value - which works in all those cases - and harvest the length.

You can even test for the tagged value in a Shape Script, and output the value onto the shape.
No, you can't have it!