1 2 12 package com.versant.core.jdbc.sql; 13 14 import java.util.HashMap ; 15 import java.util.HashSet ; 16 17 import com.versant.core.common.BindingSupportImpl; 18 19 24 public class DefaultJdbcNameGenerator implements JdbcNameGenerator { 25 26 protected String databaseType; 27 28 protected int maxTableNameLength = 18; 29 protected int maxColumnNameLength = 18; 30 protected int maxConstraintNameLength = 18; 31 protected int maxIndexNameLength = 18; 32 protected String pkSuffix = "_id"; 33 protected String pkConstraintPrefix = "pk_"; 34 protected String refConstraintPrefix = "ref_"; 35 protected String wordBreak = "_"; 36 protected String sequenceColumnName = "seq"; 37 protected String valueColumnName = "val"; 38 protected String keyColumnName = "mapkey"; 39 40 protected String classIdColumnName = "jdo_class"; 41 42 43 protected String polyRefClassIdSuffix = "_class"; 44 protected String indexNamePrefix = "idx_"; 45 46 private boolean nameCanStartWithUnderscore = true; 47 48 protected HashMap reservedWords = new HashMap (); 49 50 53 protected HashMap tableMap = new HashMap (); 54 57 protected HashSet constraintNames = new HashSet (); 58 61 protected HashSet indexNames = new HashSet (); 62 63 public DefaultJdbcNameGenerator() { 64 populateReservedWords(reservedWords); 65 } 66 67 71 public void setDatabaseType(String db) { 72 databaseType = db; 73 if (db.equals("daffodil")) { 74 reservedWords.put("connection", "connectn"); 75 reservedWords.put("recursive", "recursve"); 76 reservedWords.put("timestamp", "timestmp"); 77 reservedWords.put("interval", "intervl"); 78 reservedWords.put("email", "eml"); 79 reservedWords.put("action", "actn"); 80 } else if (db.equals("mckoi")) { 81 reservedWords.put("sequence", "seqnce"); 82 } else if (db.equals("mssql")) { 83 reservedWords.put("system_user", "sys_user"); 84 reservedWords.put("identity", "ident"); 85 } else if (db.equals("sapdb")) { 86 reservedWords.put("timestamp", "timestmp"); 87 } else if (db.equals("firebird") || db.equals("interbase")) { 88 reservedWords.put("position", "positn"); 89 reservedWords.put("admin", "admn"); 90 reservedWords.put("timestamp", "timestmp"); 91 reservedWords.put("action", "actn"); 92 } else if (db.equals("informix") || db.equals("informixse")) { 93 reservedWords.put("interval", "intervl"); 94 } else if (db.equals("mysql")) { 95 reservedWords.put("interval", "intervl"); 96 reservedWords.put("change", "chnge"); 97 reservedWords.put("keys", "kys"); 98 reservedWords.put("xor", "xr"); 99 } else if (db.equals("cache")) { 100 reservedWords.put("connection", "connectn"); 101 reservedWords.put("timestamp", "timestmp"); 102 reservedWords.put("interval", "intrval"); 103 reservedWords.put("action", "actn"); 104 } else if (db.equals("hypersonic")) { 105 reservedWords.put("position", "pos"); 106 } else if (db.equals("oracle")) { 107 nameCanStartWithUnderscore = false; 108 } 109 } 110 111 116 protected void populateReservedWords(HashMap rw) { 117 rw.put("abort", "abrt"); 118 rw.put("abs", "ab"); 119 rw.put("absolute", "abslute"); 120 rw.put("accept", "accpt"); 121 rw.put("acces", "accs"); 122 rw.put("access", "accss"); 123 rw.put("activate", "actvate"); 124 rw.put("add", "ad"); 125 rw.put("addform", "addfrm"); 126 rw.put("after", "aftr"); 127 rw.put("all", "al"); 128 rw.put("alter", "altr"); 129 rw.put("and", "nd"); 130 rw.put("andfilename", "andflename"); 131 rw.put("any", "ny"); 132 rw.put("anyfinish", "anyfnish"); 133 rw.put("append", "appnd"); 134 rw.put("archive", "archve"); 135 rw.put("array", "arry"); 136 rw.put("as", "asx"); 137 rw.put("asc", "sc"); 138 rw.put("ascending", "ascnding"); 139 rw.put("ascii", "asci"); 140 rw.put("assert", "assrt"); 141 rw.put("assign", "assgn"); 142 rw.put("at", "atx"); 143 rw.put("attribute", "attrbute"); 144 rw.put("attributes", "attrbutes"); 145 rw.put("audit", "audt"); 146 rw.put("authorization", "athorization"); 147 rw.put("autonext", "atonext"); 148 rw.put("average", "avrage"); 149 rw.put("avg", "av"); 150 rw.put("avgu", "avgup"); 151 rw.put("backout", "bckout"); 152 rw.put("before", "bfore"); 153 rw.put("begin", "bgin"); 154 rw.put("beginload", "bginload"); 155 rw.put("beginmodify", "bginmodify"); 156 rw.put("beginning", "bginning"); 157 rw.put("begwork", "bgwork"); 158 rw.put("between", "btween"); 159 rw.put("betweenby", "btweenby"); 160 rw.put("border", "brder"); 161 rw.put("bottom", "bttom"); 162 rw.put("break", "brak"); 163 rw.put("breakdisplay", "brakdisplay"); 164 rw.put("browse", "brwse"); 165 rw.put("bufered", "bfered"); 166 rw.put("buffer", "bffer"); 167 rw.put("buffered", "bffered"); 168 rw.put("bulk", "blk"); 169 rw.put("by", "byx"); 170 rw.put("byte", "byt"); 171 rw.put("call", "cll"); 172 rw.put("cancel", "cncel"); 173 rw.put("cascade", "cscade"); 174 rw.put("case", "cse"); 175 rw.put("change", "chnge"); 176 rw.put("char", "chr"); 177 rw.put("char_convert", "chr_convert"); 178 rw.put("character", "chracter"); 179 rw.put("check", "chck"); 180 rw.put("checkpoint", "chckpoint"); 181 rw.put("chr2fl", "chr2f"); 182 rw.put("chr2flo", "chr2flt"); 183 rw.put("chr2floa", "chr2fla"); 184 rw.put("chr2float", "chr2flat"); 185 rw.put("chr2int", "chr2nt"); 186 rw.put("clear", "clar"); 187 rw.put("clearrow", "clarrow"); 188 rw.put("clipped", "clpped"); 189 rw.put("close", "clse"); 190 rw.put("cluster", "clustr"); 191 rw.put("clustered", "clstered"); 192 rw.put("clustering", "clstering"); 193 rw.put("cobol", "cbol"); 194 rw.put("cold", "cld"); 195 rw.put("column", "colmn"); 196 rw.put("columns", "clumns"); 197 rw.put("command", "cmmand"); 198 rw.put("comment", "commnt"); 199 rw.put("commit", "cmmit"); 200 rw.put("committed", "cmmitted"); 201 rw.put("compress", "comprss"); 202 rw.put("compute", "cmpute"); 203 rw.put("concat", "cncat"); 204 rw.put("cond", "cnd"); 205 rw.put("config", "cnfig"); 206 rw.put("confirm", "cnfirm"); 207 rw.put("connect", "connct"); 208 rw.put("constraint", "cnstraint"); 209 rw.put("construct", "cnstruct"); 210 rw.put("contain", "cntain"); 211 rw.put("contains", "cntains"); 212 rw.put("continue", "cntinue"); 213 rw.put("controlrow", "cntrolrow"); 214 rw.put("convert", "cnvert"); 215 rw.put("copy", "cpy"); 216 rw.put("count", "cnt"); 217 rw.put("countu", "cntu"); 218 rw.put("countucreate", "cuntucreate"); 219 rw.put("crash", "crsh"); 220 rw.put("create", "creat"); 221 rw.put("current", "currnt"); 222 rw.put("cursor", "crsor"); 223 rw.put("data", "dta"); 224 rw.put("data_pgs", "dta_pgs"); 225 rw.put("database", "dtabase"); 226 rw.put("datapages", "dtapages"); 227 rw.put("date", "dte"); 228 rw.put("day", "dy"); 229 rw.put("daynum", "dynum"); 230 rw.put("dba", "dbax"); 231 rw.put("dbcc", "dbc"); 232 rw.put("dbe", "dbex"); 233 rw.put("dbefile", "dbfile"); 234 rw.put("dbefileo", "dbfileo"); 235 rw.put("dbefileset", "dbfileset"); 236 rw.put("dbspace", "dbspce"); 237 rw.put("dbyte", "dbyt"); 238 rw.put("dec", "dc"); 239 rw.put("decending", "dcending"); 240 rw.put("decimal", "deciml"); 241 rw.put("declare", "dclare"); 242 rw.put("default", "deflt"); 243 rw.put("defaults", "dfaults"); 244 rw.put("defer", "dfer"); 245 rw.put("define", "dfine"); 246 rw.put("definition", "dfinition"); 247 rw.put("delete", "delte"); 248 rw.put("deleterow", "dleterow"); 249 rw.put("desc", "dsc"); 250 rw.put("descending", "dscending"); 251 rw.put("descendng", "dscendng"); 252 rw.put("describe", "dscribe"); 253 rw.put("descriptor", "dscriptor"); 254 rw.put("destpos", "dstpos"); 255 rw.put("destroy", "dstroy"); 256 rw.put("device", "dvice"); 257 rw.put("devspace", "dvspace"); 258 rw.put("direct", "drect"); 259 rw.put("dirty", "drty"); 260 rw.put("disconnect", "dsconnect"); 261 rw.put("disk", "dsk"); 262 rw.put("displace", "dsplace"); 263 rw.put("display", "dsplay"); 264 rw.put("distinct", "distnct"); 265 rw.put("distribution", "dstribution"); 266 rw.put("div", "dv"); 267 rw.put("do", "d"); 268 rw.put("does", "des"); 269 rw.put("domain", "dmain"); 270 rw.put("double", "duble"); 271 rw.put("down", "dwn"); 272 rw.put("drop", "drp"); 273 rw.put("dual", "dal"); 274 rw.put("dummy", "dmmy"); 275 rw.put("dump", "dmp"); 276 rw.put("duplicates", "dplicates"); 277 rw.put("each", "ech"); 278 rw.put("ebcdic", "ebcdc"); 279 rw.put("ed_string", "ed_strng"); 280 rw.put("editadd", "edtadd"); 281 rw.put("editupdate", "edtupdate"); 282 rw.put("else", "els"); 283 rw.put("elseif", "elsif"); 284 rw.put("end", "en"); 285 rw.put("end_error", "end_rror"); 286 rw.put("end_fetch", "end_ftch"); 287 rw.put("end_for", "end_fr"); 288 rw.put("end_get", "end_gt"); 289 rw.put("end_modify", "end_mdify"); 290 rw.put("end_place", "end_plce"); 291 rw.put("end_segment_s", "end_sgment_s"); 292 rw.put("end_segment_string", "end_sgment_string"); 293 rw.put("end_store", "end_stre"); 294 rw.put("end_stream", "end_stram"); 295 rw.put("enddata", "enddta"); 296 rw.put("enddisplay", "enddsplay"); 297 rw.put("endforms", "endfrms"); 298 rw.put("endif", "endf"); 299 rw.put("ending", "endng"); 300 rw.put("endload", "endlad"); 301 rw.put("endloop", "endlop"); 302 rw.put("endmodify", "endmdify"); 303 rw.put("endpos", "endps"); 304 rw.put("endretrieve", "endrtrieve"); 305 rw.put("endselect", "endslect"); 306 rw.put("endwhile", "endwhle"); 307 rw.put("eq", "e"); 308 rw.put("erase", "erse"); 309 rw.put("errlvl", "errlv"); 310 rw.put("error", "errr"); 311 rw.put("errorexit", "errrexit"); 312 rw.put("evaluate", "evluate"); 313 rw.put("evaluating", "evluating"); 314 rw.put("every", "evry"); 315 rw.put("except", "excpt"); 316 rw.put("exclusive", "exclusve"); 317 rw.put("exec", "exc"); 318 rw.put("execute", "excute"); 319 rw.put("exists", "exsts"); 320 rw.put("exit", "ext"); 321 rw.put("explicit", "explcit"); 322 rw.put("extent", "extnt"); 323 rw.put("external", "extrnal"); 324 rw.put("false", "flse"); 325 rw.put("fetch", "ftch"); 326 rw.put("field", "feld"); 327 rw.put("file", "fle"); 328 rw.put("filename", "flename"); 329 rw.put("fillfactor", "fllfactor"); 330 rw.put("finalise", "fnalise"); 331 rw.put("finalize", "fnalize"); 332 rw.put("findstr", "fndstr"); 333 rw.put("finish", "fnish"); 334 rw.put("first", "frst"); 335 rw.put("firstpos", "frstpos"); 336 rw.put("fixed", "fxed"); 337 rw.put("fl", "flx"); 338 rw.put("float", "flt"); 339 rw.put("flush", "flsh"); 340 rw.put("for", "fr"); 341 rw.put("foreach", "freach"); 342 rw.put("format", "frmat"); 343 rw.put("formdata", "frmdata"); 344 rw.put("forminit", "frminit"); 345 rw.put("forms", "frms"); 346 rw.put("fortran", "frtran"); 347 rw.put("found", "foundx"); 348 rw.put("frant", "frnt"); 349 rw.put("fraphic", "frphic"); 350 rw.put("free", "fre"); 351 rw.put("from", "frm"); 352 rw.put("frs", "frss"); 353 rw.put("function", "fnction"); 354 rw.put("get", "gett"); 355 rw.put("getform", "gtform"); 356 rw.put("getoper", "gtoper"); 357 rw.put("getrow", "gtrow"); 358 rw.put("global", "glbal"); 359 rw.put("globals", "glbals"); 360 rw.put("go", "gox"); 361 rw.put("goto", "gotox"); 362 rw.put("grant", "grnt"); 363 rw.put("graphic", "grphic"); 364 rw.put("group", "grp"); 365 rw.put("gt", "gtx"); 366 rw.put("having", "havng"); 367 rw.put("header", "hader"); 368 rw.put("help", "hlp"); 369 rw.put("help_frs", "hlp_frs"); 370 rw.put("helpfile", "hlpfile"); 371 rw.put("hold", "hld"); 372 rw.put("holdlock", "hldlock"); 373 rw.put("identified", "identifd"); 374 rw.put("identifield", "idntifield"); 375 rw.put("if", "ifx"); 376 rw.put("ifdef", "ifdf"); 377 rw.put("ignore", "ignre"); 378 rw.put("image", "imge"); 379 rw.put("immediate", "immediat"); 380 rw.put("immidiate", "immidiat"); 381 rw.put("implicit", "implcit"); 382 rw.put("in", "inx"); 383 rw.put("include", "inclde"); 384 rw.put("increment", "incremnt"); 385 rw.put("index", "indx"); 386 rw.put("indexed", "indxed"); 387 rw.put("indexname", "indxname"); 388 rw.put("indexpages", "indxpages"); 389 rw.put("indicator", "indcator"); 390 rw.put("infield", "infeld"); 391 rw.put("info", "inf"); 392 rw.put("ingres", "ingrs"); 393 rw.put("init", "initt"); 394 rw.put("initial", "initl"); 395 rw.put("initialise", "intialise"); 396 rw.put("initialize", "intialize"); 397 rw.put("inittable", "inttable"); 398 rw.put("input", "inpt"); 399 rw.put("inquir_frs", "inqir_frs"); 400 rw.put("inquire_equel", "inqire_equel"); 401 rw.put("inquire_frs", "inqire_frs"); 402 rw.put("inquire_ingres", "inqire_ingres"); 403 rw.put("insert", "insrt"); 404 rw.put("insertrow", "insrtrow"); 405 rw.put("instructions", "instrctions"); 406 rw.put("int", "inte"); 407 rw.put("int2chr", "int2ch"); 408 rw.put("integer", "integr"); 409 rw.put("integrity", "intgrity"); 410 rw.put("interesect", "intresect"); 411 rw.put("interrupt", "intrrupt"); 412 rw.put("intersect", "intersct"); 413 rw.put("into", "intox"); 414 rw.put("intschr", "intsch"); 415 rw.put("invoke", "invke"); 416 rw.put("is", "isx"); 417 rw.put("isam", "ism"); 418 rw.put("isolation", "islation"); 419 rw.put("journaling", "jurnaling"); 420 rw.put("key", "ky"); 421 rw.put("kill", "kll"); 422 rw.put("label", "lbel"); 423 rw.put("language", "lnguage"); 424 rw.put("last", "lastx"); 425 rw.put("lastpos", "lstpos"); 426 rw.put("le", "lex"); 427 rw.put("left", "lft"); 428 rw.put("length", "lngth"); 429 rw.put("lenstr", "lnstr"); 430 rw.put("let", "lett"); 431 rw.put("level", "lvl"); 432 rw.put("like", "lke"); 433 rw.put("likeproceduretp", "lkeproceduretp"); 434 rw.put("line", "lne"); 435 rw.put("lineno", "lneno"); 436 rw.put("lines", "lnes"); 437 rw.put("link", "lnk"); 438 rw.put("list", "lst"); 439 rw.put("load", "ld"); 440 rw.put("loadtable", "ldtable"); 441 rw.put("loadtableresume", "ldtableresume"); 442 rw.put("local", "lcal"); 443 rw.put("location", "lcation"); 444 rw.put("lock", "lck"); 445 rw.put("locking", "lcking"); 446 rw.put("log", "lg"); 447 rw.put("long", "lng"); 448 rw.put("lower", "lwer"); 449 rw.put("lpad", "lpd"); 450 rw.put("lt", "ltx"); 451 rw.put("main", "mainx"); 452 rw.put("manual", "mnual"); 453 rw.put("manuitem", "manitem"); 454 rw.put("margin", "mrgin"); 455 rw.put("matches", "mtches"); 456 rw.put("matching", "mtching"); 457 rw.put("max", "mx"); 458 rw.put("maxextents", "maxextnts"); 459 rw.put("maxpublicunion", "mxpublicunion"); 460 rw.put("maxreclen", "mxreclen"); 461 rw.put("mdy", "mdyy"); 462 rw.put("menu", "mnu"); 463 rw.put("menuitem", "mnuitem"); 464 rw.put("menuitemscreen", "mnuitemscreen"); 465 rw.put("message", "msg"); 466 rw.put("messagerelocate", "msgrelocate"); 467 rw.put("messagescroll", "msgscroll"); 468 rw.put("mfetch", "mftch"); 469 rw.put("min", "minx"); 470 rw.put("minreclen", "mnreclen"); 471 rw.put("minreturnuntil", "mnreturnuntil"); 472 rw.put("minus", "mnus"); 473 rw.put("mirrorexit", "mrrorexit"); 474 rw.put("missing", "mssing"); 475 rw.put("mixed", "mxed"); 476 rw.put("mlslabel", "mlslabl"); 477 rw.put("mod", "modd"); 478 rw.put("mode", "mde"); 479 rw.put("modify", "modfy"); 480 rw.put("modifyrevokeupdat", "mdifyrevokeupdat"); 481 rw.put("module", "mdule"); 482 rw.put("money", "mney"); 483 rw.put("monitor", "mnitor"); 484 rw.put("month", "mnth"); 485 rw.put("move", "mve"); 486 rw.put("multi", "mlti"); 487 rw.put("name", "nme"); 488 rw.put("ne", "nex"); 489 rw.put("need", "ned"); 490 rw.put("new", "nw"); 491 rw.put("newlog", "nwlog"); 492 rw.put("next", "nxt"); 493 rw.put("nextscrolldown", "nxtscrolldown"); 494 rw.put("no", "nox"); 495 rw.put("noaudit", "noaudt"); 496 rw.put("nocompress", "nocomprss"); 497 rw.put("nocr", "ncr"); 498 rw.put("nojournaling", "njournaling"); 499 rw.put("nolist", "nlist"); 500 rw.put("nolog", "nlog"); 501 rw.put("nonclustered", "nnclustered"); 502 rw.put("normal", "nrmal"); 503 rw.put("nosyssort", "nsyssort"); 504 rw.put("not", "nt"); 505 rw.put("notffound", "ntffound"); 506 rw.put("notfound", "ntfound"); 507 rw.put("notrans", "ntrans"); 508 rw.put("notrim", "ntrim"); 509 rw.put("notrimscrollup", "ntrimscrollup"); 510 rw.put("notrollbackuser", "ntrollbackuser"); 511 rw.put("nowait", "nowt"); 512 rw.put("null", "nll"); 513 rw.put("nullify", "nllify"); 514 rw.put("nullsaveusing", "nllsaveusing"); 515 rw.put("nullval", "nllval"); 516 rw.put("num", "numbr"); 517 rw.put("number", "numbr"); 518 rw.put("numeric", "numerc"); 519 rw.put("nxfield", "nxfeld"); 520 rw.put("of", "ofx"); 521 rw.put("off", "offx"); 522 rw.put("offline", "offln"); 523 rw.put("offsets", "offsts"); 524 rw.put("ofsavepointvalues", "ofsvepointvalues"); 525 rw.put("old", "oldd"); 526 rw.put("on", "onx"); 527 rw.put("once", "onc"); 528 rw.put("online", "onln"); 529 rw.put("onselectwhere", "onslectwhere"); 530 rw.put("onto", "ont"); 531 rw.put("open", "opn"); 532 rw.put("opensetwhile", "opnsetwhile"); 533 rw.put("opensleep", "opnsleep"); 534 rw.put("optimize", "optmize"); 535 rw.put("option", "optn"); 536 rw.put("options", "optons"); 537 rw.put("or", "orx"); 538 rw.put("order", "ordr"); 539 rw.put("ordersqlwork", "ordrsqlwork"); 540 rw.put("orsomewith", "orsmewith"); 541 rw.put("orsort", "orsrt"); 542 rw.put("otherwise", "othrwise"); 543 rw.put("out", "ot"); 544 rw.put("outer", "outerx"); 545 rw.put("output", "outputx"); 546 rw.put("output page", "otput page"); 547 rw.put("outstop", "otstop"); 548 rw.put("over", "ovr"); 549 rw.put("owner", "ownr"); 550 rw.put("ownership", "ownrship"); 551 rw.put("page", "pge"); 552 rw.put("pageno", "pgeno"); 553 rw.put("pages", "pges"); 554 rw.put("param", "parm"); 555 rw.put("partition", "prtition"); 556 rw.put("pascal", "pscal"); 557 rw.put("password", "passwd"); 558 rw.put("pathname", "pthname"); 559 rw.put("pattern", "pttern"); 560 rw.put("pause", "puse"); 561 rw.put("pctfree", "pctfr"); 562 rw.put("percent", "prcent"); 563 rw.put("perm", "prm"); 564 rw.put("permanent", "prmanent"); 565 rw.put("permit", "prmit"); 566 rw.put("permitsum", "prmitsum"); 567 rw.put("pipe", "ppe"); 568 rw.put("place", "plce"); 569 rw.put("plan", "pln"); 570 rw.put("pli", "pl"); 571 rw.put("pos", "ps"); 572 rw.put("power", "pwer"); 573 rw.put("precision", "prcision"); 574 rw.put("prepare", "prpare"); 575 rw.put("preparetable", "prparetable"); 576 rw.put("preserve", "prserve"); 577 rw.put("prev", "prv"); 578 rw.put("previous", "prvious"); 579 rw.put("prevision", "prvision"); 580 rw.put("print", "prnt"); 581 rw.put("printer", "prnter"); 582 rw.put("printscreen", "prntscreen"); 583 rw.put("printscreenscroll", "prntscreenscroll"); 584 rw.put("printsubmenu", "prntsubmenu"); 585 rw.put("printsumu", "prntsumu"); 586 rw.put("prior", "prr"); 587 rw.put("priv", "privx"); 588 rw.put("private", "prvate"); 589 rw.put("privilages", "prvilages"); 590 rw.put("privilagesthen", "prvilagesthen"); 591 rw.put("privileges", "privilgs"); 592 rw.put("proc", "prc"); 593 rw.put("procedure", "prcedure"); 594 rw.put("processexit", "prcessexit"); 595 rw.put("program", "prgram"); 596 rw.put("progusage", "prgusage"); 597 rw.put("prompt", "prmpt"); 598 rw.put("promptscrolldown", "prmptscrolldown"); 599 rw.put("prompttabledata", "prmpttabledata"); 600 rw.put("protect", "prtect"); 601 rw.put("psect", "psct"); 602 rw.put("public", "publc"); 603 rw.put("publicread", "pblicread"); 604 rw.put("put", "pt"); 605 rw.put("putform", "ptform"); 606 rw.put("putformscrollup", "ptformscrollup"); 607 rw.put("putformunloadtab", "ptformunloadtab"); 608 rw.put("putoper", "ptoper"); 609 rw.put("putopersleep", "ptopersleep"); 610 rw.put("putrow", "ptrow"); 611 rw.put("putrowsubmenu", "ptrowsubmenu"); 612 rw.put("putrowup", "ptrowup"); 613 rw.put("query", "qery"); 614 rw.put("quick", "qick"); 615 rw.put("quit", "qit"); 616 rw.put("raiserror", "riserror"); 617 rw.put("range", "rnge"); 618 rw.put("rangeto", "rngeto"); 619 rw.put("raw", "rawx"); 620 rw.put("rdb$db_key", "rdb$db_ky"); 621 rw.put("rdb$length", "rdb$lngth"); 622 rw.put("rdb$missing", "rdb$mssing"); 623 rw.put("rdb$value", "rdb$vlue"); 624 rw.put("rdb4db_key", "rdb4db_ky"); 625 rw.put("rdb4length", "rdb4lngth"); 626 rw.put("rdb4missing", "rdb4mssing"); 627 rw.put("rdb4value", "rdb4vlue"); 628 rw.put("read", "rad"); 629 rw.put("read_only", "rd_only"); 630 rw.put("read_write", "rd_write"); 631 rw.put("readonly", "rdonly"); 632 rw.put("readpass", "rdpass"); 633 rw.put("readtext", "rdtext"); 634 rw.put("readwrite", "rdwrite"); 635 rw.put("ready", "rdy"); 636 rw.put("real", "rl"); 637 rw.put("reconfigure", "rconfigure"); 638 rw.put("reconnect", "rconnect"); 639 rw.put("record", "rcord"); 640 rw.put("recover", "rcover"); 641 rw.put("redisplay", "rdisplay"); 642 rw.put("redisplaytabledata", "rdisplaytabledata"); 643 rw.put("redisplayvalidate", "rdisplayvalidate"); 644 rw.put("reduced", "rduced"); 645 rw.put("register", "rgister"); 646 rw.put("registerunloaddata", "rgisterunloaddata"); 647 rw.put("registervalidrow", "rgistervalidrow"); 648 rw.put("reject", "rject"); 649 rw.put("relative", "rlative"); 650 rw.put("release", "rlease"); 651 rw.put("reload", "rload"); 652 rw.put("relocate", "rlocate"); 653 rw.put("relocateunique", "rlocateunique"); 654 rw.put("remove", "rmove"); 655 rw.put("removeuprelocatev", "rmoveuprelocatev"); 656 rw.put("removevalidate", "rmovevalidate"); 657 rw.put("removewhenever", "rmovewhenever"); 658 rw.put("rename", "renme"); 659 rw.put("repeat", "rpeat"); 660 rw.put("repeatable", "rpeatable"); 661 rw.put("repeated", "rpeated"); 662 rw.put("repeatvalidrow", "rpeatvalidrow"); 663 rw.put("replace", "rplace"); 664 rw.put("replaceuntil", "rplaceuntil"); 665 rw.put("replstr", "rplstr"); 666 rw.put("report", "rport"); 667 rw.put("request_handle", "rquest_handle"); 668 rw.put("reserved_pgs", "rserved_pgs"); 669 rw.put("reserving", "rserving"); 670 rw.put("reset", "rset"); 671 rw.put("resource", "resrce"); 672 rw.put("rest", "rst"); 673 rw.put("restart", "rstart"); 674 rw.put("restore", "rstore"); 675 rw.put("restrict", "rstrict"); 676 rw.put("resume", "rsume"); 677 rw.put("retrieve", "rtrieve"); 678 rw.put("retrieveupdate", "rtrieveupdate"); 679 rw.put("return", "rturn"); 680 rw.put("returning", "rturning"); 681 rw.put("revoke", "revke"); 682 rw.put("right", "rght"); 683 rw.put("role", "rle"); 684 rw.put("rollback", "rllback"); 685 rw.put("rollforward", "rllforward"); 686 rw.put("rololback", "rlolback"); 687 rw.put("round", "rund"); 688 rw.put("row", "rowx"); 689 rw.put("rowcnt", "rwcnt"); 690 rw.put("rowcount", "rwcount"); 691 rw.put("rowid", "rwid"); 692 rw.put("rownum", "rwnum"); 693 rw.put("rows", "rws"); 694 rw.put("rpad", "rpd"); 695 rw.put("rule", "rle"); 696 rw.put("run", "rn"); 697 rw.put("runtime", "rntime"); 698 rw.put("samplstdev", "smplstdev"); 699 rw.put("save", "sve"); 700 rw.put("savepoint", "svepoint"); 701 rw.put("savepointwhere", "svepointwhere"); 702 rw.put("saveview", "sveview"); 703 rw.put("schema", "schma"); 704 rw.put("scope", "scpe"); 705 rw.put("screen", "scren"); 706 rw.put("scroll", "scrll"); 707 rw.put("scrolldown", "scrlldown"); 708 rw.put("scrollup", "scrllup"); 709 rw.put("search", "sarch"); 710 rw.put("segment", "sgment"); 711 rw.put("sel", "sl"); 712 rw.put("sele", "sle"); 713 rw.put("selec", "slec"); 714 rw.put("select", "selct"); 715 rw.put("selupd", "slupd"); 716 rw.put("serial", "srial"); 717 rw.put("session", "sessn"); 718 rw.put("set", "st"); 719 rw.put("set_equel", "st_equel"); 720 rw.put("set_frs", "st_frs"); 721 rw.put("set_ingres", "st_ingres"); 722 rw.put("setuser", "stuser"); 723 rw.put("setwith", "stwith"); 724 rw.put("share", "shre"); 725 rw.put("shared", "shred"); 726 rw.put("short", "shrt"); 727 rw.put("show", "shw"); 728 rw.put("shutdown", "shtdown"); 729 rw.put("size", "sze"); 730 rw.put("skip", "skp"); 731 rw.put("sleep", "slep"); 732 rw.put("smallfloat", "smllfloat"); 733 rw.put("smallint", "smallnt"); 734 rw.put("some", "sme"); 735 rw.put("sort", "srt"); 736 rw.put("sorterd", "srterd"); 737 rw.put("sounds", "sunds"); 738 rw.put("sourcepos", "surcepos"); 739 rw.put("space", "spce"); 740 rw.put("spaces", "spces"); 741 rw.put("sql", "sq"); 742 rw.put("sqlcode", "sqlcde"); 743 rw.put("sqlda", "sqld"); 744 rw.put("sqlerror", "sqlrror"); 745 rw.put("sqlexeption", "sqlxeption"); 746 rw.put("sqlexplain", "sqlxplain"); 747 rw.put("sqlnotfound", "sqlntfound"); 748 rw.put("sqrt", "sqr"); 749 rw.put("stability", "stbility"); 750 rw.put("start", "strt"); 751 rw.put("start_segment", "strt_segment"); 752 rw.put("start_segmented_?", "strt_segmented"); 753 rw.put("start_stream", "strt_stream"); 754 rw.put("start_transaction", "strt_transaction"); 755 rw.put("starting", "strting"); 756 rw.put("startpos", "strtpos"); 757 rw.put("state", "stte"); 758 rw.put("statistics", "sttistics"); 759 rw.put("stdev", "stdv"); 760 rw.put("step", "stepx"); 761 rw.put("stop", "stopx"); 762 rw.put("store", "stre"); 763 rw.put("string", "strng"); 764 rw.put("submenu", "sbmenu"); 765 rw.put("substr", "sbstr"); 766 rw.put("succesfull", "sccesfull"); 767 rw.put("successful", "successfl"); 768 rw.put("successfull", "sccessfull"); 769 rw.put("sum", "sm"); 770 rw.put("sumu", "smu"); 771 rw.put("superdba", "sperdba"); 772 rw.put("syb_terminate", "syb_trminate"); 773 rw.put("synonym", "synonm"); 774 rw.put("sysdate", "sysdte"); 775 rw.put("syssort", "syssrt"); 776 rw.put("table", "tble"); 777 rw.put("tabledata", "tbledata"); 778 rw.put("temp", "tmp"); 779 rw.put("temporary", "tmporary"); 780 rw.put("terminate", "trminate"); 781 rw.put("text", "txt"); 782 rw.put("textsize", "txtsize"); 783 rw.put("then", "thn"); 784 rw.put("through", "thrugh"); 785 rw.put("thru", "thr"); 786 rw.put("tid", "td"); 787 rw.put("time", "tme"); 788 rw.put("to", "tox"); 789 rw.put("today", "tday"); 790 rw.put("tolower", "tlower"); 791 rw.put("top", "topp"); 792 rw.put("total", "ttal"); 793 rw.put("toupper", "tupper"); 794 rw.put("tp", "tpx"); 795 rw.put("trailer", "triler"); 796 rw.put("tran", "trn"); 797 rw.put("trans", "trns"); 798 rw.put("transaction", "trnsaction"); 799 rw.put("transaction_handle", "trnsaction_handle"); 800 rw.put("transfer", "trnsfer"); 801 rw.put("trigger", "triggr"); 802 rw.put("tring", "trng"); 803 rw.put("true", "tre"); 804 rw.put("trunc", "trnc"); 805 rw.put("truncate", "trncate"); 806 rw.put("tsequal", "tsqual"); 807 rw.put("type", "typ"); 808 rw.put("uid", "uidx"); 809 rw.put("unbuffered", "unbffered"); 810 rw.put("union", "unn"); 811 rw.put("unique", "unque"); 812 rw.put("unload", "unlad"); 813 rw.put("unloaddata", "unladdata"); 814 rw.put("unloadtable", "unladtable"); 815 rw.put("unlock", "unlck"); 816 rw.put("until", "untl"); 817 rw.put("up", "u"); 818 rw.put("update", "updte"); 819 rw.put("upper", "uppr"); 820 rw.put("usage", "usge"); 821 rw.put("use", "us"); 822 rw.put("used_pgs", "usd_pgs"); 823 rw.put("user", "usr"); 824 rw.put("using", "usng"); 825 rw.put("validate", "validte"); 826 rw.put("validrow", "vlidrow"); 827 rw.put("value", "val"); 828 rw.put("values", "vals"); 829 rw.put("varc", "vrc"); 830 rw.put("varch", "vrch"); 831 rw.put("varcha", "vrcha"); 832 rw.put("varchar", "varchr"); 833 rw.put("varchar2", "varch2r"); 834 rw.put("vargraphic", "vrgraphic"); 835 rw.put("verb_time", "vrb_time"); 836 rw.put("verify", "vrify"); 837 rw.put("version", "vrsion"); 838 rw.put("view", "vw"); 839 rw.put("wait", "wit"); 840 rw.put("waitfor", "witfor"); 841 rw.put("waiting", "witing"); 842 rw.put("warning", "wrning"); 843 rw.put("weekday", "wekday"); 844 rw.put("when", "whn"); 845 rw.put("whenever", "whenevr"); 846 rw.put("where", "whre"); 847 rw.put("while", "whle"); 848 rw.put("window", "wndow"); 849 rw.put("with", "wth"); 850 rw.put("without", "wthout"); 851 rw.put("work", "wrk"); 852 rw.put("wrap", "wrp"); 853 rw.put("write", "wrte"); 854 rw.put("writepass", "wrtepass"); 855 rw.put("writetext", "wrtetext"); 856 rw.put("year", "yr"); 857 } 858 859 public int getMaxTableNameLength() { 860 return maxTableNameLength; 861 } 862 863 866 public void setMaxTableNameLength(int maxTableNameLength) { 867 this.maxTableNameLength = maxTableNameLength; 868 } 869 870 public int getMaxColumnNameLength() { 871 return maxColumnNameLength; 872 } 873 874 877 public void setMaxColumnNameLength(int maxColumnNameLength) { 878 this.maxColumnNameLength = maxColumnNameLength; 879 } 880 881 public String getPkSuffix() { 882 return pkSuffix; 883 } 884 885 888 public void setMaxConstraintNameLength(int maxConstraintNameLength) { 889 this.maxConstraintNameLength = maxConstraintNameLength; 890 } 891 892 public int getMaxConstraintNameLength() { 893 return maxConstraintNameLength; 894 } 895 896 899 public void setMaxIndexNameLength(int maxIndexNameLength) { 900 this.maxIndexNameLength = maxIndexNameLength; 901 } 902 903 public int getMaxIndexNameLength() { 904 return maxIndexNameLength; 905 } 906 907 912 public void setPkSuffix(String pkSuffix) { 913 this.pkSuffix = pkSuffix; 914 } 915 916 public String getPkConstraintPrefix() { 917 return pkConstraintPrefix; 918 } 919 920 924 public void setPkConstraintPrefix(String pkConstraintPrefix) { 925 this.pkConstraintPrefix = pkConstraintPrefix; 926 } 927 928 932 public void setWordBreak(String wordBreak) { 933 this.wordBreak = wordBreak; 934 } 935 936 public String getWordBreak() { 937 return wordBreak; 938 } 939 940 945 public void setSequenceColumnName(String sequenceColumnName) { 946 this.sequenceColumnName = sequenceColumnName; 947 } 948 949 public String getSequenceColumnName() { 950 return sequenceColumnName; 951 } 952 953 957 public void setValueColumnName(String valueColumnName) { 958 this.valueColumnName = valueColumnName; 959 } 960 961 public String getValueColumnName() { 962 return valueColumnName; 963 } 964 965 969 public void setKeyColumnName(String keyColumnName) { 970 this.keyColumnName = keyColumnName; 971 } 972 973 public String getKeyColumnName() { 974 return keyColumnName; 975 } 976 977 981 public void setClassIdColumnName(String classIdColumnName) { 982 this.classIdColumnName = classIdColumnName; 983 } 984 985 public String getClassIdColumnName() { 986 return classIdColumnName; 987 } 988 989 public String getIndexNamePrefix() { 990 return indexNamePrefix; 991 } 992 993 996 public void setIndexNamePrefix(String indexNamePrefix) { 997 this.indexNamePrefix = indexNamePrefix; 998 } 999 1000 1007 protected String getJdbcName(String name) { 1008 int n = name.length(); 1009 StringBuffer ans = new StringBuffer (n + 4); 1010 int i = 0; 1011 for (; i < n && name.charAt(i) == '_'; i++) ; 1012 for (; i < n; i++) { 1013 char c = name.charAt(i); 1014 if (Character.isUpperCase(c)) { 1015 c = Character.toLowerCase(c); 1016 if (i > 0) ans.append(wordBreak); 1017 } 1018 if (c == '/') { 1019 ans.append(wordBreak); 1020 } else if (c != '$' && c != '.') { 1021 ans.append(c); 1022 } 1023 } 1024 name = ans.toString(); 1025 String rep = (String )reservedWords.get(name); 1026 if (rep != null) name = rep; 1027 return name; 1028 } 1029 1030 1035 protected String shrinkName(String name, int maxlen) { 1036 if (!nameCanStartWithUnderscore){ 1037 int n = name.length(); 1038 int j = 0; 1039 for (; j < n && name.charAt(j) == '_'; j++); 1040 name = name.substring(j,n); 1041 } 1042 int len = name.length(); 1043 if (len <= maxlen) return name; 1044 int todo = len - maxlen; 1045 StringBuffer s = new StringBuffer (); 1046 s.append(name.charAt(0)); 1047 int i; 1048 for (i = 1; todo > 0 && i < len;) { 1049 char c = name.charAt(i++); 1050 if (c == 'e' || c == 'a' || c == 'i' || c == 'o' || c == 'u') { 1051 --todo; 1052 } else { 1053 s.append(c); 1054 } 1055 } 1056 if (todo == 0) { 1057 s.append(name.substring(i)); 1058 } 1059 if (s.length() > maxlen) s.setLength(maxlen); 1060 return s.toString(); 1061 } 1062 1063 1068 protected String appendInt(String name, int i, int maxLen) { 1069 String is = Integer.toString(i); 1070 int cut = name.length() + is.length() - maxLen; 1071 if (cut > 0) { 1072 int len = maxLen - cut; 1073 if (len < 1) len = 1; 1074 return name.substring(0, len) + is; 1075 } else { 1076 return name + is; 1077 } 1078 } 1079 1080 1087 public void addTableName(String name) throws IllegalArgumentException { 1088 if (tableMap.containsKey(name)) { 1089 throw BindingSupportImpl.getInstance().illegalArgument("Duplicate table name '" + 1090 name + "'"); 1091 } 1092 tableMap.put(name, new HashSet ()); 1093 } 1094 1095 1098 public void removeTableName(String name) { 1099 tableMap.remove(name); 1100 } 1101 1102 1108 public String generateClassTableName(String className) { 1109 int dot = className.lastIndexOf('.'); 1110 if (dot >= 0) className = className.substring(dot + 1); 1111 1112 1113 1114 String name = shrinkName(getJdbcName(className), maxTableNameLength); 1115 String n = name; 1116 for (int i = 2; tableMap.containsKey(n); i++) { 1117 n = appendInt(name, i, maxTableNameLength); 1118 } 1119 addTableName(n); 1120 return n; 1121 } 1122 1123 1133 public String generateLinkTableName(String tableName, String fieldName, 1134 String elementTableName) { 1135 String name; 1136 if (elementTableName == null) { 1137 name = tableName + wordBreak + getJdbcName(fieldName); 1138 } else { 1139 name = tableName + wordBreak + elementTableName; 1140 } 1141 name = shrinkName(name, maxTableNameLength); 1142 String n = name; 1143 for (int i = 2; tableMap.containsKey(n); i++) { 1144 n = appendInt(name, i, maxTableNameLength); 1145 } 1146 addTableName(n); 1147 return n; 1148 } 1149 1150 1155 public void addPkConstraintName(String tableName, String pkConstraintName) 1156 throws IllegalArgumentException { 1157 if (constraintNames.contains(pkConstraintName)) { 1158 throw BindingSupportImpl.getInstance().illegalArgument("Duplicate constraint name: " + 1159 pkConstraintName); 1160 } 1161 constraintNames.add(pkConstraintName); 1162 } 1163 1164 1167 public String generatePkConstraintName(String tableName) { 1168 int maxlen = maxConstraintNameLength - pkConstraintPrefix.length(); 1169 String name = pkConstraintPrefix + shrinkName(tableName, maxlen); 1170 String n = name; 1171 for (int i = 2; constraintNames.contains(n); i++) { 1172 n = appendInt(name, i, maxConstraintNameLength); 1173 } 1174 addPkConstraintName(tableName, n); 1175 return n; 1176 } 1177 1178 1183 public void addRefConstraintName(String tableName, 1184 String refConstraintName) 1185 throws IllegalArgumentException { 1186 if (constraintNames.contains(refConstraintName)) { 1187 throw BindingSupportImpl.getInstance().illegalArgument("Duplicate constraint name: " + 1188 refConstraintName); 1189 } 1190 constraintNames.add(refConstraintName); 1191 } 1192 1193 1203 public String generateRefConstraintName(String tableName, 1204 String refTableName, String [] fkNames, String [] refPkNames) { 1205 int maxlen = maxConstraintNameLength - refConstraintPrefix.length(); 1206 String name = refConstraintPrefix + shrinkName( 1207 tableName + wordBreak + refTableName, maxlen); 1208 String n = name; 1209 for (int i = 2; constraintNames.contains(n); i++) { 1210 n = appendInt(name, i, maxConstraintNameLength); 1211 } 1212 addRefConstraintName(tableName, n); 1213 return n; 1214 } 1215 1216 1223 public void addColumnName(String tableName, String columnName) 1224 throws IllegalArgumentException { 1225 String err = addColumnNameImp(tableName, columnName); 1226 if (err != null) throw BindingSupportImpl.getInstance().illegalArgument(err); 1227 } 1228 1229 1232 public boolean isColumnInTable(String tableName, String columnName) { 1233 HashSet cols = (HashSet )tableMap.get(tableName); 1234 if (cols == null) { 1235 throw BindingSupportImpl.getInstance().internal( 1236 "isColumnInTable called with unknown table: '" + tableName + "'"); 1237 } 1238 return cols.contains(columnName); 1239 } 1240 1241 1246 protected String addColumnNameImp(String tableName, String columnName) { 1247 HashSet cols = (HashSet )tableMap.get(tableName); 1248 if (cols == null) { 1249 throw BindingSupportImpl.getInstance().internal( 1250 "addColumnName called with unknown table: '" + tableName + "'"); 1251 } 1252 if (cols.contains(columnName)) { 1253 return "Duplicate column name '" + columnName + 1254 "' in table '" + tableName + "'"; 1255 } 1256 cols.add(columnName); 1257 return null; 1258 } 1259 1260 1264 public String generateDatastorePKName(String tableName) { 1265 String name = getPKNameForTableName(tableName, 0); 1266 for (int j = 2; addColumnNameImp(tableName, name) != null; j++) { 1267 name = getPKNameForTableName(tableName, j); 1268 } 1269 return name; 1270 } 1271 1272 1278 protected String getPKNameForTableName(String tableName, int i) { 1279 int maxlen = maxColumnNameLength - pkSuffix.length(); 1280 if (i < 2) { 1281 return shrinkName(tableName, maxlen) + pkSuffix; 1282 } else { 1283 return appendInt(tableName, i, maxlen) + pkSuffix; 1284 } 1285 } 1286 1287 1292 public String generateClassIdColumnName(String tableName) { 1293 String name = shrinkName(classIdColumnName, maxColumnNameLength); 1294 for (int j = 2; addColumnNameImp(tableName, name) != null; j++) { 1295 name = appendInt(classIdColumnName, j, maxColumnNameLength); 1296 } 1297 return name; 1298 } 1299 1300 1303 public String generateFieldColumnName(String tableName, String fieldName, 1304 boolean primaryKey) { 1305 fieldName = fieldName.substring(fieldName.lastIndexOf('.')+1); 1306 String name = getColumnNameForFieldName(fieldName, 0); 1307 for (int j = 2; addColumnNameImp(tableName, name) != null; j++) { 1308 name = getColumnNameForFieldName(fieldName, j); 1309 } 1310 return name; 1311 } 1312 1313 1319 protected String getColumnNameForFieldName(String fieldName, int i) { 1320 fieldName = getJdbcName(fieldName); 1321 if (i < 2) { 1322 return shrinkName(fieldName, maxColumnNameLength); 1323 } else { 1324 return appendInt(fieldName, i, maxColumnNameLength); 1325 } 1326 } 1327 1328 1336 protected String getColumnNameForFieldName(String fieldName, int col, 1337 int i) { 1338 fieldName = getJdbcName(fieldName); 1339 String suffix = Integer.toString(col); 1340 int maxlen = maxColumnNameLength - suffix.length(); 1341 if (i < 2) { 1342 return appendInt(fieldName, col, maxlen) + suffix; 1343 } else { 1344 return shrinkName(fieldName, maxlen) + suffix; 1345 } 1346 } 1347 1348 1360 public void generateRefFieldColumnNames(String tableName, 1361 String fieldName, String [] columnNames, String refTableName, 1362 String [] refPkNames, boolean otherRefs) { 1363 if (refTableName == null) { 1364 columnNames[0] = generateFieldColumnName(tableName, fieldName, 1365 false); 1366 return; 1367 } 1368 String prefix; 1369 if (otherRefs || tableName.equals(refTableName)) { 1370 int maxlen = 0; 1371 for (int i = refPkNames.length - 1; i >= 0; i--) { 1372 int n = refPkNames[i].length(); 1373 if (n > maxlen) maxlen = n; 1374 } 1375 int n2 = maxColumnNameLength / 2 - 1; 1376 maxlen = n2 - maxlen; 1377 if (maxlen < n2) maxlen = n2; 1378 prefix = shrinkName(getJdbcName(fieldName), maxlen) + "_"; 1379 } else { 1380 prefix = ""; 1381 } 1382 int n = columnNames.length; 1383 for (int i = 0; i < n; i++) { 1384 String name = columnNames[i]; 1385 if (name != null) { 1386 if (!isColumnInTable(tableName, name)) { 1387 addColumnNameImp(tableName, name); 1388 } 1389 continue; 1390 } 1391 String base = prefix + refPkNames[i]; 1392 name = getColumnNameForRefColumn(base, 0); 1393 for (int j = 2; addColumnNameImp(tableName, name) != null; j++) { 1394 name = getColumnNameForRefColumn(base, j); 1395 } 1396 columnNames[i] = name; 1397 } 1398 } 1399 1400 1406 protected String getColumnNameForRefColumn(String base, int i) { 1407 if (i < 2) { 1408 return shrinkName(base, maxColumnNameLength); 1409 } else { 1410 return appendInt(base, i, maxColumnNameLength); 1411 } 1412 } 1413 1414 1424 public void generatePolyRefFieldColumnNames(String tableName, 1425 String fieldName, String [] columnNames) 1426 throws IllegalArgumentException { 1427 String fieldJdbc = getJdbcName(fieldName); 1428 if (columnNames[0] == null) { 1429 String name = fieldJdbc + polyRefClassIdSuffix; 1430 String n = name; 1431 for (int j = 2; addColumnNameImp(tableName, n) != null; j++) { 1432 n = appendInt(name, j, maxColumnNameLength); 1433 } 1434 columnNames[0] = n; 1435 } 1436 int nc = columnNames.length; 1437 boolean onePk = nc == 2; 1438 for (int i = 1; i < nc; i++) { 1439 String name; 1440 if (onePk) { 1441 name = fieldJdbc + pkSuffix; 1442 } else { 1443 name = fieldJdbc + pkSuffix + (char)('a' + i - 1); 1444 } 1445 String n = name; 1446 for (int j = 2; addColumnNameImp(tableName, n) != null; j++) { 1447 n = appendInt(name, j, maxColumnNameLength); 1448 } 1449 columnNames[i] = n; 1450 } 1451 } 1452 1453 1462 public void generateLinkTableMainRefNames(String tableName, 1463 String [] mainTablePkNames, String [] linkMainRefNames) { 1464 int len = linkMainRefNames.length; 1465 for (int i = 0; i < len; i++) { 1466 String name = linkMainRefNames[i]; 1467 if (name != null) continue; 1468 name = mainTablePkNames[i]; 1469 String n = name; 1470 for (int j = 2; addColumnNameImp(tableName, n) != null; j++) { 1471 n = appendInt(name, j, maxColumnNameLength); 1472 } 1473 linkMainRefNames[i] = n; 1474 } 1475 } 1476 1477 1481 public String generateLinkTableSequenceName(String tableName) { 1482 String n = sequenceColumnName; 1483 for (int j = 2; addColumnNameImp(tableName, n) != null; j++) { 1484 n = appendInt(sequenceColumnName, j, maxColumnNameLength); 1485 } 1486 return n; 1487 } 1488 1489 1501 public void generateLinkTableValueRefNames(String tableName, 1502 String [] valuePkNames, String valueClassName, 1503 String [] linkValueRefNames, boolean key) { 1504 String valueBaseName = null; 1505 if (valuePkNames == null) { 1506 int dot = valueClassName.lastIndexOf('.'); 1507 if (dot >= 0) valueClassName = valueClassName.substring(dot + 1); 1508 valueBaseName = shrinkName(getJdbcName(valueClassName), 1509 maxColumnNameLength); 1510 } 1511 int len = linkValueRefNames.length; 1512 for (int i = 0; i < len; i++) { 1513 String name = linkValueRefNames[i]; 1514 if (name != null) continue; 1515 if (valuePkNames == null) { 1516 name = valueBaseName; 1517 } else { 1518 name = valuePkNames[i]; 1519 } 1520 String n = name; 1521 for (int j = 2; addColumnNameImp(tableName, n) != null; j++) { 1522 n = appendInt(name, j, maxColumnNameLength); 1523 } 1524 linkValueRefNames[i] = n; 1525 } 1526 } 1527 1528 1536 public String generateLinkTableValueName(String tableName, 1537 Class valueCls, boolean key) { 1538 String name = key ? keyColumnName : valueColumnName; 1539 String n = name; 1540 for (int j = 2; addColumnNameImp(tableName, n) != null; j++) { 1541 n = appendInt(name, j, maxColumnNameLength); 1542 } 1543 return n; 1544 } 1545 1546 1549 public void addIndexName(String tableName, String indexName) { 1550 indexNames.add(indexName); 1554 } 1555 1556 1561 public String generateIndexName(String tableName, String [] columnNames) { 1562 StringBuffer s = new StringBuffer (); 1563 s.append(indexNamePrefix); 1564 s.append(tableName); 1565 s.append(wordBreak); 1566 int nc = columnNames.length; 1567 for (int i = 0; i < nc; i++) { 1568 if (i > 0) s.append(wordBreak); 1569 s.append(columnNames[i]); 1570 } 1571 String name = shrinkName(s.toString(), maxIndexNameLength); 1572 String n = name; 1573 for (int i = 2; indexNames.contains(n); i++) { 1574 n = appendInt(name, i, maxIndexNameLength); 1575 } 1576 addIndexName(tableName, n); 1577 return n; 1578 } 1579 1580 public String getPolyRefClassIdSuffix() { 1581 return polyRefClassIdSuffix; 1582 } 1583 1584 public void setPolyRefClassIdSuffix(String polyRefClassIdSuffix) { 1585 this.polyRefClassIdSuffix = polyRefClassIdSuffix; 1586 } 1587} 1588 1589 | Popular Tags |