svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.api / src / main / java / org / gvsig / fmap / dal / SupportTransactionsHelper.java @ 47778
History | View | Annotate | Download (1.46 KB)
1 | 47611 | fdiaz | /*
|
---|---|---|---|
2 | * To change this license header, choose License Headers in Project Properties.
|
||
3 | * To change this template file, choose Tools | Templates
|
||
4 | * and open the template in the editor.
|
||
5 | */
|
||
6 | package org.gvsig.fmap.dal; |
||
7 | |||
8 | import java.util.HashMap; |
||
9 | import java.util.Map; |
||
10 | |||
11 | /**
|
||
12 | *
|
||
13 | * @author fdiaz
|
||
14 | */
|
||
15 | public class SupportTransactionsHelper implements SupportTransactions { |
||
16 | |||
17 | private Map<Long, DataTransaction> transactions; |
||
18 | |||
19 | @Override
|
||
20 | public void setTransaction(DataTransaction transaction) { |
||
21 | if (this.transactions == null) { |
||
22 | this.transactions = new HashMap<>(); |
||
23 | } |
||
24 | long threadId = Thread.currentThread().getId(); |
||
25 | if (transaction == null) { |
||
26 | this.transactions.remove(threadId);
|
||
27 | return;
|
||
28 | } |
||
29 | DataTransaction t = transactions.get(threadId); |
||
30 | if (t == null) { |
||
31 | transactions.put(threadId, transaction); |
||
32 | return;
|
||
33 | } |
||
34 | if (t == transaction) {
|
||
35 | return;
|
||
36 | } |
||
37 | 47659 | jjdelcerro | throw new IllegalArgumentException("Can't add the object ("+(this.getClass().getName())+") to more than one transaction in the same thread ("+t.getCode()+", "+transaction.getCode()+")"); |
38 | 47611 | fdiaz | } |
39 | |||
40 | @Override
|
||
41 | public DataTransaction getTransaction() {
|
||
42 | if (this.transactions == null) { |
||
43 | this.transactions = new HashMap<>(); |
||
44 | } |
||
45 | long threadId = Thread.currentThread().getId(); |
||
46 | DataTransaction t = transactions.get(threadId); |
||
47 | return t;
|
||
48 | } |
||
49 | |||
50 | } |