-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
197 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.huifer.design.adapter.ChaTou; | ||
|
||
/** | ||
* 描述: | ||
* 全球标准 | ||
* | ||
* @author huifer | ||
* @date 2019-03-13 | ||
*/ | ||
public interface QqCha { | ||
void method(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.huifer.zk; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; | ||
|
||
/** | ||
* <p>Title : DiscoveryApp </p> | ||
* <p>Description : </p> | ||
* | ||
* @author huifer | ||
* @date 2019-05-29 | ||
*/ | ||
@SpringBootApplication | ||
@EnableDiscoveryClient | ||
public class DiscoveryApp { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(DiscoveryApp.class, args); | ||
} | ||
} |
163 changes: 163 additions & 0 deletions
163
docs/spring/cs29543de6-9596-11ef-8e35-acde48001122.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
/** | ||
* Copyright 2009-2019 the original author or authors. | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.ibatis.session.defaults; | ||
|
||
import org.apache.ibatis.exceptions.ExceptionFactory; | ||
import org.apache.ibatis.executor.ErrorContext; | ||
import org.apache.ibatis.executor.Executor; | ||
import org.apache.ibatis.mapping.Environment; | ||
import org.apache.ibatis.session.*; | ||
import org.apache.ibatis.transaction.Transaction; | ||
import org.apache.ibatis.transaction.TransactionFactory; | ||
import org.apache.ibatis.transaction.managed.ManagedTransactionFactory; | ||
|
||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
|
||
/** | ||
* @author Clinton Begin | ||
*/ | ||
public class DefaultSqlSessionFactory implements SqlSessionFactory { | ||
|
||
private final Configuration configuration; | ||
|
||
/** | ||
* @param configuration 配置文件 | ||
*/ | ||
public DefaultSqlSessionFactory(Configuration configuration) { | ||
this.configuration = configuration; | ||
} | ||
|
||
@Override | ||
public SqlSession openSession() { | ||
return openSessionFromDataSource(configuration.getDefaultExecutorType(), null, false); | ||
} | ||
|
||
@Override | ||
public SqlSession openSession(boolean autoCommit) { | ||
return openSessionFromDataSource(configuration.getDefaultExecutorType(), null, autoCommit); | ||
} | ||
|
||
@Override | ||
public SqlSession openSession(ExecutorType execType) { | ||
return openSessionFromDataSource(execType, null, false); | ||
} | ||
|
||
@Override | ||
public SqlSession openSession(TransactionIsolationLevel level) { | ||
return openSessionFromDataSource(configuration.getDefaultExecutorType(), level, false); | ||
} | ||
|
||
@Override | ||
public SqlSession openSession(ExecutorType execType, TransactionIsolationLevel level) { | ||
return openSessionFromDataSource(execType, level, false); | ||
} | ||
|
||
@Override | ||
public SqlSession openSession(ExecutorType execType, boolean autoCommit) { | ||
return openSessionFromDataSource(execType, null, autoCommit); | ||
} | ||
|
||
@Override | ||
public SqlSession openSession(Connection connection) { | ||
return openSessionFromConnection(configuration.getDefaultExecutorType(), connection); | ||
} | ||
|
||
@Override | ||
public SqlSession openSession(ExecutorType execType, Connection connection) { | ||
return openSessionFromConnection(execType, connection); | ||
} | ||
|
||
@Override | ||
public Configuration getConfiguration() { | ||
return configuration; | ||
} | ||
|
||
/** | ||
* <setting name="defaultExecutorType" value="SIMPLE"/> | ||
* | ||
* @param execType setting 标签的 defaultExecutorType 属性 | ||
* @param level 事物级别 | ||
* @param autoCommit | ||
* @return | ||
*/ | ||
private SqlSession openSessionFromDataSource(ExecutorType execType, TransactionIsolationLevel level, boolean autoCommit) { | ||
Transaction tx = null; | ||
try { | ||
final Environment environment = configuration.getEnvironment(); | ||
// <transactionManager type="JDBC"/> | ||
// org.apache.ibatis.transaction.jdbc.JdbcTransaction | ||
final TransactionFactory transactionFactory = getTransactionFactoryFromEnvironment(environment); | ||
tx = transactionFactory.newTransaction(environment.getDataSource(), level, autoCommit); | ||
final Executor executor = configuration.newExecutor(tx, execType); | ||
return new DefaultSqlSession(configuration, executor, autoCommit); | ||
} catch (Exception e) { | ||
closeTransaction(tx); // may have fetched a connection so lets call close() | ||
throw ExceptionFactory.wrapException("Error opening session. Cause: " + e, e); | ||
} finally { | ||
ErrorContext.instance().reset(); | ||
} | ||
} | ||
|
||
private SqlSession openSessionFromConnection(ExecutorType execType, Connection connection) { | ||
try { | ||
boolean autoCommit; | ||
try { | ||
autoCommit = connection.getAutoCommit(); | ||
} catch (SQLException e) { | ||
// Failover to true, as most poor drivers | ||
// or databases won't support transactions | ||
autoCommit = true; | ||
} | ||
final Environment environment = configuration.getEnvironment(); | ||
final TransactionFactory transactionFactory = getTransactionFactoryFromEnvironment(environment); | ||
final Transaction tx = transactionFactory.newTransaction(connection); | ||
final Executor executor = configuration.newExecutor(tx, execType); | ||
return new DefaultSqlSession(configuration, executor, autoCommit); | ||
} catch (Exception e) { | ||
throw ExceptionFactory.wrapException("Error opening session. Cause: " + e, e); | ||
} finally { | ||
ErrorContext.instance().reset(); | ||
} | ||
} | ||
|
||
/** | ||
* 获取 事物工厂 | ||
* @param environment | ||
* @return | ||
*/ | ||
private TransactionFactory getTransactionFactoryFromEnvironment(Environment environment) { | ||
if (environment == null || environment.getTransactionFactory() == null) { | ||
return new ManagedTransactionFactory(); | ||
} | ||
return environment.getTransactionFactory(); | ||
} | ||
|
||
/** | ||
* 关闭失误 | ||
* @param tx | ||
*/ | ||
private void closeTransaction(Transaction tx) { | ||
if (tx != null) { | ||
try { | ||
tx.close(); | ||
} catch (SQLException ignore) { | ||
// Intentionally ignore. Prefer previous error. | ||
} | ||
} | ||
} | ||
|
||
} |