📄 booktitle.java
字号:
package library;
import java.sql.*;
/**
* A class representing a book title
*
* @author dms
* @version 1.0
*/
public class BookTitle extends LibraryObject {
private String callNumber;
private String name;
private String authors;
private String isbn;
private String edition;
private String publisher;
private int year;
/**
* class BookTitle constructor
*
*/
public BookTitle(){}
/**
* Class constructor which runs a
* specified sql statement to populate
* the BookTitle object. Use inherited
* method <code>getNext</code> to
* iterate through the resulting
* BookTitle objects
* @param sql SQL statement
* @throws SQLException
*/
public BookTitle(String sql) throws SQLException {
ensureconnection();
mr = db.runQuery(sql);
}
/**
* Sets the object to a specific title based on call number.
*
* @param cn String containing call number
* @return true if success, false if otherwise
*/
public boolean getBookTitle(String cn) {
ensureconnection();
String sSQL = "";
sSQL = "SELECT * FROM BookTitle WHERE CallNumber = '" + cn + "'";
try {
ResultSet r = db.runQuery(sSQL);
r.next();
setVariables(r);
return true;
}
catch (SQLException e) {
System.err.println(e.toString());
return false;
}
}
protected void setVariables(ResultSet r) throws SQLException {
callNumber = r.getString("CallNumber");
name = r.getString("name");
authors = r.getString("author");
edition = r.getString("edition");
isbn = r.getString("isbn");
year = r.getInt("year");
publisher = r.getString("publisher");
}
/**
* Retrives the holds for this book title
*
* @return Hold object, ready to be iterated using
* inherited getNext routine
* @throws SQLException
*/
public Hold getHolds() throws SQLException {
String sql = "SELECT * FROM Hold WHERE CallNumber = '" + this.getCallNumber() + "'";
return new Hold(sql);
}
/**
* Determines the number of holds this title has.
*
* @return int containing number of holds for this title
*/
public int getHoldCount() {
ensureconnection();
String sql = "SELECT Count(*) as counted FROM Hold WHERE CallNumber = '" + this.getCallNumber() + "'";
try {
ResultSet r = db.runQuery(sql);
r.next();
return r.getInt("counted");
}
catch (SQLException e) {
System.err.println(e.toString());
return 0;
}
}
/**
* Retrieves the books for this title
*
* @return Book object, ready to be iterated using
* inherited method <code>getNext</code>
* @throws SQLException
*/
public Book getBooks() throws SQLException {
String sql = "SELECT * FROM Book WHERE CallNumber = '" + this.getCallNumber() + "'";
return new Book(sql);
}
/**
* Determines the number of copies (books) this title has.
*
* @return int containing number of books for this title
*/
public int getBookCount() {
ensureconnection();
String sql = "SELECT Count(*) as counted FROM Book WHERE CallNumber = '" + this.getCallNumber() + "'";
try {
ResultSet r = db.runQuery(sql);
r.next();
return r.getInt("counted");
}
catch (SQLException e) {
System.err.println(e.toString());
return 0;
}
}
/**
* Determines the number of available copies (books) this title has.
*
* @return int containing number of available books for this title
*/
public int getAvailableBookCount() {
ensureconnection();
String sql = "SELECT Count(*) as counted FROM Book WHERE (DueDate IS NULL) AND CallNumber = '" + this.getCallNumber() + "'";
try {
ResultSet r = db.runQuery(sql);
r.next();
return r.getInt("counted");
}
catch (SQLException e) {
System.err.println(e.toString());
return 0;
}
}
/**
* Accessor for Call Number
* @return String
*/
public String getCallNumber() {return callNumber;}
/**
* Accessor for Name
* @return String
*/
public String getName() {return name;}
/**
* Accessor for isbn
* @return String
*/
public String getISBN() {return isbn;}
/**
* Accessor for Edition
* @return String
*/
public String getEdition() {return edition;}
/**
* Accessor for year of publication
* @return int
*/
public int getYear() {return year;}
/**
* Accessor for authors
* @return String
*
*/
public String getAuthors() {return authors;}
/**
* Accessor for publisher
* @return String
*/
public String getPublisher() {return publisher;}
/**
* Method used to determine if book title
* is currently held.
*
* @return boolean true if held, false if not held
* @throws SQLException
*/
public boolean isBookTitleHeld() throws SQLException {
Hold hold = this.getHolds();
if (hold.getNext())
return true;
else
return false;
}
/**
* Returns a lightweight version of this object, which
* only contains the necessary information to display
* as a search result.
*
* @return A SearchResult object representing this title
*/
public SearchResult getSearchResult() {
SearchResult sr = new SearchResult(getName(), getAuthors(), getCallNumber(), getEdition(), getYear());
return sr;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -