All Downloads are FREE. Search and download functionalities are using the official Maven repository.

co.realtime.storage.entities.Key Maven / Gradle / Ivy

package co.realtime.storage.entities;

import java.util.HashMap;
import java.util.Map;

/**
 * Specification of the key structure of a table.
 * @author RTCS Development team
 *
 */
public class Key implements IORMapping {
	private KeySchema primaryKey;
	private KeySchema secondaryKey;
	
	/**
	 * Builds a key structure with a primary key.
	 * @param primaryKey 
	 * 		The primary key schema.
	 */
	public Key(KeySchema primaryKey) {
		this.primaryKey = primaryKey;
	}
	
	/**
	 * Builds a key structure with primary and secondary keys.
	 * @param 
	 * 		primaryKey The primary key schema.
	 * @param 
	 * 		secondaryKey The secondary key schema.
	 */	
	public Key(KeySchema primaryKey, KeySchema secondaryKey) {
		this.primaryKey = primaryKey;
		this.secondaryKey = secondaryKey;
	}

	/**
	 * Retrieves the primary key schema.
	 * @return 
	 * 		primary key schema.
	 */
	KeySchema getPrimaryKey() {
		return primaryKey;
	}

	/**
	 * Assigns the primary key schema.
	 * @param primaryKey 
	 * 		The primary key schema.
	 */
	void setPrimaryKey(KeySchema primaryKey) {
		this.primaryKey = primaryKey;
	}
	
	/**
	 * Retrieves the secondary key schema.
	 * @return 
	 * 		secondary key schema.
	 */
	KeySchema getSecondaryKey() {
		return secondaryKey;
	}

	/**
	 * Assigns the secondary key schema.
	 * @param secondary 
	 * 		The secondary key schema.
	 */
	void setSecondaryKey(KeySchema secondaryKey) {
		this.secondaryKey = secondaryKey;
	}
	
	public Map map() {
		Map throughputMap = new HashMap();
		throughputMap.put("primary", getPrimaryKey().map());
		
		if(getSecondaryKey() != null)
			throughputMap.put("secondary", getSecondaryKey().map());	
		
		return throughputMap;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy