Marcantonio,

If I undesrstood it, you are only changing the value of the object, but the 
instnace is the same as you invoked into the "singleton" isn't it?

I think that this is the right behaviour, so as you are persisting this object, 
is it being persisted into application or session?

Regards,

Marcos Placon�
Desenvolvedor - NAVITA
Fone: 55 11 3055-2001
Mobile: 55 11 9560-3260
http://www.navita.com.br


------------- Segue mensagem original! -------------

De: "Marcantonio Silva" <[EMAIL PROTECTED]>
Data: Mon, 10 Jan 2005 10:15:01 -0200
Para: <[email protected]>
Assunto: Re: [CFCDev] Shared persistent objects pattern ?


Hi Micha,

I'm not working with queries or recordsets in the repository, what I do is that 
I have a DAO that retrieves the objects 
from the database based on the parameter (id for while).

The object is then created in the bean and stored in the repository (whish is 
an application.Structure[id].

Next time I come to the repository to get an objects, it's still there.

My queries don�t change, since any filters, groups or business logic are 
managed by the "manager" cfc,
if I need to get a subset of articles, I will get them though the gateway 
(which returns a query or a list) and then 
I get the objects from the repository again.

Resuming:
if I need object article id =1 I do: 
myArticle = repository.getArticle("1");

The repository tries to get it from the application.stArticles["1"], if its not 
there, gets it from the DAO through the bean by doing:

if NOT structKeyExists(application.stArticles,"1")
myArticlenotPersisted =  articleBean.getArticle("1"); (which invokes articleDAO 
to query the database,  and then maps the query to an article object)
/if

and then stores te returned object in the repository application by doing:

addToRepository(myArticlenotPersisted ); (here I add a timestamp just to have 
some metrics)

Next time someone wants object article  id = 1, the repository gets it from the 
application.structure.

Getting objects based on property values, as you mentioned, is another feature, 
that will be managed by the gateway, but I'm not there yet.

Here comes a doubt:
Since the object is hold by reference, when someone changes its properties, it 
will automatically change the shared instance.
I don�t know if this is right behavior, but since we dont have 
duplicate(object) I guess it will work fine whenever myArticle.setName("new 
name") is invoked.

Regards,


Marcantonio Silva
Diretor de Desenvolvimento de Produtos - Navita
[EMAIL PROTECTED]
www.navita.com.br
Tel: +55 11 3055.2004 
Cel: +55 11 7732.4907 (novo)

 

  ----- Original Message ----- 
  From: Micha Schopman 
  To: [email protected] 
  Sent: Monday, January 10, 2005 7:28 AM
  Subject: RE: [CFCDev] Shared persistent objects pattern ?


  The biggest challenge is separating different record sets in different 
reusable objects in your persistency layer. 

   

  You need to create those objects based on the query executed, one time you 
use 

  SELECT * FROM ARTICLE WHERE id = 1 and in some other moments u use SELECT * 
FROM ARTICLE WHERE id = 2.

   

  You might even do 
  SELECT * FROM ARTICLE WHERE id = 2 AND publisheddate BETWEEN [] AND 
authorName LIKE 'Barney' AND Categories IN (SELECT * From Categories WHERE . )  
. etc.. 

   

  Hey another object to manage .. I think this managing process, is pretty 
difficult to do it right.

  Micha Schopman 
  Software Engineer 

  Modern Media, Databankweg 12 M, 3821 AL  Amersfoort 
  Tel 033-4535377, Fax 033-4535388 
  KvK Amersfoort 39081679, Rabo 39.48.05.380 

  
-----------------------------------------------------------------------------------------------------------------------------------------------------

  Modern Media, Making You Interact Smarter. Onze oplossingen verbeteren de 
interactie met uw doelgroep. 
  Wilt u meer omzet, lagere kosten of een beter service niveau? Voor meer 
informatie zie www.modernmedia.nl 
  
-----------------------------------------------------------------------------------------------------------------------------------------------------

  -----Original Message-----
  From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Marcantonio 
Silva
  Sent: zaterdag 8 januari 2005 21:37
  To: [email protected]
  Subject: Re: [CFCDev] Shared persistent objects pattern ?

   

  Oi Aldo,

   

  In my very  humble (and beginner) opinion, the singleton is an answer for the 
problem of having only one instance of a class, very usefull for example, to 
instantiate a single application, or maybe even to init a single facade of an 
app.

  There is an excelent article by Brendon O'Hara on the CFDJ site explaining 
the Singleton Pattern: http://www.sys-con.com/coldfusion/article.cfm?id=624

   

  The problem that I need to address is how to have a repository of single 
objects, without having to go to the database to get them everytime I need one, 

  and without having to instantiate them all when initializing the app.

   

  I got the solution from the source: Martin Fowler's site has a very brief 
description for a patterm that does exactly what I need, here is a quote from 
the site: 

   

  "Objects can be added to and removed from the Repository, as they can from a 
simple collection of objects, and the mapping code encapsulated by the 
Repository will carry out the appropriate operations behind the scenes. 
Conceptually, a Repository encapsulates the set of objects persisted in a data 
store and the operations performed over them, providing a more object-oriented 
view of the persistence layer."

   

  It didn't surprised me that the Pattern is called "Repository Pattern", here 
is the URL: http://www.martinfowler.com/eaaCatalog/repository.html

   

  I also found the "Lazy Load" pattern, which will help me on second part of 
the problem, that is not having to load all my objects from the database when 
initializing the app, only when it's really needed for the application.

   

  I would love to see ColdFusion implementations of both patterns, but since I 
didn�t find it, I will try to figure out by myself.

   

  Regards,

   

  Marcantonio Silva
  Diretor de Desenvolvimento de Produtos - Navita
  [EMAIL PROTECTED]
  www.navita.com.br
  Tel: +55 11 3055.2004 
  Cel: +55 11 7732.4907 (novo)

   

    ----- Original Message ----- 

    From: Aldo d'Aquino 

    To: [email protected] 

    Sent: Friday, January 07, 2005 5:36 PM

    Subject: Re: [CFCDev] Shared persistent objects pattern ?

     

    Marcantonio,

     

    maybe the Singleton Pattern could be used to grant only one instance for 
this shared repository.  But even in this case we need to implement the rules 
(in any Business Object) to check the repository first or to insert a new 
content in the repository.

     

    Anything else?

     

    Aldo Menezes d'Aquino Neto
    L�der de Projetos - Navita
    [EMAIL PROTECTED]
    www.navita.com.br
    Tel: +55 48 225.5396
    Cel: +55 48 9911.5598

     

     

      ----- Original Message ----- 

      From: Marcantonio Silva 

      To: [email protected] 

      Sent: Friday, January 07, 2005 4:11 PM

      Subject: [CFCDev] Shared persistent objects pattern ?

       

      Hello,

       

      I have a problem and I don't know if there is a pattern for this, or even 
if this is considered a good design:

       

      - Due to performance factors, I don't want to go to the database every 
time someone gets a content object, I rather prefere to "store" this object 

      in memory so I can reuse it whenever it's invoked from the view.

       

      - In traditional (or procedural) development, I would store an array of 
structures (or queryes) into an application var, and every time someone want 
some content,

      I would first try to get it from the application array, if it's not 
there, I would go the database, retrieve it and also insert it into the shared 
array.

       

      - If someone "updates" one of the the records, I can update the table, 
and the application.array.structure content, so I would have both, 

      the persistent and the "etereal" records both updated.

      This is all very straightforward to do in CF, I have done it before since 
CF 4.

       

      I'm considering to use the gateway in Blackstone to send a message to the 
CFC that will update the database, 

      so I won't even have this database access action contributing for the 
overall system performance.

       

      When transporting this concept to objectland, it seems obvious to me that 
a design pattern must be used, 

      both for the "shared object reposytory" and for the "message that will 
update the database" functions.

       

      So comes the question: Is there any patterns out there for doing this ?

       

       

      Regards,

      Marcantonio Silva
      Diretor de Desenvolvimento de Produtos - Navita
      [EMAIL PROTECTED]
      www.navita.com.br
      Tel: +55 11 3055.2004 
      Cel: +55 11 7732.4907 (novo)


--------------------------------------------------------------------------

      No virus found in this incoming message.
      Checked by AVG Anti-Virus.
      Version: 7.0.300 / Virus Database: 265.6.9 - Release Date: 6/1/2005


----------------------------------------------------------------------------

    No virus found in this outgoing message.
    Checked by AVG Anti-Virus.
    Version: 7.0.300 / Virus Database: 265.6.9 - Release Date: 6/1/2005


----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' 
in the message of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).

An archive of the CFCDev list is available at 
www.mail-archive.com/[email protected]

Reply via email to