Circle.java 880 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * The Java mapping of the SQL user-defined type "circle".
  3. *
  4. */
  5. import java.sql.*;
  6. public class Circle implements SQLData
  7. {
  8. private static double PI = 3.14159;
  9. /*
  10. * JDBC 2.0 style SQL/Java object mapping
  11. */
  12. private double x;
  13. private double y;
  14. private double radius;
  15. private String type;
  16. public String getSQLTypeName() { return type; }
  17. public void readSQL (SQLInput stream, String typeName)
  18. throws SQLException
  19. {
  20. type = typeName;
  21. x = stream.readDouble();
  22. y = stream.readDouble();
  23. radius = stream.readDouble();
  24. }
  25. public void writeSQL (SQLOutput stream)
  26. throws SQLException
  27. {
  28. stream.writeDouble(x);
  29. stream.writeDouble(y);
  30. stream.writeDouble(radius);
  31. }
  32. /* A Java UDR that returns the area of the circle.
  33. */
  34. public static double area(Circle c)
  35. {
  36. return PI * c.radius * c.radius;
  37. }
  38. }