OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 17 | Rev 73 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 17 Rev 25
Line 14... Line 14...
14
 package org.openconcerto.sql.request;
14
 package org.openconcerto.sql.request;
15
 
15
 
16
import org.openconcerto.sql.model.SQLData;
16
import org.openconcerto.sql.model.SQLData;
17
import org.openconcerto.sql.model.SQLDataListener;
17
import org.openconcerto.sql.model.SQLDataListener;
18
import org.openconcerto.sql.model.SQLTable;
18
import org.openconcerto.sql.model.SQLTable;
19
import org.openconcerto.sql.model.SQLTableListener;
19
import org.openconcerto.sql.model.SQLTableModifiedListener;
20
import org.openconcerto.utils.cache.CacheWatcher;
20
import org.openconcerto.utils.cache.CacheWatcher;
21
 
21
 
22
/**
22
/**
23
 * A listener to invalidate cache results when their data is modified. Currently datum can either be
23
 * A listener to invalidate cache results when their data is modified. Currently datum can either be
24
 * a SQLTable or a SQLRow.
24
 * a SQLTable or a SQLRow.
25
 * 
25
 * 
26
 * @param <K> type of keys
26
 * @param <K> type of keys
27
 */
27
 */
28
public class SQLCacheWatcher<K> extends CacheWatcher<K, SQLData> {
28
public class SQLCacheWatcher<K> extends CacheWatcher<K, SQLData> {
29
 
29
 
30
    private final SQLTableListener listener;
30
    private final SQLTableModifiedListener listener;
31
 
31
 
32
    SQLCacheWatcher(final SQLCache<K, ?> c, final SQLData t) {
32
    SQLCacheWatcher(final SQLCache<K, ?> c, final SQLData t) {
33
        super(c, t);
33
        super(c, t);
34
        this.listener = t.createTableListener(new SQLDataListener() {
34
        this.listener = t.createTableListener(new SQLDataListener() {
35
            public void dataChanged() {
35
            public void dataChanged() {
36
                clearCache();
36
                clearCache();
37
            }
37
            }
38
        });
38
        });
39
        this.getTable().addPremierTableListener(this.listener);
39
        this.getTable().addPremierTableModifiedListener(this.listener);
40
    }
40
    }
41
 
41
 
42
    private final SQLTable getTable() {
42
    private final SQLTable getTable() {
43
        return this.getData().getTable();
43
        return this.getData().getTable();
44
    }
44
    }
45
 
45
 
46
    @Override
46
    @Override
47
    protected void dying() {
47
    protected void dying() {
48
        this.getTable().removeTableListener(this.listener);
48
        this.getTable().removeTableModifiedListener(this.listener);
49
    }
49
    }
50
 
50
 
51
}
51
}