001/* 002 * Copyright (c) 2009 The openGion Project. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 013 * either express or implied. See the License for the specific language 014 * governing permissions and limitations under the License. 015 */ 016package org.opengion.hayabusa.io; 017 018import java.sql.Connection; 019// import java.sql.Date; 020import java.sql.ResultSet; 021import java.sql.ResultSetMetaData; 022import java.sql.SQLException; 023import java.sql.Statement; 024// import java.sql.Types; 025// import java.util.Locale; 026 027import java.util.Date; 028import java.util.Calendar; 029 030import org.opengion.fukurou.util.Closer; 031import org.opengion.fukurou.util.LogWriter; 032import org.opengion.fukurou.util.HybsDateUtil; 033 034import org.jfree.data.gantt.TaskSeriesCollection; 035import org.jfree.data.gantt.TaskSeries; 036import org.jfree.data.gantt.Task; 037// import org.jfree.data.time.SimpleTimePeriod; 038 039/** 040 * HybsTaskSeriesCollection は、org.jfree.data.gantt.TaskSeriesCollection を継承したサブクラスで、 041 * オブジェクト作成とともに JDBC接続して、TaskSeries データを作成し、セットします。 042 * TaskSeriesCollection は、IntervalCategoryDataset, GanttCategoryDataset インターフェースを継承しています。 043 * 044 * データ形式は、シリーズ名、タスク名、開始日時、終了日時 の順で、シリーズ名でソートしておく必要があります。 045 * シリーズ名 は、キーブレイクで、設定する為です。 046 * 047 * select series,task,st(時間),ed(時間) from XX order by series,task,st(時間) 048 * 049 * @og.rev 5.6.1.0 (2013/02/01) 新規作成 050 * 051 * @version 0.9.0 2001/05/05 052 * @author Kazuhiko Hasegawa 053 * @since JDK1.1, 054 */ 055public class HybsTaskSeriesCollection extends TaskSeriesCollection { 056 private static final long serialVersionUID = 561020130201L ; 057 058 /** 059 * HybsTaskSeriesCollection オブジェクトの内部に、DB検索結果のデータを設定します(縦持)。 060 * 061 * select series,task,st(時間),ed(時間) from XX order by series,task,st(時間) 062 * シリーズ名 は、キーブレイクで、設定します。 063 * 064 * @param con the connection. 065 * @param query the query. 066 * @throws SQLException データベース実行エラーが発生した場合 067 * 068 */ 069 public void executeQuery( final Connection con, final String query ) throws SQLException { 070 071 Statement statement = null; 072 ResultSet resultSet = null; 073 try { 074 statement = con.createStatement(); 075 resultSet = statement.executeQuery(query); 076 ResultSetMetaData metaData = resultSet.getMetaData(); 077 078 int columnCount = metaData.getColumnCount(); 079 080 if(columnCount < 4) { 081 String errMsg = "HybsTaskSeriesCollection.executeQuery() : 実行できません。\n" 082 + "select series,task,st(時間),ed(時間) は、最低必要です。それ以降は無視します。" 083 + " SQL=" + query ; 084 throw new SQLException( errMsg ); 085 } 086 087 String bkSeries = null; // キーブレイクのための過去のSeries 088 089 TaskSeries taskseries = null; 090 while (resultSet.next()) { 091 // first column contains the row key... 092 String seriVal = resultSet.getString(1); // シリーズ名 093 if( seriVal != null && !seriVal.equals( bkSeries ) ) { 094 if( taskseries != null ) { add( taskseries ); } // キーブレイクでTaskSeriesCollectionにセット 095 taskseries = new TaskSeries( seriVal ); 096 bkSeries = seriVal ; 097 } 098 099 String taskVal = resultSet.getString(2); // タスク名 100 String stDataVal = resultSet.getString(3); // st(時間) 101 String edDateVal = resultSet.getString(4); // ed(時間) 102 103 Date stDate = HybsDateUtil.getCalendar( stDataVal ).getTime() ; 104 Date edDate = HybsDateUtil.getCalendar( edDateVal ).getTime() ; 105 106 Task task = new Task( taskVal, stDate, edDate ); 107 108 taskseries.add( task ); 109 } 110 if( taskseries != null ) { add( taskseries ); } // キーブレイクでTaskSeriesCollectionにセット 111 } 112 finally { 113 Closer.resultClose( resultSet ) ; 114 Closer.stmtClose( statement ) ; 115 } 116 } 117}