| 1 5 6 package com.raptus.owxv3.api; 7 8 import java.sql.*; 9 import java.util.*; 10 11 import javax.sql.DataSource ; 12 13 import com.raptus.owxv3.*; 14 import com.raptus.owxv3.api.dataxs.*; 15 import com.raptus.owxv3.modules.categories.CategoryConstants; 16 17 39 public class GlobalResources extends Object  40 { 41 44 public static final String FILETYPE_FILE = "file"; 45 public static final String FILETYPE_PICTURE = "picture"; 46 50 53 protected DataSource ds = null; 54 55 58 protected OwxmsgsManager msgsMgr = null; 59 60 63 protected OwxurlsManager urlsMgr = null; 64 65 68 protected OwxfilesManager filesMgr = null; 69 70 73 protected OwxflinksManager flinksMgr = null; 74 75 76 79 protected OwxcategoryManager categoryMgr=null; 80 81 84 protected OwxcatlinksManager catlinksMgr=null; 85 86 89 protected OwxfieldsManager fieldsMgr=null; 90 91 92 95 public GlobalResources() 96 { 97 ds = VModuleManager.getInstance().getDataSource(VModuleManager.GLOBALRESOURCES_DS); 98 99 msgsMgr = new OwxmsgsManager(); 100 msgsMgr.setDataSource(ds); 101 102 urlsMgr = new OwxurlsManager(); 103 urlsMgr.setDataSource(ds); 104 105 filesMgr = new OwxfilesManager(); 106 filesMgr.setDataSource(ds); 107 108 flinksMgr = new OwxflinksManager(); 109 flinksMgr.setDataSource(ds); 110 111 categoryMgr=new OwxcategoryManager(); 112 categoryMgr.setDataSource(ds); 113 114 catlinksMgr=new OwxcatlinksManager(); 115 catlinksMgr.setDataSource(ds); 116 117 fieldsMgr=new OwxfieldsManager(); 118 fieldsMgr.setDataSource(ds); 119 } 120 121 124 protected void prepareURLObject(Owxurls url, GResURL grURL) 125 { 126 if(url == null || grURL == null) 127 return; 128 129 grURL.setRowID(url.getRowid()); 130 grURL.setProtocol(url.getFname()); 131 grURL.setFullURL(url.getUrl()); 132 } 133 134 137 protected void prepareFileObject(Owxfiles file, GResFile grFile) 138 { 139 if(file == null || grFile == null) 140 return; 141 142 grFile.setRowID(file.getRowid()); 143 grFile.setUsageCount(file.getUsagectr()); 144 grFile.setFileSize(file.getFsize()); 145 grFile.setFileURL(file.getUrl()); 146 grFile.setCategory(file.getCategory()); 147 grFile.setType(file.getFtype()); 148 grFile.setInfo(file.getFinfo()); 149 } 150 151 153 156 public String loadMessage(String srctable, int srcrowid, String field, Locale locale) 157 throws SQLException 158 { 159 String where = "srctbl = '" + srctable + "' AND srcrowid = " + srcrowid + " AND " + 160 "fname = '" + field + "' AND localekey = '" + locale.toString() + "'"; 161 Owxmsgs[] msgs = msgsMgr.loadByWhere(where); 163 if(msgs != null && msgs.length > 0) 164 return msgs[0].getMsg(); 165 166 return null; 167 } 168 169 172 public boolean saveMessage(String srctable, int srcrowid, String field, Locale locale, String msg) 173 throws SQLException 174 { 175 Owxmsgs msgObj = null; 177 String where = "srctbl = '" + srctable + "' AND srcrowid = " + srcrowid + " AND " + 178 "fname = '" + field + "' AND localekey = '" + locale.toString() + "'"; 179 Owxmsgs[] msgObjs = msgsMgr.loadByWhere(where); 180 if(msgObjs.length == 0) 181 { 182 msgObj = new Owxmsgs(); 184 msgObj.setSrctbl(srctable); 185 msgObj.setSrcrowid(srcrowid); 186 msgObj.setFname(field); 187 msgObj.setLocalekey(locale.toString()); 188 } 189 else 190 msgObj = msgObjs[0]; 191 192 if(msg == null || msg.trim().length() == 0) 195 msgObj.setMsg(null); 196 else 197 msgObj.setMsg(msg); 198 199 msgsMgr.save(msgObj); 200 LoggingManager.log("Saved message for " + srctable + " #" + srcrowid + ", " + 201 field + ", " + locale.getDisplayLanguage(), this); 202 203 return true; 204 } 205 206 209 public boolean deleteMessage(String srctable, int srcrowid, String field, Locale locale) 210 throws SQLException 211 { 212 213 String where = "srctbl = '" + srctable + "' AND srcrowid = " + srcrowid + " AND " + 215 "fname = '" + field + "' AND localekey = '" + locale.toString() + "'"; 216 Owxmsgs[] msgObjs = msgsMgr.loadByWhere(where); 217 if(msgObjs.length > 0) 218 { 219 int result = msgsMgr.deleteByKey(msgObjs[0].getRowid()); 220 LoggingManager.log("Deleted message #" + msgObjs[0].getRowid() + " for " + srctable + ", " + 221 field + ", " + locale.getDisplayLanguage() + ", count " + result, this); 222 return true; 223 } 224 225 return false; 226 } 227 228 231 public boolean deleteMessages(String srctable, int srcrowid, String field) 232 throws SQLException 233 { 234 String where = "srctbl = '" + srctable + "' AND srcrowid = " + srcrowid + " AND " + 236 "fname = '" + field + "'"; 237 Owxmsgs[] msgObjs = msgsMgr.loadByWhere(where); 238 for(int i = 0; i < msgObjs.length; i ++) 239 { 240 int result = msgsMgr.deleteByKey(msgObjs[i].getRowid()); 241 LoggingManager.log("Deleted message #" + msgObjs[i].getRowid() + " for " + srctable + ", " + 242 field + ", count " + result, this); 243 } 244 245 return true; 246 } 247 248 249 252 public boolean deleteAllMessages(String srctable, int srcrowid) 253 throws SQLException 254 { 255 String where = "srctbl = '" + srctable + "' AND srcrowid = " + srcrowid ; 257 Owxmsgs[] msgObjs = msgsMgr.loadByWhere(where); 258 for(int i = 0; i < msgObjs.length; i ++) 259 { 260 int result = msgsMgr.deleteByKey(msgObjs[i].getRowid()); 261 LoggingManager.log("Deleted message #" + msgObjs[i].getRowid() + " for " + srctable + ", " 262 +msgObjs[i].getFname()+ ", count " + result, this); 263 } 264 265 return true; 266 } 267 268 269 271 274 public Vector loadURLsAndTitles(String srctable, int srcrowid, String field,Locale locale) 275 throws SQLException 276 { 277 String where = "srctbl = '" + srctable + "' AND srcrowid = " + srcrowid + " AND " + 278 "fname = '" + field + "'"; 279 280 Vector ret = new Vector(); 281 Owxurls[] urls = urlsMgr.loadByWhere(where); 282 for(int i = 0; i < urls.length; i ++) 283 { 284 GResTitledURL grURL = new GResTitledURL(); 285 prepareURLObject(urls[i], grURL); 286 grURL.setTitle( loadMessage(urlsMgr.getTableID(),urls[i].getRowid() , field, locale) ); 287 ret.add(grURL); 288 } 289 290 return ret; 291 } 292 293 294 297 public Vector loadURLs(String srctable, int srcrowid, String field) 298 throws SQLException 299 { 300 String where = "srctbl = '" + srctable + "' AND srcrowid = " + srcrowid + " AND " + 301 "fname = '" + field + "'"; 302 303 Vector ret = new Vector(); 304 Owxurls[] urls = urlsMgr.loadByWhere(where); 305 for(int i = 0; i < urls.length; i ++) 306 { 307 GResURL grURL = new GResURL(); 308 prepareURLObject(urls[i], grURL); 309 ret.add(grURL); 310 } 311 312 return ret; 313 } 314 315 316 317 318 321 public boolean saveURL(String srctable, int srcrowid, String field, GResURL url) 322 throws SQLException 323 { 324 Owxurls urlObj = null; 326 String where = "srctbl = '" + srctable + "' AND srcrowid = " + srcrowid + " AND " + 327 "fname = '" + field + "' AND url = '" + url.getURL() + "'"; 328 Owxurls[] urlObjs = urlsMgr.loadByWhere(where); 329 if(urlObjs.length == 0) 330 { 331 urlObj = new Owxurls(); 333 urlObj.setSrctbl(srctable); 334 urlObj.setSrcrowid(srcrowid); 335 urlObj.setFname(field); 336 } 337 else 338 urlObj = urlObjs[0]; 339 340 urlObj.setUrl(url.getURL()); 341 urlsMgr.save(urlObj); 342 343 url.setRowID(urlObj.getRowid()); 345 346 LoggingManager.log("Saved URL for " + srctable + " #" + srcrowid + ", " + 347 field + ", " + url.getDisplayedURL(), this); 348 return true; 349 } 350 351 354 public boolean deleteURL(GResURL url) 355 throws SQLException 356 { 357 if(url == null) 358 return false; 359 360 urlsMgr.deleteByKey(url.getRowID()); 361 362 LoggingManager.log("Deleted URL #" + url.getRowID() + ", " + url.getProtocol() + 363 ", " + url.getDisplayedURL(), this); 364 return true; 365 } 366 367 370 public Vector deleteURLs(String srctable, int srcrowid, String field) 371 throws SQLException 372 { 373 try 374 { 375 Vector ret=new Vector(); 376 377 Owxurls urlObj = null; 379 String where = "srctbl = '" + srctable + "' AND srcrowid = " + srcrowid + " AND " + 380 "fname = '" + field + "'"; 381 Owxurls[] urlObjs = urlsMgr.loadByWhere(where); 382 for(int i = 0; i < urlObjs.length; i ++) 383 { 384 ret.add( new Integer (urlObjs[i].getRowid()) ); 385 GResURL grURL = new GResURL(); 386 prepareURLObject(urlObjs[i], grURL); 387 deleteURL(grURL); 388 } 389 return ret; 390 } 391 catch(Exception e) 392 { 393 LoggingManager.log("FAILED to delete the URLs, error:"+e, this); 394 395 } 396 397 LoggingManager.log("Deleted URL for " + srctable + " #" + srcrowid + ", " + field, this); 398 return null; 399 } 400 401 403 406 public Vector loadLinkedFilesAndIds(String ftype, String srctable, int srcrowid, String field) 407 throws SQLException 408 { 409 String where = "srctbl = '" + srctable + "' AND srcrowid = " + srcrowid + " AND " + 410 "fname = '" + field + "'"; 411 Vector ret = new Vector(); 413 Owxflinks[] flinks = flinksMgr.loadByWhere(where); 414 Owxfiles files[] = filesMgr.loadAll(); 415 int i=0,j=0; 416 for(i = 0; i < flinks.length; i ++) 417 { 418 419 for(j=0;j<files.length;j++) 420 { 421 if(flinks[i].getFileid()==files[j].getRowid()) 422 { 423 GResFile grObj = (ftype.equals(FILETYPE_FILE) ? new GResFile() : (GResFile) new GResPicture()); 424 prepareFileObject(files[j], grObj); 425 PairOfObjects pair=new PairOfObjects(); 426 pair.setObjectOne(grObj); 427 pair.setObjectTwo( new Integer (flinks[i].getRowid()) ); 428 ret.add(pair); 429 break; 430 } 431 } } 434 return ret; 435 } 436 437 440 public Vector loadLinkedFiles(String ftype, String srctable, int srcrowid, String field) 441 throws SQLException 442 { 443 String where = "srctbl = '" + srctable + "' AND srcrowid = " + srcrowid + " AND " + 444 "fname = '" + field + "'"; 445 446 Vector ret = new Vector(); 447 Owxflinks[] flinks = flinksMgr.loadByWhere(where); 448 Owxfiles files[] = filesMgr.loadAll(); 449 int i=0,j=0; 450 for(i = 0; i < flinks.length; i ++) 451 { 452 for(j=0;j<files.length;j++) 453 { 454 if(flinks[i].getFileid()==files[j].getRowid()) 455 { 456 GResFile grObj = (ftype.equals(FILETYPE_FILE) ? new GResFile() : (GResFile) new GResPicture()); 457 prepareFileObject(files[j], grObj); 458 459 ret.add(grObj); 460 break; 461 } 462 } 463 } 464 465 return ret; 466 } 467 468 469 472 public Vector loadLinkedFilesAndTitles(String ftype, String srctable, int srcrowid, String field, String linkfield, Locale locale) 473 throws SQLException 474 { 475 String where = "srctbl = '" + srctable + "' AND srcrowid = " + srcrowid + " AND " + 476 "fname = '" + field + "'"; 477 478 Vector ret = new Vector(); 479 Owxflinks[] flinks = flinksMgr.loadByWhere(where); 480 Owxfiles files[] = filesMgr.loadAll(); 481 int i=0,j=0; 482 for(i = 0; i < flinks.length; i ++) 483 { 484 for(j=0;j<files.length;j++) 485 { 486 if(flinks[i].getFileid()==files[j].getRowid()) 487 { 488 GResTitledFile grObj = new GResTitledFile(); 489 prepareFileObject(files[j], grObj); 490 grObj.setTitle( loadMessage(flinksMgr.getTableID(), flinks[i].getRowid(), linkfield,locale) ); 491 ret.add(grObj); 492 break; 493 } 494 } 495 } 496 497 return ret; 498 } 499 500 501 502 505 public Vector loadLinkablePics() 506 throws SQLException 507 { 508 String where = "ftype = '" + FILETYPE_PICTURE + 509 "' AND fsize > 0 AND (url != '' OR url != null)"; 510 511 Vector ret = new Vector(); 512 Owxfiles[] pics = filesMgr.loadByWhere(where, "category DESC", 0); 513 for(int i = 0; i < pics.length; i ++) 514 { 515 GResPicture grPic = new GResPicture(); 516 prepareFileObject((Owxfiles) pics[i], grPic); 517 ret.add(grPic); 518 } 519 520 return ret; 521 } 522 523 526 public String [] loadAllPictureCategories() 527 throws SQLException 528 { 529 String sql = "select distinct category from owxfiles where ftype='" + 530 FILETYPE_PICTURE + "' AND (url != '' OR url != null);"; 531 532 ResultSet rs = null; 533 Statement stmt = null; 534 Connection conn = ds.getConnection(); 535 try 536 { 537 stmt = conn.createStatement(); 538 rs = stmt.executeQuery(sql); 539 540 Vector v = new Vector(); 541 while(rs.next()) 542 v.addElement(rs.getString(1)); 543 544 rs.close(); 545 stmt.close(); 546 if(conn!=null) conn.close(); 547 return (String []) v.toArray( new String [v.size()] ); 548 } 549 catch(SQLException e) { 550 if(rs != null) try { rs.close(); } catch(Exception e2) { } 551 if(stmt !=null) try { stmt.close(); } catch(Exception e2) { } 552 throw e; 553 } 554 555 } 556 557 558 559 561 562 563 564 567 public String [] loadAllFileCategories() 568 throws SQLException 569 { 570 String sql = "select distinct category from owxfiles where ftype='" + 571 FILETYPE_FILE + "' AND url != '' AND url IS NOT NULL;"; 572 573 ResultSet rs = null; 574 Statement stmt = null; 575 Connection conn = ds.getConnection(); 576 try 577 { 578 stmt = conn.createStatement(); 579 rs = stmt.executeQuery(sql); 580 581 Vector v = new Vector(); 582 while(rs.next()) 583 v.addElement(rs.getString(1)); 584 585 rs.close(); 586 stmt.close(); 587 if(conn!=null) conn.close(); 588 return (String []) v.toArray( new String [v.size()] ); 589 } 590 catch(SQLException e) { 591 if(rs != null) try { rs.close(); } catch(Exception e2) { } 592 if(stmt !=null) try { stmt.close(); } catch(Exception e2) { } 593 throw e; 594 } 595 596 } 597 598 599 600 601 602 605 public Vector loadLinkableFiles() 606 throws SQLException 607 { 608 String where = "ftype = '" + FILETYPE_FILE + 609 "' AND fsize > 0 AND url != '' AND url IS NOT null"; 610 611 Vector ret = new Vector(); 612 Owxfiles[] pics = filesMgr.loadByWhere(where, "category, ftype, url desc", 0); 613 for(int i = 0; i < pics.length; i ++) 614 { 615 GResFile grfile = new GResFile(); 616 prepareFileObject((Owxfiles) pics[i], grfile); 617 ret.add(grfile); 618 } 619 620 return ret; 621 } 622 623 624 625 626 627 628 629 630 631 632 636 637 638 public String [] loadAllCategories() 639 throws SQLException 640 { 641 String sql = "select distinct category from owxfiles where url != '' AND url IS NOT NULL;"; 642 643 ResultSet rs = null; 644 Statement stmt = null; 645 Connection conn = ds.getConnection(); 646 try 647 { 648 stmt = conn.createStatement(); 649 rs = stmt.executeQuery(sql); 650 651 Vector v = new Vector(); 652 while(rs.next()) 653 v.addElement(rs.getString(1)); 654 655 rs.close(); 656 stmt.close(); 657 if(conn!=null) conn.close(); 658 659 return (String []) v.toArray( new String [v.size()] ); 660 } 661 catch(SQLException e) { 662 if(rs != null) try { rs.close(); } catch(Exception e2) { } 663 if(stmt !=null) try { stmt.close(); } catch(Exception e2) { } 664 throw e; 665 } 666 667 } 668 669 672 public Vector loadFiles() 673 throws SQLException 674 { 675 return loadFiles(""); 676 } 677 678 681 public Vector loadFiles(String filter) 682 throws SQLException 683 { 684 String where = "fsize > 0 and url!='' and url IS NOT NULL"; 685 if(filter!=null && !filter.trim().equals("")) 686 { 687 String f=filter.toLowerCase(); 688 where=where+" and (lower(url) LIKE '%"+FILETYPE_FILE.toLowerCase()+"/%"+f+"%' or lower(url) LIKE '%"+FILETYPE_PICTURE.toLowerCase()+"/%"+f+"%' or lower(category) LIKE '%"+f+"%'"+ 689 " or lower(ftype) LIKE '%"+f+"%')"; 690 } 691 692 Vector ret = new Vector(); 693 Owxfiles[] files = filesMgr.loadByWhere(where, "category, ftype, url desc", 0); 694 for(int i = 0; i < files.length; i ++) 695 { 696 if(files[i].getFtype().compareToIgnoreCase(FILETYPE_PICTURE)==0) 697 { 698 GResPicture gresPic=new GResPicture(); 699 prepareFileObject((Owxfiles) files[i], gresPic); 700 ret.add(gresPic); 701 } 702 else 703 { 704 GResFile gresFile=new GResFile(); 705 prepareFileObject((Owxfiles) files[i], gresFile); 706 ret.add(gresFile); 707 } 708 } 709 710 return ret; 711 } 712 713 714 715 716 717 718 721 public GResFile loadFile(int fileid) 722 throws SQLException 723 { 724 String where = "rowid="+fileid; 725 726 727 728 Owxfiles[] files = filesMgr.loadByWhere(where); 729 if(files.length==0) 730 return null; 731 732 if(files[0].getFtype().compareToIgnoreCase(FILETYPE_PICTURE)==0) 733 { 734 GResPicture gresPic=new GResPicture(); 735 prepareFileObject((Owxfiles) files[0], gresPic); 736 return gresPic; 737 } 738 else 739 { 740 GResFile gresFile=new GResFile(); 741 prepareFileObject((Owxfiles) files[0], gresFile); 742 return gresFile; 743 } 744 745 } 746 747 748 751 public GResFile loadFile(String filename) 752 throws SQLException 753 { 754 String where = "url LIKE '%"+filename+"'"; 755 756 757 758 Owxfiles[] files = filesMgr.loadByWhere(where); 759 if(files.length==0) 760 return null; 761 762 if(files[0].getFtype().compareToIgnoreCase(FILETYPE_PICTURE)==0) 763 { 764 GResPicture gresPic=new GResPicture(); 765 prepareFileObject((Owxfiles) files[0], gresPic); 766 return gresPic; 767 } 768 else 769 { 770 GResFile gresFile=new GResFile(); 771 prepareFileObject((Owxfiles) files[0], gresFile); 772 return gresFile; 773 } 774 775 } 776 777 778 781 public Vector loadFileLinks() throws SQLException 782 { 783 return loadFileLinks(""); 784 } 785 786 790 791 public Vector loadFileLinks(String filter) throws SQLException 792 { 793 794 Vector ret=new Vector(); 795 Owxflinks[] links=null; 796 VModuleManager vmanager=VModuleManager.getInstance(); 797 if(filter.equals("")) 798 { 799 links=flinksMgr.loadAll(); 800 for(int i=0;i<links.length;i++) 801 { 802 GResFileLink gresflink=new GResFileLink(); 803 804 gresflink.setSrctable(links[i].getSrctbl()); 805 gresflink.setOwnerVModule( vmanager.getTableOwnerVModule(links[i].getSrctbl()) ); 806 gresflink.setLinkid(links[i].getRowid()); 807 gresflink.setGResFile( loadFile(links[i].getFileid()) ); 808 ret.add(gresflink); 809 } } 811 else 812 { 813 Vector files=loadFiles(filter); 814 if(files.size()==0) 815 { 816 return ret; 818 } 819 StringBuffer where=new StringBuffer (); 820 where.append("fileid IN("); 821 String sep=""; 822 for(int i=0;i<files.size();i++) 823 { 824 where.append(sep); 825 where.append(((GResFile)files.get(i)).getRowID()); 826 sep=","; 827 } where.append(")"); 829 links=flinksMgr.loadByWhere(where.toString()); 830 GResFile file=null; 831 for(int i=0;i<links.length;i++) 832 { 833 GResFileLink gresflink=new GResFileLink(); 834 835 gresflink.setSrctable(links[i].getSrctbl()); 836 gresflink.setOwnerVModule( vmanager.getTableOwnerVModule(links[i].getSrctbl()) ); 837 gresflink.setLinkid(links[i].getRowid()); 838 839 for(int j=0;j<files.size();j++) 840 { 841 file=(GResFile)files.get(j); 842 if(file.getRowID()==links[i].getFileid()) 843 { 844 gresflink.setGResFile(file); 845 break; 846 } 847 } ret.add(gresflink); 849 } } return ret; 852 853 } 854 855 856 857 860 public int getUsedFileSpace() throws SQLException 861 { 862 String sql = "select sum(fsize) from owxfiles;"; 863 864 ResultSet rs = null; 865 Statement stmt = null; 866 Connection conn = ds.getConnection(); 867 try 868 { 869 stmt = conn.createStatement(); 870 rs = stmt.executeQuery(sql); 871 872 int usedspace=0; 873 if(rs.next()) 874 usedspace=rs.getInt(1); 875 876 rs.close(); 877 stmt.close(); 878 if(conn!=null) conn.close(); 879 return usedspace; 880 } 881 catch(SQLException e) { 882 if(rs != null) try { rs.close(); } catch(Exception e2) { } 883 if(stmt !=null) try { stmt.close(); } catch(Exception e2) { } 884 throw e; 885 } 886 887 } 888 889 890 891 896 public int saveFileLink(String srctable, int srcrowid, String field, GResFile grFile) 897 throws SQLException 898 { 899 900 901 String where = "srctbl = '" + srctable + "' AND srcrowid = " + srcrowid + " AND " + 902 "fname = '" + field + "' AND fileid = " + grFile.getRowID(); 903 Owxflinks[] flinksObjs = flinksMgr.loadByWhere(where); 904 905 Owxflinks flinksObj=null; 906 boolean newFileLink=false; 907 if(flinksObjs.length==0) 908 { 909 flinksObj=new Owxflinks(); 910 flinksObj.setSrctbl(srctable); 911 flinksObj.setSrcrowid(srcrowid); 912 flinksObj.setFname(field); 913 flinksObj.setFileid(grFile.getRowID()); 914 newFileLink=true; 915 } 916 else flinksObj=flinksObjs[0]; 917 918 flinksMgr.save(flinksObj); 919 if(newFileLink) 920 { 921 incFileUsage(grFile); 922 } 923 return flinksObj.getRowid(); 924 } 925 926 927 928 933 934 935 public int deleteFileLink(String srctable, int srcrowid, String field,GResFile grFile) 936 throws SQLException 937 { 938 String where = "srctbl = '" + srctable + "' AND srcrowid = " + srcrowid + " AND " + 939 "fname = '" + field + "' and fileid="+grFile.getRowID(); 940 941 Owxflinks flinks[]=flinksMgr.loadByWhere(where); 942 if(flinks.length==0) return -1; 943 flinksMgr.deleteByKey(flinks[0].getRowid()); 944 decFileUsage(grFile); 945 return flinks[0].getRowid(); 946 } 947 948 949 953 954 public boolean deleteFileLink(GResFile grFile) 955 throws SQLException 956 { 957 958 return false; 959 } 960 961 962 965 public Vector deleteFileLinks(String srctable, int srcrowid, String field) 966 throws SQLException 967 { 968 try 969 { 970 Vector ret=new Vector(); 971 972 String where = "srctbl = '" + srctable + "' AND srcrowid = " + srcrowid + " AND " + 973 "fname = '" + field + "'"; 974 975 Owxflinks flinks[]=flinksMgr.loadByWhere(where); 976 for(int i=0;i<flinks.length;i++) 977 { 978 GResFile grFile=loadFile(flinks[i].getFileid()); 979 flinksMgr.deleteByKey(flinks[i].getRowid()); 980 decFileUsage(grFile); 981 ret.add( new Integer (flinks[i].getRowid()) ); 982 } 983 984 return ret; 985 } 986 catch(Exception e) 987 { 988 LoggingManager.log("FAILED to delete the file Links"+e,this); 989 return null; 990 } 991 } 992 993 994 995 998 999 private boolean incFileUsage(GResFile grFile) throws SQLException{ 1000 grFile.setUsageCount(grFile.getUsageCount()+1); 1001 return saveFile(grFile); 1002 } 1003 1004 1005 1008 1009 private boolean decFileUsage(GResFile grFile) throws SQLException{ 1010 int usagecount=grFile.getUsageCount(); 1011 if(usagecount>0) 1012 { 1013 grFile.setUsageCount(usagecount-1); 1014 return saveFile(grFile); 1015 } 1016 return false; 1017 } 1018 1019 1020 1021 1024 public boolean saveFile(GResFile grFile) 1025 throws SQLException 1026 { 1027 1028 Owxfiles fileobj=new Owxfiles(); 1029 if(grFile.getRowID()!=0) 1030 { 1031 fileobj.setRowid(grFile.getRowID()); 1032 fileobj.setIsNew(false); 1033 } 1034 fileobj.setUrl( grFile.getFileURL() ); 1035 fileobj.setCategory( grFile.getCategory() ); 1036 fileobj.setUsagectr( grFile.getUsageCount() ); 1037 fileobj.setFtype( grFile.getType() ); 1038 fileobj.setFsize( (int)grFile.getFileSize() ); 1039 fileobj.setFinfo( grFile.getInfo() ); 1040 1041 filesMgr.save(fileobj); 1042 return true; 1043 } 1044 1045 1048 public boolean saveFileOverwrite(GResFile grFile) 1049 throws SQLException 1050 { 1051 String where = "url ='"+grFile.getFileURL()+"'"; 1052 1053 1054 1055 Owxfiles[] files = filesMgr.loadByWhere(where); 1056 if(files.length>0) 1057 { 1058 grFile.setRowID(files[0].getRowid()); 1059 } 1060 return saveFile(grFile); 1061 } 1062 1063 1064 1067 public boolean saveFileCategory(int rowId,String category) 1068 throws SQLException 1069 { 1070 String where = "rowid="+rowId; 1071 1072 1073 Owxfiles[] files = filesMgr.loadByWhere(where); 1074 files[0].setCategory(category); 1075 filesMgr.save(files[0]); 1076 return true; 1077 1078 } 1079 1080 1081 1084 public boolean deleteFile(GResFile grFile) 1085 throws SQLException 1086 { 1087 int rowdeleted=filesMgr.deleteByKey(grFile.getRowID()); 1088 if(rowdeleted==1) return true; 1089 return false; 1090 } 1091 1092 1093 1094 1098 public boolean deleteLink(int linkid) 1099 throws SQLException 1100 { 1101 1103 String where = "rowid="+linkid; 1104 Owxflinks[] flinks = flinksMgr.loadByWhere(where); 1105 1106 if(flinks.length==0) return false; 1107 1109 where="rowid="+flinks[0].getFileid(); 1110 Owxfiles files[]=filesMgr.loadByWhere(where); 1111 1112 if(files.length>0) 1113 { 1114 GResFile gresFile=new GResFile(); 1115 prepareFileObject((Owxfiles) files[0], gresFile); 1116 decFileUsage(gresFile); 1117 } 1118 1119 1120 flinksMgr.deleteByKey(linkid); 1121 return true; 1122 } 1123 1124 1125 1126 1127 1133 public int saveCategory(GResCategory grCat) 1134 throws SQLException 1135 { 1136 1137 GResCategory oldcat=loadCategory(grCat.getCategoryID()); 1138 if(oldcat!=null) return -1; 1139 Owxcategory catobj=new Owxcategory(); 1140 if(grCat.getRowID()!=0) 1141 { 1142 catobj.setRowid(grCat.getRowID()); 1143 catobj.setIsNew(false); 1144 } 1145 else 1146 { 1147 catobj.setUsagectr(0); 1148 } 1149 catobj.setParent( grCat.getParent() ); 1150 catobj.setOwner( grCat.getOwner() ); 1151 catobj.setId( grCat.getCategoryID() ); 1152 catobj.setLevel( grCat.getLevel() ); 1153 1154 catobj.setStatic(grCat.getStatic() ); 1156 categoryMgr.save(catobj); 1157 grCat.setRowID( catobj.getRowid() ); 1158 return 1; 1159 } 1160 1161 1165 1166 public String getCategoryTableName() 1167 { 1168 return categoryMgr.getTableID(); 1169 } 1170 1171 1172 1178 protected void prepareCategoryObject(Owxcategory owxcat, GResCategory grCat) 1179 { 1180 if(owxcat==null || grCat==null) return; 1181 1182 grCat.setRowID(owxcat.getRowid()); 1183 grCat.setCategoryID(owxcat.getId()); 1184 grCat.setOwner(owxcat.getOwner()); 1185 grCat.setParent(owxcat.getParent()); 1186 grCat.setUsageCount(owxcat.getUsagectr()); 1187 grCat.setLevel(owxcat.getLevel()); 1188 grCat.setStatic(owxcat.getStatic()); 1189 } 1190 1191 1192 1198 protected void prepareCatLinkObject(Owxcatlinks owxcatlink, GResCatLink grCatLink) 1199 { 1200 if(owxcatlink==null || grCatLink==null) return; 1201 1202 grCatLink.setRowID(owxcatlink.getRowid()); 1203 grCatLink.setSrctbl(owxcatlink.getSrctbl()); 1204 grCatLink.setSrcRowID(owxcatlink.getSrcrowid()); 1205 grCatLink.setFname(owxcatlink.getFname()); 1206 grCatLink.setCatID(owxcatlink.getCatid()); 1207 } 1208 1209 1210 1211 1212 1217 public GResCategory loadCategory( int rowid) throws SQLException 1218 { 1219 String where = "rowid="+rowid; 1220 Owxcategory[] owxcategs = categoryMgr.loadByWhere(where); 1221 if(owxcategs.length==0) 1222 return null; 1223 1224 GResCategory cat=new GResCategory(); 1225 prepareCategoryObject(owxcategs[0],cat); 1226 1227 return cat; 1228 } 1229 1230 1236 public GResCategory loadCategory( String id, String owner) throws SQLException 1237 { 1238 String where = "id='"+id+"' and owner='"+owner+"'"; 1239 Owxcategory[] owxcategs = categoryMgr.loadByWhere(where); 1240 if(owxcategs.length==0) 1241 return null; 1242 1243 GResCategory cat=new GResCategory(); 1244 prepareCategoryObject(owxcategs[0],cat); 1245 1246 return cat; 1247 } 1248 1249 1254 public GResCategory loadCategory( String id) throws SQLException 1255 { 1256 String where = "id='"+id+"'"; 1257 Owxcategory[] owxcategs = categoryMgr.loadByWhere(where); 1258 if(owxcategs.length==0) 1259 return null; 1260 1261 GResCategory cat=new GResCategory(); 1262 prepareCategoryObject(owxcategs[0],cat); 1263 1264 return cat; 1265 } 1266 1267 1268 1269 1276 public Vector loadCategories(int level,String owner) throws SQLException 1277 { 1278 String where =new String (); 1279 if(owner.equals("")) where="level="+level; 1280 else where="level="+level+" and owner='"+owner+"'"; 1281 Vector ret=new Vector(); 1282 String orderBy=" rowid ASC"; 1283 Owxcategory[] owxcategs = categoryMgr.loadByWhere(where,orderBy,0); 1284 1285 for(int i=0;i<owxcategs.length;i++) 1286 { 1287 GResCategory cat=new GResCategory(); 1288 prepareCategoryObject(owxcategs[i],cat); 1289 ret.add(cat); 1290 } 1292 return ret; 1293 } 1294 1295 1298 public Vector loadStaticCategories() throws SQLException 1299 { 1300 String where="static='1'"; 1301 String orderBy=" rowid ASC"; 1302 Vector ret=new Vector(); 1303 Owxcategory[] owxcategs = categoryMgr.loadByWhere(where,orderBy,0); 1304 for(int i=0;i<owxcategs.length;i++) 1305 { 1306 GResCategory cat=new GResCategory(); 1307 prepareCategoryObject(owxcategs[i],cat); 1308 ret.add(cat); 1309 } 1311 return ret; 1312 } 1313 1314 1320 1321 public Vector loadChildCategories(int parentid,String owner) throws SQLException 1322 { 1323 String where =new String (); 1324 if(owner.equals("")) where="parent="+parentid; 1325 else where="parent="+parentid+" and owner='"+owner+"'"; 1326 String orderBy=" rowid ASC"; 1327 Vector ret=new Vector(); 1328 Owxcategory[] owxcategs = categoryMgr.loadByWhere(where,orderBy,0); 1329 for(int i=0;i<owxcategs.length;i++) 1330 { 1331 GResCategory cat=new GResCategory(); 1332 prepareCategoryObject(owxcategs[i],cat); 1333 ret.add(cat); 1334 } 1336 return ret; 1337 } 1338 1339 1340 1344 1345 protected void doSQLUpdate(String sqlupdate) throws java.sql.SQLException  1346 { 1347 Statement stmt = null; 1348 try 1349 { 1350 Connection conn = ds.getConnection(); 1351 stmt = conn.createStatement(); 1352 stmt.executeUpdate(sqlupdate); 1353 stmt.close(); 1354 if(conn!=null) conn.close(); 1355 } 1356 catch(SQLException e) { 1357 if(stmt !=null) try { stmt.close(); } catch(Exception e2) { } 1358 throw e; 1359 } 1360 } 1361 1362 1366 public void deleteCategory(GResCategory cat) throws SQLException 1367 { 1368 categoryMgr.deleteByKey(cat.getRowID()); 1369 doSQLUpdate("DELETE FROM owxcatlinks WHERE catid='"+cat.getRowID()+"'"); 1370 deleteMessages( 1371 getCategoryTableName(), 1372 cat.getRowID(), 1373 CategoryConstants.RESCATFIELD_NAME); 1374 } 1375 1376 1380 public Vector loadCategoryItemIDs(String catID) throws java.sql.SQLException  1381 { 1382 GResCategory cat=loadCategory(catID); 1383 String sql = "select * from owxcatlinks where catid="+cat.getRowID()+";"; 1384 Vector result = new Vector(); 1386 1387 ResultSet rs = null; 1388 Statement stmt = null; 1389 Connection conn = ds.getConnection(); 1390 try 1391 { 1392 stmt = conn.createStatement(); 1393 rs = stmt.executeQuery(sql); 1394 1395 while(rs.next()) 1396 { 1397 int id = rs.getInt("srcrowid"); 1398 result.addElement(new Integer (id)); 1399 } 1400 1401 rs.close(); 1402 stmt.close(); 1403 if(conn!=null) conn.close(); 1404 return result; 1406 } 1407 catch(SQLException e) { 1408 if(rs != null) try { rs.close(); } catch(Exception e2) { } 1409 if(stmt !=null) try { stmt.close(); } catch(Exception e2) { } 1410 throw e; 1411 } 1412 } 1413 1414 1418 public Vector loadCategoryItemIDs(int rowID) throws java.sql.SQLException  1419 { 1420 1421 String sql = "select * from owxcatlinks where catid="+rowID+";"; 1422 Vector result = new Vector(); 1424 1425 ResultSet rs = null; 1426 Statement stmt = null; 1427 Connection conn = ds.getConnection(); 1428 try 1429 { 1430 stmt = conn.createStatement(); 1431 rs = stmt.executeQuery(sql); 1432 1433 while(rs.next()) 1434 { 1435 int id = rs.getInt("srcrowid"); 1436 result.addElement(new Integer (id)); 1437 } 1438 1439 rs.close(); 1440 stmt.close(); 1441 if(conn!=null) conn.close(); 1442 return result; 1444 } 1445 catch(SQLException e) { 1446 if(rs != null) try { rs.close(); } catch(Exception e2) { } 1447 if(stmt !=null) try { stmt.close(); } catch(Exception e2) { } 1448 throw e; 1449 } 1450 } 1451 1452 1453 1454 1459 public Vector loadCatLinks(int catRowID) throws java.sql.SQLException  1460 { 1461 String where = "catid="+catRowID; 1463 Owxcatlinks[] catlinksObj = catlinksMgr.loadByWhere(where); 1464 Vector ret=new Vector(); 1465 for(int i=0;i<catlinksObj.length;i++) 1466 { 1467 GResCatLink grCatLink=new GResCatLink(); 1468 prepareCatLinkObject(catlinksObj[i],grCatLink); 1469 ret.add(grCatLink); 1470 } 1471 1472 return ret; 1473 1474 } 1475 1476 1477 1483 1484 public Vector loadCategoryLinksForItem( String srctable, int srcrowid,String fname) 1485 throws SQLException 1486 { 1487 String where = "srctbl='"+srctable+"' and srcrowid="+srcrowid+" and fname='"+fname+"'"; 1489 Owxcatlinks[] catlinksObj = catlinksMgr.loadByWhere(where); 1490 Vector ret=new Vector(); 1491 for(int i=0;i<catlinksObj.length;i++) 1492 { 1493 1494 ret.add(new Integer (catlinksObj[i].getCatid()) ); 1495 } 1496 1497 return ret; 1498 } 1499 1500 1501 1502 1503 1508 public boolean deleteCatLink(int linkid) 1509 throws SQLException 1510 { 1511 String where = "rowid="+linkid; 1513 Owxcatlinks[] catlinksObj = catlinksMgr.loadByWhere(where); 1514 if(catlinksObj.length==0) return false; 1515 catlinksMgr.deleteByKey(catlinksObj[0].getRowid()); 1516 decCategoryUsageCtr( catlinksObj[0].getCatid() ); 1517 return true; 1518 } 1519 1520 1526 public boolean deleteCatLink(String srctable,int srcrowid) 1527 throws SQLException 1528 { 1529 String where = "srctbl='"+srctable+"' AND srcrowid="+srcrowid; 1531 Owxcatlinks[] catlinksObj = catlinksMgr.loadByWhere(where); 1532 if(catlinksObj.length==0) return false; 1533 for(int i=0;i<catlinksObj.length;i++) 1534 { 1535 catlinksMgr.deleteByKey(catlinksObj[i].getRowid()); 1536 decCategoryUsageCtr( catlinksObj[i].getCatid() ); 1537 } 1538 return true; 1539 } 1540 1541 1542 1547 protected void decCategoryUsageCtr(int catId) throws SQLException 1548 { 1549 String where = "rowid="+catId; 1550 Owxcategory[] owxcategs = categoryMgr.loadByWhere(where); 1551 if(owxcategs.length==0) return; 1552 1553 int usagectr=owxcategs[0].getUsagectr(); 1554 1555 if(usagectr>0) owxcategs[0].setUsagectr(usagectr-1); 1556 categoryMgr.save(owxcategs[0]); 1557 } 1558 1559 1560 1561 1566 protected void incCategoryUsageCtr(int catId) throws SQLException 1567 { 1568 String where = "rowid="+catId; 1569 Owxcategory[] owxcategs = categoryMgr.loadByWhere(where); 1570 if(owxcategs.length==0) return; 1571 1572 int usagectr=owxcategs[0].getUsagectr(); 1573 1574 owxcategs[0].setUsagectr(usagectr+1); 1575 categoryMgr.save(owxcategs[0]); 1576 } 1577 1578 1579 1580 1583 public Vector getTree(GResCategory cat,Locale l) throws SQLException 1584 { 1585 return getTree(cat.getRowID(), l); 1586 } 1587 1588 1595 public Vector getTree(int rowID, Locale l) throws SQLException 1596 { 1597 GResCategory ccat = loadCategory( rowID); 1598 Vector result; 1599 1600 if(ccat == null) 1602 { 1603 return new Vector(); 1604 } 1605 1606 if(ccat.getParent() != 0) 1607 { 1608 result = getTree(ccat.getParent(), l); 1609 } 1610 else 1611 { 1612 result = new Vector(); 1613 } 1614 1615 result.addElement(loadCategoryName(ccat, l)); 1616 1617 return result; 1618 } 1619 1620 public Vector getTree(String catId,Locale l) throws SQLException 1621 { 1622 GResCategory ccat = loadCategory(catId); 1623 Vector result; 1624 if(ccat.getParent() != 0) 1625 { 1626 result = getTree(ccat.getParent(), l); 1627 } 1628 else 1629 { 1630 result = new Vector(); 1631 } 1632 1633 result.addElement(loadCategoryName(ccat, l)); 1634 1635 return result; 1636 } 1637 1638 1639 1645 public Vector getTreeWithIDs(int rowID, Locale l) throws SQLException 1646 { 1647 GResCategory ccat = loadCategory( rowID); 1648 Vector result; 1649 if(ccat.getParent() != 0) 1650 { 1651 result = getTree(ccat.getParent(), l); 1652 } 1653 else 1654 { 1655 result = new Vector(); 1656 } 1657 PairOfObjects pair=new PairOfObjects(); 1658 pair.setObjectOne(loadCategoryName(ccat, l)); 1659 pair.setObjectTwo(new Integer (ccat.getRowID())); 1660 result.addElement(pair); 1661 1662 return result; 1663 } 1664 1665 1666 1671 protected String loadCategoryName(GResCategory grcat, Locale l) throws java.sql.SQLException  1672 { 1673 if(grcat!=null) 1674 { 1675 return loadMessage(getCategoryTableName(),grcat.getRowID(), CategoryConstants.RESCATFIELD_NAME,l); 1676 } 1677 else 1678 { 1679 return "No name"; 1680 } 1681 } 1683 1684 1685 1686 1694 public boolean saveCatLink(String srctable, int srcrowid, String field, int catid) 1695 throws SQLException 1696 { 1697 String where = "srctbl = '" + srctable + "' AND srcrowid = " + srcrowid + " AND " + 1698 "fname = '" + field + "' AND catid = " + catid; 1699 Owxcatlinks[] catlinksObjs = catlinksMgr.loadByWhere(where); 1700 1701 Owxcatlinks catlinksObj=null; 1702 if(catlinksObjs.length==0) 1703 { 1704 catlinksObj=new Owxcatlinks(); 1705 catlinksObj.setSrctbl(srctable); 1706 catlinksObj.setSrcrowid(srcrowid); 1707 catlinksObj.setFname(field); 1708 catlinksObj.setCatid(catid); 1709 } 1710 else catlinksObj=catlinksObjs[0]; 1711 1712 catlinksMgr.save(catlinksObj); 1713 incCategoryUsageCtr(catid); 1714 1715 return true; 1716 } 1717 1718 1719 1720 1721 1729 public boolean deleteCatLink(String srctable, int srcrowid, String field, int catid) 1730 throws SQLException 1731 { 1732 1733 String where = "srctbl = '" + srctable + "' AND srcrowid = " + srcrowid + " AND " + 1734 "fname = '" + field + "' AND catid = " + catid; 1735 1736 Owxcatlinks[] catlinksObj = catlinksMgr.loadByWhere(where); 1737 if(catlinksObj.length==0) return false; 1738 catlinksMgr.deleteByKey(catlinksObj[0].getRowid()); 1739 decCategoryUsageCtr( catlinksObj[0].getCatid() ); 1740 return true; 1741 } 1742 1743 1744 1750 1751 public Vector loadCategoryLinks(String srctable,int srcrowid,String fname) 1752 throws SQLException 1753 { 1754 String where = "srctbl='"+srctable+"' AND srcrowid="+srcrowid+" and fname='"+fname+"'"; 1756 Owxcatlinks[] catlinksObj = catlinksMgr.loadByWhere(where); 1757 Vector ret=new Vector(); 1758 for(int i=0;i<catlinksObj.length;i++) 1759 { 1760 1761 ret.add(new Integer (catlinksObj[i].getCatid()) ); 1762 } 1763 1764 return ret; 1765 } 1766 1767 1768 1769 1771 1772 1773 1774 1778 public Hashtable loadFields(String srctable,int srcrowid) 1779 throws SQLException 1780 { 1781 String where = "srctbl='"+srctable+"' AND srcrowid="+srcrowid; 1782 Owxfields[] fieldsObj = fieldsMgr.loadByWhere(where); 1783 Hashtable ret=new Hashtable(); 1784 for(int i=0;i<fieldsObj.length;i++) 1785 { 1786 GResField grfield=new GResField(); 1787 grfield.setName(fieldsObj[i].getFname()); 1788 grfield.setNumberValue( new Double (fieldsObj[i].getNumberval()) ); 1789 1790 grfield.setTextValue(fieldsObj[i].getTextval()); 1791 grfield.setDateValue(fieldsObj[i].getDateval()); 1792 grfield.setFieldType(fieldsObj[i].getType()); 1793 ret.put(grfield.getName(),grfield ); 1794 } 1795 1796 return ret; 1797 } 1798 1799 1803 public Hashtable loadFieldValues(String srctable,int srcrowid) 1804 throws SQLException 1805 { 1806 String where = "srctbl='"+srctable+"' AND srcrowid="+srcrowid; 1807 Owxfields[] fieldsObj = fieldsMgr.loadByWhere(where); 1808 Hashtable ret=new Hashtable(); 1809 for(int i=0;i<fieldsObj.length;i++) 1810 { 1811 GResField grfield=new GResField(); 1812 grfield.setName(fieldsObj[i].getFname()); 1813 grfield.setNumberValue( new Double (fieldsObj[i].getNumberval()) ); 1814 grfield.setTextValue(fieldsObj[i].getTextval()); 1815 grfield.setDateValue(fieldsObj[i].getDateval()); 1816 grfield.setFieldType(fieldsObj[i].getType()); 1817 ret.put(grfield.getName(),grfield.getValue() ); 1818 } 1819 1820 return ret; 1821 } 1822 1823 1826 public void saveField(String srctable,int srcrowid,GResField field) 1827 throws SQLException 1828 { 1829 Owxfields saveField=null; 1830 String where = "srctbl='"+srctable+"' AND srcrowid="+srcrowid+" AND fname='"+field.getName()+"'"; 1831 Owxfields[] fieldsObj = fieldsMgr.loadByWhere(where); 1833 if(fieldsObj.length >0) saveField=fieldsObj[0]; 1834 else saveField=new Owxfields(); 1835 1836 saveField.setSrctbl(srctable); 1837 saveField.setSrcrowid(srcrowid); 1838 saveField.setFname(field.getName()); 1839 if(field.getFieldType()==Constants.FIELDTYPE_NUMBER) 1840 { 1841 if(field.getNumberValue()!=null) saveField.setNumberval(field.getNumberValue().doubleValue()); 1842 } 1843 else if(field.getFieldType()==Constants.FIELDTYPE_TEXT) 1844 { 1845 saveField.setTextval(field.getTextValue()); 1846 } 1847 else if(field.getFieldType()==Constants.FIELDTYPE_DATE) 1848 { 1849 saveField.setDateval(field.getDateValue()); 1850 } 1851 else if(field.getFieldType()==Constants.FIELDTYPE_PRICE) 1852 { 1853 if(field.getNumberValue()!=null) saveField.setNumberval(field.getNumberValue().doubleValue()); 1854 saveField.setTextval(field.getTextValue()); 1855 } 1856 saveField.setType(field.getFieldType()); 1857 fieldsMgr.save(saveField); 1858 } 1859 1860 1863 public void deleteFields(String srctable,int srcrowid) 1864 throws SQLException 1865 { 1866 1867 String where = "srctbl='"+srctable+"' AND srcrowid="+srcrowid; 1868 Owxfields[] fieldsObj = fieldsMgr.loadByWhere(where); 1869 for(int i=0;i<fieldsObj.length;i++) 1870 { 1871 int result = fieldsMgr.deleteByKey(fieldsObj[i].getRowid()); 1872 LoggingManager.log("Deleted field #" + fieldsObj[i].getRowid() + " for " + srctable + ", " + 1873 fieldsObj[i].getFname() + ", count " + result, this); 1874 } 1875 } 1876 1877 1878 1879 1883 public Hashtable loadLocalizedFields(String srctable,int srcrowid) 1884 throws SQLException 1885 { 1886 String where = "srctbl='"+srctable+"' AND srcrowid="+srcrowid; 1887 Owxmsgs[] msgs = msgsMgr.loadByWhere(where); 1888 Hashtable ret=new Hashtable(); 1889 PairOfObjects po=null; 1890 for(int i=0;i<msgs.length;i++) 1891 { 1892 GResLocalizedField grlfield=null; 1893 grlfield=(GResLocalizedField)ret.get(msgs[i].getFname()); 1894 if(grlfield==null) grlfield=new GResLocalizedField(); 1895 grlfield.setName( msgs[i].getFname() ); 1896 po = LocaleManager.stripLocaleString( msgs[i].getLocalekey() ); 1897 grlfield.setValue( msgs[i].getMsg(),new Locale((String ) po.getObjectOne(), (String ) po.getObjectTwo()) ); 1898 ret.put(grlfield.getName(),grlfield); 1899 1900 } 1901 1902 return ret; 1903 } 1904 1905 1906 1910 public Hashtable loadLocalizedFieldValues(String srctable,int srcrowid,Locale locale) 1911 throws SQLException 1912 { 1913 String where = "srctbl='"+srctable+"' AND srcrowid="+srcrowid+" AND localekey='"+locale.toString()+"'"; 1914 Owxmsgs[] msgs = msgsMgr.loadByWhere(where); 1915 Hashtable ret=new Hashtable(); 1916 PairOfObjects po=null; 1917 for(int i=0;i<msgs.length;i++) 1918 { 1919 GResLocalizedField grlfield=null; 1920 grlfield=(GResLocalizedField)ret.get(msgs[i].getFname()); 1921 if(grlfield==null) grlfield=new GResLocalizedField(); 1922 if(msgs[i].getMsg()==null) 1923 { 1924 ret.put( msgs[i].getFname(),""); 1925 } 1926 else 1927 { 1928 ret.put( msgs[i].getFname(),msgs[i].getMsg() ); 1929 } 1930 } 1932 return ret; 1933 } 1934 1935 1940 public Vector loadValuesFor(String srctable,String fieldname,String locale, boolean numeric) 1941 { 1942 Vector ret=new Vector(); 1943 Connection conn=null; 1944 Statement stmt=null; 1945 ResultSet rs=null; 1946 String sql = null; 1947 try 1948 { 1949 conn = ds.getConnection(); 1950 stmt = conn.createStatement(); 1951 1952 if(locale == null || locale.length() == 0 || numeric == true) 1958 { 1959 String fldtype = ((numeric == true) ? "numberval" : "textval"); 1960 sql = "select distinct " + fldtype + " from owxfields, " + srctable + " where srctbl=" + 1961 "'" + srctable + "' and owxfields.srcrowid=" + srctable + 1962 ".rowid and fname='" + fieldname + "' and flagVisible = true AND " + 1963 "(flagtimedpub = false OR (flagtimedpub = true AND " + 1964 "( (showfrom = null OR showfrom<=now()) AND " + 1965 "(showuntil = null OR showuntil > now()))) ) ;"; 1966 } 1967 else 1968 { 1969 sql = "select distinct msg from owxmsgs, " + srctable + " where srctbl=" + 1970 "'" + srctable + "' and owxmsgs.srcrowid=" + srctable + 1971 ".rowid and fname='" + fieldname + "' and localekey='" + locale + "' and " + 1972 " flagVisible = true AND (flagtimedpub = false OR " + 1973 "(flagtimedpub = true AND ( (showfrom = null OR " + 1974 "showfrom<=now()) AND (showuntil = null OR showuntil > " + 1975 "now()))) ) ;"; 1976 } 1977 1978 rs = stmt.executeQuery(sql); 1980 while(rs.next()) 1981 { 1982 String str = rs.getString(1); 1983 if(str != null) 1984 { 1985 ret.add(str); 1986 } 1988 } 1989 1990 rs.close(); 1991 stmt.close(); 1992 conn.close(); 1993 } 1994 catch(SQLException e) 1995 { 1996 if(rs != null) try { rs.close(); } catch(Exception e2) { } 1997 if(stmt !=null) try { stmt.close(); } catch(Exception e2) { } 1998 if(conn !=null) try { conn.close(); } catch(Exception e2) { } 1999 LoggingManager.log("Exception while loading combobox entries. " + 2000 "Query was " + sql + " ExceptionMessage: " + 2001 e.getMessage(), this); 2002 } 2003 return ret; 2004 } 2006 2009 public void saveLocalizedField(String srctable,int srcrowid,GResLocalizedField field) 2010 throws SQLException 2011 { 2012 Hashtable h=field.getValues(); 2013 Locale l=null; 2014 for(Enumeration e=h.keys();e.hasMoreElements();) 2015 { 2016 l=(Locale)e.nextElement(); 2017 saveMessage(srctable, srcrowid, field.getName(), l, (String )h.get(l)); 2018 } 2020 } 2021 2022 2025 public void deleteLocalizedFields(String srctable,int srcrowid) 2026 throws SQLException 2027 { 2028 deleteAllMessages(srctable,srcrowid); 2029 } 2030 2031 2032 public String loadField(String srctable, int srcrowid, String field, Locale locale) 2033 throws SQLException 2034 { 2035 String fieldVal=loadMessage(srctable, srcrowid,field,locale); 2037 if(fieldVal!=null) return fieldVal; 2038 2040 String where = "srctbl='"+srctable+"' AND srcrowid="+srcrowid+" AND fname='"+field+"'"; 2041 Owxfields[] fieldsObj = fieldsMgr.loadByWhere(where); 2042 2043 if(fieldsObj.length>0) 2044 { 2045 GResField grfield=new GResField(); 2046 grfield.setName(fieldsObj[0].getFname()); 2047 grfield.setNumberValue( new Double (fieldsObj[0].getNumberval()) ); 2048 grfield.setTextValue(fieldsObj[0].getTextval()); 2049 grfield.setDateValue(fieldsObj[0].getDateval()); 2050 grfield.setFieldType(fieldsObj[0].getType()); 2051 return grfield.getValue(); 2052 } 2054 return null; 2055 } 2057 2058} 2059 | Popular Tags |