001/* 002 * HA-JDBC: High-Availability JDBC 003 * Copyright (c) 2004-2007 Paul Ferraro 004 * 005 * This library is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU Lesser General Public License as published by the 007 * Free Software Foundation; either version 2.1 of the License, or (at your 008 * option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, but WITHOUT 011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 013 * for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public License 016 * along with this library; if not, write to the Free Software Foundation, 017 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 018 * 019 * Contact: ferraro@users.sourceforge.net 020 */ 021package net.sf.hajdbc.distributable; 022 023import java.io.Externalizable; 024import java.io.IOException; 025import java.io.ObjectInput; 026import java.io.ObjectOutput; 027 028/** 029 * Represents a database command to be executed on a given database cluster. 030 * @author Paul Ferraro 031 * @since 1.0 032 */ 033public abstract class AbstractCommand implements Command<Boolean>, Externalizable 034{ 035 protected String databaseId; 036 037 /** 038 * Constructs a new AbstractDatabaseCommand. 039 */ 040 protected AbstractCommand() 041 { 042 // Do nothing 043 } 044 045 /** 046 * Constructs a new AbstractDatabaseCommand. 047 * @param databaseId a database identifier 048 */ 049 public AbstractCommand(String databaseId) 050 { 051 this.databaseId = databaseId; 052 } 053 054 /** 055 * @see java.io.Externalizable#writeExternal(java.io.ObjectOutput) 056 */ 057 @Override 058 public void writeExternal(ObjectOutput output) throws IOException 059 { 060 output.writeUTF(this.databaseId); 061 } 062 063 /** 064 * @see java.io.Externalizable#readExternal(java.io.ObjectInput) 065 */ 066 @Override 067 public void readExternal(ObjectInput input) throws IOException 068 { 069 this.databaseId = input.readUTF(); 070 } 071 072 /** 073 * @see java.lang.Object#toString() 074 */ 075 @Override 076 public String toString() 077 { 078 return this.getClass().getName() + " [" + this.databaseId + "]"; //$NON-NLS-1$ //$NON-NLS-2$ 079 } 080 081 /** 082 * @see net.sf.hajdbc.distributable.Command#marshalResult(java.lang.Object) 083 */ 084 @Override 085 public Object marshalResult(Boolean result) 086 { 087 return result; 088 } 089 090 /** 091 * @see net.sf.hajdbc.distributable.Command#unmarshalResult(java.lang.Object) 092 */ 093 @Override 094 public Boolean unmarshalResult(Object result) 095 { 096 return (Boolean) result; 097 } 098}