本文整理汇总了Java中org.springframework.jdbc.datasource.DriverManagerDataSource类的典型用法代码示例。如果您正苦于以下问题:Java DriverManagerDataSource类的具体用法?Java DriverManagerDataSource怎么用?Java DriverManagerDataSource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DriverManagerDataSource类属于org.springframework.jdbc.datasource包,在下文中一共展示了DriverManagerDataSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: entityManagerFactory
import org.springframework.jdbc.datasource.DriverManagerDataSource; //导入依赖的package包/类
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
JpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter();
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setUsername("root");
dataSource.setPassword("");
dataSource.setUrl("jdbc:mysql://localhost:3306/ensaiospring");
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
Properties props = new Properties();
props.setProperty("hibernate.dialect",
"org.hibernate.dialect.MySQL5Dialect");
props.setProperty("hibernate.show_sql", "true");
props.setProperty("hibernate.hbm2ddl.auto", "update");
factory.setJpaVendorAdapter(jpaVendorAdapter);
factory.setDataSource(dataSource);
factory.setJpaProperties(props);
factory.setPackagesToScan("br.com.ciaware.springmvc.ensaio.models");
return factory;
}
示例2: mysqlDataSource
import org.springframework.jdbc.datasource.DriverManagerDataSource; //导入依赖的package包/类
@Bean
public DataSource mysqlDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(MYSQL_DRIVER_CLASS_NAME);
dataSource.setUrl(MYSQL_URL);
dataSource.setUsername(MYSQL_USER_NAME);
dataSource.setPassword(MYSQL_USER_PASSWORD);
return dataSource;
}
示例3: setup
import org.springframework.jdbc.datasource.DriverManagerDataSource; //导入依赖的package包/类
@Setup
public void setup() throws PropertyVetoException {
dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
dataSource.setUrl(propertyOr("jdbcUrl", "jdbc:mysql://127.0.0.1:3306?useSSL=false"));
dataSource.setUsername(propertyOr("username", "root"));
dataSource.setPassword(propertyOr("password", "root"));
JdbcTemplate delegate = new JdbcTemplate(dataSource);
delegate.setDataSource(dataSource);
proxy = new SenderProxy(new JdbcTemplateSender(delegate));
proxy.onMessages(updated -> counter.addAndGet(updated.size()));
reporter = reporter(proxy);
batch = new BatchJdbcTemplate(delegate, reporter);
batch.setDataSource(dataSource);
unbatch = new JdbcTemplate(dataSource);
unbatch.setDataSource(dataSource);
unbatch.update(CREATE_DATABASE);
unbatch.update(DROP_TABLE);
unbatch.update(CREATE_TABLE);
}
示例4: getCurrentUser
import org.springframework.jdbc.datasource.DriverManagerDataSource; //导入依赖的package包/类
public static LeafUser getCurrentUser() {
LeafUser leafuser = null;
User User = null;
Authentication a = SecurityContextHolder.getContext().getAuthentication();
try{
if(a.getPrincipal() != null) {
User = (User) a.getPrincipal();
} else {
return null;
}
}catch(Exception e) {
return null;
}
if(User!=null) {
DriverManagerDataSource datasource = new JdbcUtil().getAccountsDataSource();
JdbcUserDAO userDAO = new JdbcUserDAO();
userDAO.setDataSource(datasource);
leafuser = userDAO.loadUserByUsername(User.getUsername());
}
return leafuser;
}
示例5: getUserFromToken
import org.springframework.jdbc.datasource.DriverManagerDataSource; //导入依赖的package包/类
public static LeafUser getUserFromToken(String token) {
//return new TokenHandler(DatatypeConverter.parseBase64Binary(AppResources.getInstance().getTokeSecret())).parseUserFromToken(token);
Claims claims = new TokenHandler(DatatypeConverter.parseBase64Binary(AppResources.getInstance().getTokeSecret())).parseJWT(token);
String claimsId = claims.getId();
DriverManagerDataSource datasource = new JdbcUtil().getAccountsDataSource();
// Inject the datasource into the dao
JdbcUserDAO userDAO = new JdbcUserDAO();
userDAO.setDataSource(datasource);
LeafUser user = userDAO.findByCustomerId(Integer.parseInt(claimsId));
if(user.getUsername().equals(claims.getIssuer()) && user.getEmail().equals(claims.getSubject())) {
return user;
}
else {
return null;
}
}
示例6: createDataSource
import org.springframework.jdbc.datasource.DriverManagerDataSource; //导入依赖的package包/类
/**
* Creates and returns a new data source from the given connection information. Creates a new {@link DriverManagerDataSource}.
*
* @param jdbcConnection the JDBC connection
* @param variables the optional map of key-value for expression evaluation
*
* @return a new {@link DataSource}
*/
private DataSource createDataSource(JdbcConnection jdbcConnection, Map<String, Object> variables)
{
String url = evaluate(jdbcConnection.getUrl(), variables, "jdbc connection url");
String username = evaluate(jdbcConnection.getUsername(), variables, "jdbc connection username");
String password = evaluate(jdbcConnection.getPassword(), variables, "jdbc connection password");
validateUrl(url);
DriverManagerDataSource driverManagerDataSource = new DriverManagerDataSource();
driverManagerDataSource.setUrl(url);
driverManagerDataSource.setUsername(username);
driverManagerDataSource.setPassword(password);
driverManagerDataSource.setDriverClassName(getDriverClassName(jdbcConnection.getDatabaseType()));
return driverManagerDataSource;
}
示例7: dataSource
import org.springframework.jdbc.datasource.DriverManagerDataSource; //导入依赖的package包/类
@Bean(name = "dataSource")
public DataSource dataSource() {
DriverManagerDataSource ds = new DriverManagerDataSource();
ds.setDriverClassName(driverClassName);
ds.setUrl(databaseUrl);
Properties p = new Properties();
Map<String, String> datasourceProperties = mapPropertyNames("datasource", hibernateConfiguration());
p.putAll(datasourceProperties);
ds.setConnectionProperties(p);
if (!StringUtils.isEmpty(username)) {
ds.setUsername(username);
}
if (!StringUtils.isEmpty(password)) {
ds.setPassword(password);
}
return ds;
}
示例8: configureDataSource
import org.springframework.jdbc.datasource.DriverManagerDataSource; //导入依赖的package包/类
@Bean
public DataSource configureDataSource() {
log.info("*************** Env Variables configureDataSource *************** ");
String driver = System.getenv(EnviromentVariables.DATASOURCE_DRIVER_CLASS.getCode());
String url = System.getenv(EnviromentVariables.DATASOURCE_URL.getCode());
String username = System.getenv(EnviromentVariables.DATASOURCE_USERNAME.getCode());
String password = System.getenv(EnviromentVariables.DATASOURCE_PASSWORD.getCode());
log.info("dataSource.driverClassName: " + driver);
log.info("dataSource.url: " + url);
log.info("dataSource.username: " + username);
log.info("dataSource.password: ***");
log.info("*************** END Env Variables configureDataSource *************** ");
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(driver);
dataSource.setUrl(url);
dataSource.setUsername(username);
dataSource.setPassword(password);
return dataSource;
}
示例9: getDataSource
import org.springframework.jdbc.datasource.DriverManagerDataSource; //导入依赖的package包/类
/**
* @param host
* @param port
* @param service
* @param user
* @param pw
* @return
* @throws Exception
*/
public DriverManagerDataSource getDataSource(String host, String port, String service, String user, String pw) throws Exception
{
// Override this method if your datasource is different
try
{
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(JDBC_DRIVER);
String url = String.format("jdbc:oracle:thin:@%s:%s:%s", host, port, service);
dataSource.setUrl(url);
dataSource.setUsername(user);
dataSource.setPassword(pw);
return dataSource;
}
catch (Exception e)
{
throw new Exception("Unable to get data source. Reason: " + e.getMessage());
}
}
示例10: setup
import org.springframework.jdbc.datasource.DriverManagerDataSource; //导入依赖的package包/类
/**
* Setup of test data: set attributes, purge and initialize test datbase
*/
@Before
public void setup() throws SQLException, LiquibaseException {
// Init jdbcTemplate
this.jdbcTemplate = new JdbcTemplate(datasource);
// Set test db properties
DriverManagerDataSource ds = (DriverManagerDataSource)datasource;
this.paasTestDbUrl = ds.getUrl();
this.paasTestDbUser = ds.getUsername();
this.paasTestDbPassword = ds.getPassword();
// purge test database
liquibaseWrapper.purgeDatabase(paasTestDbUrl, paasTestDbUser, paasTestDbPassword);
// init database state
liquibaseWrapper.applyChangeLog(paasTestDbUrl, paasTestDbUser, paasTestDbPassword, basicInitialChangeLofFile);
}
示例11: createDriverManagerDataSources
import org.springframework.jdbc.datasource.DriverManagerDataSource; //导入依赖的package包/类
/**
* 建立多個DriverManagerDataSource
*
* @return
* @throws Exception
*/
protected DriverManagerDataSource[] createDriverManagerDataSources() throws Exception {
DriverManagerDataSource[] result = null;
try {
int maxDataSourceSize = extendedProperties.getInt(MAX_DATA_SOURCE_SIZE, DEFAULT_MAX_DATA_SOURCE_SIZE);
result = new DriverManagerDataSource[maxDataSourceSize];
//
for (int i = 0; i < maxDataSourceSize; i++) {
DriverManagerDataSource dataSource = createDriverManagerDataSource(i);
result[i] = dataSource;
}
} catch (Exception e) {
LOGGER.error(new StringBuilder("Exception encountered during createDriverManagerDataSources()").toString(),
e);
try {
result = (DriverManagerDataSource[]) shutdownDriverManagerDataSources();
} catch (Exception sie) {
throw sie;
}
throw e;
}
return result;
}
示例12: shutdownDriverManagerDataSources
import org.springframework.jdbc.datasource.DriverManagerDataSource; //导入依赖的package包/类
/**
* 關閉
*
* @return
*/
protected DriverManagerDataSource[] shutdownDriverManagerDataSources() throws Exception {
try {
if (this.driverManagerDataSources != null) {
for (int i = 0; i < this.driverManagerDataSources.length; i++) {
DriverManagerDataSource oldInstance = this.driverManagerDataSources[i];
// oldInstance.close();
this.driverManagerDataSources[i] = null;
}
//
this.driverManagerDataSources = null;
}
} catch (Exception e) {
LOGGER.error(
new StringBuilder("Exception encountered during shutdownDriverManagerDataSources()").toString(), e);
throw e;
}
return this.driverManagerDataSources;
}
示例13: setup
import org.springframework.jdbc.datasource.DriverManagerDataSource; //导入依赖的package包/类
@Before
public void setup() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(DATASOURCE_DRIVER_CLASS_NAME);
dataSource.setUrl(DATASOURCE_URL);
dataSource.setUsername(DATASOURCE_USER_NAME);
dataSource.setPassword(DATASOURCE_USER_PASSWORD);
this.dataSource = dataSource;
try {
this.server = Server.createTcpServer("-tcp", "-tcpAllowOthers", "-tcpPort", String.valueOf(randomPort))
.start();
}
catch (SQLException e) {
throw new IllegalStateException(e);
}
}
示例14: getPool
import org.springframework.jdbc.datasource.DriverManagerDataSource; //导入依赖的package包/类
/**
* 获得一个可用的池
*
* @param ds
* @param profile
* @param max 当Max==0时等同于Nopool
* @return
*/
public static IUserManagedPool getPool(DataSource ds, int min,int max,TransactionMode txMode) {
if(txMode==TransactionMode.JDBC || txMode==TransactionMode.JTA){
max=0;
}
if(min==0){
min = JefConfiguration.getInt(DbCfg.DB_CONNECTION_POOL, 3);
}
IUserManagedPool result;
if (ds instanceof IRoutingDataSource) {
IRoutingDataSource rds = (IRoutingDataSource) ds;
result= new RoutingDummyConnectionPool(rds);
} else if(ds instanceof DriverManagerDataSource||ds instanceof SimpleDataSource){
result= new SingleManagedConnectionPool(ds, min, max);
} else{
result= new SingleDummyConnectionPool(ds);
}
return result.setTransactionMode(txMode);
}
示例15: setUp
import org.springframework.jdbc.datasource.DriverManagerDataSource; //导入依赖的package包/类
/**
*/
@Before
public void setUp() {
final DataSource ds = new DriverManagerDataSource(System.getProperty("jdbc.url", "jdbc:sap://localhost:30115"),
System.getProperty("jdbc.user", "hibernate"), System.getProperty("jdbc.password", "hibernate"));
final LocalSessionFactoryBuilder builder = new LocalSessionFactoryBuilder(ds);
builder.setProperty(AvailableSettings.DIALECT,
System.getProperty("hibernate.dialect", HANAColumnStoreDialect.class.getName()));
builder.setProperty(AvailableSettings.HBM2DDL_AUTO, "create-drop");
builder.setProperty(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true");
builder.addAnnotatedClass(Employee.class);
this.sessionFactory = builder.buildSessionFactory();
final HibernateTemplate ht = new HibernateTemplate();
ht.setSessionFactory(this.sessionFactory);
ht.afterPropertiesSet();
this.template = ht;
final HibernateTransactionManager txnMgr = new HibernateTransactionManager();
txnMgr.setDataSource(ds);
txnMgr.setSessionFactory(this.sessionFactory);
txnMgr.afterPropertiesSet();
this.transactionTemplate = new TransactionTemplate(txnMgr);
}