/
SpaceReservationIO.java
146 lines (133 loc) · 8.85 KB
/
SpaceReservationIO.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//______________________________________________________________________________
//
// $Id: SpaceReservationIO.java 8022 2008-01-07 21:25:23Z litvinse $
// $Author: litvinse $
//
// Infrastructure to retrieve objects from DB
//
// created 11/07 by Dmitry Litvintsev (litvinse@fnal.gov)
//
//______________________________________________________________________________
package diskCacheV111.services.space;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashSet;
import java.util.Set;
import diskCacheV111.util.AccessLatency;
import diskCacheV111.util.IoPackage;
import diskCacheV111.util.RetentionPolicy;
/*
Column | Type | Modifiers
------------------+--------------------------+-----------
id | bigint | not null
vogroup | character varying(32672) |
vorole | character varying(32672) |
retentionpolicy | integer |
accesslatency | integer |
linkgroupid | bigint |
sizeinbytes | bigint |
creationtime | bigint |
lifetime | bigint |
description | character varying(32672) |
state | integer |
usedspaceinbytes | bigint |
allocatedspaceinbytes | bigint |
*/
public class SpaceReservationIO extends IoPackage<Space> {
public static final String SRM_SPACE_TABLE = ManagerSchemaConstants.SPACE_TABLE_NAME;
public static final String INSERT = "INSERT INTO "+SRM_SPACE_TABLE+
" (id,vogroup,vorole,retentionpolicy,accesslatency,linkgroupid,"+
"sizeinbytes,creationtime,lifetime,description,state,usedspaceinbytes,allocatedspaceinbytes)"+
" VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)";
public static final String UPDATE = "UPDATE "+SRM_SPACE_TABLE+
" set vogroup=?,vorole=?,retentionpolicy=?,accesslatency=?,linkgroupid=?,sizeinbytes=?,"+
" creationtime=?,lifetime=?,description=?,state=? where id=?";
public static final String SELECT_SPACE_RESERVATION_BY_ID="SELECT * FROM "+SRM_SPACE_TABLE+" where id=?";
public static final String SELECT_SPACE_RESERVATION_BY_LINKGROUP_ID="SELECT * FROM "+SRM_SPACE_TABLE+
" where linkgroupid=? and state = "+SpaceState.RESERVED.getStateId();
public static final String SELECT_SPACE_RESERVATION_BY_DESC="SELECT * FROM "+SRM_SPACE_TABLE+" where description ~ ?";
public static final String SELECT_SPACE_RESERVATION_BY_DESC_AND_LINKGROUP_ID="SELECT * FROM "+SRM_SPACE_TABLE+
" where description ~ ? and linkgroupid=? and state = "+SpaceState.RESERVED.getStateId();
public static final String SELECT_SPACE_RESERVATION_BY_VOROLE="SELECT * FROM "+SRM_SPACE_TABLE+
" where vorole ~ ? and state = "+SpaceState.RESERVED.getStateId();
public static final String SELECT_SPACE_RESERVATION_BY_VOROLE_AND_LINKGROUP_ID="SELECT * FROM "+SRM_SPACE_TABLE+
" where vorole ~ ? and linkgroupid=? and state = "+SpaceState.RESERVED.getStateId();
public static final String SELECT_SPACE_RESERVATION_BY_VOGROUP="SELECT * FROM "+SRM_SPACE_TABLE+
" where vogroup ~ ? and state = "+SpaceState.RESERVED.getStateId();
public static final String SELECT_SPACE_RESERVATION_BY_VOGROUP_AND_LINKGROUP_ID="SELECT * FROM "+SRM_SPACE_TABLE+
" where vogroup ~ ? and linkgroupid=? and state = "+SpaceState.RESERVED.getStateId();
public static final String SELECT_SPACE_RESERVATION_BY_VOGROUP_AND_VOROLE="SELECT * FROM "+SRM_SPACE_TABLE+
" where vogroup ~ ? and vorole ? and state = "+SpaceState.RESERVED.getStateId();
public static final String SELECT_SPACE_RESERVATION_BY_VOGROUP_AND_VOROLE_AND_LINKGROUP_ID="SELECT * FROM "+SRM_SPACE_TABLE+
" where vogroup ~ ? and vorole ~ ? and linkgroupid=? and state = "+SpaceState.RESERVED.getStateId();
public static final String SELECT_ALL_SPACE_RESERVATIONS ="SELECT * FROM "+SRM_SPACE_TABLE;
public static final String SELECT_EXPIRED_SPACE_RESERVATIONS="SELECT * FROM "+SRM_SPACE_TABLE+ " WHERE state = "+SpaceState.EXPIRED.getStateId();
public static final String SELECT_EXPIRED_SPACE_RESERVATIONS1="SELECT * FROM "+SRM_SPACE_TABLE+ " WHERE state = "+SpaceState.RESERVED.getStateId() +
" AND lifetime != -1 and creationTime+lifetime < ?";
public static final String SELECT_RELEASED_SPACE_RESERVATIONS="SELECT * FROM "+SRM_SPACE_TABLE+ " WHERE state = "+SpaceState.RELEASED.getStateId();
public static final String SELECT_INVALID_SPACE_RESERVATIONS="SELECT * FROM "+SRM_SPACE_TABLE+ " WHERE state !="+SpaceState.RESERVED.getStateId();
public static final String SELECT_CURRENT_SPACE_RESERVATIONS="SELECT * FROM "+SRM_SPACE_TABLE+
" WHERE state = "+SpaceState.RESERVED.getStateId();
public static final String DELETE_SPACE_RESERVATION ="DELETE FROM "+SRM_SPACE_TABLE+" where id=?";
public static final String SELECT_FOR_UPDATE_BY_ID = "SELECT * FROM "+SRM_SPACE_TABLE +
" WHERE id = ? FOR UPDATE ";
public static final String SELECT_FOR_UPDATE_BY_ID_AND_SIZE = "SELECT * FROM "+SRM_SPACE_TABLE +
" WHERE id = ? AND sizeinbytes-allocatedspaceinbytes >= ? FOR UPDATE ";
public static final String UPDATE_STATUS = "UPDATE "+SRM_SPACE_TABLE+ "SET status=? WHERE id=? ";
public static final String UPDATE_LIFETIME = "UPDATE "+SRM_SPACE_TABLE+ "SET lifetime=? WHERE id=? ";
public static final String SELECT_SPACE_RESERVATIONS_FOR_EXPIRED_FILES="select * from srmspace where id in (select distinct spacereservationid from srmspacefile where (state= "+FileState.RESERVED.getStateId()+" or state = "+ FileState.TRANSFERRING.getStateId() +") and creationtime+lifetime<?)";
public SpaceReservationIO() {
}
@Override
public Set<Space> select( Connection connection,
String txt) throws SQLException {
Set<Space> container = new HashSet<>();
Statement s = connection.createStatement();
ResultSet set = s.executeQuery(txt);
while (set.next()) {
container.add(
new Space(set.getLong("id"),
set.getString("vogroup"),
set.getString("vorole"),
RetentionPolicy.getRetentionPolicy(set.getInt("retentionPolicy")),
AccessLatency.getAccessLatency(set.getInt("accessLatency")),
set.getLong("linkgroupid"),
set.getLong("sizeinbytes"),
set.getLong("creationtime"),
set.getLong("lifetime"),
set.getString("description"),
SpaceState.getState(set.getInt("state")),
set.getLong("usedspaceinbytes"),
set.getLong("allocatedspaceinbytes")));
}
s.close();
return container;
}
@Override
public Set<Space> selectPrepared(Connection connection,
PreparedStatement statement)
throws SQLException {
Set<Space> container = new HashSet<>();
ResultSet set = statement.executeQuery();
while (set.next()) {
container.add(
new Space(set.getLong("id"),
set.getString("vogroup"),
set.getString("vorole"),
RetentionPolicy.getRetentionPolicy(set.getInt("retentionPolicy")),
AccessLatency.getAccessLatency(set.getInt("accessLatency")),
set.getLong("linkgroupid"),
set.getLong("sizeinbytes"),
set.getLong("creationtime"),
set.getLong("lifetime"),
set.getString("description"),
SpaceState.getState(set.getInt("state")),
set.getLong("usedspaceinbytes"),
set.getLong("allocatedspaceinbytes")));
}
return container;
}
}