org.mybatis.spring.SqlSessionTemplate Java Examples
The following examples show how to use
org.mybatis.spring.SqlSessionTemplate.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MyBatisAccessor.java From jstarcraft-core with Apache License 2.0 | 6 votes |
public MyBatisAccessor(Collection<Class<?>> classes, SqlSessionTemplate template) { this.template = template; Configuration configuration = template.getConfiguration(); for (Class clazz : classes) { if (!configuration.hasMapper(clazz)) { configuration.addMapper(clazz); } MyBatisMetadata metadata = new MyBatisMetadata(clazz); metadatas.put(metadata.getOrmClass(), metadata); String maximumIdSql = StringUtility.format(MAXIMUM_ID, metadata.getColumnName(metadata.getPrimaryName())); maximumIdSqls.put(metadata.getOrmClass(), maximumIdSql); String minimumIdSql = StringUtility.format(MINIMUM_ID, metadata.getColumnName(metadata.getPrimaryName())); minimumIdSqls.put(metadata.getOrmClass(), minimumIdSql); } }
Example #2
Source File: PartTreeMybatisQuery.java From spring-data-mybatis with Apache License 2.0 | 6 votes |
PartTreeMybatisQuery(MybatisQueryMethod method, SqlSessionTemplate sqlSessionTemplate) { super(method, sqlSessionTemplate); Class<?> domainClass = method.getEntityInformation().getJavaType(); this.parameters = method.getParameters(); boolean recreationRequired = parameters.hasDynamicProjection() || parameters.potentiallySortsDynamically(); try { this.tree = new PartTree(method.getName(), domainClass); } catch (Exception o_O) { throw new IllegalArgumentException( String.format("Failed to create query for method %s! %s", method, o_O.getMessage()), o_O); } this.execution = createExecution(); }
Example #3
Source File: MybatisQueryLookupStrategy.java From spring-data-mybatis with Apache License 2.0 | 6 votes |
public static QueryLookupStrategy create(SqlSessionTemplate sqlSessionTemplate, Key key, QueryMethodEvaluationContextProvider evaluationContextProvider) { Assert.notNull(sqlSessionTemplate, "SqlSessionTemplate must not be null!"); Assert.notNull(evaluationContextProvider, "EvaluationContextProvider must not be null!"); switch (key != null ? key : Key.CREATE_IF_NOT_FOUND) { case CREATE: return new CreateQueryLookupStrategy(sqlSessionTemplate); case USE_DECLARED_QUERY: return new DeclaredQueryLookupStrategy(sqlSessionTemplate, evaluationContextProvider); case CREATE_IF_NOT_FOUND: return new CreateIfNotFoundQueryLookupStrategy(sqlSessionTemplate, new CreateQueryLookupStrategy(sqlSessionTemplate), new DeclaredQueryLookupStrategy(sqlSessionTemplate, evaluationContextProvider)); default: throw new IllegalArgumentException( String.format("Unsupported query lookup strategy %s!", key)); } }
Example #4
Source File: MapperShardingInitializer.java From tsharding with MIT License | 6 votes |
@Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { Map<String, SqlSessionFactory> sqlSessionFactories = applicationContext.getBeansOfType(SqlSessionFactory.class); if (sqlSessionFactories.isEmpty()) { return; } MapperHelperForSharding mapperHelperForSharding = new MapperHelperForSharding(); List<SqlSession> sqlSessions = new ArrayList<>(sqlSessionFactories.size()); for (SqlSessionFactory sqlSessionFactory : sqlSessionFactories.values()) { SqlSession sqlSession = new SqlSessionTemplate(sqlSessionFactory); sqlSessions.add(sqlSession); } //Mapper代码增强 每个方法扩展出一个ShardingMapper类,增强为512个方法。 this.needEnhancedClassesArray = needEnhancedClasses.split(","); this.enhanceMapperClass(); mapperHelperForSharding.setMappers(needEnhancedClassesArray); mapperHelperForSharding.setSqlSessions(sqlSessions.toArray(new SqlSession[0])); mapperHelperForSharding.initMapper(); }
Example #5
Source File: JobsDatabaseAutoConfiguration.java From zuihou-admin-boot with Apache License 2.0 | 5 votes |
@Bean(DATABASE_PREFIX + "SqlSessionTemplate") public SqlSessionTemplate getSqlSessionTemplate(@Qualifier(DATABASE_PREFIX + "SqlSessionFactory") SqlSessionFactory sqlSessionFactory) { ExecutorType executorType = this.properties.getExecutorType(); if (executorType != null) { return new SqlSessionTemplate(sqlSessionFactory, executorType); } else { return new SqlSessionTemplate(sqlSessionFactory); } }
Example #6
Source File: FileDatabaseAutoConfiguration.java From zuihou-admin-cloud with Apache License 2.0 | 5 votes |
@Bean(DATABASE_PREFIX + "SqlSessionTemplate") public SqlSessionTemplate getSqlSessionTemplate(@Qualifier(DATABASE_PREFIX + "SqlSessionFactory") SqlSessionFactory sqlSessionFactory) { ExecutorType executorType = this.properties.getExecutorType(); if (executorType != null) { return new SqlSessionTemplate(sqlSessionFactory, executorType); } else { return new SqlSessionTemplate(sqlSessionFactory); } }
Example #7
Source File: DemoDatabaseAutoConfiguration.java From zuihou-admin-cloud with Apache License 2.0 | 5 votes |
@Bean(DATABASE_PREFIX + "SqlSessionTemplate") public SqlSessionTemplate getSqlSessionTemplate(@Qualifier(DATABASE_PREFIX + "SqlSessionFactory") SqlSessionFactory sqlSessionFactory) { ExecutorType executorType = this.properties.getExecutorType(); if (executorType != null) { return new SqlSessionTemplate(sqlSessionFactory, executorType); } else { return new SqlSessionTemplate(sqlSessionFactory); } }
Example #8
Source File: OauthDatabaseAutoConfiguration.java From zuihou-admin-cloud with Apache License 2.0 | 5 votes |
@Bean(DATABASE_PREFIX + "SqlSessionTemplate") public SqlSessionTemplate getSqlSessionTemplate(@Qualifier(DATABASE_PREFIX + "SqlSessionFactory") SqlSessionFactory sqlSessionFactory) { ExecutorType executorType = this.properties.getExecutorType(); if (executorType != null) { return new SqlSessionTemplate(sqlSessionFactory, executorType); } else { return new SqlSessionTemplate(sqlSessionFactory); } }
Example #9
Source File: SimpleMybatisRepository.java From spring-data-mybatis with Apache License 2.0 | 5 votes |
public SimpleMybatisRepository(SqlSessionTemplate sqlSessionTemplate, RepositoryInformation repositoryInformation, MybatisEntityInformation<T, ID> entityInformation) { super(sqlSessionTemplate); Assert.notNull(entityInformation, "EntityInformation must not be null!"); this.namespace = repositoryInformation.getRepositoryInterface().getName(); this.entityInformation = entityInformation; }
Example #10
Source File: OrderDatabaseAutoConfiguration.java From zuihou-admin-cloud with Apache License 2.0 | 5 votes |
@Bean(DATABASE_PREFIX + "SqlSessionTemplate") public SqlSessionTemplate getSqlSessionTemplate(@Qualifier(DATABASE_PREFIX + "SqlSessionFactory") SqlSessionFactory sqlSessionFactory) { ExecutorType executorType = this.properties.getExecutorType(); if (executorType != null) { return new SqlSessionTemplate(sqlSessionFactory, executorType); } else { return new SqlSessionTemplate(sqlSessionFactory); } }
Example #11
Source File: MapperAutoConfiguration.java From Mapper with MIT License | 5 votes |
@Bean @ConditionalOnMissingBean public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory) { ExecutorType executorType = this.properties.getExecutorType(); if (executorType != null) { return new SqlSessionTemplate(sqlSessionFactory, executorType); } else { return new SqlSessionTemplate(sqlSessionFactory); } }
Example #12
Source File: JobsDatabaseAutoConfiguration.java From zuihou-admin-cloud with Apache License 2.0 | 5 votes |
@Bean(DATABASE_PREFIX + "SqlSessionTemplate") public SqlSessionTemplate getSqlSessionTemplate(@Qualifier(DATABASE_PREFIX + "SqlSessionFactory") SqlSessionFactory sqlSessionFactory) { ExecutorType executorType = this.properties.getExecutorType(); if (executorType != null) { return new SqlSessionTemplate(sqlSessionFactory, executorType); } else { return new SqlSessionTemplate(sqlSessionFactory); } }
Example #13
Source File: MybatisConfiguration.java From saluki with Apache License 2.0 | 5 votes |
@Bean public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory) { if (sqlSessionFactory == null) { return null; } return new SqlSessionTemplate(sqlSessionFactory); }
Example #14
Source File: GenericJpaRepositoryFactory.java From genericdao with Artistic License 2.0 | 5 votes |
public GenericJpaRepositoryFactory(EntityManager entityManager , SqlSessionTemplate sqlSessionTemplate) { super(entityManager) ; //设置当前类的实体管理器 this.entityManager = entityManager ; //设置sqlSessionTemplate,线程安全 this.sqlSessionTemplate = sqlSessionTemplate ; this.extractor = PersistenceProvider.fromEntityManager(entityManager); }
Example #15
Source File: MyBatisDaoImpl.java From aaden-pay with Apache License 2.0 | 5 votes |
public Connection getConnection() { SqlSessionTemplate st = (SqlSessionTemplate) getSqlSession(); Connection connection = SqlSessionUtils .getSqlSession(st.getSqlSessionFactory(), st.getExecutorType(), st.getPersistenceExceptionTranslator()) .getConnection(); return connection; // return getSqlSession().getConnection(); }
Example #16
Source File: MybatisQueryLookupStrategy.java From spring-data-mybatis with Apache License 2.0 | 5 votes |
@Override protected RepositoryQuery resolveQuery(MybatisQueryMethod method, SqlSessionTemplate sqlSessionTemplate, NamedQueries namedQueries) { if (method.isAnnotatedQuery()) { return new SimpleMybatisQuery(method, sqlSessionTemplate); } throw new IllegalStateException(String.format( "Did neither find a NamedQuery nor an annotated query for method %s!", method)); }
Example #17
Source File: MybatisAutoConfiguration.java From spring-boot-mybatis-rw with Apache License 2.0 | 5 votes |
@Bean public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory) { ExecutorType executorType = this.properties.getExecutorType(); if (executorType != null) { return new SqlSessionTemplate(sqlSessionFactory, executorType); } else { return new SqlSessionTemplate(sqlSessionFactory); } }
Example #18
Source File: MybatisRepositoryQuery.java From genericdao with Artistic License 2.0 | 5 votes |
public MybatisRepositoryQuery(SqlSessionTemplate sqlSessionTemplate , Method method, RepositoryMetadata repositoryMetadata){ this.sqlSessionTemplate = sqlSessionTemplate ; this.method = method ; this.repositoryMetadata = repositoryMetadata ; log.info("{}的领域类{}",repositoryMetadata.getRepositoryInterface().getName() , repositoryMetadata.getDomainType() ); if(!mybatisMapperMap.containsKey(getMapperKey())){ Object mapper = sqlSessionTemplate.getMapper(repositoryMetadata.getRepositoryInterface()) ; mybatisMapperMap.put(getMapperKey() , mapper) ; } }
Example #19
Source File: SqlSessionTemplateITBase.java From pinpoint with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); Configuration configuration = mock(Configuration.class); TransactionFactory transactionFactory = mock(TransactionFactory.class); DataSource dataSource = mock(DataSource.class); Environment environment = new Environment("test", transactionFactory, dataSource); when(configuration.getEnvironment()).thenReturn(environment); when(this.sqlSessionFactory.getConfiguration()).thenReturn(configuration); when(this.sqlSessionFactory.openSession(EXECUTOR_TYPE)).thenReturn(this.sqlSessionProxy); this.sqlSessionTemplate = new SqlSessionTemplate(this.sqlSessionFactory, EXECUTOR_TYPE); }
Example #20
Source File: DataSourceConfig.java From EasyReport with Apache License 2.0 | 5 votes |
@Primary @Bean(name = "sqlSessionTemplate") public SqlSessionTemplate sqlSessionTemplate(@Qualifier("sqlSessionFactory") final SqlSessionFactory sqlSessionFactory) throws Exception { return this.createSqlSessionTemplate(sqlSessionFactory); }
Example #21
Source File: SimpleMybatisQuery.java From spring-data-mybatis with Apache License 2.0 | 5 votes |
protected SimpleMybatisQuery(MybatisQueryMethod method, SqlSessionTemplate sqlSessionTemplate) { super(method, sqlSessionTemplate); commandType = SELECT; if (StringUtils.hasText(method.getAnnotatedQuery())) { String sql = method.getAnnotatedQuery(); stringQuery = new StringQuery(sql); if (method.isModifyingQuery()) { SqlCommandType type = method.getModifyingType(); if (null == type) { // auto judge if (sql.toLowerCase().startsWith("insert")) { commandType = INSERT; } else if (sql.toLowerCase().startsWith("update")) { commandType = UPDATE; } else if (sql.toLowerCase().startsWith("delete")) { commandType = DELETE; } else { commandType = UNKNOWN; } } else { commandType = type; } } } this.execution = createExecution(); }
Example #22
Source File: DataSource2Config.java From Resource with GNU General Public License v3.0 | 5 votes |
@Bean(name = "db2SqlSessionTemplate") public SqlSessionTemplate setSqlSessionTemplate( @Qualifier("db2SqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception { return new SqlSessionTemplate(sqlSessionFactory); }
Example #23
Source File: MapperAutoConfiguration.java From mapper-boot-starter with MIT License | 5 votes |
@Bean @ConditionalOnMissingBean public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory) { ExecutorType executorType = this.properties.getExecutorType(); if (executorType != null) { return new SqlSessionTemplate(sqlSessionFactory, executorType); } else { return new SqlSessionTemplate(sqlSessionFactory); } }
Example #24
Source File: MapperAutoConfiguration.java From mapper-boot-starter with MIT License | 5 votes |
@Bean @ConditionalOnMissingBean public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory) { ExecutorType executorType = this.properties.getExecutorType(); if (executorType != null) { return new SqlSessionTemplate(sqlSessionFactory, executorType); } else { return new SqlSessionTemplate(sqlSessionFactory); } }
Example #25
Source File: LocaleDAOImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
public final void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) { this.template = sqlSessionTemplate; }
Example #26
Source File: SqlSessionTemplateWrapper.java From tcc-transaction with Apache License 2.0 | 4 votes |
@Override public SqlSessionTemplate getObject() throws Exception { return sqlSessionTemplate; }
Example #27
Source File: ContentDataDAOImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
public final void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) { this.template = sqlSessionTemplate; }
Example #28
Source File: AbstractDataSourceConfig.java From EasyReport with Apache License 2.0 | 4 votes |
protected SqlSessionTemplate createSqlSessionTemplate(final SqlSessionFactory sqlSessionFactory) throws Exception { return new SqlSessionTemplate(sqlSessionFactory); }
Example #29
Source File: LockDAOImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
public final void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) { this.template = sqlSessionTemplate; }
Example #30
Source File: MybatisQueryLookupStrategy.java From spring-data-mybatis with Apache License 2.0 | 4 votes |
@Override protected RepositoryQuery resolveQuery(MybatisQueryMethod method, SqlSessionTemplate sqlSessionTemplate, NamedQueries namedQueries) { return new PartTreeMybatisQuery(method, sqlSessionTemplate); }