package dao;

import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.Cluster;
import com.couchbase.client.java.CouchbaseCluster;
import com.couchbase.client.java.error.FlushDisabledException;
import util.Configuration;

/**
 * Created by jeremy on 09/04/15.
 */
public class DAOManager {

    /**
     * Current Connection
     */
    protected static Cluster currentCluster = CouchbaseCluster.create(Configuration.COUCHBASE_HOSTNAME);

    /**
     * Instance of the DAOManager
     */
    private static DAOManager instance = new DAOManager();

    /**
     * Current Bucket
     */
    protected static Bucket currentBucket;

    public static void connect(){
        if (currentCluster != null && currentBucket==null) {
            // Open a bucket
            currentBucket = currentCluster.openBucket(Configuration.BUCKET_NAME);
        }
    }

    public static void connectTest(){
        if (currentCluster != null && currentBucket==null) {
            // Open a bucket
            currentBucket = currentCluster.openBucket(Configuration.BUCKET_NAME_TEST);
        }
    }

    public static void disconnect() {
        if(currentCluster != null)
        {
            if (currentBucket != null && currentBucket.close()){
                currentBucket = null;
            }
        }
    }


    /**
     * flush our bucket
     * @return
     */
    public static boolean flush()
    {
        if(currentBucket!=null && currentCluster!=null)
        {
            try
            {
                return currentBucket.bucketManager().flush();
            }
            catch (FlushDisabledException e)
            {
                e.printStackTrace();
                return false;
            }
        }
        return false;
    }

    public static Bucket getCurrentBucket() {
        return currentBucket;
    }
}

@@ -232,16 +232,58 @@
 ation;%0A%0A
+import java.util.NoSuchElementException;%0A%0A
 /**%0A * C
@@ -1172,24 +1172,42 @@
 connect() %7B%0A
+        try %7B%0A    
         if(c
@@ -1196,32 +1196,33 @@
 %7B%0A            if
+ 
 (currentCluster 
@@ -1225,35 +1225,31 @@
 ter != null)
-%0A    
+ %7B%0A
     
-%7B%0A
             
@@ -1299,18 +1299,23 @@
 close())
+ 
 %7B%0A
+    
         
@@ -1348,33 +1348,106 @@
 ll;%0A            
-%7D
+    %7D%0A            %7D%0A        %7D%0A        catch (NoSuchElementException ex) %7B%0A
 %0A        %7D%0A    %7D

FIX DU BUG DE LOGIN