当前位置: 首页>>代码示例>>Java>>正文


Java Configuration类代码示例

本文整理汇总了Java中org.apache.ibatis.session.Configuration的典型用法代码示例。如果您正苦于以下问题:Java Configuration类的具体用法?Java Configuration怎么用?Java Configuration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Configuration类属于org.apache.ibatis.session包,在下文中一共展示了Configuration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: intercept

import org.apache.ibatis.session.Configuration; //导入依赖的package包/类
public Object intercept(Invocation invocation) throws Throwable {
    /**
     * 处理 DELETE UPDATE 语句
     */
    MappedStatement ms = (MappedStatement) invocation.getArgs()[0];
    if (ms.getSqlCommandType() == SqlCommandType.DELETE || ms.getSqlCommandType() == SqlCommandType.UPDATE) {
        Executor executor = (Executor) invocation.getTarget();
        Configuration configuration = ms.getConfiguration();
        Object parameter = invocation.getArgs()[1];
        BoundSql boundSql = ms.getBoundSql(parameter);
        Connection connection = executor.getTransaction().getConnection();
        String databaseVersion = connection.getMetaData().getDatabaseProductVersion();
        if (GlobalConfigUtils.getDbType(configuration).equals(DBType.MYSQL)
                && VersionUtils.compare(minMySQLVersion, databaseVersion)) {
            logger.warn("Warn: Your mysql version needs to be greater than '5.6.3' to execute of Sql Explain!");
            return invocation.proceed();
        }
        /**
         * 执行 SQL 分析
         */
        sqlExplain(configuration, ms, boundSql, connection, parameter);
    }
    return invocation.proceed();
}
 
开发者ID:Caratacus,项目名称:mybatis-plus-mini,代码行数:25,代码来源:SqlExplainInterceptor.java

示例2: intercept

import org.apache.ibatis.session.Configuration; //导入依赖的package包/类
@Override
public Object intercept(Invocation invocation) throws Throwable {
    if (!statementTracer.isTraceEnabled()) {
        return invocation.proceed();
    }
    MetaObject metaObject = MetaObjectUtils.findTargetObject(invocation);
    BoundSql boundSql = MetaObjectUtils.getBoundSql(metaObject);
    Configuration configuration = MetaObjectUtils.getConfiguration(metaObject);
    Exception queryException = null;
    try {
        beginTrace(boundSql.getSql(), configuration.getEnvironment());
        return invocation.proceed();
    } catch (Exception ex) {
        queryException = ex;
        throw ex;
    } finally {
        statementTracer.endTrace(0, queryException);
    }
}
 
开发者ID:YanXs,项目名称:nighthawk,代码行数:20,代码来源:MybatisTracingInterceptor.java

示例3: bindAlias

import org.apache.ibatis.session.Configuration; //导入依赖的package包/类
void bindAlias(_MyBatis myBatis)
{
    SqlSessionFactory sqlSessionFactory = mybatisConfig.mSqlSessionFactoryBuilder.getFactory();
    Configuration configuration = sqlSessionFactory.getConfiguration();
    TypeAliasRegistry typeAliasRegistry = configuration.getTypeAliasRegistry();

    if (WPTool.notNullAndEmpty(myBatis.daoAlias))
    {
        typeAliasRegistry.registerAlias(myBatis.daoAlias, myBatis.daoClass);
    } else if (myBatis.isAutoAlias)
    {
        typeAliasRegistry.registerAlias(myBatis.daoClass);
    }

    if (!myBatis.entityClass.equals(MyBatis.class))
    {
        if (WPTool.notNullAndEmpty(myBatis.entityAlias))
        {
            typeAliasRegistry.registerAlias(myBatis.entityAlias, myBatis.entityClass);
        } else if (myBatis.isAutoAlias)
        {
            typeAliasRegistry.registerAlias(myBatis.entityClass);
        }
    }

}
 
开发者ID:gzxishan,项目名称:OftenPorter,代码行数:27,代码来源:MyBatisDaoGen.java

示例4: ExampleValidSqlNode

import org.apache.ibatis.session.Configuration; //导入依赖的package包/类
@Deprecated
public IfSqlNode ExampleValidSqlNode(Configuration configuration) {
    List<SqlNode> whenSqlNodes = new ArrayList<SqlNode>();
    IfSqlNode noValueSqlNode = new IfSqlNode(new TextSqlNode(" and ${criterion.condition}"), "criterion.noValue");
    whenSqlNodes.add(noValueSqlNode);
    IfSqlNode singleValueSqlNode = new IfSqlNode(new TextSqlNode(" and ${criterion.condition} #{criterion.value}"), "criterion.singleValue");
    whenSqlNodes.add(singleValueSqlNode);
    IfSqlNode betweenValueSqlNode = new IfSqlNode(new TextSqlNode(" and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}"), "criterion.betweenValue");
    whenSqlNodes.add(betweenValueSqlNode);

    List<SqlNode> listValueContentSqlNodes = new ArrayList<SqlNode>();
    listValueContentSqlNodes.add(new TextSqlNode(" and ${criterion.condition}"));
    ForEachSqlNode listValueForEachSqlNode = new ForEachSqlNode(configuration, new StaticTextSqlNode("#{listItem}"), "criterion.value", null, "listItem", "(", ")", ",");
    listValueContentSqlNodes.add(listValueForEachSqlNode);
    IfSqlNode listValueSqlNode = new IfSqlNode(new MixedSqlNode(listValueContentSqlNodes), "criterion.listValue");
    whenSqlNodes.add(listValueSqlNode);

    ChooseSqlNode chooseSqlNode = new ChooseSqlNode(whenSqlNodes, null);

    ForEachSqlNode criteriaSqlNode = new ForEachSqlNode(configuration, chooseSqlNode, "criteria.criteria", null, "criterion", null, null, null);

    TrimSqlNode trimSqlNode = new TrimSqlNode(configuration, criteriaSqlNode, "(", "and", ")", null);
    IfSqlNode validSqlNode = new IfSqlNode(trimSqlNode, "criteria.valid");
    return validSqlNode;
}
 
开发者ID:Yanweichen,项目名称:MybatisGeneatorUtil,代码行数:26,代码来源:MapperTemplate.java

示例5: RollupResultHandler

import org.apache.ibatis.session.Configuration; //导入依赖的package包/类
/**
 * @param keyProperties         the properties that make up the unique key
 * @param collectionProperty    the property mapped using a nested <b>ResultMap</b>
 * @param resultHandler         the result handler that will receive the rolled-up results
 * @param maxResults            the maximum number of results to retrieve (-1 for no limit).
 *                              Make sure that the query result limit is large enough to produce this
 *                              at least this number of results
 */
public RollupResultHandler(Configuration configuration, String[] keyProperties, String collectionProperty, ResultHandler resultHandler, int maxResults)
{
    if (keyProperties == null || keyProperties.length == 0)
    {
        throw new IllegalArgumentException("RollupRowHandler can only be used with at least one key property.");
    }
    if (collectionProperty == null)
    {
        throw new IllegalArgumentException("RollupRowHandler must have a collection property.");
    }
    this.configuration = configuration;
    this.keyProperties = keyProperties;
    this.collectionProperty = collectionProperty;
    this.resultHandler = resultHandler;
    this.maxResults = maxResults;
    this.rawResults = new ArrayList<Object>(100);
}
 
开发者ID:Alfresco,项目名称:alfresco-core,代码行数:26,代码来源:RollupResultHandler.java

示例6: coalesceResults

import org.apache.ibatis.session.Configuration; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static Object coalesceResults(Configuration configuration, List<Object> valueObjects, String collectionProperty)
{
    // Take the first result as the base value
    Object resultObject = null;
    MetaObject probe = null;
    Collection<Object> collection = null;
    for (Object object : valueObjects)
    {
        if (collection == null)
        {
            resultObject = object;
            probe = configuration.newMetaObject(resultObject);
            collection = (Collection<Object>) probe.getValue(collectionProperty);
        }
        else
        {
            Collection<?> addedValues = (Collection<Object>) probe.getValue(collectionProperty);
            collection.addAll(addedValues);
        }
    }
    // Done
    return resultObject;
}
 
开发者ID:Alfresco,项目名称:alfresco-core,代码行数:25,代码来源:RollupResultHandler.java

示例7: build

import org.apache.ibatis.session.Configuration; //导入依赖的package包/类
/**
 * Create an instance of MyBatis.
 *
 * @param environment The dropwizard environment
 * @param configuration The data source factory/configuration
 * @param dataSource The datasource you want to use.
 * @param name The name of this mybatis factory used for metrics
 * @return An instance of MyBatis.
 */
public final SqlSessionFactory build(Environment environment,
        DataSourceFactory configuration,
        ManagedDataSource dataSource,
        String name) {
    // Initialize validation query
    final String validationQuery = configuration.getValidationQuery();

    // Build mybatis session factory
    TransactionFactory transactionFactory = new JdbcTransactionFactory();
    org.apache.ibatis.mapping.Environment myBatisEnvironment =
            new org.apache.ibatis.mapping.Environment(ENV_NAME, transactionFactory, dataSource);
    Configuration mybatisConfiguration = new Configuration(myBatisEnvironment);
    SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(mybatisConfiguration);

    // Setup managed data source and health checks
    environment.lifecycle().manage(dataSource);
    environment.healthChecks().register(name, new MyBatisHealthCheck(sessionFactory, validationQuery));

    return sessionFactory;
}
 
开发者ID:cvent,项目名称:dropwizard-mybatis,代码行数:30,代码来源:MyBatisFactory.java

示例8: processConfiguration

import org.apache.ibatis.session.Configuration; //导入依赖的package包/类
/**
 * 配置指定的接口
 *
 * @param configuration
 * @param mapperInterface
 */
public void processConfiguration(Configuration configuration, Class<?> mapperInterface) {
    String prefix;
    if (mapperInterface != null) {
        prefix = mapperInterface.getCanonicalName();
    } else {
        prefix = "";
    }
    for (Object object : new ArrayList<Object>(configuration.getMappedStatements())) {
        if (object instanceof MappedStatement) {
            MappedStatement ms = (MappedStatement) object;
            if (ms.getId().startsWith(prefix) && isMapperMethod(ms.getId())) {
                if (ms.getSqlSource() instanceof ProviderSqlSource) {
                    setSqlSource(ms);
                }
            }
        }
    }
}
 
开发者ID:godlike110,项目名称:tk-mybatis,代码行数:25,代码来源:MapperHelper.java

示例9: createSqlSessionManager

import org.apache.ibatis.session.Configuration; //导入依赖的package包/类
/**
 * This method creates the sqlSessionManager of myBatis. It integrates all the SQL mappers
 *
 * @return a {@link SqlSessionFactory}
 */
private SqlSessionManager createSqlSessionManager() {
    Environment environment = new Environment(DEFAULT, this.transactionFactory,
        taskanaEngineConfiguration.getDatasource());
    Configuration configuration = new Configuration(environment);
    // add mappers
    configuration.addMapper(TaskMapper.class);
    configuration.addMapper(TaskMonitorMapper.class);
    configuration.addMapper(WorkbasketMapper.class);
    configuration.addMapper(DistributionTargetMapper.class);
    configuration.addMapper(ClassificationMapper.class);
    configuration.addMapper(WorkbasketAccessMapper.class);
    configuration.addMapper(ObjectReferenceMapper.class);
    configuration.addMapper(QueryMapper.class);
    configuration.addMapper(AttachmentMapper.class);
    configuration.getTypeHandlerRegistry().register(MapTypeHandler.class);
    SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(configuration);
    SqlSessionManager sessionManager = SqlSessionManager.newInstance(sessionFactory);
    return sessionManager;
}
 
开发者ID:Taskana,项目名称:taskana,代码行数:25,代码来源:TaskanaEngineImpl.java

示例10: init

import org.apache.ibatis.session.Configuration; //导入依赖的package包/类
public void init() throws IOException, SAXException, ParserConfigurationException, ClassNotFoundException {
	log.info("parse " + configLocation);
	// 解析xml
	InputStream inputStream=MapperScanApplication.class.getClassLoader().getResourceAsStream(configLocation);
	
	Configuration configuration = sqlSessionFactory.getConfiguration();

	if(inputStream==null){
		return;
	}
	XPathParser xPathParser = new XPathParser(inputStream);
	XNode root = xPathParser.evalNode("/configuration");

	handleSetting(configuration, root);

	handleTypeAlias(configuration, root);

	handleMappers(configuration, root);
}
 
开发者ID:babymm,项目名称:mumu,代码行数:20,代码来源:MapperScanApplication.java

示例11: selectUnionAll

import org.apache.ibatis.session.Configuration; //导入依赖的package包/类
public SqlNode selectUnionAll(Configuration configuration, String conditions, String orderBy, LockMode lockMode) {
	String sql = select(conditions, orderBy).toString();
	StringBuffer sqlSb = new StringBuffer();
	Matcher matcher = ARGUMENT_REGEX.matcher(sql);
	while (matcher.find()) {
		String name = matcher.group(1);
		matcher.appendReplacement(sqlSb, "#{item." + name + "}");
	}
	matcher.appendTail(sqlSb);
	if (lockMode == LockMode.UPGRADE) {
		sqlSb.append(" FOR UPDATE");
	} else if (lockMode == LockMode.UPGRADE_NOWAIT) {
		sqlSb.append(" FOR UPDATE NOWAIT");
	}
	SqlNode contents = new TextSqlNode(sqlSb.toString());
	String collectionExpression = "list";
	String index = "index";
	String item = "item";
	String open = "";
	String close = "";
	String separator = " UNION ALL ";
	return new ForEachSqlNode(configuration, contents, collectionExpression, index, item, open, close, separator);
}
 
开发者ID:yaoakeji,项目名称:hibatis,代码行数:24,代码来源:SqlBuilder.java

示例12: intercept

import org.apache.ibatis.session.Configuration; //导入依赖的package包/类
@Override
public Object intercept(Invocation invocation) throws Throwable {
	Object object=invocation.getArgs()[0];
	if(object instanceof MappedStatement){
		MappedStatement  statement=(MappedStatement) object;
		Configuration config = statement.getConfiguration();
		DataSource dataSource= config.getEnvironment().getDataSource();
		if(dataSource instanceof DynamicDataSource){
			DynamicDataSource dynamicDataSource=((DynamicDataSource)dataSource); 
			Dialect dialect= dynamicDataSource.getDialect();
			if(pageHelpers.containsKey(dialect)){
				log.debug("将使用{}的PageHelper....",dialect);
				return pageHelpers.get(dialect).intercept(invocation);
			}else{
				log.debug("将使用默认的PageHelper,dialect=({})的....",this.dialect);
			}
		}else{
			log.debug("将使用默认的PageHelper,dialect=({})的....",this.dialect);
		}
	}else{
		log.debug("将使用默认的PageHelper,dialect=({})的....",this.dialect);
	}
	return pageHelper.intercept(invocation);
}
 
开发者ID:halober,项目名称:spring-boot-starter-dao,代码行数:25,代码来源:CustomPageInterceptor.java

示例13: createSqlSessionFactoryBean

import org.apache.ibatis.session.Configuration; //导入依赖的package包/类
protected final AbstractBeanDefinition createSqlSessionFactoryBean(String dataSourceName, String mapperPackage,
		String typeAliasesPackage, Dialect dialect, Configuration configuration) {
	configuration.setDatabaseId(dataSourceName);
	BeanDefinitionBuilder bdb = BeanDefinitionBuilder.rootBeanDefinition(SqlSessionFactoryBean.class);
	bdb.addPropertyValue("configuration", configuration);
	bdb.addPropertyValue("failFast", true);
	bdb.addPropertyValue("typeAliases", this.saenTypeAliases(typeAliasesPackage));
	bdb.addPropertyReference("dataSource", dataSourceName);
	bdb.addPropertyValue("plugins", new Interceptor[] { new CustomPageInterceptor(dialect) });
	if (!StringUtils.isEmpty(mapperPackage)) {
		try {
			mapperPackage = new StandardEnvironment().resolveRequiredPlaceholders(mapperPackage);
			String mapperPackages = ClassUtils.convertClassNameToResourcePath(mapperPackage);
			String mapperPackagePath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + mapperPackages + "/*.xml";
			Resource[] resources = new PathMatchingResourcePatternResolver().getResources(mapperPackagePath);
			bdb.addPropertyValue("mapperLocations", resources);
		} catch (Exception e) {
			log.error("初始化失败", e);
			throw new RuntimeException( String.format("SqlSessionFactory 初始化失败  mapperPackage=%s", mapperPackage + ""));
		}
	}
	return bdb.getBeanDefinition();
}
 
开发者ID:halober,项目名称:spring-boot-starter-dao,代码行数:24,代码来源:AbstractDataBaseBean.java

示例14: build

import org.apache.ibatis.session.Configuration; //导入依赖的package包/类
/**
 * @param configuration
 * @param entity
 */
public static void build(Configuration configuration, LanguageDriver languageDriver,
                         EntityInfo entity) {
    String[] names = GeneralSqlGenerator.methodDefines.updateName().split(",");
    for (String name : names) {
        String msId = entity.getMapperClass().getName() + "." + name;

        EntityMapper entityMapper = EntityHelper.getEntityMapper(entity.getEntityClass());

        String sql = buildUpdateSql(entityMapper, name.endsWith("Selective"));

        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql,
                entity.getEntityClass());

        MappedStatement.Builder statementBuilder = new MappedStatement.Builder(configuration,
                msId, sqlSource, SqlCommandType.UPDATE);

        MappedStatement statement = statementBuilder.build();

        configuration.addMappedStatement(statement);
    }
}
 
开发者ID:warlock-china,项目名称:azeroth,代码行数:26,代码来源:UpdateBuilder.java

示例15: build

import org.apache.ibatis.session.Configuration; //导入依赖的package包/类
/**
 * @param configuration
 * @param entity
 */
public static void build(Configuration configuration, LanguageDriver languageDriver, EntityInfo entity) {
    String msId = entity.getMapperClass().getName() + "." + GeneralSqlGenerator.methodDefines.deleteName();

    // 从参数对象里提取注解信息
    EntityMapper entityMapper = EntityHelper.getEntityMapper(entity.getEntityClass());
    // 生成sql
    String sql = buildDeleteSql(entityMapper);

    SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, entity.getEntityClass());

    MappedStatement.Builder statementBuilder = new MappedStatement.Builder(configuration, msId, sqlSource, SqlCommandType.DELETE);

    MappedStatement statement = statementBuilder.build();
    configuration.addMappedStatement(statement);
}
 
开发者ID:warlock-china,项目名称:azeroth,代码行数:20,代码来源:DeleteBuilder.java


注:本文中的org.apache.ibatis.session.Configuration类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。