Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2014-2015 the original author or authors.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  * either express or implied. See the License for the specific language
  * governing permissions and limitations under the License.
  */
 package org.dbflute.s2dao.identity;
 
 
 

Author(s):
modified by jflute (originated in S2Dao)
 
 public abstract class TnIdentifierAbstractGenerator implements TnIdentifierGenerator {
 
     // ===================================================================================
     //                                                                           Attribute
     //                                                                           =========
     protected final TnPropertyType _propertyType;
     protected final TnResultSetHandler _resultSetHandler;
 
     // ===================================================================================
     //                                                                         Constructor
     //                                                                         ===========
     public TnIdentifierAbstractGenerator(TnPropertyType propertyType) {
         if (propertyType == null) {
             String msg = "The arguement 'propertyType' should not be null.";
             throw new IllegalArgumentException(msg);
         }
          = propertyType;
          = new TnIdentifierResultSetHandler(propertyType.getValueType());
     }
 
     // ===================================================================================
     //                                                                       Determination
     //                                                                       =============
     public boolean isPrimaryKey() {
         return .isPrimaryKey();
     }
 
     // ===================================================================================
     //                                                                       Assist Helper
     //                                                                       =============
     protected Object executeSql(DataSource dsString sqlObject[] args) {
         TnBasicSelectHandler selectHandler = createSelectHandler(dssql);
         if (args != null) {
             selectHandler.setExceptionMessageSqlArgs(args);
         }
         return selectHandler.execute(args);
     }
 
     protected TnBasicSelectHandler createSelectHandler(DataSource dsString sql) {
         // Use original statement factory for identifier generator.
         return new TnBasicSelectHandler(dssqlcreateStatementFactory(dssql)) {
             @Override
             protected void saveResultSqlLogInfo(SqlLogInfo sqlLogInfo) {
                 // do nothing because of recursive call
             }
         };
     }
 
     protected StatementFactory createStatementFactory(DataSource dsString sql) {
         return new TnIdentifierGeneratorStatementFactory();
     }
 
     protected void reflectIdentifier(Object beanObject value) {
         final DfPropertyDesc pd = .getPropertyDesc();
         pd.setValue(beanvalue); // setting by reflection here
     }
 
     // ===================================================================================
     //                                                                  Result Set Handler
     //                                                                  ==================
    protected static class TnIdentifierResultSetHandler implements TnResultSetHandler {
        private ValueType _valueType;
        public TnIdentifierResultSetHandler(ValueType valueType) {
            this. = valueType;
        }
        public Object handle(ResultSet rsthrows SQLException {
            if (rs.next()) {
                return .getValue(rs, 1);
            }
            return null;
        }
    }
    // ===================================================================================
    //                                                                   Statement Factory
    //                                                                   =================
    protected static class TnIdentifierGeneratorStatementFactory implements StatementFactory {
        public PreparedStatement createPreparedStatement(Connection connString sql) {
            try {
                return conn.prepareStatement(sql);
            } catch (SQLException e) {
                final SQLExceptionResource resource = createSQLExceptionResource();
                resource.setNotice("Failed to prepare the statement for identity.");
                handleSQLException(eresource);
                return null// unreachable
            }
        }
        public CallableStatement createCallableStatement(Connection connString sql) {
            try {
                return conn.prepareCall(sql);
            } catch (SQLException e) {
                final SQLExceptionResource resource = createSQLExceptionResource();
                resource.setNotice("Failed to prepare callable statement for identity.");
                handleSQLException(eresource);
                return null// unreachable
            }
        }
        protected void handleSQLException(SQLException eSQLExceptionResource resource) {
            createSQLExceptionHandler().handleSQLException(eresource);
        }
        protected SQLExceptionHandler createSQLExceptionHandler() {
            return ResourceContext.createSQLExceptionHandler();
        }
        protected SQLExceptionResource createSQLExceptionResource() {
            return new SQLExceptionResource();
        }
    }
    // ===================================================================================
    //                                                                            Accessor
    //                                                                            ========
    public String getPropertyName() {
        return .getPropertyName();
    }
New to GrepCode? Check out our FAQ X