/**
 * Copyright © 2008-2009 DRIVER PROJECT (ICM UW)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package eu.dnetlib.resultset.impl;

import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.Transient;

/**
 * Push Result Set Object.
 * @author Marek Horst
 * @version 0.01
 *
 */
@Entity
public class PushResultSetObject extends ResultSetObject {

	/**
	 * CreatePush Result Set type.
	 */
	private CreatePushRSType createPushRS_type;
	
	/**
	 * Result Set data content.
	 */
	private String[] data = new String[0];
	
	/**
	 * Default construnctor for hibernate3 purposes.
	 */
	public PushResultSetObject() {
		super(null, Integer.MIN_VALUE);
	}
	
	/**
	 * Default constructor.
	 * @param resultSetId
	 * @param expiryTime
	 * @param createPushRS_type
	 */
	public PushResultSetObject(String resultSetId, int expiryTime, 
			CreatePushRSType createPushRS_type) {
		super(resultSetId, expiryTime);
		this.createPushRS_type = createPushRS_type;
	}
	
	/* (non-Javadoc)
	 * @see eu.dnetlib.resultset.impl.ResultSetObject#getExpirationTime()
	 */
	@Transient
	public long getExpirationTime() {
		return getCreationTime() + (getExpiryTime() * 1000);
	}
	
	/* (non-Javadoc)
	 * @see eu.dnetlib.resultset.impl.ResultSetObject#getResultSetType()
	 */
	@Override
	@Transient
	public ResultSetType getResultSetType() {
		return ResultSetType.PUSH_RS;
	}

	/* (non-Javadoc)
	 * @see eu.dnetlib.resultset.impl.ResultSetObject#getSize()
	 */
	@Override
	@Transient
	public int getSize() {
		if (data!=null)
			return data.length;
		else
			return 0;
	}
	
	/**
	 * Returns data.
	 * @return data
	 */
	public String[] getData() {
		return data;
	}

	/**
	 * Sets data.
	 * @param data
	 */
	public void setData(String[] data) {
		this.data = data;
	}
	
	/**
	 * Returns CreatePush Result Set type
	 * @return CreatePush Result Set type
	 */
	@Embedded
    @AttributeOverrides({
        @AttributeOverride(name = "keepAliveTime", column = @Column(name = "typeKeepAliveTime"))
                })
	public CreatePushRSType getCreatePushRS_type() {
		return createPushRS_type;
	}

	/**
	 * Sets CreatePush Result Set type.
	 * @param createPushRS_type
	 */
	public void setCreatePushRS_type(CreatePushRSType createPushRS_type) {
		this.createPushRS_type = createPushRS_type;
	}

}
