Env.java 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import java.lang.*;
  2. import java.sql.*;
  3. import com.informix.udr.*;
  4. /**
  5. * Example UDRs to demonstrate the use of the UDREnv object.
  6. */
  7. public class Env
  8. {
  9. /**
  10. * Return the UDR's SQL signature.
  11. */
  12. public static String signature(int xint, String xchar, String
  13. xvchar, boolean xboolean)
  14. throws SQLException
  15. {
  16. UDREnv env = UDRManager.getUDREnv();
  17. String res = env.getReturnTypeName() + " " + env.getName() + "(";
  18. String param[] = env.getParamTypeName();
  19. for (int j = 0; j < param.length; ++ j)
  20. {
  21. if (j > 0)
  22. res += ",";
  23. res += param[j];
  24. }
  25. res += ")";
  26. return res;
  27. }
  28. public int count;
  29. /**
  30. * A simple iterative function that count down from N through 1.
  31. */
  32. public static String countDown(int N)
  33. throws SQLException
  34. {
  35. UDREnv env = UDRManager.getUDREnv();
  36. int iter = env.getSetIterationState();
  37. UDRLog log = env.getLog();
  38. if (iter == UDREnv.UDR_SET_INIT)
  39. {
  40. /* before 1st call, allocate state object and set its value */
  41. Env state = new Env();
  42. state.count = N;
  43. env.setUDRState(state);
  44. env.setSetIterationIsDone(false);
  45. return null;
  46. }
  47. else if (iter == UDREnv.UDR_SET_END)
  48. {
  49. /* after last call, clean up (a no-op for this example) */
  50. env.setSetIterationIsDone(true);
  51. return null;
  52. }
  53. else if (iter == UDREnv.UDR_SET_RETONE)
  54. {
  55. Env state = (Env)env.getUDRState();
  56. -- state.count;
  57. if (state.count < 0)
  58. env.setSetIterationIsDone(true);
  59. else
  60. env.setSetIterationIsDone(false);
  61. log.log("#" + (state.count + 1));
  62. return "#" + (state.count + 1);
  63. }
  64. else
  65. throw new SQLException("Unknown iterator code");
  66. }
  67. }