// Path: fabric.lib/src/fabric/registry/exception/PersistenceException.java
// public class PersistenceException extends Exception {
// 
// 	/** Copyright notice. */
// 	public static final String copyrightNotice = "(C) Copyright IBM Corp. 2009";
// 
// 	private static final long serialVersionUID = 1L;
// 
// 	private String errorMessage = null;
// 	private int errorCode = 0;
// 	private String sqlState = null;
// 
// 	/**
// 	 * 
// 	 */
// 	public PersistenceException() {
// 	}
// 
// 	/**
// 	 * 
// 	 * @param msg
// 	 */
// 	public PersistenceException(String msg) {
// 		super(msg);
// 	}
// 
// 	/**
// 	 * 
// 	 * @param detailMessage
// 	 * @param throwable
// 	 */
// 	public PersistenceException(String detailMessage, Throwable throwable) {
// 		super(detailMessage, throwable);
// 	}
// 
// 	/**
// 	 * 
// 	 * @param throwable
// 	 */
// 	public PersistenceException(Throwable throwable) {
// 		super(throwable);
// 	}
// 
// 	/**
// 	 * 
// 	 * @param message
// 	 * @param errorMessage
// 	 * @param errorCode
// 	 * @param sqlState
// 	 */
// 	public PersistenceException(String message, String errorMessage, int errorCode, String sqlState) {
// 		super(message);
// 
// 		this.errorMessage = errorMessage;
// 		this.errorCode = errorCode;
// 		this.sqlState = sqlState;
// 	}
// 
// 	/**
// 	 * 
// 	 * @return
// 	 */
// 	public int getErrorCode() {
// 		return errorCode;
// 	}
// 
// 	/**
// 	 * 
// 	 * @param errorCode
// 	 */
// 	public void setErrorCode(int errorCode) {
// 		this.errorCode = errorCode;
// 	}
// 
// 	/**
// 	 * 
// 	 * @return
// 	 */
// 	public String getErrorMessage() {
// 		return errorMessage;
// 	}
// 
// 	/**
// 	 * 
// 	 * @param errorMessage
// 	 */
// 	public void setErrorMessage(String errorMessage) {
// 		this.errorMessage = errorMessage;
// 	}
// 
// 	/**
// 	 * 
// 	 * @return
// 	 */
// 	public String getSqlState() {
// 		return sqlState;
// 	}
// 
// 	/**
// 	 * 
// 	 * @param sqlState
// 	 */
// 	public void setSqlState(String sqlState) {
// 		this.sqlState = sqlState;
// 	}
// }


import fabric.registry.FabricRegistry;
import fabric.registry.NodeIpMapping;
import fabric.registry.NodeIpMappingFactory;
import fabric.registry.QueryScope;
import fabric.registry.RegistryObject;
import fabric.registry.exception.DuplicateKeyException;
import fabric.registry.exception.IncompleteObjectException;
import fabric.registry.exception.PersistenceException;
import fabric.registry.persistence.IPersistenceResultRow;
/*
 * (C) Copyright IBM Corp. 2009
 *
 * LICENSE: Eclipse Public License v1.0
 * http://www.eclipse.org/legal/epl-v10.html
 */

package fabric.registry.impl;


/**
 * Factory used to create NodeIpMapping objects and persist them in the Fabric Registry.
 */
public class NodeIpMappingFactoryImpl extends AbstractFactory implements NodeIpMappingFactory {

    /** Copyright notice. */
    public static final String copyrightNotice = "(C) Copyright IBM Corp. 2009";

    /*
     * Class fields
     */

    /** Factory for local (singleton) Registry operations */
    private static NodeIpMappingFactoryImpl localQueryInstance = null;

    /** Factory for distributed (Gaian) Registry operations */
    private static NodeIpMappingFactoryImpl remoteQueryInstance = null;

    /* Query definitions */

    /** Select all records. */
    private String SELECT_ALL_QUERY = null;

    /** Select records matching a specified node ID. */
    private String BY_ID_QUERY = null;

    /** Select records matching a specified node ID and node Interface. */
    private String BY_ID_AND_INTERFACE_QUERY = null;

    /** Select records using an arbitrary SQL <code>WHERE</code> clause. */
    private String PREDICATE_QUERY = null;

    /*
     * Class static initialization
     */

    static {

        /* Create an instance for local (singleton) Registry operations */
        localQueryInstance = new NodeIpMappingFactoryImpl(QueryScope.LOCAL);

        /* Create an instance for distributed (Gaian) Registry operations */
        remoteQueryInstance = new NodeIpMappingFactoryImpl(QueryScope.DISTRIBUTED);
    }

    /*
     * Class methods
     */

    private NodeIpMappingFactoryImpl(QueryScope queryScope) {
        this.queryScope = queryScope;

        /* Build the predefined queries to reflect the selected tables */

        SELECT_ALL_QUERY = format("select * from %s", FabricRegistry.NODE_IP_MAPPING);

        BY_ID_QUERY = format("select * from %s where NODE_ID='\\%s'", FabricRegistry.NODE_IP_MAPPING);

        BY_ID_AND_INTERFACE_QUERY = format("select * from %s where NODE_ID='\\%s' AND NODE_INTERFACE='\\%s'",
                FabricRegistry.NODE_IP_MAPPING);

        PREDICATE_QUERY = format("select * from %s where \\%s", FabricRegistry.NODE_IP_MAPPING);

    }

    /**
     * Get the singleton instance of this factory.
     *
     * @return an instance of the factory.
     */
    public static NodeIpMappingFactoryImpl getInstance(QueryScope queryScope) {
        if (queryScope == QueryScope.LOCAL) {
            return localQueryInstance;
        } else {
            return remoteQueryInstance;
        }
    }

    @Override
// Path: fabric.lib/src/fabric/registry/exception/PersistenceException.java
// public class PersistenceException extends Exception {
// 
// 	/** Copyright notice. */
// 	public static final String copyrightNotice = "(C) Copyright IBM Corp. 2009";
// 
// 	private static final long serialVersionUID = 1L;
// 
// 	private String errorMessage = null;
// 	private int errorCode = 0;
// 	private String sqlState = null;
// 
// 	/**
// 	 * 
// 	 */
// 	public PersistenceException() {
// 	}
// 
// 	/**
// 	 * 
// 	 * @param msg
// 	 */
// 	public PersistenceException(String msg) {
// 		super(msg);
// 	}
// 
// 	/**
// 	 * 
// 	 * @param detailMessage
// 	 * @param throwable
// 	 */
// 	public PersistenceException(String detailMessage, Throwable throwable) {
// 		super(detailMessage, throwable);
// 	}
// 
// 	/**
// 	 * 
// 	 * @param throwable
// 	 */
// 	public PersistenceException(Throwable throwable) {
// 		super(throwable);
// 	}
// 
// 	/**
// 	 * 
// 	 * @param message
// 	 * @param errorMessage
// 	 * @param errorCode
// 	 * @param sqlState
// 	 */
// 	public PersistenceException(String message, String errorMessage, int errorCode, String sqlState) {
// 		super(message);
// 
// 		this.errorMessage = errorMessage;
// 		this.errorCode = errorCode;
// 		this.sqlState = sqlState;
// 	}
// 
// 	/**
// 	 * 
// 	 * @return
// 	 */
// 	public int getErrorCode() {
// 		return errorCode;
// 	}
// 
// 	/**
// 	 * 
// 	 * @param errorCode
// 	 */
// 	public void setErrorCode(int errorCode) {
// 		this.errorCode = errorCode;
// 	}
// 
// 	/**
// 	 * 
// 	 * @return
// 	 */
// 	public String getErrorMessage() {
// 		return errorMessage;
// 	}
// 
// 	/**
// 	 * 
// 	 * @param errorMessage
// 	 */
// 	public void setErrorMessage(String errorMessage) {
// 		this.errorMessage = errorMessage;
// 	}
// 
// 	/**
// 	 * 
// 	 * @return
// 	 */
// 	public String getSqlState() {
// 		return sqlState;
// 	}
// 
// 	/**
// 	 * 
// 	 * @param sqlState
// 	 */
// 	public void setSqlState(String sqlState) {
// 		this.sqlState = sqlState;
// 	}
// }


// Path: fabric.lib/src/fabric/registry/impl/NodeIpMappingFactoryImpl.java
import fabric.registry.FabricRegistry;
import fabric.registry.NodeIpMapping;
import fabric.registry.NodeIpMappingFactory;
import fabric.registry.QueryScope;
import fabric.registry.RegistryObject;
import fabric.registry.exception.DuplicateKeyException;
import fabric.registry.exception.IncompleteObjectException;
import fabric.registry.exception.PersistenceException;
import fabric.registry.persistence.IPersistenceResultRow;

/*
 * (C) Copyright IBM Corp. 2009
 *
 * LICENSE: Eclipse Public License v1.0
 * http://www.eclipse.org/legal/epl-v10.html
 */

package fabric.registry.impl;


/**
 * Factory used to create NodeIpMapping objects and persist them in the Fabric Registry.
 */
public class NodeIpMappingFactoryImpl extends AbstractFactory implements NodeIpMappingFactory {

    /** Copyright notice. */
    public static final String copyrightNotice = "(C) Copyright IBM Corp. 2009";

    /*
     * Class fields
     */

    /** Factory for local (singleton) Registry operations */
    private static NodeIpMappingFactoryImpl localQueryInstance = null;

    /** Factory for distributed (Gaian) Registry operations */
    private static NodeIpMappingFactoryImpl remoteQueryInstance = null;

    /* Query definitions */

    /** Select all records. */
    private String SELECT_ALL_QUERY = null;

    /** Select records matching a specified node ID. */
    private String BY_ID_QUERY = null;

    /** Select records matching a specified node ID and node Interface. */
    private String BY_ID_AND_INTERFACE_QUERY = null;

    /** Select records using an arbitrary SQL <code>WHERE</code> clause. */
    private String PREDICATE_QUERY = null;

    /*
     * Class static initialization
     */

    static {

        /* Create an instance for local (singleton) Registry operations */
        localQueryInstance = new NodeIpMappingFactoryImpl(QueryScope.LOCAL);

        /* Create an instance for distributed (Gaian) Registry operations */
        remoteQueryInstance = new NodeIpMappingFactoryImpl(QueryScope.DISTRIBUTED);
    }

    /*
     * Class methods
     */

    private NodeIpMappingFactoryImpl(QueryScope queryScope) {
        this.queryScope = queryScope;

        /* Build the predefined queries to reflect the selected tables */

        SELECT_ALL_QUERY = format("select * from %s", FabricRegistry.NODE_IP_MAPPING);

        BY_ID_QUERY = format("select * from %s where NODE_ID='\\%s'", FabricRegistry.NODE_IP_MAPPING);

        BY_ID_AND_INTERFACE_QUERY = format("select * from %s where NODE_ID='\\%s' AND NODE_INTERFACE='\\%s'",
                FabricRegistry.NODE_IP_MAPPING);

        PREDICATE_QUERY = format("select * from %s where \\%s", FabricRegistry.NODE_IP_MAPPING);

    }

    /**
     * Get the singleton instance of this factory.
     *
     * @return an instance of the factory.
     */
    public static NodeIpMappingFactoryImpl getInstance(QueryScope queryScope) {
        if (queryScope == QueryScope.LOCAL) {
            return localQueryInstance;
        } else {
            return remoteQueryInstance;
        }
    }

    @Override
    public RegistryObject create(IPersistenceResultRow row) throws PersistenceException {