1 21 package oracle.toplink.essentials.internal.databaseaccess; 23 24 import java.sql.*; 25 import java.util.*; 26 import java.math.*; 27 import java.io.*; 28 import oracle.toplink.essentials.exceptions.*; 29 import oracle.toplink.essentials.queryframework.*; 30 import oracle.toplink.essentials.internal.helper.*; 31 import oracle.toplink.essentials.sessions.SessionProfiler; 32 import oracle.toplink.essentials.sequencing.*; 33 import oracle.toplink.essentials.internal.sequencing.Sequencing; 34 import oracle.toplink.essentials.internal.sessions.AbstractSession; 35 import oracle.toplink.essentials.internal.expressions.ParameterExpression; 36 import oracle.toplink.essentials.descriptors.ClassDescriptor; 37 import oracle.toplink.essentials.tools.schemaframework.TableDefinition; 38 import oracle.toplink.essentials.tools.schemaframework.FieldDefinition; 39 40 55 public class DatabasePlatform extends DatasourcePlatform { 56 57 58 protected transient Hashtable fieldTypes; 59 60 62 protected boolean usesNativeSQL; 63 64 65 protected boolean usesByteArrayBinding; 66 67 68 protected boolean shouldBindAllParameters; 69 70 71 protected boolean shouldCacheAllStatements; 72 73 74 protected int statementCacheSize; 75 76 77 protected boolean shouldForceFieldNamesToUpperCase; 78 79 80 protected boolean shouldTrimStrings; 81 82 83 protected boolean usesStreamsForBinding; 84 85 86 protected int stringBindingSize; 87 88 89 protected boolean usesStringBinding; 90 91 92 protected int cursorCode; 93 94 95 protected int transactionIsolation; 96 97 98 protected boolean supportsAutoCommit; 99 100 104 protected boolean shouldOptimizeDataConversion; 105 106 107 protected transient Hashtable classTypes; 108 109 110 protected static boolean shouldIgnoreCaseOnFieldComparisons = false; 111 112 public DatabasePlatform() { 113 this.tableQualifier = ""; 114 this.usesNativeSQL = false; 115 this.usesByteArrayBinding = true; 116 this.usesStringBinding = false; 117 this.stringBindingSize = 255; 118 this.shouldTrimStrings = true; 119 this.shouldBindAllParameters = false; 120 this.shouldCacheAllStatements = false; 121 this.shouldOptimizeDataConversion = true; 122 this.statementCacheSize = 50; 123 this.shouldForceFieldNamesToUpperCase = false; 124 this.transactionIsolation = -1; 125 this.cursorCode = -10; 126 this.supportsAutoCommit = true; 127 } 128 129 132 public boolean allowsSizeInProcedureArguments() { 133 return true; 134 } 135 136 139 protected void appendBoolean(Boolean bool, Writer writer) throws IOException { 140 if (bool.booleanValue()) { 141 writer.write("1"); 142 } else { 143 writer.write("0"); 144 } 145 } 146 147 151 protected void appendByteArray(byte[] bytes, Writer writer) throws IOException { 152 writer.write("{b '"); 153 Helper.writeHexString(bytes, writer); 154 writer.write("'}"); 155 } 156 157 161 protected void appendDate(java.sql.Date date, Writer writer) throws IOException { 162 writer.write("{d '"); 163 writer.write(Helper.printDate(date)); 164 writer.write("'}"); 165 } 166 167 171 protected void appendNumber(Number number, Writer writer) throws IOException { 172 writer.write(number.toString()); 173 } 174 175 179 public void appendLiteralToCall(Call call, Writer writer, Object literal) { 180 ((DatabaseCall)call).appendLiteral(writer, literal); 181 } 182 183 190 public void appendParameter(Call call, Writer writer, Object parameter) { 191 appendParameterInternal(call, writer, parameter); 192 } 193 194 198 public int appendParameterInternal(Call call, Writer writer, Object parameter) { 199 int nBoundParameters = 0; 200 DatabaseCall databaseCall = (DatabaseCall)call; 201 try { 202 if (parameter instanceof Calendar) { 205 appendCalendar((Calendar)parameter, writer); 206 return nBoundParameters; 207 } 208 Object dbValue = convertToDatabaseType(parameter); 209 210 if (dbValue instanceof String ) { if (usesStringBinding() && (((String )dbValue).length() >= getStringBindingSize())) { 212 databaseCall.bindParameter(writer, dbValue); 213 nBoundParameters = 1; 214 } else { 215 appendString((String )dbValue, writer); 216 } 217 } else if (dbValue instanceof Number ) { 218 appendNumber((Number )dbValue, writer); 219 } else if (dbValue instanceof java.sql.Time ) { 220 appendTime((java.sql.Time )dbValue, writer); 221 } else if (dbValue instanceof java.sql.Timestamp ) { 222 appendTimestamp((java.sql.Timestamp )dbValue, writer); 223 } else if (dbValue instanceof java.sql.Date ) { 224 appendDate((java.sql.Date )dbValue, writer); 225 } else if (dbValue == null) { 226 writer.write("NULL"); 227 } else if (dbValue instanceof Boolean ) { 228 appendBoolean((Boolean )dbValue, writer); 229 } else if (dbValue instanceof byte[]) { 230 if (usesByteArrayBinding()) { 231 databaseCall.bindParameter(writer, dbValue); 232 nBoundParameters = 1; 233 } else { 234 appendByteArray((byte[])dbValue, writer); 235 } 236 } else if (dbValue instanceof Vector) { 237 nBoundParameters = printValuelist((Vector)dbValue, databaseCall, writer); 238 } else if ((parameter instanceof Struct) || (parameter instanceof Array) || (parameter instanceof Ref)) { 239 databaseCall.bindParameter(writer, parameter); 240 nBoundParameters = 1; 241 } else if (oracle.toplink.essentials.internal.helper.Helper.isCollection(dbValue)) { 242 nBoundParameters = printValuelist(Helper.makeVectorFromObject(dbValue), databaseCall, writer); 243 } else if (dbValue.getClass() == int[].class) { 244 nBoundParameters = printValuelist((int[])dbValue, databaseCall, writer); 245 } else if (dbValue instanceof AppendCallCustomParameter) { 246 ((AppendCallCustomParameter)dbValue).append(writer); 248 nBoundParameters = 1; 249 } else if (dbValue instanceof BindCallCustomParameter) { 250 databaseCall.bindParameter(writer, dbValue); 252 nBoundParameters = 1; 253 } else if ((dbValue instanceof Struct) || (dbValue instanceof Array) || (dbValue instanceof Ref)) { 254 databaseCall.bindParameter(writer, dbValue); 255 nBoundParameters = 1; 256 } else { 257 writer.write(dbValue.toString()); 260 } 261 } catch (IOException exception) { 262 throw ValidationException.fileError(exception); 263 } 264 265 return nBoundParameters; 266 } 267 268 271 protected void appendString(String string, Writer writer) throws IOException { 272 writer.write('\''); 273 for (int position = 0; position < string.length(); position++) { 274 if (string.charAt(position) == '\'') { 275 writer.write("''"); 276 } else { 277 writer.write(string.charAt(position)); 278 } 279 } 280 writer.write('\''); 281 } 282 283 287 protected void appendTime(java.sql.Time time, Writer writer) throws IOException { 288 writer.write("{t '"); 289 writer.write(Helper.printTime(time)); 290 writer.write("'}"); 291 } 292 293 297 protected void appendTimestamp(java.sql.Timestamp timestamp, Writer writer) throws IOException { 298 writer.write("{ts '"); 299 writer.write(Helper.printTimestamp(timestamp)); 300 writer.write("'}"); 301 } 302 303 307 protected void appendCalendar(Calendar calendar, Writer writer) throws IOException { 308 writer.write("{ts '"); 309 writer.write(Helper.printCalendar(calendar)); 310 writer.write("'}"); 311 } 312 313 316 public void autoCommit(DatabaseAccessor accessor) throws SQLException { 317 if (!supportsAutoCommit()) { 318 accessor.getConnection().commit(); 319 } 320 } 321 322 326 public void beginTransaction(DatabaseAccessor accessor) throws SQLException { 327 if (!supportsAutoCommit()) { 328 Statement statement = accessor.getConnection().createStatement(); 329 try { 330 statement.executeUpdate("BEGIN TRANSACTION"); 331 } finally { 332 statement.close(); 333 } 334 } 335 } 336 337 341 public DatabaseCall buildCallWithReturning(SQLCall sqlCall, Vector returnFields) { 342 throw ValidationException.platformDoesNotSupportCallWithReturning(Helper.getShortClassName(this)); 343 } 344 345 348 protected Hashtable buildClassTypes() { 349 Hashtable classTypeMapping; 350 351 classTypeMapping = new Hashtable(); 352 classTypeMapping.put("NUMBER", java.math.BigInteger .class); 354 classTypeMapping.put("DECIMAL", java.math.BigDecimal .class); 355 classTypeMapping.put("INTEGER", Integer .class); 356 classTypeMapping.put("INT", Integer .class); 357 classTypeMapping.put("NUMERIC", Long .class); 358 classTypeMapping.put("FLOAT(16)", Float .class); 359 classTypeMapping.put("FLOAT(32)", Double .class); 360 classTypeMapping.put("NUMBER(1) default 0", Boolean .class); 361 classTypeMapping.put("SHORT", Short .class); 362 classTypeMapping.put("BYTE", Byte .class); 363 classTypeMapping.put("DOUBLE", Double .class); 364 classTypeMapping.put("FLOAT", Float .class); 365 classTypeMapping.put("SMALLINT", Short .class); 366 367 classTypeMapping.put("BIT", Boolean .class); 368 classTypeMapping.put("SMALLINT DEFAULT 0", Boolean .class); 369 370 classTypeMapping.put("VARCHAR", String .class); 371 classTypeMapping.put("CHAR", Character .class); 372 classTypeMapping.put("LONGVARBINARY", Byte [].class); 373 classTypeMapping.put("TEXT", Character [].class); 374 classTypeMapping.put("LONGTEXT", Character [].class); 375 classTypeMapping.put("MEMO", Character [].class); 377 classTypeMapping.put("VARCHAR2", String .class); 378 classTypeMapping.put("LONG RAW", Byte [].class); 379 classTypeMapping.put("LONG", Character [].class); 380 381 classTypeMapping.put("DATE", java.sql.Date .class); 382 classTypeMapping.put("TIMESTAMP", java.sql.Timestamp .class); 383 classTypeMapping.put("TIME", java.sql.Time .class); 384 classTypeMapping.put("DATETIME", java.sql.Timestamp .class); 385 386 classTypeMapping.put("BIGINT", java.math.BigInteger .class); 387 classTypeMapping.put("DOUBLE PRECIS", Double .class); 388 classTypeMapping.put("IMAGE", Byte [].class); 389 classTypeMapping.put("LONGVARCHAR", Character [].class); 390 classTypeMapping.put("REAL", Float .class); 391 classTypeMapping.put("TINYINT", Short .class); 392 394 classTypeMapping.put("BLOB", Byte [].class); 395 classTypeMapping.put("CLOB", Character [].class); 396 397 return classTypeMapping; 398 } 399 400 403 protected Hashtable buildFieldTypes() { 404 Hashtable fieldTypeMapping; 405 406 fieldTypeMapping = new Hashtable(); 407 fieldTypeMapping.put(Boolean .class, new FieldTypeDefinition("NUMBER", 1)); 408 409 fieldTypeMapping.put(Integer .class, new FieldTypeDefinition("NUMBER", 10)); 410 fieldTypeMapping.put(Long .class, new FieldTypeDefinition("NUMBER", 19)); 411 fieldTypeMapping.put(Float .class, new FieldTypeDefinition("NUMBER", 12, 5).setLimits(19, 0, 19)); 412 fieldTypeMapping.put(Double .class, new FieldTypeDefinition("NUMBER", 10, 5).setLimits(19, 0, 19)); 413 fieldTypeMapping.put(Short .class, new FieldTypeDefinition("NUMBER", 5)); 414 fieldTypeMapping.put(Byte .class, new FieldTypeDefinition("NUMBER", 3)); 415 fieldTypeMapping.put(java.math.BigInteger .class, new FieldTypeDefinition("NUMBER", 19)); 416 fieldTypeMapping.put(java.math.BigDecimal .class, new FieldTypeDefinition("NUMBER", 19, 0).setLimits(19, 0, 19)); 417 418 fieldTypeMapping.put(String .class, new FieldTypeDefinition("VARCHAR")); 419 fieldTypeMapping.put(Character .class, new FieldTypeDefinition("CHAR")); 420 421 fieldTypeMapping.put(Byte [].class, new FieldTypeDefinition("BLOB")); 422 fieldTypeMapping.put(Character [].class, new FieldTypeDefinition("CLOB")); 423 fieldTypeMapping.put(byte[].class, new FieldTypeDefinition("BLOB")); 424 fieldTypeMapping.put(char[].class, new FieldTypeDefinition("CLOB")); 425 fieldTypeMapping.put(java.sql.Blob .class, new FieldTypeDefinition("BLOB")); 426 fieldTypeMapping.put(java.sql.Clob .class, new FieldTypeDefinition("CLOB")); 427 428 fieldTypeMapping.put(java.sql.Date .class, new FieldTypeDefinition("DATE")); 429 fieldTypeMapping.put(java.sql.Timestamp .class, new FieldTypeDefinition("TIMESTAMP")); 430 fieldTypeMapping.put(java.sql.Time .class, new FieldTypeDefinition("TIME")); 431 432 return fieldTypeMapping; 433 } 434 435 441 public boolean canBuildCallWithReturning() { 442 return false; 443 } 444 445 449 public void commitTransaction(DatabaseAccessor accessor) throws SQLException { 450 if (!supportsAutoCommit()) { 451 accessor.getConnection().commit(); 452 } 453 } 454 455 460 public Object convertToDatabaseType(Object value) { 461 if (value == null) { 462 return null; 463 } 464 if (value.getClass() == ClassConstants.UTILDATE) { 465 return Helper.timestampFromDate((java.util.Date )value); 466 } else if (value instanceof Character ) { 467 return ((Character )value).toString(); 468 } else if (value instanceof Calendar) { 469 return Helper.timestampFromDate(((Calendar)value).getTime()); 470 } else if (value instanceof BigInteger) { 471 return new BigDecimal((BigInteger)value); 472 } else if (value instanceof char[]) { 473 return new String ((char[])value); 474 } else if (value instanceof Character []) { 475 return convertObject(value, ClassConstants.STRING); 476 } else if (value instanceof Byte []) { 477 return convertObject(value, ClassConstants.APBYTE); 478 } 479 return value; 480 } 481 482 485 public void copyInto(Platform platform) { 486 super.copyInto(platform); 487 if (!(platform instanceof DatabasePlatform)) { 488 return; 489 } 490 DatabasePlatform databasePlatform = (DatabasePlatform)platform; 491 databasePlatform.setShouldTrimStrings(shouldTrimStrings()); 492 databasePlatform.setUsesNativeSQL(usesNativeSQL()); 493 databasePlatform.setUsesByteArrayBinding(usesByteArrayBinding()); 494 databasePlatform.setUsesStringBinding(usesStringBinding()); 495 databasePlatform.setShouldBindAllParameters(shouldBindAllParameters()); 496 databasePlatform.setShouldCacheAllStatements(shouldCacheAllStatements()); 497 databasePlatform.setStatementCacheSize(getStatementCacheSize()); 498 databasePlatform.setTransactionIsolation(getTransactionIsolation()); 499 databasePlatform.setShouldForceFieldNamesToUpperCase(shouldForceFieldNamesToUpperCase()); 500 databasePlatform.setShouldOptimizeDataConversion(shouldOptimizeDataConversion()); 501 databasePlatform.setStringBindingSize(getStringBindingSize()); 502 databasePlatform.setUsesStreamsForBinding(usesStreamsForBinding()); 503 } 504 505 508 public String getBatchBeginString() { 509 return ""; 510 } 511 512 515 public String getBatchDelimiterString() { 516 return "; "; 517 } 518 519 522 public String getBatchEndString() { 523 return ""; 524 } 525 526 529 public String getConstraintDeletionString() { 530 return " DROP CONSTRAINT "; 531 } 532 533 536 public String getCreateViewString() { 537 return "CREATE VIEW "; 538 } 539 540 543 public String getProcedureEndString() { 544 return getBatchEndString(); 545 } 546 547 550 public String getProcedureBeginString() { 551 return getBatchBeginString(); 552 } 553 554 557 public String getProcedureAsString() { 558 return " AS"; 559 } 560 561 564 public Hashtable getClassTypes() { 565 if (classTypes == null) { 566 classTypes = buildClassTypes(); 567 } 568 return classTypes; 569 } 570 571 574 public String getAssignmentString() { 575 return "= "; 576 } 577 578 582 public String getCreationInOutputProcedureToken() { 583 return getInOutputProcedureToken(); 584 } 585 586 590 public String getCreationOutputProcedureToken() { 591 return getOutputProcedureToken(); 592 } 593 594 599 public int getCursorCode() { 600 return cursorCode; 601 } 602 603 607 public FieldTypeDefinition getFieldTypeDefinition(Class javaClass) { 608 return (FieldTypeDefinition)getFieldTypes().get(javaClass); 609 } 610 611 614 public Hashtable getFieldTypes() { 615 if (fieldTypes == null) { 616 fieldTypes = buildFieldTypes(); 617 } 618 return fieldTypes; 619 } 620 621 624 public String getFunctionCallHeader() { 625 return getProcedureCallHeader() + "? " + getAssignmentString(); 626 } 627 628 632 public String getInOutputProcedureToken() { 633 return "IN OUT"; 634 } 635 636 639 public String getJDBCOuterJoinString() { 640 return "{oj "; 641 } 642 643 646 public int getJDBCType(DatabaseField field) { 647 if (field != null) { 648 if (field.getSqlType() != -1) { 651 return field.getSqlType(); 652 } else { 653 return getJDBCType(ConversionManager.getObjectClass(field.getType())); 654 } 655 } else { 656 return getJDBCType((Class )null); 657 } 658 } 659 660 663 public int getJDBCType(Class javaType) { 664 if (javaType == null) { 665 return Types.VARCHAR; } else if (javaType == ClassConstants.STRING) { 667 return Types.VARCHAR; 668 } else if (javaType == ClassConstants.BIGDECIMAL) { 669 return Types.DECIMAL; 670 } else if (javaType == ClassConstants.BIGINTEGER) { 671 return Types.BIGINT; 672 } else if (javaType == ClassConstants.BOOLEAN) { 673 return Types.BIT; 674 } else if (javaType == ClassConstants.BYTE) { 675 return Types.TINYINT; 676 } else if (javaType == ClassConstants.CHAR) { 677 return Types.CHAR; 678 } else if (javaType == ClassConstants.DOUBLE) { 679 return Types.DOUBLE; 680 } else if (javaType == ClassConstants.FLOAT) { 681 return Types.FLOAT; 682 } else if (javaType == ClassConstants.INTEGER) { 683 return Types.INTEGER; 684 } else if (javaType == ClassConstants.LONG) { 685 return Types.INTEGER; 686 } else if (javaType == ClassConstants.NUMBER) { 687 return Types.DECIMAL; 688 } else if (javaType == ClassConstants.SHORT ) { 689 return Types.SMALLINT; 690 } else if (javaType == ClassConstants.CALENDAR ) { 691 return Types.TIMESTAMP; 692 } else if (javaType == ClassConstants.UTILDATE ) { 693 return Types.TIMESTAMP; 694 } else if (javaType == ClassConstants.TIME) { 695 return Types.TIME; 696 } else if (javaType == ClassConstants.SQLDATE) { 697 return Types.DATE; 698 } else if (javaType == ClassConstants.TIMESTAMP) { 699 return Types.TIMESTAMP; 700 } else if (javaType == ClassConstants.ABYTE) { 701 return Types.LONGVARBINARY; 702 } else if (javaType == ClassConstants.APBYTE) { 703 return Types.LONGVARBINARY; 704 } else if (javaType == ClassConstants.BLOB) { 705 return Types.BLOB; 706 } else if (javaType == ClassConstants.ACHAR) { 707 return Types.LONGVARCHAR; 708 } else if (javaType == ClassConstants.APCHAR) { 709 return Types.LONGVARCHAR; 710 } else if (javaType == ClassConstants.CLOB) { 711 return Types.CLOB; 712 } else { 713 return Types.VARCHAR; } 715 } 716 717 721 public String getJdbcTypeName(int jdbcType) { 722 return null; 723 } 724 725 730 public int getMaxFieldNameSize() { 731 return 50; 732 } 733 734 739 public int getMaxForeignKeyNameSize() { 740 return getMaxFieldNameSize(); 741 } 742 743 748 public int getMaxUniqueKeyNameSize() { 749 return getMaxFieldNameSize(); 750 } 751 752 758 public Object getObjectFromResultSet(ResultSet resultSet, int columnNumber, int type) throws java.sql.SQLException { 759 return resultSet.getObject(columnNumber); 760 } 761 762 766 public String getOutputProcedureToken() { 767 return "OUT"; 768 } 769 770 773 public String getProcedureArgumentSetter() { 774 return " = "; 775 } 776 777 780 public String getProcedureArgumentString() { 781 return ""; 782 } 783 784 787 public String getProcedureCallHeader() { 788 return "EXECUTE PROCEDURE "; 789 } 790 791 794 public String getProcedureCallTail() { 795 return ""; 796 } 797 798 public String getQualifiedSequenceTableName() { 799 if (getDefaultSequence() instanceof TableSequence) { 800 String sequenceTableName = ((TableSequence)getDefaultSequence()).getTableName(); 801 if (getTableQualifier().equals("")) { 802 return sequenceTableName; 803 } else { 804 return getTableQualifier() + "." + sequenceTableName; 805 } 806 } else { 807 throw ValidationException.wrongSequenceType(Helper.getShortClassName(getDefaultSequence()), "getTableName"); 808 } 809 } 810 811 815 public String getSelectForUpdateNoWaitString() { 816 return " NOWAIT"; 817 } 818 819 823 public String getSelectForUpdateOfString() { 824 return " FOR UPDATE OF "; 825 } 826 827 831 public String getSelectForUpdateString() { 832 return " FOR UPDATE OF *"; 833 } 834 835 public String getSequenceCounterFieldName() { 836 if (getDefaultSequence() instanceof TableSequence) { 837 return ((TableSequence)getDefaultSequence()).getCounterFieldName(); 838 } else { 839 throw ValidationException.wrongSequenceType(Helper.getShortClassName(getDefaultSequence()), "getCounterFieldName"); 840 } 841 } 842 843 public String getSequenceNameFieldName() { 844 if (getDefaultSequence() instanceof TableSequence) { 845 return ((TableSequence)getDefaultSequence()).getNameFieldName(); 846 } else { 847 throw ValidationException.wrongSequenceType(Helper.getShortClassName(getDefaultSequence()), "getNameFieldName"); 848 } 849 } 850 851 public int getSequencePreallocationSize() { 852 return getDefaultSequence().getPreallocationSize(); 853 } 854 855 public String getSequenceTableName() { 856 if (getDefaultSequence() instanceof TableSequence) { 857 return ((TableSequence)getDefaultSequence()).getTableName(); 858 } else { 859 throw ValidationException.wrongSequenceType(Helper.getShortClassName(getDefaultSequence()), "getTableName"); 860 } 861 } 862 863 866 public int getStatementCacheSize() { 867 return statementCacheSize; 868 } 869 870 public String getStoredProcedureParameterPrefix() { 871 return ""; 872 } 873 874 public String getStoredProcedureTerminationToken() { 875 return ";"; 876 } 877 878 public int getStringBindingSize() { 879 return stringBindingSize; 880 } 881 882 886 public int getTransactionIsolation() { 887 return transactionIsolation; 888 } 889 890 894 public boolean isInformixOuterJoin() { 895 return false; 896 } 897 898 903 public Hashtable maximumNumericValues() { 904 Hashtable values = new Hashtable(); 905 906 values.put(Integer .class, new Integer (Integer.MAX_VALUE)); 907 values.put(Long .class, new Long (Long.MAX_VALUE)); 908 values.put(Double .class, new Double (Double.MAX_VALUE)); 909 values.put(Short .class, new Short (Short.MAX_VALUE)); 910 values.put(Byte .class, new Byte (Byte.MAX_VALUE)); 911 values.put(Float .class, new Float (Float.MAX_VALUE)); 912 values.put(java.math.BigInteger .class, new java.math.BigInteger ("999999999999999999999999999999999999999")); 913 values.put(java.math.BigDecimal .class, new java.math.BigDecimal ("99999999999999999999.9999999999999999999")); 914 return values; 915 } 916 917 922 public Hashtable minimumNumericValues() { 923 Hashtable values = new Hashtable(); 924 925 values.put(Integer .class, new Integer (Integer.MIN_VALUE)); 926 values.put(Long .class, new Long (Long.MIN_VALUE)); 927 values.put(Double .class, new Double (Double.MIN_VALUE)); 928 values.put(Short .class, new Short (Short.MIN_VALUE)); 929 values.put(Byte .class, new Byte (Byte.MIN_VALUE)); 930 values.put(Float .class, new Float (Float.MIN_VALUE)); 931 values.put(java.math.BigInteger .class, new java.math.BigInteger ("-99999999999999999999999999999999999999")); 932 values.put(java.math.BigDecimal .class, new java.math.BigDecimal ("-9999999999999999999.9999999999999999999")); 933 return values; 934 } 935 936 939 public void printFieldIdentityClause(Writer writer, AbstractSession session, String qualifiedFieldName) throws ValidationException { 940 if (shouldAcquireSequenceValueAfterInsert(session, qualifiedFieldName)) { 941 printFieldIdentityClause(writer); 942 } 943 } 944 945 948 public void printFieldIdentityClause(Writer writer) throws ValidationException { 949 } 951 952 955 public void printFieldNotNullClause(Writer writer) throws ValidationException { 956 try { 957 writer.write(" NOT NULL"); 958 } catch (IOException ioException) { 959 throw ValidationException.fileError(ioException); 960 } 961 } 962 963 966 public void printFieldNullClause(Writer writer) throws ValidationException { 967 } 969 970 977 public int printValuelist(int[] theObjects, DatabaseCall call, Writer writer) throws IOException { 978 int nBoundParameters = 0; 979 writer.write("("); 980 981 for (int i = 0; i < theObjects.length; i++) { 982 nBoundParameters = nBoundParameters + appendParameterInternal(call, writer, new Integer (theObjects[i])); 983 if (i < (theObjects.length - 1)) { 984 writer.write(", "); 985 } 986 } 987 988 writer.write(")"); 989 return nBoundParameters; 990 } 991 992 995 public int printValuelist(Vector theObjects, DatabaseCall call, Writer writer) throws IOException { 996 int nBoundParameters = 0; 997 Enumeration enumtr = theObjects.elements(); 998 while (enumtr.hasMoreElements()) { 999 nBoundParameters = nBoundParameters + appendParameterInternal(call, writer, enumtr.nextElement()); 1000 if (enumtr.hasMoreElements()) { 1001 writer.write(", "); 1002 } 1003 } 1004 return nBoundParameters; 1005 } 1006 1007 protected Object processResultSet(ResultSet resultSet, DatabaseCall dbCall, PreparedStatement statement, DatabaseAccessor accessor, AbstractSession session) throws SQLException { 1008 Object result = null; 1009 ResultSetMetaData metaData = resultSet.getMetaData(); 1010 1011 session.startOperationProfile(SessionProfiler.ROW_FETCH); 1012 try { 1013 if (dbCall.isOneRowReturned()) { 1014 if (resultSet.next()) { 1015 result = accessor.fetchRow(dbCall.getFields(), resultSet, metaData, session); 1016 if (resultSet.next()) { 1017 session.getEventManager().moreRowsDetected(dbCall); 1019 } 1020 } else { 1021 result = null; 1022 } 1023 } else { 1024 Vector results = new Vector(20); 1025 while (resultSet.next()) { 1026 results.addElement(accessor.fetchRow(dbCall.getFields(), resultSet, metaData, session)); 1027 } 1028 result = results; 1029 } 1030 resultSet.close(); } finally { 1032 session.endOperationProfile(SessionProfiler.ROW_FETCH); 1033 } 1034 return result; 1035 } 1036 1037 1041 public void registerOutputParameter(CallableStatement statement, int index, int jdbcType) throws SQLException { 1042 statement.registerOutParameter(index, jdbcType); 1043 } 1044 1045 1048 public boolean requiresNamedPrimaryKeyConstraints() { 1049 return false; 1050 } 1051 1052 1055 public boolean requiresProcedureCallBrackets() { 1056 return true; 1057 } 1058 1059 1062 public boolean requiresProcedureCallOuputToken() { 1063 return false; 1064 } 1065 1066 1071 public boolean requiresTypeNameToRegisterOutputParameter() { 1072 return false; 1073 } 1074 1075 1079 public void rollbackTransaction(DatabaseAccessor accessor) throws SQLException { 1080 if (!supportsAutoCommit()) { 1081 accessor.getConnection().rollback(); 1082 } 1083 } 1084 1085 protected void setClassTypes(Hashtable classTypes) { 1086 this.classTypes = classTypes; 1087 } 1088 1089 1094 public void setCursorCode(int cursorCode) { 1095 this.cursorCode = cursorCode; 1096 } 1097 1098 protected void setFieldTypes(Hashtable theFieldTypes) { 1099 fieldTypes = theFieldTypes; 1100 } 1101 1102 public void setSequenceCounterFieldName(String name) { 1103 if (getDefaultSequence() instanceof TableSequence) { 1104 ((TableSequence)getDefaultSequence()).setCounterFieldName(name); 1105 } else { 1106 if (!name.equals((new TableSequence()).getCounterFieldName())) { 1107 ValidationException.wrongSequenceType(Helper.getShortClassName(getDefaultSequence()), "setCounterFieldName"); 1108 } 1109 } 1110 } 1111 1112 public void setSequenceNameFieldName(String name) { 1113 if (getDefaultSequence() instanceof TableSequence) { 1114 ((TableSequence)getDefaultSequence()).setNameFieldName(name); 1115 } else { 1116 if (!name.equals((new TableSequence()).getNameFieldName())) { 1117 throw ValidationException.wrongSequenceType(Helper.getShortClassName(getDefaultSequence()), "setNameFieldName"); 1118 } 1119 } 1120 } 1121 1122 public void setSequenceTableName(String name) { 1123 if (getDefaultSequence() instanceof TableSequence) { 1124 ((TableSequence)getDefaultSequence()).setTableName(name); 1125 } else { 1126 if (!name.equals((new TableSequence()).getTableName())) { 1127 throw ValidationException.wrongSequenceType(Helper.getShortClassName(getDefaultSequence()), "setTableName"); 1128 } 1129 } 1130 } 1131 1132 1135 public void setShouldBindAllParameters(boolean shouldBindAllParameters) { 1136 this.shouldBindAllParameters = shouldBindAllParameters; 1137 } 1138 1139 1142 public void setShouldCacheAllStatements(boolean shouldCacheAllStatements) { 1143 this.shouldCacheAllStatements = shouldCacheAllStatements; 1144 } 1145 1146 1149 public void setShouldForceFieldNamesToUpperCase(boolean shouldForceFieldNamesToUpperCase) { 1150 this.shouldForceFieldNamesToUpperCase = shouldForceFieldNamesToUpperCase; 1151 } 1152 1153 1156 public static void setShouldIgnoreCaseOnFieldComparisons(boolean newShouldIgnoreCaseOnFieldComparisons) { 1157 shouldIgnoreCaseOnFieldComparisons = newShouldIgnoreCaseOnFieldComparisons; 1158 } 1159 1160 1165 public void setShouldOptimizeDataConversion(boolean value) { 1166 this.shouldOptimizeDataConversion = value; 1167 } 1168 1169 public void setShouldTrimStrings(boolean aBoolean) { 1170 shouldTrimStrings = aBoolean; 1171 } 1172 1173 1176 public void setStatementCacheSize(int statementCacheSize) { 1177 this.statementCacheSize = statementCacheSize; 1178 } 1179 1180 public void setStringBindingSize(int aSize) { 1181 stringBindingSize = aSize; 1182 } 1183 1184 1188 public void setSupportsAutoCommit(boolean supportsAutoCommit) { 1189 this.supportsAutoCommit = supportsAutoCommit; 1190 } 1191 1192 1195 public void setTransactionIsolation(int isolationLevel) { 1196 transactionIsolation = isolationLevel; 1197 } 1198 1199 public void setUsesByteArrayBinding(boolean usesByteArrayBinding) { 1200 this.usesByteArrayBinding = usesByteArrayBinding; 1201 } 1202 1203 public void setUsesNativeSQL(boolean usesNativeSQL) { 1204 this.usesNativeSQL = usesNativeSQL; 1205 } 1206 1207 public void setUsesStreamsForBinding(boolean usesStreamsForBinding) { 1208 this.usesStreamsForBinding = usesStreamsForBinding; 1209 } 1210 1211 public void setUsesStringBinding(boolean aBool) { 1212 usesStringBinding = aBool; 1213 } 1214 1215 1218 public boolean shouldBindAllParameters() { 1219 return shouldBindAllParameters; 1220 } 1221 1222 1225 public boolean shouldCacheAllStatements() { 1226 return shouldCacheAllStatements; 1227 } 1228 1229 1232 public boolean shouldForceFieldNamesToUpperCase() { 1233 return shouldForceFieldNamesToUpperCase; 1234 } 1235 1236 1239 public static boolean shouldIgnoreCaseOnFieldComparisons() { 1240 return shouldIgnoreCaseOnFieldComparisons; 1241 } 1242 1243 1247 public boolean shouldIgnoreException(SQLException exception) { 1248 return false; 1250 } 1251 1252 1256 public boolean shouldOptimizeDataConversion() { 1257 return shouldOptimizeDataConversion; 1258 } 1259 1260 1263 public boolean shouldPrintConstraintNameAfter() { 1264 return false; 1265 } 1266 1267 1271 public boolean shouldPrintInOutputTokenBeforeType() { 1272 return true; 1273 } 1274 1275 1278 public boolean shouldPrintOuterJoinInWhereClause() { 1279 return false; 1280 } 1281 1282 1286 public boolean shouldPrintOutputTokenBeforeType() { 1287 return true; 1288 } 1289 1290 1294 public boolean shouldPrintOutputTokenAtStart() { 1295 return false; 1296 } 1297 1298 public boolean shouldTrimStrings() { 1299 return shouldTrimStrings; 1300 } 1301 1302 1305 public boolean shouldUseJDBCOuterJoinSyntax() { 1306 return true; 1307 } 1308 1309 1313 public boolean supportsAutoCommit() { 1314 return supportsAutoCommit; 1315 } 1316 1317 public boolean supportsForeignKeyConstraints() { 1318 return true; 1319 } 1320 1321 public boolean supportsUniqueKeyConstraints() { 1322 return true; 1323 } 1324 1325 public boolean supportsNativeSequenceNumbers() { 1326 return false; 1327 } 1328 1329 public boolean supportsPrimaryKeyConstraint() { 1330 return true; 1331 } 1332 1333 public boolean supportsStoredFunctions() { 1334 return false; 1335 } 1336 1337 1342 public Object executeStoredProcedure(DatabaseCall dbCall, PreparedStatement statement, DatabaseAccessor accessor, AbstractSession session) throws SQLException { 1343 Object result = null; 1344 ResultSet resultSet = null; 1345 if (!dbCall.getReturnsResultSet()) { if (dbCall.isCursorOutputProcedure()) { 1347 result = accessor.executeNoSelect(dbCall, statement, session); 1348 resultSet = (ResultSet)((CallableStatement)statement).getObject(dbCall.getCursorOutIndex()); 1349 } else { 1350 accessor.executeDirectNoSelect(statement, dbCall, session); 1351 result = accessor.buildOutputRow((CallableStatement)statement, dbCall, session); 1352 1353 if (dbCall.areManyRowsReturned()) { 1356 Vector tempResult = new Vector(); 1357 ((Vector)tempResult).add(result); 1358 result = tempResult; 1359 } 1360 } 1361 } else { 1362 resultSet = accessor.executeSelect(dbCall, statement, session); 1365 } 1366 if (resultSet != null) { 1367 dbCall.matchFieldOrder(resultSet, accessor, session); 1368 1369 if (dbCall.isCursorReturned()) { 1370 dbCall.setStatement(statement); 1371 dbCall.setResult(resultSet); 1372 return dbCall; 1373 } 1374 result = processResultSet(resultSet, dbCall, statement, accessor, session); 1375 1376 } 1377 return result; 1378 } 1379 1380 1385 public void setParameterValueInDatabaseCall(Object parameter, PreparedStatement statement, int index, AbstractSession session) throws SQLException { 1386 parameter = convertToDatabaseType(parameter); 1388 if (! setComplexParameterValue(session, statement, index, parameter)) { 1389 setPrimitiveParameterValue(statement, index, parameter); 1390 } 1391 } 1392 1393 1397 protected void setPrimitiveParameterValue(final PreparedStatement statement, final int index, 1398 final Object parameter) throws SQLException { 1399 statement.setObject(index, parameter); 1400 } 1401 1402 1406 private boolean setComplexParameterValue(final AbstractSession session, final PreparedStatement statement, final int index, final Object parameter) throws SQLException { 1407 if (parameter == null) { 1408 statement.setNull(index, getJDBCType((Class )null)); 1410 } else if (parameter instanceof DatabaseField) { 1411 int jdbcType = getJDBCType((DatabaseField)parameter); 1414 statement.setNull(index, jdbcType); 1415 } else if ((parameter instanceof byte[]) && (usesStreamsForBinding())) { 1416 ByteArrayInputStream inputStream = new ByteArrayInputStream((byte[])parameter); 1417 statement.setBinaryStream(index, inputStream, ((byte[])parameter).length); 1418 } else if ((parameter instanceof String ) && usesStringBinding() && (((String )parameter).length() > getStringBindingSize())) { 1419 CharArrayReader reader = new CharArrayReader(((String )parameter).toCharArray()); 1420 statement.setCharacterStream(index, reader, ((String )parameter).length()); 1421 } else if (parameter instanceof BindCallCustomParameter) { 1422 ((BindCallCustomParameter)(parameter)).set(this, statement, index, session); 1423 } else { 1424 return false; 1425 } 1426 return true; 1427 } 1428 1429 1437 public void setParameterValueInDatabaseCall(Vector parameters, PreparedStatement statement, int parameterIndex, AbstractSession session) throws SQLException { 1438 setParameterValueInDatabaseCall(parameters, statement, parameterIndex, parameterIndex + 1, session); 1439 } 1440 1441 1449 public void setParameterValueInDatabaseCall(Vector parameters, PreparedStatement statement, int parameterIndex, int index, AbstractSession session) throws SQLException { 1450 setParameterValueInDatabaseCall(parameters.elementAt(parameterIndex), statement, index, session); 1451 } 1452 1453 public boolean usesByteArrayBinding() { 1454 return usesByteArrayBinding; 1455 } 1456 1457 public boolean usesSequenceTable() { 1458 return getDefaultSequence() instanceof TableSequence; 1459 } 1460 1461 public boolean usesNativeSQL() { 1462 return usesNativeSQL; 1463 } 1464 1465 public boolean usesStreamsForBinding() { 1466 return usesStreamsForBinding; 1467 } 1468 1469 public boolean usesStringBinding() { 1470 return usesStringBinding; 1471 } 1472 1473 1477 public void writeLOB(DatabaseField field, Object value, ResultSet resultSet, AbstractSession session) throws SQLException { 1478 } 1480 1481 1486 public boolean shouldNativeSequenceUseTransaction() { 1487 return false; 1488 } 1489 1490 1496 public boolean shouldNativeSequenceAcquireValueAfterInsert() { 1497 return false; 1498 } 1499 1500 1501 1504 public ValueReadQuery buildSelectQueryForNativeSequence() { 1505 return null; 1506 } 1507 1508 1511 public ValueReadQuery buildSelectQueryForNativeSequence(String seqName, Integer size) { 1512 return null; 1513 } 1514 1515 1519 protected Sequence createPlatformDefaultSequence() { 1520 return new TableSequence(); 1521 } 1522 1523 1534 public boolean supportsTempTables() { 1535 return supportsLocalTempTables() || supportsGlobalTempTables(); 1536 } 1537 1538 1547 public boolean supportsLocalTempTables() { 1548 return false; 1549 } 1550 1551 1564 public boolean supportsGlobalTempTables() { 1565 return false; 1566 } 1567 1568 1576 protected String getCreateTempTableSqlPrefix() { 1577 throw ValidationException.platformDoesNotOverrideGetCreateTempTableSqlPrefix(Helper.getShortClassName(this)); 1578 } 1579 1580 1586 public DatabaseTable getTempTableForTable(DatabaseTable table) { 1587 return new DatabaseTable("TL_" + table.getName(), table.getTableQualifier()); 1588 } 1589 1590 1598 protected String getCreateTempTableSqlSuffix() { 1599 return ""; 1600 } 1601 1602 1617 protected String getCreateTempTableSqlBodyForTable(DatabaseTable table) { 1618 return null; 1619 } 1620 1621 1640 public void writeCreateTempTableSql(Writer writer, DatabaseTable table, AbstractSession session, 1641 Collection pkFields, 1642 Collection usedFields, 1643 Collection allFields) throws IOException 1644 { 1645 String body = getCreateTempTableSqlBodyForTable(table); 1646 if(body == null) { 1647 TableDefinition tableDef = new TableDefinition(); 1648 Collection fields; 1649 if(supportsLocalTempTables()) { 1650 fields = usedFields; 1651 } else { 1652 fields = allFields; 1654 } 1655 Iterator itFields = fields.iterator(); 1656 while(itFields.hasNext()) { 1657 DatabaseField field = (DatabaseField)itFields.next(); 1658 FieldDefinition fieldDef = new FieldDefinition(field.getName(), ConversionManager.getObjectClass(field.getType())); 1659 if(pkFields.contains(field)) { 1660 fieldDef.setIsPrimaryKey(true); 1661 } 1662 tableDef.addField(fieldDef); 1663 } 1664 tableDef.setCreationPrefix(getCreateTempTableSqlPrefix()); 1665 tableDef.setName(getTempTableForTable(table).getQualifiedName()); 1666 tableDef.setCreationSuffix(getCreateTempTableSqlSuffix()); 1667 tableDef.buildCreationWriter(session, writer); 1668 } else { 1669 writer.write(getCreateTempTableSqlPrefix()); 1670 writer.write(getTempTableForTable(table).getQualifiedName()); 1671 writer.write(body); 1672 writer.write(getCreateTempTableSqlSuffix()); 1673 } 1674 } 1675 1676 1686 public void writeInsertIntoTableSql(Writer writer, DatabaseTable table, Collection usedFields) throws IOException { 1687 writer.write("INSERT INTO "); 1688 writer.write(getTempTableForTable(table).getQualifiedName()); 1689 1690 writer.write(" ("); 1691 writeFieldsList(writer, usedFields); 1692 writer.write(") "); 1693 } 1694 1695 1707 public void writeUpdateOriginalFromTempTableSql(Writer writer, DatabaseTable table, 1708 Collection pkFields, 1709 Collection assignedFields) throws IOException 1710 { 1711 writer.write("UPDATE "); 1712 String tableName = table.getQualifiedName(); 1713 writer.write(tableName); 1714 writer.write(" SET ("); 1715 writeFieldsList(writer, assignedFields); 1716 writer.write(") = (SELECT "); 1717 writeFieldsList(writer, assignedFields); 1718 writer.write(" FROM "); 1719 String tempTableName = getTempTableForTable(table).getQualifiedName(); 1720 writer.write(tempTableName); 1721 writeAutoJoinWhereClause(writer, null, tableName, pkFields); 1722 writer.write(") WHERE EXISTS(SELECT "); 1723 writer.write(((DatabaseField)pkFields.iterator().next()).getName()); 1724 writer.write(" FROM "); 1725 writer.write(tempTableName); 1726 writeAutoJoinWhereClause(writer, null, tableName, pkFields); 1727 writer.write(")"); 1728 } 1729 1730 1746 public void writeDeleteFromTargetTableUsingTempTableSql(Writer writer, DatabaseTable table, DatabaseTable targetTable, 1747 Collection pkFields, 1748 Collection targetPkFields) throws IOException 1749 { 1750 writer.write("DELETE FROM "); 1751 String targetTableName = targetTable.getQualifiedName(); 1752 writer.write(targetTableName); 1753 writer.write(" WHERE EXISTS(SELECT "); 1754 writer.write(((DatabaseField)pkFields.iterator().next()).getName()); 1755 writer.write(" FROM "); 1756 String tempTableName = getTempTableForTable(table).getQualifiedName(); 1757 writer.write(tempTableName); 1758 writeJoinWhereClause(writer, null, targetTableName, pkFields, targetPkFields); 1759 writer.write(")"); 1760 } 1761 1762 1772 public void writeCleanUpTempTableSql(Writer writer, DatabaseTable table) throws IOException { 1773 if(supportsLocalTempTables()) { 1774 writer.write("DROP TABLE "); 1775 } else { 1776 writer.write("DELETE FROM "); 1778 } 1779 writer.write(getTempTableForTable(table).getQualifiedName()); 1780 } 1781 1782 1792 public boolean shouldAlwaysUseTempStorageForModifyAll() { 1793 return false; 1794 } 1795 1796 1801 public boolean dontBindUpdateAllQueryUsingTempTables() { 1802 return false; 1803 } 1804 1805 1809 protected static void writeFieldsList(Writer writer, Collection fields) throws IOException { 1810 boolean isFirst = true; 1811 Iterator itFields = fields.iterator(); 1812 while(itFields.hasNext()) { 1813 if(isFirst) { 1814 isFirst = false; 1815 } else { 1816 writer.write(", "); 1817 } 1818 DatabaseField field = (DatabaseField)itFields.next(); 1819 writer.write(field.getName()); 1820 } 1821 } 1822 1823 1827 protected static void writeAutoAssignmentSetClause(Writer writer, String tableName1, String tableName2, Collection fields) throws IOException { 1828 writer.write(" SET "); 1829 writeFieldsAutoClause(writer, tableName1, tableName2, fields, ", "); 1830 } 1831 1832 1836 protected static void writeAutoJoinWhereClause(Writer writer, String tableName1, String tableName2, Collection pkFields) throws IOException { 1837 writer.write(" WHERE "); 1838 writeFieldsAutoClause(writer, tableName1, tableName2, pkFields, " AND "); 1839 } 1840 1841 1845 protected static void writeFieldsAutoClause(Writer writer, String tableName1, String tableName2, Collection fields, String separator) throws IOException { 1846 writeFields(writer, tableName1, tableName2, fields, fields, separator); 1847 } 1848 1852 protected static void writeJoinWhereClause(Writer writer, String tableName1, String tableName2, Collection pkFields1, Collection pkFields2) throws IOException { 1853 writer.write(" WHERE "); 1854 writeFields(writer, tableName1, tableName2, pkFields1, pkFields2, " AND "); 1855 } 1856 1857 1861 protected static void writeFields(Writer writer, String tableName1, String tableName2, Collection fields1, Collection fields2, String separator) throws IOException { 1862 boolean isFirst = true; 1863 Iterator itFields1 = fields1.iterator(); 1864 Iterator itFields2 = fields2.iterator(); 1865 while(itFields1.hasNext()) { 1866 if(isFirst) { 1867 isFirst = false; 1868 } else { 1869 writer.write(separator); 1870 } 1871 if(tableName1 != null) { 1872 writer.write(tableName1); 1873 writer.write("."); 1874 } 1875 String fieldName1 = ((DatabaseField)itFields1.next()).getName(); 1876 writer.write(fieldName1); 1877 writer.write(" = "); 1878 if(tableName2 != null) { 1879 writer.write(tableName2); 1880 writer.write("."); 1881 } 1882 String fieldName2 = ((DatabaseField)itFields2.next()).getName(); 1883 writer.write(fieldName2); 1884 } 1885 } 1886 1887 public boolean shouldAcquireSequenceValueAfterInsert(AbstractSession session, String qualifiedFieldName) { 1888 if (!supportsNativeSequenceNumbers() || !shouldNativeSequenceAcquireValueAfterInsert()) { 1889 return false; 1890 } 1891 if ((session.getSequencing() == null) || (session.getSequencing().whenShouldAcquireValueForAll() == Sequencing.BEFORE_INSERT)) { 1892 return false; 1893 } 1894 1895 boolean shouldAcquireSequenceValueAfterInsert = false; 1896 DatabaseField field = new DatabaseField(qualifiedFieldName); 1897 Iterator descriptors = session.getDescriptors().values().iterator(); 1898 while (descriptors.hasNext()) { 1899 ClassDescriptor descriptor = (ClassDescriptor)descriptors.next(); 1900 if (!descriptor.usesSequenceNumbers()) { 1901 continue; 1902 } 1903 if (descriptor.getSequenceNumberField().equals(field)) { 1904 String seqName = descriptor.getSequenceNumberName(); 1905 Sequence sequence = getSequence(seqName); 1906 shouldAcquireSequenceValueAfterInsert = sequence.shouldAcquireValueAfterInsert(); 1907 break; 1908 } 1909 } 1910 return shouldAcquireSequenceValueAfterInsert; 1911 } 1912 1913 public void printFieldTypeSize(Writer writer, FieldDefinition field, 1914 FieldTypeDefinition fieldType, AbstractSession session, String qualifiedFieldName) throws IOException { 1915 writer.write(fieldType.getName()); 1916 if ((fieldType.isSizeAllowed()) && ((field.getSize() != 0) || (fieldType.isSizeRequired()))) { 1917 writer.write("("); 1918 if (field.getSize() == 0) { 1919 writer.write(new Integer (fieldType.getDefaultSize()).toString()); 1920 } else { 1921 writer.write(new Integer (field.getSize()).toString()); 1922 } 1923 if (field.getSubSize() != 0) { 1924 writer.write(","); 1925 writer.write(new Integer (field.getSubSize()).toString()); 1926 } else if (fieldType.getDefaultSubSize() != 0) { 1927 writer.write(","); 1928 writer.write(new Integer (fieldType.getDefaultSubSize()).toString()); 1929 } 1930 writer.write(")"); 1931 } 1932 } 1933 1934 public void printFieldUnique(Writer writer, boolean isUnique, 1935 AbstractSession session, String qualifiedFieldName) throws IOException { 1936 if (isUnique) { 1937 if (supportsPrimaryKeyConstraint()) { 1938 writer.write(" UNIQUE"); 1939 } 1940 } 1941 } 1942 1943 public void writeParameterMarker(Writer writer, ParameterExpression expression) throws IOException { 1944 writer.write("?"); 1945 } 1946} 1947 | Popular Tags |