Created
May 11, 2011 15:55
-
-
Save detsam/966736 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.dpv.dao.account; | |
import java.util.Map; | |
import java.util.concurrent.ConcurrentHashMap; | |
import java.util.concurrent.atomic.AtomicInteger; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import com.dpv.domain.Account; | |
import com.dpv.domain.AccountAlias; | |
import com.dpv.service.activation.ActivationKey; | |
public class InMemoryAccountDao implements AccountDao { | |
private final Logger logger = LoggerFactory.getLogger(getClass()); | |
private final Map<String, Account> accountsByEmail = new ConcurrentHashMap<String, Account>(); | |
private final Map<Integer, Account> accountsById = new ConcurrentHashMap<Integer, Account>(); | |
private final AtomicInteger nextAccountId = new AtomicInteger(); | |
@Override | |
public Account findAccountByEmail(String email) { | |
return accountsByEmail.get(email); | |
} | |
@Override | |
public Account findAccountById(int accountId) { | |
return accountsById.get(accountId); | |
} | |
@Override | |
public void saveAccount(Account account) { | |
if (account.isNew()) { | |
account.setId(nextAccountId.getAndIncrement()); | |
} | |
accountsById.put(account.getId(), account); | |
accountsByEmail.put(account.getEmail(), account); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment