/* DB0.java * * Copyright (c) 2000, Ted Nelson and Tuomas Lukka * * You may use and distribute under the terms of either the GNU Lesser * General Public License, either version 2 of the license or, * at your choice, any later version. Alternatively, you may use and * distribute under the terms of the XPL. * * See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of * the licenses. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the README * file for more details. * */ /* * Written by Tuomas Lukka */ package org.gzigzag.module; import org.gzigzag.*; import java.sql.*; import java.io.*; import java.text.*; import java.util.*; import java.awt.*; public class DB0 { public static final String rcsid = "$Id: DB0.java,v 1.1 2002/10/07 12:37:34 tuukkah Exp $"; public static boolean dbg = true; static final void p(String s) { if(dbg) System.out.println(s); } static final void pa(String s) { System.out.println(s); } static public class StrComp implements ZZUtil.Comparator { public int compare(ZZCell c1, ZZCell c2) { return c1.getText().compareTo(c2.getText()); } } static public class DHeadComp implements ZZUtil.Comparator { DHeadComp(String dim) { this.dim = dim; } String dim; public int compare(ZZCell c1, ZZCell c2) { return c1.h(dim, -1).getText().compareTo( c2.h(dim, -1).getText()); } } static public void insertCells(ZZCell head, String x, String y, ResultSet rs, String maincol, Hashtable id2col ) throws SQLException { ResultSetMetaData meta = rs.getMetaData(); int n = meta.getColumnCount(); ZZCell[] hdr = new ZZCell[n]; ZZCell[] cur = new ZZCell[n]; ZZCell nextnew = head; int mcid = -1; int idid = -1; for(int i=0; i"); // Create people rank in alphabetical order rs = st.executeQuery("select * from members order by name"); ZZCell prev = null; while(rs.next()) { ZZCell curr = (ZZCell)id2mem.get(rs.getString(1)); if(prev != null) prev.connect("d.people", 1, curr); prev = curr; } // Create sig rank in alphabetical order rs = st.executeQuery("select * from sigs order by name"); prev = null; while(rs.next()) { ZZCell curr = (ZZCell)id2sig.get(rs.getString(1)); if(prev != null) prev.connect("d.insigs", 1, curr); prev = curr; } p("Rels: "); // Insert relcells after the positions table rs = st.executeQuery("select * from positions"); while(rs.next()) { String pers = rs.getString(1); String sig = rs.getString(2); // p("Rel: "+pers+" "+sig); ZZCell pc = (ZZCell)id2mem.get(pers); ZZCell sc = (ZZCell)id2sig.get(sig); if(pc == null || sc == null) throw new Error("No such relation "+pers+" "+sig); ZZCell relc = pc.N("d.insigs",1); sc.insert("d.people", 1, relc); relc.setText("+"); } rs.close(); // Sort the ranks of the in-which-sigs tables. for(Enumeration e = id2mem.elements(); e.hasMoreElements(); ) { ZZCell c = (ZZCell)e.nextElement(); ZZUtil.sortRank(c, "d.insigs", 1, new DHeadComp("d.people"), false); } for(Enumeration e = id2sig.elements(); e.hasMoreElements(); ) { ZZCell c = (ZZCell)e.nextElement(); ZZUtil.sortRank(c, "d.people", 1, new DHeadComp("d.insigs"), false); } st.close(); db.close(); } } /* else if(id.equals("IMPORT")) { // XXX How to give 2 arguments: the file name and the home cell (new XML()).load(new File(target.getText()), }*/ } catch(SQLException e) { System.out.println(e); e.printStackTrace(); } catch(ClassNotFoundException e) { System.out.println(e); e.printStackTrace(); } } }; }