88import ru .curs .celesta .dbutils .stmt .PreparedStmtHolder ;
99import ru .curs .celesta .dbutils .term .AlwaysTrue ;
1010import ru .curs .celesta .dbutils .term .FromTerm ;
11- import ru .curs .celesta .score .*;
11+ import ru .curs .celesta .score .DataGrainElement ;
12+ import ru .curs .celesta .score .ParseException ;
13+ import ru .curs .celesta .score .Table ;
1214import ru .curs .celesta .syscursors .ISchemaCursor ;
1315
1416import java .sql .PreparedStatement ;
1517import java .sql .ResultSet ;
1618import java .sql .SQLException ;
17- import java .util .Arrays ;
1819import java .util .Collections ;
1920import java .util .Date ;
20- import java .util .Objects ;
21- import java .util .stream .Collectors ;
2221
2322public class SchemaDataAccessor extends CsqlBasicDataAccessor <CallContext > implements ISchemaCursor {
2423
@@ -103,8 +102,9 @@ public String getId() {
103102 }
104103
105104 @ Override
106- public void setId (String id ) {
105+ public SchemaDataAccessor setId (String id ) {
107106 this .id = id ;
107+ return this ;
108108 }
109109
110110 @ Override
@@ -113,8 +113,9 @@ public String getVersion() {
113113 }
114114
115115 @ Override
116- public void setVersion (String version ) {
116+ public SchemaDataAccessor setVersion (String version ) {
117117 this .version = version ;
118+ return this ;
118119 }
119120
120121 @ Override
@@ -123,8 +124,9 @@ public Integer getLength() {
123124 }
124125
125126 @ Override
126- public void setLength (Integer length ) {
127+ public SchemaDataAccessor setLength (Integer length ) {
127128 this .length = length ;
129+ return this ;
128130 }
129131
130132 @ Override
@@ -133,8 +135,9 @@ public String getChecksum() {
133135 }
134136
135137 @ Override
136- public void setChecksum (String checksum ) {
138+ public SchemaDataAccessor setChecksum (String checksum ) {
137139 this .checksum = checksum ;
140+ return this ;
138141 }
139142
140143 @ Override
@@ -143,8 +146,9 @@ public Integer getState() {
143146 }
144147
145148 @ Override
146- public void setState (Integer state ) {
149+ public SchemaDataAccessor setState (Integer state ) {
147150 this .state = state ;
151+ return this ;
148152 }
149153
150154 @ Override
@@ -153,24 +157,27 @@ public Date getLastmodified() {
153157 }
154158
155159 @ Override
156- public void setLastmodified (Date lastmodified ) {
160+ public SchemaDataAccessor setLastmodified (Date lastmodified ) {
157161 this .lastmodified = lastmodified ;
162+ return this ;
158163 }
159164
160165 public String getMessage () {
161166 return message ;
162167 }
163168
164169 @ Override
165- public void setMessage (String message ) {
170+ public SchemaDataAccessor setMessage (String message ) {
166171 this .message = message ;
172+ return this ;
167173 }
168174
169175
170176 @ Override
171177 public void update () throws CelestaException {
172- if (updatingIsDisabled )
178+ if (updatingIsDisabled ) {
173179 return ;
180+ }
174181 try (PreparedStatement stmt = update .getStatement (currentValues (), 0 )) {
175182 stmt .execute ();
176183 } catch (SQLException e ) {
@@ -179,15 +186,15 @@ public void update() throws CelestaException {
179186 }
180187
181188 @ Override
182- public void get (Object ... values ) throws CelestaException {
183- try (PreparedStatement stmt = get .getStatement (values , 0 );
189+ public void get (String id ) throws CelestaException {
190+ try (PreparedStatement stmt = get .getStatement (new String []{ id } , 0 );
184191 ResultSet rs = stmt .executeQuery ()) {
185192 if (rs .next ()) {
186193 parseResult (rs );
187194 } else {
188- String sb = Arrays . stream ( values ). map ( Objects :: toString ). collect ( Collectors . joining ( ", " ));
189- if (! updatingIsDisabled )
190- throw new CelestaException ( "There is no %s (%s)." , meta (). getName (), sb );
195+ if (! updatingIsDisabled ) {
196+ throw new CelestaException ( "There is no %s (%s)." , meta (). getName (), id );
197+ }
191198 }
192199 } catch (SQLException e ) {
193200 throw new CelestaException (e );
@@ -205,9 +212,9 @@ public boolean nextInSet() throws CelestaException {
205212
206213 boolean result ;
207214 try {
208- if (cursor == null )
215+ if (cursor == null ) {
209216 result = findSet ();
210- else {
217+ } else {
211218 result = cursor .next ();
212219 }
213220 if (result ) {
@@ -226,8 +233,9 @@ private boolean findSet() throws CelestaException {
226233 PreparedStatement ps = findSet .getStatement (currentValues (), 0 );
227234 boolean result ;
228235 try {
229- if (cursor != null )
236+ if (cursor != null ) {
230237 cursor .close ();
238+ }
231239 cursor = ps .executeQuery ();
232240 result = cursor .next ();
233241 if (result ) {
@@ -251,8 +259,9 @@ private void parseResult(ResultSet rs) throws SQLException {
251259
252260 @ Override
253261 public void insert () throws CelestaException {
254- if (updatingIsDisabled )
262+ if (updatingIsDisabled ) {
255263 return ;
264+ }
256265 try (PreparedStatement stmt = insert .getStatement (currentValues (), 0 )) {
257266 stmt .execute ();
258267 } catch (SQLException e ) {
@@ -266,9 +275,8 @@ public final Table meta() throws CelestaException {
266275 }
267276
268277 private Object [] currentValues () {
269- Object [] result = {id != null ? id .replace ("\" " , "" ) : null , version , length , checksum , state , lastmodified ,
270- message };
271- return result ;
278+ return new Object []{id != null ? id .replace ("\" " , "" ) : null ,
279+ version , length , checksum , state , lastmodified , message };
272280 }
273281
274282}
0 commit comments