public interface TransactionFactory {
/**
* Callback mechanism; a context is always a {@link org.hibernate.Session}
* in the Hibernate usage.
*/
public static interface Context {
public SessionFactoryImplementor getFactory();
public boolean isClosed();
public boolean isFlushModeNever();
public boolean isFlushBeforeCompletionEnabled();
public void managedFlush();
public boolean shouldAutoClose();
public void managedClose();
}
/**
* Begin a transaction and return the associated <tt>Transaction</tt> instance.
*
* @param jdbcContext The jdbc context to which the transaction belongs
* @param context The contract regarding the context in which this transaction will operate.
* @return Transaction
* @throws HibernateException Indicates a problem generating a transaction instance
*/
public Transaction createTransaction(JDBCContext jdbcContext, Context context) throws HibernateException;
..........
接口里弄个接口,这样做是啥目的呢??外国人写代码就不一样
这样的做法是很明确的,当你想表示这里的Context是用在TransactionFactory的,一般的写法是怎样呢?可能去到把Context放在某个package下。而这里的写法,任谁都看得出,就是TransactionFactory的Context,外部想用,也就是TransactionFactory.Context就可以了
是不是写的有问题?那个大括号已经封闭了阿 :roll:
看错了,不好意思。
这样的话,你就只能通过TransactionFactory来访问他了阿,你要实现他的接口,必须通过TransactionFactory类来访问,不能直接访问的,这可能就是他的初衷吧。 :arrow:
[code="java"]
public class T {
public static interface Interface1{
void print();
}
public static void main(String[] args) {
Sub sub = new Sub();
sub.print();
}
}
class Sub implements T.Interface1{
public void print(){
System.out.println("Implementation");
}
}
[/code]
就当成是一个类的静态内部类来理解吧