From 68930d845c27578c60fbf6d083a5a9e36fd5078e Mon Sep 17 00:00:00 2001 From: bartolomiew Date: Sun, 28 Oct 2012 08:41:27 +0100 Subject: Allows to gain full control of transactions --- src/com/iciql/Db.java | 38 ++++++++++++++++++++++++++++++++++++++ src/com/iciql/TableDefinition.java | 6 +++++- 2 files changed, 43 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/com/iciql/Db.java b/src/com/iciql/Db.java index caec637..32b7c6a 100644 --- a/src/com/iciql/Db.java +++ b/src/com/iciql/Db.java @@ -1,6 +1,7 @@ /* * Copyright 2004-2011 H2 Group. * Copyright 2011 James Moger. + * Copyright 2012 Frederic Gaillard. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -68,6 +69,9 @@ public class Db { private DbUpgrader dbUpgrader = new DefaultDbUpgrader(); private final Set> upgradeChecked = Collections.synchronizedSet(new HashSet>()); + private boolean skipCreate; + private boolean autoSavePoint = true; + static { TOKENS = Collections.synchronizedMap(new WeakIdentityHashMap()); DIALECTS = Collections.synchronizedMap(new HashMap>()); @@ -563,6 +567,11 @@ public class Db { } Savepoint prepareSavepoint() { + // don't change auto-commit mode. + // don't create save point. + if (!autoSavePoint) { + return null; + } // create a savepoint Savepoint savepoint = null; try { @@ -731,4 +740,33 @@ public class Db { JdbcUtils.closeSilently(stat); } } + + /** + * Allow to enable/disable globally createIfRequired in TableDefinition. + * For advanced user wanting to gain full control of transactions. + * Default value is false. + * @param skipCreate + */ + public void setSkipCreate(boolean skipCreate) { + this.skipCreate = skipCreate; + } + + public boolean getSkipCreate() { + return this.skipCreate; + } + + /** + * Allow to enable/disable usage of save point. + * For advanced user wanting to gain full control of transactions. + * Default value is false. + * @param autoSavePoint + */ + public void setAutoSavePoint(boolean autoSavePoint) { + this.autoSavePoint = autoSavePoint; + } + + public boolean getAutoSavePoint() { + return this.autoSavePoint; + } + } diff --git a/src/com/iciql/TableDefinition.java b/src/com/iciql/TableDefinition.java index 1ecf394..e96b61c 100644 --- a/src/com/iciql/TableDefinition.java +++ b/src/com/iciql/TableDefinition.java @@ -1,7 +1,7 @@ /* * Copyright 2004-2011 H2 Group. * Copyright 2011 James Moger. - * Copyright 2012 Frédéric Gaillard. + * Copyright 2012 Frederic Gaillard. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -839,6 +839,10 @@ public class TableDefinition { } TableDefinition createIfRequired(Db db) { + // globally enable/disable check of create if required + if (db.getSkipCreate()) { + return this; + } if (!createIfRequired) { // skip table and index creation // but still check for upgrades -- cgit v1.2.3