當前位置: 首頁>>代碼示例>>Java>>正文


Java Resources類代碼示例

本文整理匯總了Java中org.apache.ibatis.io.Resources的典型用法代碼示例。如果您正苦於以下問題:Java Resources類的具體用法?Java Resources怎麽用?Java Resources使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Resources類屬於org.apache.ibatis.io包,在下文中一共展示了Resources類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: bindMapperForNamespace

import org.apache.ibatis.io.Resources; //導入依賴的package包/類
private void bindMapperForNamespace() {
    String namespace = builderAssistant.getCurrentNamespace();
    if (namespace != null) {
        Class<?> boundType = null;
        try {
            boundType = Resources.classForName(namespace);
        } catch (ClassNotFoundException e) {
            // ignore, bound type is not required
        }
        if (boundType != null) {
            if (!configuration.hasMapper(boundType)) {
                // Spring may not know the real resource name so we set a
                // flag
                // to prevent loading again this resource from the mapper
                // interface
                // look at MapperAnnotationBuilder#loadXmlResource
                configuration.addLoadedResource("namespace:" + namespace);
                configuration.addMapper(boundType);
            }
            //TODO 注入 CURD 動態 SQL
            if (BaseMapper.class.isAssignableFrom(boundType)) {
                GlobalConfigUtils.getSqlInjector(configuration).inspectInject(builderAssistant, boundType);
            }
        }
    }
}
 
開發者ID:Caratacus,項目名稱:mybatis-plus-mini,代碼行數:27,代碼來源:MybatisXMLMapperBuilder.java

示例2: loadXmlResource

import org.apache.ibatis.io.Resources; //導入依賴的package包/類
/**
 * <p>
 * 是否存在XML(該方法並不能客觀的判斷resource的路徑,隻是Mybatis默認認為的xml路徑)
 * </p>
 *
 * @return true 存在, false 不存在
 */
private boolean loadXmlResource() {
    boolean flag = true;
    // Spring may not know the real resource name so we check a flag
    // to prevent loading again a resource twice
    // this flag is set at XMLMapperBuilder#bindMapperForNamespace
    if (!configuration.isResourceLoaded("namespace:" + type.getName())) {
        String xmlResource = type.getName().replace('.', '/') + ".xml";
        InputStream inputStream = null;
        try {
            inputStream = Resources.getResourceAsStream(type.getClassLoader(), xmlResource);
        } catch (IOException e) {
            // ignore, resource is not required
            flag = false;
        }
        if (inputStream != null) {
            MybatisXMLMapperBuilder xmlParser = new MybatisXMLMapperBuilder(inputStream, assistant.getConfiguration(),
                    xmlResource, configuration.getSqlFragments(), type.getName());
            xmlParser.parse();
        }
    }
    return flag;
}
 
開發者ID:Caratacus,項目名稱:mybatis-plus-mini,代碼行數:30,代碼來源:MybatisMapperAnnotationBuilder.java

示例3: typeAliasesElement

import org.apache.ibatis.io.Resources; //導入依賴的package包/類
private void typeAliasesElement(XNode parent) {
    if (parent != null) {
        for (XNode child : parent.getChildren()) {
            if ("package".equals(child.getName())) {
                String typeAliasPackage = child.getStringAttribute("name");
                configuration.getTypeAliasRegistry().registerAliases(typeAliasPackage);
            } else {
                String alias = child.getStringAttribute("alias");
                String type = child.getStringAttribute("type");
                try {
                    Class<?> clazz = Resources.classForName(type);
                    if (alias == null) {
                        typeAliasRegistry.registerAlias(clazz);
                    } else {
                        typeAliasRegistry.registerAlias(alias, clazz);
                    }
                } catch (ClassNotFoundException e) {
                    throw new BuilderException("Error registering typeAlias for '" + alias + "'. Cause: " + e, e);
                }
            }
        }
    }
}
 
開發者ID:Caratacus,項目名稱:mybatis-plus-mini,代碼行數:24,代碼來源:MybatisXMLConfigBuilder.java

示例4: propertiesElement

import org.apache.ibatis.io.Resources; //導入依賴的package包/類
private void propertiesElement(XNode context) throws Exception {
    if (context != null) {
        Properties defaults = context.getChildrenAsProperties();
        String resource = context.getStringAttribute("resource");
        String url = context.getStringAttribute("url");
        if (resource != null && url != null) {
            throw new BuilderException("The properties element cannot specify both a URL and a resource based property file reference.  Please specify one or the other.");
        }
        if (resource != null) {
            defaults.putAll(Resources.getResourceAsProperties(resource));
        } else if (url != null) {
            defaults.putAll(Resources.getUrlAsProperties(url));
        }
        Properties vars = configuration.getVariables();
        if (vars != null) {
            defaults.putAll(vars);
        }
        parser.setVariables(defaults);
        configuration.setVariables(defaults);
    }
}
 
開發者ID:Caratacus,項目名稱:mybatis-plus-mini,代碼行數:22,代碼來源:MybatisXMLConfigBuilder.java

示例5: mapperElement

import org.apache.ibatis.io.Resources; //導入依賴的package包/類
private void mapperElement(XNode parent) throws Exception {
    /**
     * 定義集合 用來分類放置mybatis的Mapper與XML 按順序依次遍曆
     */
    if (parent != null) {
        //指定在classpath中的mapper文件
        Set<String> resources = new HashSet<>();
        //指向一個mapper接口
        Set<Class<?>> mapperClasses = new HashSet<>();
        setResource(parent, resources, mapperClasses);
        // 依次遍曆 首先 resource 然後 mapper
        for (String resource : resources) {
            ErrorContext.instance().resource(resource);
            InputStream inputStream = Resources.getResourceAsStream(resource);
            //TODO
            MybatisXMLMapperBuilder mapperParser = new MybatisXMLMapperBuilder(inputStream, configuration, resource,
                    configuration.getSqlFragments());
            mapperParser.parse();
        }
        for (Class<?> mapper : mapperClasses) {
            //TODO
            configuration.addMapper(mapper);
        }
    }
}
 
開發者ID:Caratacus,項目名稱:mybatis-plus-mini,代碼行數:26,代碼來源:MybatisXMLConfigBuilder.java

示例6: propertiesElement

import org.apache.ibatis.io.Resources; //導入依賴的package包/類
private void propertiesElement(XNode context) throws Exception {
  if (context != null) {
    Properties defaults = context.getChildrenAsProperties();
    String resource = context.getStringAttribute("resource");
    String url = context.getStringAttribute("url");
    if (resource != null && url != null) {
      throw new BuilderException("The properties element cannot specify both a URL and a resource based property file reference.  Please specify one or the other.");
    }
    if (resource != null) {
      defaults.putAll(Resources.getResourceAsProperties(resource));
    } else if (url != null) {
      defaults.putAll(Resources.getUrlAsProperties(url));
    }
    Properties vars = configuration.getVariables();
    if (vars != null) {
      defaults.putAll(vars);
    }
    parser.setVariables(defaults);
    configuration.setVariables(defaults);
  }
}
 
開發者ID:Alfresco,項目名稱:alfresco-core,代碼行數:22,代碼來源:HierarchicalXMLConfigBuilder.java

示例7: BaseDao

import org.apache.ibatis.io.Resources; //導入依賴的package包/類
BaseDao() {
    //判斷SessionFactory是否初始化過,初始化過後就不重複初始化,保證係統的運行效率。
    if (!isInit) {
        try {
            //讀入Mybatis配置文件
            inputStream = Resources.getResourceAsStream(resource);
            //通過配置文件構建sql數據工廠
            sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
            System.out.println("getConnectionSuccful");
            isInit = true;
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {
        System.out.println("already init");
    }
}
 
開發者ID:okingjerryo,項目名稱:WeiMusicCommunity-server,代碼行數:18,代碼來源:BaseDao.java

示例8: setUp

import org.apache.ibatis.io.Resources; //導入依賴的package包/類
@BeforeClass
public static void setUp() throws Exception {
    System.out.println("Starting up CmsCmProcessor tests");
 String resource = "mybatis-config.xml";
 Reader reader = Resources.getResourceAsReader( resource );
 SqlSessionFactory sf = new SqlSessionFactoryBuilder().build(reader);
    session = sf.openSession();
 clazzMapper = session.getMapper(ClazzMapper.class);
    ciMapper = session.getMapper(CIMapper.class);
    mdValidator = new CmsMdValidator();
    cmValidator = new CmsCmValidator();
 mdProcessor = new CmsMdProcessor();
 mdProcessor.setClazzMapper( clazzMapper );
 mdProcessor.setMdValidator(mdValidator);
    cmProcessor = new CmsCmProcessor();
    cmProcessor.setCiMapper(ciMapper);
    cmProcessor.setMdProcessor(mdProcessor);
    cmProcessor.setCmValidator(cmValidator);
    RelationMapper relationMapper=session.getMapper(RelationMapper.class);
    mdProcessor.setRelationMapper(relationMapper);
    
}
 
開發者ID:oneops,項目名稱:oneops,代碼行數:23,代碼來源:CmsCmProcessorTest.java

示例9: build

import org.apache.ibatis.io.Resources; //導入依賴的package包/類
/**
 * Create an instance of MyBatis.
 *
 * @param environment The dropwizard environment
 * @param config A Mybatis config object
 * @param dataSource
 * @param name The name of this mybatis factory used for metrics
 * @return An instance of MyBatis.
 */
public final SqlSessionFactory build(Environment environment,
        MyBatisConfiguration config,
        ManagedDataSource dataSource,
        String name) {

    SqlSessionFactory sessionFactory = null;

    // Try to use the mybatis configuration file if it is specified and exists.
    try (InputStream inputStream = Resources.getResourceAsStream(config.getConfigFile())) {
        sessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
    } catch (IOException ioe) {
        // Build session factory from configuration values given in the dropwizard config.
        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);
        sessionFactory = new SqlSessionFactoryBuilder().build(mybatisConfiguration);
    }

    environment.lifecycle().manage(dataSource);
    environment.healthChecks().register(name,
            new MyBatisHealthCheck(sessionFactory, config.getConfig().getValidationQuery()));

    return sessionFactory;
}
 
開發者ID:cvent,項目名稱:dropwizard-mybatis,代碼行數:35,代碼來源:MyBatisFactory.java

示例10: setUp

import org.apache.ibatis.io.Resources; //導入依賴的package包/類
@BeforeClass
public static void setUp() throws Exception {
  // create a SqlSessionFactory
  Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/call_setters_on_nulls/mybatis-config-2.xml");
  sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
  reader.close();

  // populate in-memory database
  SqlSession session = sqlSessionFactory.openSession();
  Connection conn = session.getConnection();
  reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/call_setters_on_nulls/CreateDB.sql");
  ScriptRunner runner = new ScriptRunner(conn);
  runner.setLogWriter(null);
  runner.runScript(reader);
  reader.close();
  session.close();
}
 
開發者ID:yuexiahandao,項目名稱:MybatisCode,代碼行數:18,代碼來源:DoNotCallSettersOnNullsTest.java

示例11: classForName

import org.apache.ibatis.io.Resources; //導入依賴的package包/類
@Override
public Class classForName(String className, Map context) throws ClassNotFoundException {
  Class<?> result = null;
  if ((result = classes.get(className)) == null) {
    try {
      result = Resources.classForName(className);
    } catch (ClassNotFoundException e1) {
      if (className.indexOf('.') == -1) {
        result = Resources.classForName("java.lang." + className);
        classes.put("java.lang." + className, result);
      }
    }
    classes.put(className, result);
  }
  return result;
}
 
開發者ID:yuexiahandao,項目名稱:MybatisCode,代碼行數:17,代碼來源:OgnlClassResolver.java

示例12: setUp

import org.apache.ibatis.io.Resources; //導入依賴的package包/類
@BeforeClass
public static void setUp() throws Exception {
  Connection conn = null;

  try {
    Class.forName("org.hsqldb.jdbcDriver");
    conn = DriverManager.getConnection("jdbc:hsqldb:mem:gname", "sa", "");
    Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/quotedcolumnnames/CreateDB.sql");
    ScriptRunner runner = new ScriptRunner(conn);
    runner.setLogWriter(null);
    runner.setErrorLogWriter(null);
    runner.runScript(reader);
    conn.commit();
    reader.close();

    reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/quotedcolumnnames/MapperConfig.xml");
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
    reader.close();

  } finally {
    if (conn != null) {
      conn.close();
    }
  }
}
 
開發者ID:txazo,項目名稱:mybatis,代碼行數:26,代碼來源:QuotedColumnNamesTest.java

示例13: setUp

import org.apache.ibatis.io.Resources; //導入依賴的package包/類
@BeforeClass
public static void setUp() throws Exception {
  // create a SqlSessionFactory
  Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/extendresultmap/mybatis-config.xml");
  sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
  reader.close();

  // populate in-memory database
  SqlSession session = sqlSessionFactory.openSession();
  Connection conn = session.getConnection();
  reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/extendresultmap/CreateDB.sql");
  ScriptRunner runner = new ScriptRunner(conn);
  runner.setLogWriter(null);
  runner.runScript(reader);
  reader.close();
  session.close();
}
 
開發者ID:txazo,項目名稱:mybatis,代碼行數:18,代碼來源:ExtendResultMapTest.java

示例14: testGetMessageForEmptyDatabase

import org.apache.ibatis.io.Resources; //導入依賴的package包/類
@BeforeClass
public static void testGetMessageForEmptyDatabase() throws Exception {
  final String resource = "org/apache/ibatis/submitted/initialized_collection_property/mybatis-config.xml";
  Reader reader = Resources.getResourceAsReader(resource);
  factory = new SqlSessionFactoryBuilder().build(reader);

  SqlSession session = factory.openSession();

  Connection conn = session.getConnection();
  ScriptRunner runner = new ScriptRunner(conn);
  runner.setLogWriter(null);
  runner.setErrorLogWriter(null);
  reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/initialized_collection_property/create.sql");
  runner.runScript(reader);
  session.close();
}
 
開發者ID:txazo,項目名稱:mybatis,代碼行數:17,代碼來源:AuthorDAOTest.java

示例15: initDatabase

import org.apache.ibatis.io.Resources; //導入依賴的package包/類
@Before
public void initDatabase() throws Exception {
  Connection conn = null;

  try {
    Class.forName("org.hsqldb.jdbcDriver");
    conn = DriverManager.getConnection("jdbc:hsqldb:mem:force_flush_on_select", "sa", "");

    Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/force_flush_on_select/CreateDB.sql");
    ScriptRunner runner = new ScriptRunner(conn);
    runner.setLogWriter(null);
    runner.setErrorLogWriter(null);
    runner.runScript(reader);
    conn.commit();
    reader.close();

    reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/force_flush_on_select/ibatisConfig.xml");
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
    reader.close();
  } finally {
    if (conn != null) {
      conn.close();
    }
  }
}
 
開發者ID:txazo,項目名稱:mybatis,代碼行數:26,代碼來源:ForceFlushOnSelectTest.java


注:本文中的org.apache.ibatis.io.Resources類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。