Quantcast

tips on making a grails website readonly

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

tips on making a grails website readonly

micke_
Hi

I wonder if there is a trick to disable database writes?

I'd love a feature like this when upgrading so I could keep one instance running in readonly mode while bringing up a new instance with the latest release. Something for when there aren't massive domain model changes.

Currently I've persisting things all over the place and thought I'd check and see if there was a way to disable it in GORM etc.

Cheers,
 micke
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: tips on making a grails website readonly

cdeszaq
Depending on what you are using for the database, you could simply remove all but SELECT privileges from the DB user the grails app is running as.

This seems much simpler than trying to tweak Hibernate, although I am sure this is possible.

- Rick


On Thu, Mar 1, 2012 at 4:33 PM, Mikael Andersson <[hidden email]> wrote:
Hi

I wonder if there is a trick to disable database writes?

I'd love a feature like this when upgrading so I could keep one instance running in readonly mode while bringing up a new instance with the latest release. Something for when there aren't massive domain model changes.

Currently I've persisting things all over the place and thought I'd check and see if there was a way to disable it in GORM etc.

Cheers,
 micke

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: tips on making a grails website readonly

Jonathan Rosenberg

You can tell Hibernate to make the session read-only.  Search through the archives.  The technique has shown up a few times.

On Mar 1, 2012 6:01 PM, "Rick Jensen" <[hidden email]> wrote:
Depending on what you are using for the database, you could simply remove all but SELECT privileges from the DB user the grails app is running as.

This seems much simpler than trying to tweak Hibernate, although I am sure this is possible.

- Rick


On Thu, Mar 1, 2012 at 4:33 PM, Mikael Andersson <[hidden email]> wrote:
Hi

I wonder if there is a trick to disable database writes?

I'd love a feature like this when upgrading so I could keep one instance running in readonly mode while bringing up a new instance with the latest release. Something for when there aren't massive domain model changes.

Currently I've persisting things all over the place and thought I'd check and see if there was a way to disable it in GORM etc.

Cheers,
 micke

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: tips on making a grails website readonly

robelsner
In reply to this post by micke_
Or add beforeUpdate or beforeDelete closures to your domain objects,
and in these closures check a setting and throw an exception to
prevent the action from executing.

This will let you disable writing while the app is running.

Rob

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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: tips on making a grails website readonly

Lauro Becker
I didn't test it, but you could set cache 'read_only' to your domain classes.

This can be set to all domains in Config, with grails.gorm.default.mapping.

Lauro L. V. Becker
---------------------------
Blog: http://laurobecker.wordpress.com


2012/3/1 Rob Elsner <[hidden email]>
Or add beforeUpdate or beforeDelete closures to your domain objects,
and in these closures check a setting and throw an exception to
prevent the action from executing.

This will let you disable writing while the app is running.

Rob

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

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: tips on making a grails website readonly

Konstantinos Kostarellis
Don't know if it helps in your situation but you can set a dataSource readOnly 


Cheers,
   Kosta

2012/3/2 Lauro Becker <[hidden email]>
I didn't test it, but you could set cache 'read_only' to your domain classes.

This can be set to all domains in Config, with grails.gorm.default.mapping.

Lauro L. V. Becker
---------------------------
Blog: http://laurobecker.wordpress.com



2012/3/1 Rob Elsner <[hidden email]>
Or add beforeUpdate or beforeDelete closures to your domain objects,
and in these closures check a setting and throw an exception to
prevent the action from executing.

This will let you disable writing while the app is running.

Rob

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

   http://xircles.codehaus.org/manage_email




Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: tips on making a grails website readonly

jeffpogo
In reply to this post by micke_
You can put in a DDL filter to ignore certain tables for table changes too.

See:  http://www.slideshare.net/gr8conf/gorm-burt-beckwith2011

import java.util.ArrayList;
import java.util.List;

import org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsAnnotationConfiguration;
import org.hibernate.HibernateException;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.HSQLDialect;
import org.hibernate.tool.hbm2ddl.DatabaseMetadata;

@SuppressWarnings("serial")
public class DdlFilterConfiguration extends GrailsAnnotationConfiguration {

        private static final String[] IGNORED_NAMES = { "com.billto",
                        "com.company", "trk.eqmast", "trk.eqowner", "trk.locprof",
                        "trk.move", "trk.order" };

        @Override
        public String[] generateSchemaCreationScript(Dialect dialect)
                        throws HibernateException {
                return prune(super.generateSchemaCreationScript(dialect), dialect);
        }

        @Override
        public String[] generateDropSchemaScript(Dialect dialect)
                        throws HibernateException {
                return prune(super.generateDropSchemaScript(dialect), dialect);
        }

        @Override
        public String[] generateSchemaUpdateScript(Dialect dialect,
                        DatabaseMetadata databaseMetadata) throws HibernateException {
                return prune(
                                super.generateSchemaUpdateScript(dialect, databaseMetadata),
                                dialect);
        }

        private String[] prune(String[] script, Dialect dialect) {
                if (dialect instanceof HSQLDialect) {
                        // do nothing for test env
                        return script;
                }

                List<String> pruned = new ArrayList<String>();
                for (String command : script) {

                        if (!isIgnored(command)) {
                                pruned.add(command);
                                System.out.println("RUNNING: " + command);
                        } else {
                                System.out.println("IGNORING: " + command);
                        }
                }

                return pruned.toArray(new String[pruned.size()]);
        }

        private boolean isIgnored(String command) {
                command = command.toLowerCase();
                for (String table : IGNORED_NAMES) {
                        if (command.startsWith("create table " + table + " ")
                                        || command.startsWith("alter table " + table + " ")
                                        || command.startsWith("drop table " + table + " ")
                                        || command.startsWith("drop table if exists" + table + " ")) {
                                return true;
                        }
                }
                return false;
        }
}
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: tips on making a grails website readonly

micke_
In reply to this post by Konstantinos Kostarellis
Many thanks, now I've got a couple of different approaches.

Please keep the advice coming ;)

Cheers,
 micke




On 2 March 2012 13:07, Konstantinos Kostarellis <[hidden email]> wrote:
Don't know if it helps in your situation but you can set a dataSource readOnly 


Cheers,
   Kosta

2012/3/2 Lauro Becker <[hidden email]>
I didn't test it, but you could set cache 'read_only' to your domain classes.

This can be set to all domains in Config, with grails.gorm.default.mapping.

Lauro L. V. Becker
---------------------------
Blog: http://laurobecker.wordpress.com



2012/3/1 Rob Elsner <[hidden email]>
Or add beforeUpdate or beforeDelete closures to your domain objects,
and in these closures check a setting and throw an exception to
prevent the action from executing.

This will let you disable writing while the app is running.

Rob

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

   http://xircles.codehaus.org/manage_email





Loading...