// Path: coopr-server/src/main/java/co/cask/coopr/account/Account.java
// public final class Account {
//   public static final Account SUPERADMIN = new Account(Constants.ADMIN_USER, Constants.SUPERADMIN_TENANT);
//   private final String userId;
//   private final String tenantId;
// 
//   public Account(String userId, String tenantId) {
//     Preconditions.checkArgument(userId != null && !userId.isEmpty(), "Account must have a user id.");
//     Preconditions.checkArgument(tenantId != null && !tenantId.isEmpty(), "Account must have a tenant id.");
//     this.userId = userId;
//     this.tenantId = tenantId;
//   }
// 
//   public String getUserId() {
//     return userId;
//   }
// 
//   public String getTenantId() {
//     return tenantId;
//   }
// 
//   public boolean isAdmin() {
//     return Constants.ADMIN_USER.equals(userId);
//   }
// 
//   public boolean isSuperadmin() {
//     return Constants.ADMIN_USER.equals(userId) && Constants.SUPERADMIN_TENANT.equals(tenantId);
//   }
// 
//   @Override
//   public boolean equals(Object o) {
//     if (this == o) {
//       return true;
//     }
//     if (!(o instanceof Account)) {
//       return false;
//     }
// 
//     Account other = (Account) o;
//     return Objects.equal(userId, other.userId) &&
//       Objects.equal(tenantId, other.tenantId);
//   }
// 
//   @Override
//   public int hashCode() {
//     return Objects.hashCode(userId, tenantId);
//   }
// 
//   @Override
//   public String toString() {
//     return Objects.toStringHelper(this)
//       .add("userId", userId)
//       .add("tenantId", tenantId)
//       .toString();
//   }
// }
// 
// Path: coopr-server/src/main/java/co/cask/coopr/store/DBPut.java
// public abstract class DBPut {
// 
//   /**
//    * Execute the put using the given connection.
//    *
//    * @param conn Connection to use to execute the put
//    * @throws SQLException
//    */
//   public void executePut(Connection conn) throws SQLException {
//     PreparedStatement updateStatement = createUpdateStatement(conn);
//     try {
//       int rowsUpdated = updateStatement.executeUpdate();
//       // if no rows are updated, perform the insert
//       if (rowsUpdated == 0) {
//         PreparedStatement insertStatement = createInsertStatement(conn);
//         try {
//           insertStatement.executeUpdate();
//         } finally {
//           insertStatement.close();
//         }
//       }
//     } finally {
//       updateStatement.close();
//     }
//   }
// 
//   protected abstract PreparedStatement createUpdateStatement(Connection conn) throws SQLException;
// 
//   protected abstract PreparedStatement createInsertStatement(Connection conn) throws SQLException;
// }


import java.util.Map;
import co.cask.coopr.account.Account;
import co.cask.coopr.store.DBConnectionPool;
import co.cask.coopr.store.DBHelper;
import co.cask.coopr.store.DBPut;
import co.cask.coopr.store.DBQueryExecutor;
import com.google.common.util.concurrent.AbstractIdleService;
import com.google.gson.reflect.TypeToken;
import com.google.inject.Inject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
    }
  }

  @Override
  public void deleteProfile(Account account) throws IOException {
    try {
      Connection conn = dbConnectionPool.getConnection();
      try {
        PreparedStatement statement =
          conn.prepareStatement("UPDATE users SET profile=null WHERE user_id=? AND tenant_id=?");
        try {
          statement.setString(1, account.getUserId());
          statement.setString(2, account.getTenantId());
          statement.executeUpdate();
        } finally {
          statement.close();
        }
      } finally {
        conn.close();
      }
    } catch (SQLException e) {
      LOG.error("Exception getting profile for account {}.", account, e);
      throw new IOException(e);
    }
  }

  private class ProfileDBPut extends DBPut {
    private final Account account;
    private final Map<String, Object> profile;

// Path: coopr-server/src/main/java/co/cask/coopr/account/Account.java
// public final class Account {
//   public static final Account SUPERADMIN = new Account(Constants.ADMIN_USER, Constants.SUPERADMIN_TENANT);
//   private final String userId;
//   private final String tenantId;
// 
//   public Account(String userId, String tenantId) {
//     Preconditions.checkArgument(userId != null && !userId.isEmpty(), "Account must have a user id.");
//     Preconditions.checkArgument(tenantId != null && !tenantId.isEmpty(), "Account must have a tenant id.");
//     this.userId = userId;
//     this.tenantId = tenantId;
//   }
// 
//   public String getUserId() {
//     return userId;
//   }
// 
//   public String getTenantId() {
//     return tenantId;
//   }
// 
//   public boolean isAdmin() {
//     return Constants.ADMIN_USER.equals(userId);
//   }
// 
//   public boolean isSuperadmin() {
//     return Constants.ADMIN_USER.equals(userId) && Constants.SUPERADMIN_TENANT.equals(tenantId);
//   }
// 
//   @Override
//   public boolean equals(Object o) {
//     if (this == o) {
//       return true;
//     }
//     if (!(o instanceof Account)) {
//       return false;
//     }
// 
//     Account other = (Account) o;
//     return Objects.equal(userId, other.userId) &&
//       Objects.equal(tenantId, other.tenantId);
//   }
// 
//   @Override
//   public int hashCode() {
//     return Objects.hashCode(userId, tenantId);
//   }
// 
//   @Override
//   public String toString() {
//     return Objects.toStringHelper(this)
//       .add("userId", userId)
//       .add("tenantId", tenantId)
//       .toString();
//   }
// }
// 
// Path: coopr-server/src/main/java/co/cask/coopr/store/DBPut.java
// public abstract class DBPut {
// 
//   /**
//    * Execute the put using the given connection.
//    *
//    * @param conn Connection to use to execute the put
//    * @throws SQLException
//    */
//   public void executePut(Connection conn) throws SQLException {
//     PreparedStatement updateStatement = createUpdateStatement(conn);
//     try {
//       int rowsUpdated = updateStatement.executeUpdate();
//       // if no rows are updated, perform the insert
//       if (rowsUpdated == 0) {
//         PreparedStatement insertStatement = createInsertStatement(conn);
//         try {
//           insertStatement.executeUpdate();
//         } finally {
//           insertStatement.close();
//         }
//       }
//     } finally {
//       updateStatement.close();
//     }
//   }
// 
//   protected abstract PreparedStatement createUpdateStatement(Connection conn) throws SQLException;
// 
//   protected abstract PreparedStatement createInsertStatement(Connection conn) throws SQLException;
// }


// Path: coopr-server/src/main/java/co/cask/coopr/store/user/SQLUserStore.java
import java.util.Map;
import co.cask.coopr.account.Account;
import co.cask.coopr.store.DBConnectionPool;
import co.cask.coopr.store.DBHelper;
import co.cask.coopr.store.DBPut;
import co.cask.coopr.store.DBQueryExecutor;
import com.google.common.util.concurrent.AbstractIdleService;
import com.google.gson.reflect.TypeToken;
import com.google.inject.Inject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

    }
  }

  @Override
  public void deleteProfile(Account account) throws IOException {
    try {
      Connection conn = dbConnectionPool.getConnection();
      try {
        PreparedStatement statement =
          conn.prepareStatement("UPDATE users SET profile=null WHERE user_id=? AND tenant_id=?");
        try {
          statement.setString(1, account.getUserId());
          statement.setString(2, account.getTenantId());
          statement.executeUpdate();
        } finally {
          statement.close();
        }
      } finally {
        conn.close();
      }
    } catch (SQLException e) {
      LOG.error("Exception getting profile for account {}.", account, e);
      throw new IOException(e);
    }
  }

  private class ProfileDBPut extends DBPut {
    private final Account account;
    private final Map<String, Object> profile;

    private ProfileDBPut(Account account, Map<String, Object> profile) {