How to make sure a domain object cannot be save?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

How to make sure a domain object cannot be save?

marcopas
Hi there,

I have a situation where i replace some values in my domain object
based on a method call.
What i would like to make sure is that if a record is modified i am
not able to accidentally persist it. Is there a way
to make sure that i can not save the object when i have modified the values?

Greetings Marco

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

RE: How to make sure a domain object cannot be save?

netwiser
In GORM, there is a method to verify the domain instance has been modified or not, you can call isDirty() to check it .

Here is the doc: http://grails.org/doc/latest/ref/Domain%20Classes/isDirty.html

> Date: Mon, 3 Oct 2011 21:28:53 +0200

> From: [hidden email]
> To: [hidden email]
> Subject: [grails-user] How to make sure a domain object cannot be save?
>
> Hi there,
>
> I have a situation where i replace some values in my domain object
> based on a method call.
> What i would like to make sure is that if a record is modified i am
> not able to accidentally persist it. Is there a way
> to make sure that i can not save the object when i have modified the values?
>
> Greetings Marco
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
> http://xircles.codehaus.org/manage_email
>
>
Reply | Threaded
Open this post in threaded view
|

Re: How to make sure a domain object cannot be save?

marcopas
Thanks for the tip, but my question is not on how to identify if an
object is dirty but somehow force
that an object cannot be saved.



2011/10/3 James Zhang <[hidden email]>:

> In GORM, there is a method to verify the domain instance has been modified
> or not, you can call isDirty() to check it .
> Here is the
> doc: http://grails.org/doc/latest/ref/Domain%20Classes/isDirty.html
>
>> Date: Mon, 3 Oct 2011 21:28:53 +0200
>> From: [hidden email]
>> To: [hidden email]
>> Subject: [grails-user] How to make sure a domain object cannot be save?
>>
>> Hi there,
>>
>> I have a situation where i replace some values in my domain object
>> based on a method call.
>> What i would like to make sure is that if a record is modified i am
>> not able to accidentally persist it. Is there a way
>> to make sure that i can not save the object when i have modified the
>> values?
>>
>> Greetings Marco
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>> http://xircles.codehaus.org/manage_email
>>
>>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

RE: How to make sure a domain object cannot be save?

netwiser
If you want ALL domain objects are read only, you can do this in your BootStrap.groovy if you are using datasource. 

class BootStrap { 

     
def dataSource

     
def init = { servletContext ->
         dataSource
.defaultReadOnly = true
     
}

     
def destroy = {}
}
This will prevents your domain object never get updated. 

With multiple datasource plugin (http://grails.org/plugin/datasources), you can configure another datasource for your CUD purpose. 

I am not really sure this is all you want or not. 



> Date: Mon, 3 Oct 2011 21:45:34 +0200

> From: [hidden email]
> To: [hidden email]
> Subject: Re: [grails-user] How to make sure a domain object cannot be save?
>
> Thanks for the tip, but my question is not on how to identify if an
> object is dirty but somehow force
> that an object cannot be saved.
>
>
>
> 2011/10/3 James Zhang <[hidden email]>:
> > In GORM, there is a method to verify the domain instance has been modified
> > or not, you can call isDirty() to check it .
> > Here is the
> > doc: http://grails.org/doc/latest/ref/Domain%20Classes/isDirty.html
> >
> >> Date: Mon, 3 Oct 2011 21:28:53 +0200
> >> From: [hidden email]
> >> To: [hidden email]
> >> Subject: [grails-user] How to make sure a domain object cannot be save?
> >>
> >> Hi there,
> >>
> >> I have a situation where i replace some values in my domain object
> >> based on a method call.
> >> What i would like to make sure is that if a record is modified i am
> >> not able to accidentally persist it. Is there a way
> >> to make sure that i can not save the object when i have modified the
> >> values?
> >>
> >> Greetings Marco
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe from this list, please visit:
> >>
> >> http://xircles.codehaus.org/manage_email
> >>
> >>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
> http://xircles.codehaus.org/manage_email
>
>
Reply | Threaded
Open this post in threaded view
|

Re: How to make sure a domain object cannot be save?

elvanor
In reply to this post by marcopas
You can declare your Hibernate session to be read only.

On Mon, Oct 3, 2011 at 9:45 PM, Marco Pas <[hidden email]> wrote:

> Thanks for the tip, but my question is not on how to identify if an
> object is dirty but somehow force
> that an object cannot be saved.
>
>
>
> 2011/10/3 James Zhang <[hidden email]>:
>> In GORM, there is a method to verify the domain instance has been modified
>> or not, you can call isDirty() to check it .
>> Here is the
>> doc: http://grails.org/doc/latest/ref/Domain%20Classes/isDirty.html
>>
>>> Date: Mon, 3 Oct 2011 21:28:53 +0200
>>> From: [hidden email]
>>> To: [hidden email]
>>> Subject: [grails-user] How to make sure a domain object cannot be save?
>>>
>>> Hi there,
>>>
>>> I have a situation where i replace some values in my domain object
>>> based on a method call.
>>> What i would like to make sure is that if a record is modified i am
>>> not able to accidentally persist it. Is there a way
>>> to make sure that i can not save the object when i have modified the
>>> values?
>>>
>>> Greetings Marco
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe from this list, please visit:
>>>
>>> http://xircles.codehaus.org/manage_email
>>>
>>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: How to make sure a domain object cannot be save?

Nick Vaidyanathan
In reply to this post by marcopas
right. So define a beforeSave method in your domain class that checks if the object isDirty and vetoes the save:

http://grails.org/doc/2.0.x/guide/single.html#GORM

5.5.1 Events and Auto Timestamping

GORM supports the registration of events as methods that get fired when certain events occurs such as deletes, inserts and updates. The following is a list of supported events:
  • beforeInsert - Executed before an object is initially persisted to the database
  • beforeUpdate - Executed before an object is updated
  • beforeDelete - Executed before an object is deleted
  • beforeValidate - Executed before an object is validated
  • afterInsert - Executed after an object is persisted to the database
  • afterUpdate - Executed after an object has been updated
  • afterDelete - Executed after an object has been deleted
  • onLoad - Executed when an object is loaded from the database

To add an event simply register the relevant closure with your domain class.



On Mon, Oct 3, 2011 at 12:45 PM, Marco Pas <[hidden email]> wrote:
Thanks for the tip, but my question is not on how to identify if an
object is dirty but somehow force
that an object cannot be saved.



2011/10/3 James Zhang <[hidden email]>:
> In GORM, there is a method to verify the domain instance has been modified
> or not, you can call isDirty() to check it .
> Here is the
> doc: http://grails.org/doc/latest/ref/Domain%20Classes/isDirty.html
>
>> Date: Mon, 3 Oct 2011 21:28:53 +0200
>> From: [hidden email]
>> To: [hidden email]
>> Subject: [grails-user] How to make sure a domain object cannot be save?
>>
>> Hi there,
>>
>> I have a situation where i replace some values in my domain object
>> based on a method call.
>> What i would like to make sure is that if a record is modified i am
>> not able to accidentally persist it. Is there a way
>> to make sure that i can not save the object when i have modified the
>> values?
>>
>> Greetings Marco
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>> http://xircles.codehaus.org/manage_email
>>
>>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: How to make sure a domain object cannot be save?

tomas lin
In reply to this post by marcopas
You can also just read your domain objects

MyDomain.read( id ) instead of get


On Mon, Oct 3, 2011 at 8:28 PM, Marco Pas <[hidden email]> wrote:

> Hi there,
>
> I have a situation where i replace some values in my domain object
> based on a method call.
> What i would like to make sure is that if a record is modified i am
> not able to accidentally persist it. Is there a way
> to make sure that i can not save the object when i have modified the values?
>
> Greetings Marco
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: How to make sure a domain object cannot be save?

marcopas
To be clear what i am trying to achieve is that a domain object can be
localized using m17n. This involves a standard domain object with
properties and a overlay object which contains the translations for
some of the properties in a specific language.

So during runtime i am reading the domain object and if needed i
replace some of the properties with localized versions. What may not
occur is that i save the domain instance, because then the current
localized version will be persisted into the standard domain object.

2011/10/3 Tomas Lin <[hidden email]>:

> You can also just read your domain objects
>
> MyDomain.read( id ) instead of get
>
>
> On Mon, Oct 3, 2011 at 8:28 PM, Marco Pas <[hidden email]> wrote:
>> Hi there,
>>
>> I have a situation where i replace some values in my domain object
>> based on a method call.
>> What i would like to make sure is that if a record is modified i am
>> not able to accidentally persist it. Is there a way
>> to make sure that i can not save the object when i have modified the values?
>>
>> Greetings Marco
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>    http://xircles.codehaus.org/manage_email
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


np
Reply | Threaded
Open this post in threaded view
|

RE: How to make sure a domain object cannot be save?

np
It seems this requirement would be contained in one of two scenarios:
1. There is no persistence necessary in your workflow, in which case some of the previously mentioned options would work.
2. There is need for persistence but just not for these particular domain objects, in which case I'd suggest you evict them prior to your localization.  This would remove them from consideration in your active session so other persistence activities could occur without having to worry about these objects.

Nate Perkins
Project Architect/Software Developer
Glynlyon


-----Original Message-----
From: Marco Pas [mailto:[hidden email]]
Sent: Monday, October 03, 2011 1:29 PM
To: [hidden email]
Subject: Re: [grails-user] How to make sure a domain object cannot be save?

To be clear what i am trying to achieve is that a domain object can be
localized using m17n. This involves a standard domain object with
properties and a overlay object which contains the translations for
some of the properties in a specific language.

So during runtime i am reading the domain object and if needed i
replace some of the properties with localized versions. What may not
occur is that i save the domain instance, because then the current
localized version will be persisted into the standard domain object.

2011/10/3 Tomas Lin <[hidden email]>:

> You can also just read your domain objects
>
> MyDomain.read( id ) instead of get
>
>
> On Mon, Oct 3, 2011 at 8:28 PM, Marco Pas <[hidden email]> wrote:
>> Hi there,
>>
>> I have a situation where i replace some values in my domain object
>> based on a method call.
>> What i would like to make sure is that if a record is modified i am
>> not able to accidentally persist it. Is there a way
>> to make sure that i can not save the object when i have modified the values?
>>
>> Greetings Marco
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>    http://xircles.codehaus.org/manage_email
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email