GetFieldsName.java 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package baseclass.tools;
  2. import p2.p2server.P2Server;
  3. import p2.pao.PaoSetRemote;
  4. import p2.util.P2Exception;
  5. import java.util.ArrayList;
  6. import java.util.Arrays;
  7. import java.util.HashMap;
  8. import java.util.List;
  9. public class GetFieldsName {
  10. String objectname;
  11. PaoSetRemote ps_objectcols;
  12. public static HashMap<String, String[]> objectcolsmap = new HashMap<String, String[]>(16);
  13. /**
  14. * 构造函数
  15. *
  16. * @param objectname 数据表名称
  17. */
  18. public GetFieldsName(String objectname) throws P2Exception {
  19. this.objectname = objectname.toUpperCase();
  20. if (!objectcolsmap.containsKey(this.objectname)) {
  21. this.ps_objectcols = P2Server.getP2Server().getPaoSet("ps_objectcols",
  22. P2Server.getP2Server().getSystemUserInfo());
  23. ps_objectcols.setWhere("objectname='" + this.objectname
  24. + "' and fieldname!='rmkenable' and fieldname!='recversion' and PERSISTENT=1");
  25. ps_objectcols.reset();
  26. int count = ps_objectcols.count();
  27. String[] allfields = new String[count];
  28. int i = 0;
  29. while (ps_objectcols.getPao(i) != null) {
  30. allfields[i] = ps_objectcols.getPao(i).getString("fieldname");
  31. i++;
  32. }
  33. objectcolsmap.put(this.objectname, allfields);
  34. ps_objectcols.close();
  35. }
  36. }
  37. /**
  38. * 获取所有栏位名称
  39. *
  40. * @return
  41. * @throws P2Exception
  42. */
  43. public String[] getFields() throws P2Exception {
  44. return objectcolsmap.get(objectname);
  45. }
  46. /**
  47. * 获取除指定栏位外的栏位名称
  48. *
  49. * @param exceptfields 需排除的栏位名称
  50. * @return
  51. * @throws P2Exception
  52. */
  53. public String[] getFields(String[] exceptfields) throws P2Exception {
  54. StringBuilder a = new StringBuilder(objectname);
  55. for (String exceptfield : exceptfields) {
  56. a.append(exceptfield);
  57. }
  58. if (objectcolsmap.containsKey(a.toString())) {
  59. return objectcolsmap.get(a.toString());
  60. } else {
  61. List<String> exceptlist = Arrays.asList(exceptfields);
  62. String[] allfields = objectcolsmap.get(objectname);
  63. List<String> list = new ArrayList<String>();
  64. for (String field : allfields) {
  65. if (!exceptlist.contains(field)) {
  66. list.add(field);
  67. }
  68. }
  69. String[] s = list.toArray(new String[0]);
  70. objectcolsmap.put(a.toString(), s);
  71. return s;
  72. }
  73. }
  74. }