@@ -834,8 +834,14 @@ public void addCustomFunction(String name, int numArgs, CustomFunction function)
834834
835835 synchronized (mLock ) {
836836 throwIfNotOpenLocked ();
837+
837838 mConfigurationLocked .customFunctions .add (wrapper );
838- mConnectionPoolLocked .reconfigure (mConfigurationLocked );
839+ try {
840+ mConnectionPoolLocked .reconfigure (mConfigurationLocked );
841+ } catch (RuntimeException ex ) {
842+ mConfigurationLocked .customFunctions .remove (wrapper );
843+ throw ex ;
844+ }
839845 }
840846 }
841847
@@ -1733,8 +1739,15 @@ public void setLocale(Locale locale) {
17331739
17341740 synchronized (mLock ) {
17351741 throwIfNotOpenLocked ();
1742+
1743+ final Locale oldLocale = mConfigurationLocked .locale ;
17361744 mConfigurationLocked .locale = locale ;
1737- mConnectionPoolLocked .reconfigure (mConfigurationLocked );
1745+ try {
1746+ mConnectionPoolLocked .reconfigure (mConfigurationLocked );
1747+ } catch (RuntimeException ex ) {
1748+ mConfigurationLocked .locale = oldLocale ;
1749+ throw ex ;
1750+ }
17381751 }
17391752 }
17401753
@@ -1759,8 +1772,15 @@ public void setMaxSqlCacheSize(int cacheSize) {
17591772
17601773 synchronized (mLock ) {
17611774 throwIfNotOpenLocked ();
1775+
1776+ final int oldMaxSqlCacheSize = mConfigurationLocked .maxSqlCacheSize ;
17621777 mConfigurationLocked .maxSqlCacheSize = cacheSize ;
1763- mConnectionPoolLocked .reconfigure (mConfigurationLocked );
1778+ try {
1779+ mConnectionPoolLocked .reconfigure (mConfigurationLocked );
1780+ } catch (RuntimeException ex ) {
1781+ mConfigurationLocked .maxSqlCacheSize = oldMaxSqlCacheSize ;
1782+ throw ex ;
1783+ }
17641784 }
17651785 }
17661786
@@ -1805,6 +1825,10 @@ public void setMaxSqlCacheSize(int cacheSize) {
18051825 * </p>
18061826 *
18071827 * @return true if write-ahead-logging is set. false otherwise
1828+ *
1829+ * @throw IllegalStateException if there are transactions in progress at the
1830+ * time this method is called. WAL mode can only be changed when there are no
1831+ * transactions in progress.
18081832 */
18091833 public boolean enableWriteAheadLogging () {
18101834 synchronized (mLock ) {
@@ -1835,18 +1859,32 @@ public boolean enableWriteAheadLogging() {
18351859 return false ;
18361860 }
18371861
1838- mIsWALEnabledLocked = true ;
1862+ final int oldMaxConnectionPoolSize = mConfigurationLocked .maxConnectionPoolSize ;
1863+ final String oldSyncMode = mConfigurationLocked .syncMode ;
1864+ final String oldJournalMode = mConfigurationLocked .journalMode ;
18391865 mConfigurationLocked .maxConnectionPoolSize = SQLiteGlobal .getWALConnectionPoolSize ();
18401866 mConfigurationLocked .syncMode = SQLiteGlobal .getWALSyncMode ();
18411867 mConfigurationLocked .journalMode = "WAL" ;
1842- mConnectionPoolLocked .reconfigure (mConfigurationLocked );
1868+ try {
1869+ mConnectionPoolLocked .reconfigure (mConfigurationLocked );
1870+ } catch (RuntimeException ex ) {
1871+ mConfigurationLocked .maxConnectionPoolSize = oldMaxConnectionPoolSize ;
1872+ mConfigurationLocked .syncMode = oldSyncMode ;
1873+ mConfigurationLocked .journalMode = oldJournalMode ;
1874+ throw ex ;
1875+ }
1876+
1877+ mIsWALEnabledLocked = true ;
18431878 }
18441879 return true ;
18451880 }
18461881
18471882 /**
18481883 * This method disables the features enabled by {@link #enableWriteAheadLogging()}.
1849- * @hide
1884+ *
1885+ * @throw IllegalStateException if there are transactions in progress at the
1886+ * time this method is called. WAL mode can only be changed when there are no
1887+ * transactions in progress.
18501888 */
18511889 public void disableWriteAheadLogging () {
18521890 synchronized (mLock ) {
@@ -1856,11 +1894,22 @@ public void disableWriteAheadLogging() {
18561894 return ;
18571895 }
18581896
1859- mIsWALEnabledLocked = false ;
1897+ final int oldMaxConnectionPoolSize = mConfigurationLocked .maxConnectionPoolSize ;
1898+ final String oldSyncMode = mConfigurationLocked .syncMode ;
1899+ final String oldJournalMode = mConfigurationLocked .journalMode ;
18601900 mConfigurationLocked .maxConnectionPoolSize = 1 ;
18611901 mConfigurationLocked .syncMode = SQLiteGlobal .getDefaultSyncMode ();
18621902 mConfigurationLocked .journalMode = SQLiteGlobal .getDefaultJournalMode ();
1863- mConnectionPoolLocked .reconfigure (mConfigurationLocked );
1903+ try {
1904+ mConnectionPoolLocked .reconfigure (mConfigurationLocked );
1905+ } catch (RuntimeException ex ) {
1906+ mConfigurationLocked .maxConnectionPoolSize = oldMaxConnectionPoolSize ;
1907+ mConfigurationLocked .syncMode = oldSyncMode ;
1908+ mConfigurationLocked .journalMode = oldJournalMode ;
1909+ throw ex ;
1910+ }
1911+
1912+ mIsWALEnabledLocked = false ;
18641913 }
18651914 }
18661915
0 commit comments