// TransactionManager.java
public abstract class TransactionManager {
private String separator;
public TransactionManager(String separator) {
this.separator = separator;
}
public abstract void writeTransaction(String result);
public Transaction startTransaction()
{
Transaction transaction = new Transaction(System.currentTimeMillis());
return transaction;
}
public void endTransaction(Transaction t) {
long processingTime = System.currentTimeMillis() - t.getStartTime();
StringBuilder logBuilder = new StringBuilder();
logBuilder.append(t.getStartTime());
// Notice the use of this.separator
logBuilder.append(this.separator);
logBuilder.append(processingTime);
logBuilder.append(this.separator);
logBuilder.append(t.getData());
String result = logBuilder.toString();
writeTransaction(result);
}
}
public class TransactionManagerFS extends TransactionManager{
// The IDE forces you to implement constructor.
public TransactionManagerFS(String separator) {
super(separator);
}
@Override
public void writeTransaction(String result) {
System.out.println("The following transaction has just finished: " );
System.out.println(result);
}
}
public static void main(String[] args) throws InterruptedException {
// we pass the separator explicitly in the constructor
TransactionManager transactionManager = new TransactionManagerFS(",");
Transaction transaction = transactionManager.startTransaction();
transaction.setData("This is a test transaction !!");
Thread.sleep(1500);
transactionManager.endTransaction(transaction);
}
The following transaction has just finished: 1502179140689,1501,This is a test transaction !!
public abstract class TransactionManager {
public abstract String getSeperator();
public abstract void writeTransaction(String result);
public Transaction startTransaction()
{
Transaction transaction = new Transaction(System.currentTimeMillis());
return transaction;
}
public void endTransaction(Transaction t) {
long processingTime = System.currentTimeMillis() - t.getStartTime();
StringBuilder logBuilder = new StringBuilder();
logBuilder.append(t.getStartTime());
// Notice the use of getSeparator()
logBuilder.append(getSeperator());
logBuilder.append(processingTime);
logBuilder.append(getSeperator());
logBuilder.append(t.getData());
String result = logBuilder.toString();
writeTransaction(result);
}
}
public class TransactionManagerFS extends TransactionManager{
@Override
public String getSeperator() {
return ",";
}
@Override
public void writeTransaction(String result) {
System.out.println("The following transaction has just finished: " );
System.out.println(result);
}
}
public static void main(String[] args) throws InterruptedException {
// The separator is defined implicitly using getSeparator() method of the manager
TransactionManager transactionManager = new TransactionManagerFS();
Transaction transaction = transactionManager.startTransaction();
transaction.setData("This is a test transaction !!");
Thread.sleep(1500);
transactionManager.endTransaction(transaction);
}
The following transaction has just finished: 1502179140689,1501,This is a test transaction !!
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有