Fornax-Platform
Forum

model.btdesign and Generics

View: New views
10 Messages — Rating Filter:   Alert me  

model.btdesign and Generics

by Sascha Broich :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

I'm wondering if it is possible to use generics in the design file.

For several entities that inherit from an abstract entity I want to create a single service that can handle some basic requests like save, findAll or findByName for each of the entities.

So I'd like to have

<T extends @Base> T save(T t);
<T extends @Base> Collection<T> findAll(Class<T> clazz);
<T extends @Base> T findByName(Class<T> clazz, String name);

in my service interface.

I could write it by hand into the generated Java file but this would be a Sisyphean task.
The implementation I can handle manually but the interface is my concern.


Regards,
Sascha Broich
--
TSA - Teleport Sachsen-Anhalt Service GmbH
Delitzscher Straße 70, 06112 Halle
Tel: +49 39203 8 2524 - Fax:
Mobil:   - E-Mail: Sascha.Broich@...

Firmensitz: Steinfeldstraße 5, D-39179 Barleben
Geschäftsführer: Marco Langhof
Amtsgericht: Stendal HRB 6388
http://www.tsa.de

------------------------------------------------------------------------------
_______________________________________________
Fornax-developer mailing list
Fornax-developer@...
https://lists.sourceforge.net/lists/listinfo/fornax-developer

Re: model.btdesign and Generics

by Patrik Nordwall :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I think this is a case you should implement manually or adjust the code generation templates to fit your need. Documentation: http://fornax.itemis.de/confluence/display/fornax/7.+Developer%27s+Guide+%28CSC%29#7.Developer%27sGuide%28CSC%29-ChangeGenerationTemplates

http://fornax.itemis.de/confluence/display/fornax/7.+Developer%27s+Guide+%28CSC%29#7.Developer%27sGuide%28CSC%29-Howtoexcludegeneration


I can probably help you more with the customization if you like, but then I need more information and an example to be able to understand exactly what you would like to do.

/Patrik

Sascha Broich wrote:
Hello,

I'm wondering if it is possible to use generics in the design file.

For several entities that inherit from an abstract entity I want to create a single service that can handle some basic requests like save, findAll or findByName for each of the entities.

So I'd like to have

<T extends @Base> T save(T t);
<T extends @Base> Collection<T> findAll(Class<T> clazz);
<T extends @Base> T findByName(Class<T> clazz, String name);

in my service interface.

I could write it by hand into the generated Java file but this would be a Sisyphean task.
The implementation I can handle manually but the interface is my concern.


Regards,
Sascha Broich
--
TSA - Teleport Sachsen-Anhalt Service GmbH
Delitzscher Straße 70, 06112 Halle
Tel: +49 39203 8 2524 - Fax:
Mobil:   - E-Mail: Sascha.Broich@tsa.de

Firmensitz: Steinfeldstraße 5, D-39179 Barleben
Geschäftsführer: Marco Langhof
Amtsgericht: Stendal HRB 6388
http://www.tsa.de

------------------------------------------------------------------------------
_______________________________________________
Fornax-developer mailing list
Fornax-developer@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fornax-developer

Re: model.btdesign and Generics

by Sascha Broich :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Von: Patrik Nordwall [mailto:patrik.nordwall@...]
> I can probably help you more with the customization if you like, but
> then I need more information and an example to be able to understand
> exactly what you would like to do.

Okay, I will try to explain my problem more detailed.

I have several entity classes that have different semantics but same syntax.
They are called Type because - they typify other objects.
Therefore they consist of a short key string and a description.
Such a type could be currency with the ISO 3 letter key and the currency's name or the ISO language code and the language's name.

For accessing from outside they all have the same pattern:
- Get all elements of a type.
- Get one element by its key.
- Add an element.
- Change an element.
- Remove an element.

(Hm, sounds like scaffold...)

Now I have a dozen of this types.
Creating one service function for each type and each access mode is not very object oriented.
Also I would get a service with about 60 almost identical functions.
So with generics it shrinks to one function for each access mode.

<T extends Type> T add(T t);
<T extends Type> T save(T t);
<T extends Type> T remove(T t);
<T extends Type> Collection<T> findAll(Class<T> clazz);
<T extends Type> T findByKey(Class<T> clazz, String key);

But the model language does not allow such generics.
Which makes it hard to write such a service.

I hope, this could clearify my intentions.


Regards,
Sascha Broich
--
TSA - Teleport Sachsen-Anhalt Service GmbH
Delitzscher Straße 70, 06112 Halle
Phone: +49 39203 8 2524
Email: Sascha.Broich@...

Firmensitz: Steinfeldstraße 5, D-39179 Barleben
Geschäftsführer: Marco Langhof
Amtsgericht: Stendal HRB 6388
http://www.tsa.de
------------------------------------------------------------------------------
_______________________________________________
Fornax-developer mailing list
Fornax-developer@...
https://lists.sourceforge.net/lists/listinfo/fornax-developer

Re: model.btdesign and Generics

by PaloT :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>From you explanation it looks like clear inheritance. Make BaseType
and than inherit all Types from it. Implementation should be placed
only to BaseType.

Pavel


On Mon, Jul 27, 2009 at 10:35 AM, Sascha Broich -
TSA<sascha.broich@...> wrote:

> Von: Patrik Nordwall [mailto:patrik.nordwall@...]
>> I can probably help you more with the customization if you like, but
>> then I need more information and an example to be able to understand
>> exactly what you would like to do.
>
> Okay, I will try to explain my problem more detailed.
>
> I have several entity classes that have different semantics but same syntax.
> They are called Type because - they typify other objects.
> Therefore they consist of a short key string and a description.
> Such a type could be currency with the ISO 3 letter key and the currency's name or the ISO language code and the language's name.
>
> For accessing from outside they all have the same pattern:
> - Get all elements of a type.
> - Get one element by its key.
> - Add an element.
> - Change an element.
> - Remove an element.
>
> (Hm, sounds like scaffold...)
>
> Now I have a dozen of this types.
> Creating one service function for each type and each access mode is not very object oriented.
> Also I would get a service with about 60 almost identical functions.
> So with generics it shrinks to one function for each access mode.
>
> <T extends Type> T add(T t);
> <T extends Type> T save(T t);
> <T extends Type> T remove(T t);
> <T extends Type> Collection<T> findAll(Class<T> clazz);
> <T extends Type> T findByKey(Class<T> clazz, String key);
>
> But the model language does not allow such generics.
> Which makes it hard to write such a service.
>
> I hope, this could clearify my intentions.
>
>
> Regards,
> Sascha Broich
> --
> TSA - Teleport Sachsen-Anhalt Service GmbH
> Delitzscher Straße 70, 06112 Halle
> Phone: +49 39203 8 2524
> Email: Sascha.Broich@...
>
> Firmensitz: Steinfeldstraße 5, D-39179 Barleben
> Geschäftsführer: Marco Langhof
> Amtsgericht: Stendal HRB 6388
> http://www.tsa.de
> ------------------------------------------------------------------------------
> _______________________________________________
> Fornax-developer mailing list
> Fornax-developer@...
> https://lists.sourceforge.net/lists/listinfo/fornax-developer
>

------------------------------------------------------------------------------
_______________________________________________
Fornax-developer mailing list
Fornax-developer@...
https://lists.sourceforge.net/lists/listinfo/fornax-developer

Re: model.btdesign and Generics

by Sascha Broich :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> Von: Pavel Tavoda [mailto:pavel.tavoda@...]
>
> >From you explanation it looks like clear inheritance. Make BaseType
> and than inherit all Types from it. Implementation should be placed
> only to BaseType.

This is, what I have done so far. I'm fine with the entity declaration.

My problem occurs when it comes to the service.
I'd like to specify like this:


abstract Entity Type
{
  scaffold

  String shortKey key;
  String description;

  Repository TypeRepository
  {
  }
}

Entity TypeA extends @Type
{
}

Entity TypeB extends @Type
{
}

Service TypeService
{
  >@TypeRepository

  <T extends Type> T add(T t);
  <T extends Type> T save(T t);
  <T extends Type> T remove(T t);
  <T extends Type> Collection<T> findAll(Class<T> clazz);
  <T extends Type> T findByKey(Class<T> clazz, String key);
}

So that I can call the service:

- typeService.findAll(TypeB.class);
- typeService.findByKey(TypeA.class, "ABC");


Regards,
Sascha Broich

--
TSA - Teleport Sachsen-Anhalt Service GmbH
Delitzscher Straße 70, 06112 Halle
Phone: +49 39203 8 2524
Email: Sascha.Broich@...

Firmensitz: Steinfeldstraße 5, D-39179 Barleben
Geschäftsführer: Marco Langhof
Amtsgericht: Stendal HRB 6388
http://www.tsa.de

------------------------------------------------------------------------------
_______________________________________________
Fornax-developer mailing list
Fornax-developer@...
https://lists.sourceforge.net/lists/listinfo/fornax-developer

Re: model.btdesign and Generics

by PaloT :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

OK, what is problem with this? Everything should work fine except
return parameter of service method which always return 'Type' and you
have to cast it to right type. Just do in your service declarations:
@Type remove(@Type t);
Collection<@Type> findAll();

Casting return value isn't big issue, I hope. If yes, than write your
own facade which can use generics and is using generated service at
background. This your service implementation should be put to
'more.xml' with nice name like 'TypeService' and rename your generated
service in model file to 'MyTypeHiddenService' and inject it in
more.xml into your own service.

If you really want to push Sculptor to generate generics, it's huge
amount of work because you have to change everything from syntax
definition to generation templates. However you are always welcome on
board.

Hope this help

Pavel

On Mon, Jul 27, 2009 at 12:05 PM, Sascha Broich -
TSA<sascha.broich@...> wrote:

>> Von: Pavel Tavoda [mailto:pavel.tavoda@...]
>>
>> >From you explanation it looks like clear inheritance. Make BaseType
>> and than inherit all Types from it. Implementation should be placed
>> only to BaseType.
>
> This is, what I have done so far. I'm fine with the entity declaration.
>
> My problem occurs when it comes to the service.
> I'd like to specify like this:
>
>
> abstract Entity Type
> {
>  scaffold
>
>  String shortKey key;
>  String description;
>
>  Repository TypeRepository
>  {
>  }
> }
>
> Entity TypeA extends @Type
> {
> }
>
> Entity TypeB extends @Type
> {
> }
>
> Service TypeService
> {
>  >@TypeRepository
>
>  <T extends Type> T add(T t);
>  <T extends Type> T save(T t);
>  <T extends Type> T remove(T t);
>  <T extends Type> Collection<T> findAll(Class<T> clazz);
>  <T extends Type> T findByKey(Class<T> clazz, String key);
> }
>
> So that I can call the service:
>
> - typeService.findAll(TypeB.class);
> - typeService.findByKey(TypeA.class, "ABC");
>
>
> Regards,
> Sascha Broich
>
> --
> TSA - Teleport Sachsen-Anhalt Service GmbH
> Delitzscher Straße 70, 06112 Halle
> Phone: +49 39203 8 2524
> Email: Sascha.Broich@...
>
> Firmensitz: Steinfeldstraße 5, D-39179 Barleben
> Geschäftsführer: Marco Langhof
> Amtsgericht: Stendal HRB 6388
> http://www.tsa.de
>
> ------------------------------------------------------------------------------
> _______________________________________________
> Fornax-developer mailing list
> Fornax-developer@...
> https://lists.sourceforge.net/lists/listinfo/fornax-developer
>

------------------------------------------------------------------------------
_______________________________________________
Fornax-developer mailing list
Fornax-developer@...
https://lists.sourceforge.net/lists/listinfo/fornax-developer

Re: model.btdesign and Generics

by Sascha Broich :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> Von: Pavel Tavoda [mailto:pavel.tavoda@...]
>
> OK, what is problem with this? Everything should work fine except
> return parameter of service method which always return 'Type' and you
> have to cast it to right type. Just do in your service declarations:
> @Type remove(@Type t);
> Collection<@Type> findAll();

The question for me is now, do I need a repository per subclass to achieve a
findAll for a subclass? Or do I have to go manually through the findAll result?


> Casting return value isn't big issue, I hope. If yes, than write your
> own facade which can use generics and is using generated service at
> background. This your service implementation should be put to
> 'more.xml' with nice name like 'TypeService' and rename your generated
> service in model file to 'MyTypeHiddenService' and inject it in
> more.xml into your own service.

The casting of the return values are not the big problem but a nice-to-have.

So this seems to be the solution, I assume.

 
> If you really want to push Sculptor to generate generics, it's huge
> amount of work because you have to change everything from syntax
> definition to generation templates. However you are always welcome on
> board.

If I had the time for this, but unfortunately my schedule is full.
We are using Sculptor to reduce the work. You suggest the opposite. ;-)


Regards,
Sascha Broich

--
TSA - Teleport Sachsen-Anhalt Service GmbH
Delitzscher Straße 70, 06112 Halle
Phone: +49 39203 8 2524
Email: Sascha.Broich@...

Firmensitz: Steinfeldstraße 5, D-39179 Barleben
Geschäftsführer: Marco Langhof
Amtsgericht: Stendal HRB 6388
http://www.tsa.de

------------------------------------------------------------------------------
_______________________________________________
Fornax-developer mailing list
Fornax-developer@...
https://lists.sourceforge.net/lists/listinfo/fornax-developer

Re: model.btdesign and Generics

by PaloT :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Mon, Jul 27, 2009 at 3:32 PM, Sascha Broich -
TSA<sascha.broich@...> wrote:

>> Von: Pavel Tavoda [mailto:pavel.tavoda@...]
>>
>> OK, what is problem with this? Everything should work fine except
>> return parameter of service method which always return 'Type' and you
>> have to cast it to right type. Just do in your service declarations:
>> @Type remove(@Type t);
>> Collection<@Type> findAll();
>
> The question for me is now, do I need a repository per subclass to achieve a
> findAll for a subclass? Or do I have to go manually through the findAll result?

One repository per subclass is one approach (easy for you).
Second is to define your own Custom access object where you can use
your own access parameters like Class. Look in Advanced tutorial
section 'Custom access object'
(https://fornax.itemis.de/confluence/display/fornax/3.+Advanced+Tutorial+%28CSC%29#3.AdvancedTutorial%28CSC%29-CustomAccessObjects).

Pavel

------------------------------------------------------------------------------
_______________________________________________
Fornax-developer mailing list
Fornax-developer@...
https://lists.sourceforge.net/lists/listinfo/fornax-developer

Re: model.btdesign and Generics

by Patrik Nordwall :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Yes, something like this...

        abstract Entity Type
                {
                  scaffold
               
                  String shortKey key;
                  String description;
               
                  Repository TypeRepository
                  {
                     List<@Type> findAllOf(Class typeClass) => AccessObject;
                  }
                }
               
                Entity TypeA extends @Type
                {
                }
               
                Entity TypeB extends @Type
                {
                }
               
                Service TypeService
                {
                   findAllOf => @TypeRepository.findAllOf;
                }

With FindAllOfAccessImpl:

public class FindAllOfAccessImpl extends FindAllOfAccessImplBase {
    @SuppressWarnings("unchecked")
    @Override
    public void performExecute() {
        StringBuilder queryStr = new StringBuilder();
        queryStr.append("select e from ").append(getTypeClass().getName()).append(" e");
        Query query = getEntityManager().createQuery(queryStr.toString());
        List resultList = query.getResultList();
        setResult(resultList);
    }
}

Re: model.btdesign and Generics

by Sascha Broich :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks,

this looks near enough to my original intention.

> -----Ursprüngliche Nachricht-----
> Von: Patrik Nordwall [mailto:patrik.nordwall@...]
>
> public class FindAllOfAccessImpl extends FindAllOfAccessImplBase {
>     @SuppressWarnings("unchecked")
>     @Override
>     public void performExecute() {
>         StringBuilder queryStr = new StringBuilder();
>         queryStr.append("select e from
> ").append(getTypeClass().getName()).append(" e");
>         Query query =
> getEntityManager().createQuery(queryStr.toString());
>         List resultList = query.getResultList();
>         setResult(resultList);
>     }
> }

As I found out, I don't have "getEntityManager()" but "getHibernateTemplate()" which has a function called "loadAll(Class)". So my FindAllOfAccessImpl is a one-liner.


Regards,
Sascha Broich
--
TSA - Teleport Sachsen-Anhalt Service GmbH
Delitzscher Straße 70, 06112 Halle
Phone: +49 39203 8 2524
Email: Sascha.Broich@...

Firmensitz: Steinfeldstraße 5, D-39179 Barleben
Geschäftsführer: Marco Langhof
Amtsgericht: Stendal HRB 6388
http://www.tsa.de



------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Fornax-developer mailing list
Fornax-developer@...
https://lists.sourceforge.net/lists/listinfo/fornax-developer