List of usage examples for org.apache.ibatis.session Configuration Configuration
public Configuration(Environment environment)
From source file:examples.joins.JoinMapperTest.java
License:Apache License
@BeforeEach public void setup() throws Exception { Class.forName(JDBC_DRIVER);//ww w.j a v a2 s.c om InputStream is = getClass().getResourceAsStream("/examples/joins/CreateJoinDB.sql"); try (Connection connection = DriverManager.getConnection(JDBC_URL, "sa", "")) { ScriptRunner sr = new ScriptRunner(connection); sr.setLogWriter(null); sr.runScript(new InputStreamReader(is)); } UnpooledDataSource ds = new UnpooledDataSource(JDBC_DRIVER, JDBC_URL, "sa", ""); Environment environment = new Environment("test", new JdbcTransactionFactory(), ds); Configuration config = new Configuration(environment); config.addMapper(JoinMapper.class); sqlSessionFactory = new SqlSessionFactoryBuilder().build(config); }
From source file:examples.paging.LimitAndOffsetTest.java
License:Apache License
@BeforeEach public void setup() throws Exception { Class.forName(JDBC_DRIVER);/* w w w .j av a2 s . c om*/ InputStream is = getClass().getResourceAsStream("/examples/animal/data/CreateAnimalData.sql"); try (Connection connection = DriverManager.getConnection(JDBC_URL, "sa", "")) { ScriptRunner sr = new ScriptRunner(connection); sr.setLogWriter(null); sr.runScript(new InputStreamReader(is)); } UnpooledDataSource ds = new UnpooledDataSource(JDBC_DRIVER, JDBC_URL, "sa", ""); Environment environment = new Environment("test", new JdbcTransactionFactory(), ds); Configuration config = new Configuration(environment); config.addMapper(LimitAndOffsetMapper.class); sqlSessionFactory = new SqlSessionFactoryBuilder().build(config); }
From source file:mbg.test.mb3.dsql.AbstractTest.java
License:Apache License
@Before public void setUp() throws Exception { createDatabase();/*from w w w . j a v a 2 s .c o m*/ UnpooledDataSource ds = new UnpooledDataSource(JDBC_DRIVER, JDBC_URL, "sa", ""); Environment environment = new Environment("test", new JdbcTransactionFactory(), ds); Configuration config = new Configuration(environment); config.addMapper(AwfulTableMapper.class); config.addMapper(FieldsblobsMapper.class); config.addMapper(FieldsonlyMapper.class); config.addMapper(PkblobsMapper.class); config.addMapper(PkfieldsblobsMapper.class); config.addMapper(PkfieldsMapper.class); config.addMapper(PkonlyMapper.class); sqlSessionFactory = new SqlSessionFactoryBuilder().build(config); }
From source file:mbg.test.mb3.dsql.miscellaneous.AbstractAnnotatedMiscellaneousTest.java
License:Apache License
@Before public void setUp() throws Exception { createDatabase();/* www . jav a 2 s . co m*/ UnpooledDataSource ds = new UnpooledDataSource(JDBC_DRIVER, JDBC_URL, "sa", ""); Environment environment = new Environment("test", new JdbcTransactionFactory(), ds); Configuration config = new Configuration(environment); config.addMapper(EnumtestMapper.class); config.addMapper(GeneratedalwaystestMapper.class); config.addMapper(GeneratedalwaystestnoupdatesMapper.class); config.addMapper(MyObjectMapper.class); config.addMapper(RegexrenameMapper.class); sqlSessionFactory = new SqlSessionFactoryBuilder().build(config); }
From source file:net.landora.video.data.AbstractDataManager.java
License:Open Source License
private synchronized SqlSessionFactory getFactory() { if (factory == null) { TransactionFactory transactionFactory = new JdbcTransactionFactory(); Environment environment = new Environment("development", transactionFactory, DatabaseConnectionManager.getInstance().getDataSource()); Configuration configuration = new Configuration(environment); configuration.setCacheEnabled(true); configuration.setLazyLoadingEnabled(false); configuration.getTypeHandlerRegistry().register(Calendar.class, JdbcType.TIMESTAMP, new CalendarTypeHandler()); configuration.getTypeHandlerRegistry().register(Calendar.class, JdbcType.DATE, new DateCalendarTypeHandler()); for (Class<?> clazz : getAliasTypeClasses()) { String className = clazz.getSimpleName(); configuration.getTypeAliasRegistry().registerAlias(className, clazz); }/*w w w.ja v a2 s .c om*/ for (Class<?> clazz : getMapperClasses()) { configuration.addMapper(clazz); } factory = new SqlSessionFactoryBuilder().build(configuration); } return factory; }
From source file:och.comp.db.base.BaseDb.java
License:Apache License
public BaseDb(DataSource ds, Props props, String url) { this.ds = ds; this.props = props; this.dialect = props.getStrVal(PropKey.db_dialect); String mappersPackageName = getClass().getPackage().getName(); //mybatis//from w ww . j a v a2s . c om TransactionFactory txFactory = new JdbcTransactionFactory(); Environment environment = new Environment("prod", txFactory, ds); Configuration config = new Configuration(environment); config.addMappers(mappersPackageName, BaseMapper.class); mappers = config.getMapperRegistry().getMappers(); sessionFactory = new SqlSessionFactoryBuilder().build(config); universal = new UniversalQueries(ds, props, url); }
From source file:org.codehaus.griffon.runtime.mybatis.DefaultMybatisFactory.java
License:Apache License
@Nonnull @SuppressWarnings("ConstantConditions") private SqlSessionFactory createSqlSessionFactory(@Nonnull Map<String, Object> config, @Nonnull String dataSourceName) { DataSource dataSource = getDataSource(dataSourceName); Environment environment = new Environment(dataSourceName, new JdbcTransactionFactory(), dataSource); Configuration configuration = new Configuration(environment); Map<String, Object> copyOfConfig = new LinkedHashMap<>(config); copyOfConfig.remove("connect_on_startup"); GriffonClassUtils.setProperties(configuration, copyOfConfig); if (mappers.isEmpty()) { readMappers();//from ww w.j a va 2 s .com } for (Class<?> mapper : mappers) { configuration.addMapper(mapper); } return new RecordingSqlSessionFactory(new SqlSessionFactoryBuilder().build(configuration)); }
From source file:org.fastcatsearch.analytics.db.CommonDBHandler.java
License:Open Source License
public boolean load() { if (driverProperties == null) { driverProperties = new Properties(); }//from w ww . j av a 2 s. c om String dbType = settings.getString("type"); driverProperties.setProperty("user", settings.getString("user")); driverProperties.setProperty("password", settings.getString("password")); driverProperties.setProperty("driver.encoding", "UTF-8"); boolean isAutoCommit = settings.getBoolean("autocommit", true); boolean usePooling = settings.getBoolean("usePooling", true); DataSource dataSource = null; if (usePooling) { PooledDataSource pooledDataSource = new PooledDataSource(settings.getString("driver"), settings.getString("url"), driverProperties); boolean poolPingEnabled = settings.getBoolean("poolPingEnabled", true); String poolPingQuery = settings.getString("poolPingQuery"); int poolPingConnectionsNotUsedFor = settings.getInt("poolPingConnectionsNotUsedFor", -1); int poolTimeToWait = settings.getInt("poolTimeToWait", -1); int poolMaximumActiveConnections = settings.getInt("poolMaximumActiveConnections", -1); int poolMaximumIdleConnections = settings.getInt("poolMaximumIdleConnections", -1); pooledDataSource.setPoolPingEnabled(poolPingEnabled); if (poolPingQuery != null) { pooledDataSource.setPoolPingQuery(poolPingQuery); } if (poolPingConnectionsNotUsedFor != -1) { pooledDataSource.setPoolPingConnectionsNotUsedFor(poolPingConnectionsNotUsedFor); } if (poolTimeToWait != -1) { pooledDataSource.setPoolTimeToWait(poolTimeToWait); } if (poolMaximumActiveConnections != -1) { pooledDataSource.setPoolMaximumActiveConnections(poolMaximumActiveConnections); } if (poolMaximumIdleConnections != -1) { pooledDataSource.setPoolMaximumIdleConnections(poolMaximumIdleConnections); } //autocommit pooledDataSource.setDefaultAutoCommit(isAutoCommit); dataSource = pooledDataSource; } else { UnpooledDataSource unpooledDataSource = new UnpooledDataSource(settings.getString("driver"), settings.getString("url"), driverProperties); unpooledDataSource.setAutoCommit(isAutoCommit); dataSource = unpooledDataSource; } org.apache.ibatis.mapping.Environment environment = new org.apache.ibatis.mapping.Environment("ID", new JdbcTransactionFactory(), dataSource); Configuration configuration = new Configuration(environment); if (globalParam != null) { configuration.getVariables().putAll(globalParam); } if (mapperList != null) { List<URL> mapperFileList = new ArrayList<URL>(); for (Class<?> mapperDAO : mapperList) { try { String mapperFilePath = mapperDAO.getName().replace('.', '/') + "_" + dbType + ".xml"; URL mapperFile = Resources.getResourceURL(mapperFilePath); mapperFileList.add(mapperFile); } catch (IOException e) { logger.error("error load MapperFile", e); } } for (URL mapperFile : mapperFileList) { addSqlMappings(configuration, mapperFile); } } sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration); return true; }
From source file:org.fastcatsearch.db.InternalDBModule.java
License:Open Source License
@Override protected boolean doLoad() throws ModuleException { Properties driverProperties = new Properties(); driverProperties.setProperty("driver.encoding", "UTF-8"); //******* driverProperties ***** //poolMaximumActiveConnections //poolMaximumIdleConnections //poolMaximumCheckoutTime //poolTimeToWait //poolPingQuery //poolPingEnabled //poolPingConnectionsNotUsedFor ////////////////////////////////// PooledDataSource dataSource = new PooledDataSource(derbyEmbeddedDriver, dbPath, driverProperties); org.apache.ibatis.mapping.Environment environment = new org.apache.ibatis.mapping.Environment("ID", new JdbcTransactionFactory(), dataSource); Configuration configuration = new Configuration(environment); if (mapperFileList != null) { for (URL mapperFile : mapperFileList) { addSqlMappings(configuration, mapperFile); }//w ww. ja v a2 s.c o m } sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration); logger.info("DBModule[{}] Loaded! with {}", dbPath, mapperFileList); return true; }
From source file:org.mybatis.guice.configuration.ConfigurationProvider.java
License:Apache License
/** * New configuration./*from www . j a v a2 s .co m*/ * * @param environment * the environment * @return new configuration */ protected Configuration newConfiguration(Environment environment) { return new Configuration(environment); }