--- /dev/null
+CREATE TABLE NICOCONTENT (ID NUMBER(19) NOT NULL, FILENAME VARCHAR(255), PAGELINK VARCHAR(255), TITLE VARCHAR(255), NICOID VARCHAR(255), VERSION NUMBER(19), PRIMARY KEY (ID))
+CREATE TABLE SEQUENCE (SEQ_NAME VARCHAR(50) NOT NULL, SEQ_COUNT NUMBER(19), PRIMARY KEY (SEQ_NAME))
+INSERT INTO SEQUENCE(SEQ_NAME, SEQ_COUNT) values ('SEQ_GEN', 1)
--- /dev/null
+DROP TABLE NICOCONTENT
+DELETE FROM SEQUENCE WHERE SEQ_NAME = 'SEQ_GEN'
${libs.HttpClient3.classpath}:\\r
${libs.Log4J.classpath}:\\r
${libs.Codec.classpath}:\\r
- ${libs.Rome.classpath}\r
+ ${libs.Rome.classpath}:\\r
+ ${libs.H2_DB.classpath}:\\r
+ ${libs.toplink.classpath}\r
# Space-separated list of extra javac options\r
javac.compilerargs=\r
javac.deprecation=false\r
# Property libs.Codec.classpath is set here just to make sharing of project simpler.\r
# The library definition has always preference over this property.\r
libs.Codec.classpath=../../../java/commons/commons-codec-1.3/commons-codec-1.3.jar\r
+# Property libs.H2_DB.classpath is set here just to make sharing of project simpler.\r
+# The library definition has always preference over this property.\r
+libs.H2_DB.classpath=../../../java/h2-2008-02-02/h2/bin/h2.jar\r
# Property libs.HttpClient3.classpath is set here just to make sharing of project simpler.\r
# The library definition has always preference over this property.\r
libs.HttpClient3.classpath=../../../java/commons/commons-httpclient-3.1/commons-httpclient-3.1.jar\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
+ <persistence-unit name="NicoBrowserPU" transaction-type="RESOURCE_LOCAL">
+ <provider>oracle.toplink.essentials.PersistenceProvider</provider>
+ <class>nicobrowser.NicoContent</class>
+ <properties>
+ <property name="toplink.jdbc.user" value="sa"/>
+ <property name="toplink.jdbc.password" value=""/>
+ <property name="toplink.jdbc.url" value="jdbc:h2:db/NicoDB"/>
+ <property name="toplink.jdbc.driver" value="org.h2.Driver"/>
+ <property name="toplink.ddl-generation" value="drop-and-create-tables"/>
+ </properties>
+ </persistence-unit>
+</persistence>
/*$Id$*/
package nicobrowser;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Version;
+
/**
* ニコニコ動画コンテンツ情報.
*/
-public class NicoContent {
+@Entity
+public class NicoContent implements java.io.Serializable {
+ private static final long serialVersionUID = 1L;
+ private Long id;
+ private Long version;
+ private String nicoId;
private String pageLink;
private String title;
+ private String fileName;
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ @Version
+ public Long getVersion() {
+ return version;
+ }
+
+ public void setVersion(Long version) {
+ this.version = version;
+ }
+
+ public String getNicoId() {
+ return nicoId;
+ }
+
+ protected void setNicoId(String nicoId) {
+ this.nicoId = nicoId;
+ }
public String getPageLink() {
return pageLink;
public void setPageLink(String pageLink) {
this.pageLink = pageLink;
+ String[] elm = pageLink.split("/");
+ setNicoId(elm[elm.length - 1]);
}
public String getTitle() {
public void setTitle(String title) {
this.title = title;
+ setFileName(title);
+ }
+
+ public String getFileName() {
+ return fileName;
+ }
+
+ protected void setFileName(String fileName) {
+ if (fileName == null) {
+ this.fileName = null;
+ return;
+ }
+
+ StringBuilder str = new StringBuilder();
+ try {
+ for (int i = 0; i < fileName.length(); i++) {
+ char c = fileName.charAt(i);
+ if (c == '\\' || c == '/' || c == ':' || c == '*' || c == '?' || c == '"' || c == '<' || c == '>' || c == '|') {
+ c = '_';
+ }
+ str.append(c);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ this.fileName = str.toString();
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 0;
+ hash += (id != null ? id.hashCode() : 0);
+ return hash;
+ }
+
+ @Override
+ public boolean equals(Object object) {
+ // TODO: Warning - this method won't work in the case the id fields are not set
+ if (!(object instanceof NicoContent)) {
+ return false;
+ }
+ NicoContent other = (NicoContent) object;
+ if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
+ return false;
+ }
+ return true;
}
@Override
Reader reader = new BufferedReader(new InputStreamReader(get.getResponseBodyAsStream(), "UTF-8"));
contList = getNicoContents(reader);
} catch (FeedException ex) {
- Logger.getLogger(NicoHttpClient.class.getName()).log(Level.SEVERE, null, ex);
+ Logger.getLogger(NicoHttpClient.class.getName()).log(Level.SEVERE, null, "FeedExceitpion" + listNo);
} catch (IOException ex) {
Logger.getLogger(NicoHttpClient.class.getName()).log(Level.SEVERE, null, ex);
} finally {
+++ /dev/null
-/*$Id$*/
-package nicobrowser;
-
-import java.awt.Component;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import javax.swing.ImageIcon;
-import javax.swing.JButton;
-import javax.swing.JTable;
-import javax.swing.JTextArea;
-import javax.swing.table.DefaultTableCellRenderer;
-import javax.swing.table.DefaultTableModel;
-import javax.swing.table.TableColumn;
-
-/**
- *
- * @author yuki
- */
-public class NicoTableModel extends DefaultTableModel {
-
- private static final ColumnContext[] COLUMN_CONTEXT = {
- new ColumnContext("サムネイル", ImageIcon.class),
- new ColumnContext("タイトル", String.class),
- new ColumnContext("説明", JTextArea.class),
- new ColumnContext("リンク", JButton.class)
- };
-
- private static class ColumnContext {
-
- private String columnName;
- private Class renderer;
-
- private ColumnContext(String columnName, Class renderer) {
- this.columnName = columnName;
- this.renderer = renderer;
- }
- }
-
- static class MyCellRender extends DefaultTableCellRenderer {
-
- @Override
- public Component getTableCellRendererComponent(
- JTable table, Object value,
- boolean isSelected, boolean hasFocus, int row, int column) {
- if (isSelected) {
- table.setForeground(table.getSelectionForeground());
- table.setBackground(table.getSelectionBackground());
- } else {
- table.setForeground(table.getForeground());
- table.setBackground(table.getBackground());
- }
-
- //setFont(table.getFont());
-
- try {
- Object obj = COLUMN_CONTEXT[column].renderer.newInstance();
-
-
- return (Component) obj;
- } catch (InstantiationException ex) {
- Logger.getLogger(NicoTableModel.class.getName()).log(Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- Logger.getLogger(NicoTableModel.class.getName()).log(Level.SEVERE, null, ex);
- }
- return null;
-
-
- }
- }
-
- public NicoTableModel() {
- super();
- for (ColumnContext c : COLUMN_CONTEXT) {
- addColumn(c.columnName);
- }
- TableColumn column;
-
-
- }
-
- @Override
- public Class<?> getColumnClass(int columnIndex) {
- return COLUMN_CONTEXT[columnIndex].renderer;
-
- }
-
- @Override
- public boolean isCellEditable(int rowIndex, int columnIndex) {
- return false;
- }
-}
package nicobrowser;
import java.util.List;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityTransaction;
+import javax.persistence.Persistence;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
public void loadMyListDaily() {
System.out.println("loadMyListDaily");
NicoHttpClient instance = NicoHttpClient.getInstance();
- instance.login(OK_MAIL, OK_PASS);
List<NicoContent> list = instance.loadMyListDaily();
assertNotNull(list);
assertNotSame(0, list.size());
// for (Object o : list) {
// System.out.println(o.toString());
// }
+
+ EntityManagerFactory factory;
+ EntityManager manager;
+
+ factory = Persistence.createEntityManagerFactory("NicoBrowserPU");
+ manager = factory.createEntityManager();
+
+ EntityTransaction transaction = manager.getTransaction();
+
+ transaction.begin();
+ try {
+ for (NicoContent c : list) {
+ manager.persist(c);
+ }
+
+ transaction.commit();
+ System.out.println("2つのPersonオブジェクトを永続化しました.");
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ transaction.rollback();
+ } finally {
+ manager.close();
+ factory.close();
+ }
+
}
}