package hoge;

import java.sql.ResultSet;
import java.sql.SQLException;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.model.DataModel;
import javax.faces.model.ResultSetDataModel;
import javax.sql.rowset.CachedRowSet;

public class VideoHandler {

private DataModel videosModel;

public DataModel getVideosModel() {
if (videosModel == null) {
videosModel = new ResultSetDataModel();
videosModel.setWrappedData(getAll());
}
return videosModel;
}

public String updateSelectRow() {
CachedRowSet crs = (CachedRowSet)videosModel.getWrappedData();
try {
crs.updateRow();
DBManager.acceptChanges(crs);

FacesContext.getCurrentInstance().addMessage("nouse", new FacesMessage("更新しました"));

} catch (SQLException e) {
e.printStackTrace();
}
return "nouse";
}

public ResultSet getAll() {
try {
return DBManager.executeQuery("select * from video");
} catch (SQLException e) {
throw new IllegalStateException(e);
}
}

}