001 /** 002 * Copyright (c) 2010 Yahoo! Inc. All rights reserved. 003 * Licensed under the Apache License, Version 2.0 (the "License"); 004 * you may not use this file except in compliance with the License. 005 * You may obtain a copy of the License at 006 * 007 * http://www.apache.org/licenses/LICENSE-2.0 008 * 009 * Unless required by applicable law or agreed to in writing, software 010 * distributed under the License is distributed on an "AS IS" BASIS, 011 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 * See the License for the specific language governing permissions and 013 * limitations under the License. See accompanying LICENSE file. 014 */ 015 package org.apache.oozie; 016 017 import java.io.DataInput; 018 import java.io.DataOutput; 019 import java.io.IOException; 020 021 import javax.persistence.Embeddable; 022 023 import org.apache.hadoop.io.Writable; 024 import org.apache.oozie.util.WritableUtils; 025 026 /** 027 * The composite primary key for the BundleActionBean Entity. 028 */ 029 @Embeddable 030 public class BundleActionId implements Writable { 031 private String bundleId = null; 032 private String coordName = null; 033 034 /** 035 * Set the Bundle Id 036 * 037 * @param bundleId the bundleId to set 038 */ 039 public void setBundleId(String bundleId) { 040 this.bundleId = bundleId; 041 } 042 043 /** 044 * Return the Bundle Id. 045 * 046 * @return the bundleId 047 */ 048 public String getBundleId() { 049 return bundleId; 050 } 051 052 /** 053 * Set the coordinator name 054 * 055 * @param coordName the coordName to set 056 */ 057 public void setCoordName(String coordName) { 058 this.coordName = coordName; 059 } 060 061 /** 062 * Return the coordinator name 063 * 064 * @return the coordName 065 */ 066 public String getCoordName() { 067 return coordName; 068 } 069 070 /* (non-Javadoc) 071 * @see java.lang.Object#hashCode() 072 */ 073 @Override 074 public int hashCode() { 075 return new String(bundleId + coordName).hashCode(); 076 } 077 078 /* (non-Javadoc) 079 * @see java.lang.Object#equals(java.lang.Object) 080 */ 081 @Override 082 public boolean equals(Object obj) { 083 if (obj instanceof BundleActionId) { 084 return bundleId.equals(((BundleActionId) obj).getBundleId()) 085 && coordName.equals(((BundleActionId) obj).getCoordName()); 086 } 087 else { 088 return false; 089 } 090 } 091 092 /* (non-Javadoc) 093 * @see org.apache.hadoop.io.Writable#readFields(java.io.DataInput) 094 */ 095 @Override 096 public void readFields(DataInput dataInput) throws IOException { 097 setBundleId(WritableUtils.readStr(dataInput)); 098 setCoordName(WritableUtils.readStr(dataInput)); 099 } 100 101 /* (non-Javadoc) 102 * @see org.apache.hadoop.io.Writable#write(java.io.DataOutput) 103 */ 104 @Override 105 public void write(DataOutput dataOutput) throws IOException { 106 WritableUtils.writeStr(dataOutput, getBundleId()); 107 WritableUtils.writeStr(dataOutput, getCoordName()); 108 } 109 }