litesoft
@ 151
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
// This Source Code is in the Public Domain per: http://litesoft.org/License.txt package org.litesoft.sql; import java.sql.*; import java.util.*; import org.litesoft.db.*; import org.litesoft.util.*; public class SQLProductSpecificHelperHSQL_Database_Engine extends SQLProductSpecificAbstractHelper { @Override public void initializeDB( Connection pConnection, DBinfo pDBinfo, SQLIndexColumnsLocator pIndexColumnsLocator ) throws SQLException { super.initializeDB( pConnection, pDBinfo, pIndexColumnsLocator ); pConnection.setAutoCommit( true ); Statement zStatement = pConnection.createStatement(); zStatement.execute( "SET PROPERTY \"sql.enforce_strict_size\" TRUE" ); } @Override protected void addColumnType( StringBuilder pCmd, String pSqlType, String pDim ) { super.addColumnType( pCmd, pSqlType, pDim ); if ( pDim.length() == 0 ) { if ( "VARCHAR".equalsIgnoreCase( pSqlType ) ) { pCmd.append( "(999999)" ); // should probably be: Integer.MAXVALUE } } } private static final String DUPLICATE_FIELD_VALUE_PATTERN = "duplicate value(s) for column(s)"; private static final String NON_NULLABLE_COLUMN_PATTERN = "non-nullable column: column: "; private static final String NOT_NULLABLE_COLUMN_PATTERN_2 = " table:"; /* private static final String UNIQUE_CONSTRAINT_PATTERN = "Violation of unique constraint"; private static final String PKEY_VIOLATION_PATTERN = "$$: SYS_PK_"; private static final String MISSING_COLUMNS_PATTERN = "Attempt to insert null into a non-nullable column: column: "; private static final String MISSING_COLUMN_PATTERN_2 = " table: "; */ /** * @param pProductVersion - Of The DataBase * @param pTableName - Of the Schema's Table Name * @param pSelectColumns - Of the Table (comma separated) * @param pSelectionWhereClause - null means all * @param pOrderBy - null means order immaterial * @param pOffset - Rows to Skip (>= 0 verified) * @param pLimit - Max Rows to return (>= 1 verified) @return !Null */ @Override public String buildQuery( String pProductVersion, String pTableName, // String pSelectColumns, String pSelectionWhereClause, String pOrderBy, // long pOffset, int pLimit ) { return "SELECT" + // " LIMIT " + pOffset + " " + pLimit + // " " + pSelectColumns + // " FROM " + pTableName + // " " + pSelectionWhereClause + // " " + pOrderBy; } @Override public boolean validateConnection( Connection pConnection, DBinfo pDBinfo ) throws SQLException { return LLvalidateConWith( pConnection, // "SELECT 1 AS Yup FROM INFORMATION_SCHEMA.SYSTEM_USERS" ); } @Override public boolean tableExists( Connection pConnection, DBinfo pDBinfo, String pTableName ) throws SQLException, MultipleTablesException { return LLtableExists( pConnection, pDBinfo, pTableName, // "SELECT LIMIT 0 1 1 AS Yup FROM " + pTableName ); } @Override public boolean columnExists( Connection pConnection, DBinfo pDBinfo, String pTableName, String pColumnName ) throws SQLException, MultipleTablesException { return LLcolumnExists( pConnection, pDBinfo, pTableName, pColumnName, // "SELECT LIMIT 0 1 " + pColumnName + " FROM " + pTableName ); } @SuppressWarnings({"ThrowableInstanceNeverThrown"}) @Override public WrappedSQLException createMissingSomethingException( SQLException pException ) { List<String> pColumnNames = Collections.emptyList(); String message = pException.getMessage(); int index = message.indexOf( NON_NULLABLE_COLUMN_PATTERN ); index += NON_NULLABLE_COLUMN_PATTERN.length(); message = message.substring( index ); index = message.indexOf( NOT_NULLABLE_COLUMN_PATTERN_2 ); if ( index > 0 ) { String columnName = message.substring( 0, index ); pColumnNames = Collections.singletonList( columnName ); } return new MissingRequiredValueFieldException( pException, pColumnNames ); } @SuppressWarnings({"ThrowableInstanceNeverThrown"}) @Override protected WrappedSQLException createDuplicateFieldValueException( SQLException pException ) { String message = pException.getMessage(); int index = message.lastIndexOf( DUPLICATE_FIELD_VALUE_PATTERN ); String columnList = message.substring( index + DUPLICATE_FIELD_VALUE_PATTERN.length() ).trim(); String[] zFields = Utils.parseChar( columnList, ',' ); return new DuplicateValueFieldException( pException, zFields ); } @Override protected boolean isMissingSomethingException( SQLException pException ) { return isConstraintViolation( pException ) && pException.getErrorCode() == -10; } @Override protected boolean isDuplicateFieldValueException( SQLException pException ) { return isConstraintViolation( pException ) && pException.getErrorCode() == -9; } @Override protected boolean isDuplicatePKException( SQLException pException ) { return isConstraintViolation( pException ) && pException.getErrorCode() == -104; } } |