package com.yuji.tdb.db;

import javax.jdo.PersistenceManager;

public class KeyValueDao {
	private static final String KEY_CONSUMER_KEY = "CONSUMER_KEY";
	private static final String KEY_CONSUMER_SECRET = "CONSUMER_SECRET";
	private static final String KEY_REQUEST_TOKEN = "REQUEST_TOKEN";
	private static final String KEY_REQUEST_TOKEN_SECRET = "REQUEST_TOKEN_SECRET";
	private static final String KEY_ACCESS_TOKEN = "ACCESS_TOKEN";
	private static final String KEY_ACCESS_TOKEN_SECRET = "ACCESS_TOKEN_SECRET";

	private static KeyValueDao instance = null;
	private PersistenceManager pm = PMFactory.get().getPersistenceManager();
		
	public static KeyValueDao getInstance(){
		if (instance == null){
			instance = new KeyValueDao();
		}
		return instance;
	}
	
	private KeyValueDao(){
		
	}
	
	public String get(String key){
		KeyValue keyValue = pm.getObjectById(KeyValue.class, key);
		if (keyValue == null){
			return null;
		}
		return keyValue.getValue();
	}
	
	public void put(String key, String value){
		KeyValue keyValue = new KeyValue(key, value);
		pm.makePersistent(keyValue);
	}
}
