當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。