Skip to content

Commit

Permalink
ArrayList: deprecation in comment. Miles2Kms: modernize, barely usable.
Browse files Browse the repository at this point in the history
New: buildindex (for findJava), TypeMapDemo (tries and fails to use
Type Map). Bye some old cruft.
  • Loading branch information
IanDarwin committed Sep 14, 2002
1 parent ca25ed5 commit 29be979
Show file tree
Hide file tree
Showing 12 changed files with 270 additions and 189 deletions.
1 change: 1 addition & 0 deletions .cvsignore
Expand Up @@ -2,3 +2,4 @@
err.log
index-byname.html
jabadot
oreilly
112 changes: 0 additions & 112 deletions QCam.java

This file was deleted.

21 changes: 21 additions & 0 deletions buildindex.xml
@@ -0,0 +1,21 @@
<project name="Java Src Index" default="index" basedir=".">

<!-- build and install the online index
$Id$
-->

<target name="index">
<ant dir="search" target="compile"/>
<property name="lucene.jar" value="WEB-INF/lib/lucene-1.3-dev1.jar" />
<java classname="Indexer" classpath="search:${lucene.jar}" />
<mkdir dir="WEB-INF/index"/> <!-- ensure it there for robuse move -->
<move todir="WEB-INF/index.bak">
<fileset dir="WEB-INF/index"/>
</move>
<move todir="WEB-INF/index">
<fileset dir="index"/>
</move>
<delete dir="WEB-INF/index.bak"/>
</target>

</project>
5 changes: 4 additions & 1 deletion src/main/java/compat/ArrayList.java
@@ -1,6 +1,9 @@
package java.util;

/** Crudely map Vector to ArrayList, for compatibility. */
/** Crudely map Vector to ArrayList, for "compatibility",
* that is, for use with ArrayList-based code on really ancient JDK.
* Don't do that anymore; this is really olde code. Time to upgrade.
*/
public class ArrayList {
Vector v;

Expand Down
81 changes: 81 additions & 0 deletions src/main/java/database/jdbc/TypeMapDemo.java
@@ -0,0 +1,81 @@
import java.sql.*;
import java.util.*;
import java.io.*;

* Following up on the javadoc for java.sql.Connection,
* make a TypeMap that maps a *structured* UDT into a
* MusicRecording "automatically".
* @author Ian Darwin
*/
public class TypeMapDemo {
public static void main(String[] args)
throws IOException, ClassNotFoundException, SQLException {

Properties p = new Properties();
p.load(new FileInputStream("db.properties"));
Class c = Class.forName(p.getProperty("db.driver"));
System.out.println("Loaded driverClass " + c.getName());

Connection con = DriverManager.getConnection(
p.getProperty("db.url"),
"student", "student");
System.out.println("Got Connection " + con);

Statement s = con.createStatement();
int ret;
try {
s.executeUpdate("drop table MR");
s.executeUpdate("drop type MUSICRECORDING");
} catch (SQLException andDoNothingWithIt) {
// Should use "if defined" but not sure it works for UDTs...
}
ret = s.executeUpdate(
"create type MUSICRECORDING as object (" +
" id integer," +
" title varchar(20), " +
" artist varchar(20) " +
")");
System.out.println("Created TYPE! Ret=" + ret);

ret = s.executeUpdate(
"create table MR of MUSICRECORDING");
System.out.println("Created TABLE! Ret=" + ret);

int nRows = s.executeUpdate(
"insert into MR values(123, 'Greatest Hits', 'Ian')");
System.out.println("inserted " + nRows + " rows");


// Put the data class into the connection's Type Map
// If the data class were not an inner class,
// this would likely be done with Class.forName(...);
Map map = con.getTypeMap();
map.put("MUSICRECORDING", MusicRecording.class);
con.setTypeMap(map);

ResultSet rs = s.executeQuery(
"select * from MR where id = 123");
//"select musicrecording(id,artist,title) from mr");
rs.next();
for (int i=1; i<=rs.getMetaData().getColumnCount(); i++) {
Object o = rs.getObject(i);
System.out.print(o + "(Type " +
o.getClass().getName() + ")\t");
}
System.out.println();
}

/**
* Simplified local copy of MusicRecording, so this pgm can stand alone.
* This is an inner class just for illustrative purposes;
* it would normally be an unrelated data class.
*/
public class MusicRecording {
int id;
String title;
String artist;
public String toString() {
return "MusicRecording#"+id+"["+artist+"--"+title+"]";
}
}
}
14 changes: 14 additions & 0 deletions src/main/java/database/jdbc/db.properties
@@ -0,0 +1,14 @@
# JDBC Properties

# Connection information for the Oracle database on the server
db.driver = oracle.jdbc.driver.OracleDriver
#db.url = jdbc:oracle:thin:@server:1521:db570
db.url = jdbc:oracle:thin:@ltree7:1521:db570

# Connection information for the Access database on the local machine
# db.driver = sun.jdbc.odbc.JdbcOdbcDriver
# db.url = jdbc:odbc:RainForestDSN

# userId and password for the database connection
db.user = student
db.password = student
23 changes: 13 additions & 10 deletions src/main/java/miles2kms/Miles2Kms.java
@@ -1,27 +1,30 @@
// DO NOT USE -- in transition...

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.util.*;

/**
* A simple applet panel - miles <==> kilometers
*
* @author Ian Darwin, after a temperature demo by Arthur van Hoff.
* @author Ian Darwin, based loosely on a long-ago temperature demo
* by Arthur van Hoff.
* Reworked as an "observable" demo after an example (FtoC) from Course 477.
* Should add text listeners on the textfields...
*/
public class Miles2Kms extends Applet {
Scrollbar sb;
LabelTextField miles, kms;
MyModel model;

public void init() {
setLayout(new BorderLayout());
add("North", miles = new LabelTextField('m', "Miles", 10));
add("Center", sb = new Scrollbar(Scrollbar.VERTICAL,
0, 1, 0, 239));
add("South", kms = new LabelTextField('k', "Kilometers", 10));
Panel pl, pr;
pl = new Panel();
pr = new Panel();
pl.setLayout(new BorderLayout());
pl.add(BorderLayout.NORTH, miles = new LabelTextField('m', "Miles", 10));
pr.add(sb = new Scrollbar(Scrollbar.VERTICAL, 0, 1, -240, 0));
pl.add(BorderLayout.SOUTH, kms = new LabelTextField('k', "Kilometers", 10));
add(pr);
add(pl);

model = new MyModel();
model.addObserver(miles);
Expand Down Expand Up @@ -98,6 +101,6 @@ class MyAdjustmentListener implements AdjustmentListener {
this.model = model;
}
public void adjustmentValueChanged( AdjustmentEvent e ) {
model.setMiles( e.getValue() );
model.setMiles( -e.getValue() );
}
}
3 changes: 2 additions & 1 deletion src/main/java/native1_1/HelloWorld.java
Expand Up @@ -21,6 +21,7 @@ public static void main(String[] args) {

// Static code blocks are executed once, when class file is loaded
static {
System.load("libhello.so");
System.load(System.getProperty("java.user.directory") + "/" +
"libhello.so");
}
}

0 comments on commit 29be979

Please sign in to comment.