This repository has been archived by the owner on Sep 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
4Script_Mapping_objet_Relationnel_avec_Jdbc_bankAgency_Batisse_Brault_Cousson_Sabatier.sql
978 lines (792 loc) · 27.3 KB
/
4Script_Mapping_objet_Relationnel_avec_Jdbc_bankAgency_Batisse_Brault_Cousson_Sabatier.sql
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
/*
Sabatier, Juliette Participant 1: , Activités paricipant1
Batisse, Dylann Participant 2: , Activités paricipant2
Brault, Yann Participant 3: , Activités paricipant3
Cousson, Antoine Participant 4: , Activités paricipant4
*/
/*
3. Mapping des objets complexes Oracle avec Java / JDBC
3.1 Actvités à faire
Vous devez ici effectuer le mapping des objets complexes Oracle avec Java/JDBC end développant dans java des classes personalisées. Vous devez aussi écrire les programmes de test correspondants. Le chapitre 14 de mon cours le document Oracle.
Livres Oracle pouvant entre autre aider :
- Object-Relational Developer's Guide
https://docs.oracle.com/en/database/oracle/oracle-database/21/adobj/object-relational-developers-guide.pdf
- JDBC Developer's Guide
https://docs.oracle.com/en/database/oracle/oracle-database/21/jjdbc/jdbc-developers-guide.pdf
3.2 Travail à rendre (04/01/2022)
Le travail à rendre doit être dans le fichier :
4Script_Mapping_objet_Relationnel_avec_Jdbc_NomProjet_Nom1_Nom2_Nom3_Nom4.sql
*/
-- Ce fichier regroupe les classes présentes dans le dossier java,
--nous les avons mis dans ce fichier pour être en accord avec les spécification du sujet,
--pour executer le code veuillez trouver le main dans le directory "java" (projet maven).
-- Main
import types.Location;
import java.sql.*;
import java.util.Map;
public class Main {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection(
"jdbc:oracle:thin:@(DESCRIPTION =\r\n"
+ " (ADDRESS_LIST =\r\n"
+ " (ADDRESS = (PROTOCOL = TCP)(HOST = 144.21.67.201)(PORT = 1521))\r\n"
+ " )\r\n"
+ " (CONNECT_DATA =\r\n"
+ " (SERVER = DEDICATED)\r\n"
+ " (SERVICE_NAME = pdbm1inf.631174089.oraclecloud.internal)\r\n"
+ " )\r\n"
+ " )", "Batisse1I2122", "Batisse1I212201");
System.out.println(conn);
Statement stmt = conn.createStatement();
String queryEmp = "SELECT value(oe) FROM o_employe oe";
String queryLoc = "SELECT value(ol) FROM o_location ol";
Map mapOraObjType = conn.getTypeMap();
// mapOraObjType.put((Object)"BATISSE1I2122.EMPLOYE_T", (Object)Class.forName("types.Employe"));
// mapOraObjType.put((Object)"BATISSE1I2122.DEPT_T", (Object)Class.forName("test.Dept" ));
mapOraObjType.put((Object) "BATISSE1I2122.LOCATION_T", (Object) Class.forName("types.Location"));
// ResultSet resultSet = stmt.executeQuery(queryEmp);
ResultSet resultSet = stmt.executeQuery(queryLoc);
while (resultSet.next()) {
// types.Employe emp = (types.Employe) resultSet.getObject(1);
// System.out.println(emp);
Location location = (Location) resultSet.getObject(1);
System.out.println(location);
}
}
}
--- types de la base de données
---Account
package types;
import java.sql.*;
public class Account implements SQLData {
private String sqlType;
private int accountNo;
private String accountType;
private float balance;
private float bankceiling;
private Array statements;
private Ref refAgency;
public int getAccountNo() {
return accountNo;
}
public void setAccountNo(int accountNo) {
this.accountNo = accountNo;
}
public String getAccountType() {
return accountType;
}
public void setAccountType(String accountType) {
this.accountType = accountType;
}
public float getBalance() {
return balance;
}
public void setBalance(float balance) {
this.balance = balance;
}
public float getBankceiling() {
return bankceiling;
}
public void setBankceiling(float bankceiling) {
this.bankceiling = bankceiling;
}
public Array getStatements() {
return statements;
}
public void setStatements(Array statements) {
this.statements = statements;
}
public Ref getRefAgency() {
return refAgency;
}
public void setRefAgency(Ref refAgency) {
this.refAgency = refAgency;
}
@Override
public String getSQLTypeName() throws SQLException {
return sqlType;
}
@Override
public void readSQL(SQLInput stream, String typeName) throws SQLException {
this.sqlType = typeName;
this.accountNo = stream.readInt();
this.accountType = stream.readString();
this.balance = stream.readFloat();
this.bankceiling = stream.readFloat();
this.statements = stream.readArray();
this.refAgency = stream.readRef();
}
@Override
public void writeSQL(SQLOutput stream) throws SQLException {
stream.writeInt(accountNo);
stream.writeString(accountType);
stream.writeFloat(balance);
stream.writeFloat(bankceiling);
stream.writeArray(statements);
stream.writeRef(refAgency);
}
}
--- Transaction
package types;
import java.sql.*;
public class Transaction implements SQLData {
private String sqlType;
private int tNum;
private Ref issuer;
private Ref refAccIssuer;
private Ref payee;
private Ref refAccPayee;
private float amount;
public Transaction() {
}
public Transaction(String sqlType, int tNum, Ref issuer, Ref refAccIssuer, Ref payee, Ref refAccPayee, float amount) {
this.sqlType = sqlType;
this.tNum = tNum;
this.issuer = issuer;
this.refAccIssuer = refAccIssuer;
this.payee = payee;
this.refAccPayee = refAccPayee;
this.amount = amount;
}
public int gettNum() {
return tNum;
}
public void settNum(int tNum) {
this.tNum = tNum;
}
public Ref getIssuer() {
return issuer;
}
public void setIssuer(Ref issuer) {
this.issuer = issuer;
}
public Ref getRefAccIssuer() {
return refAccIssuer;
}
public void setRefAccIssuer(Ref refAccIssuer) {
this.refAccIssuer = refAccIssuer;
}
public Ref getPayee() {
return payee;
}
public void setPayee(Ref payee) {
this.payee = payee;
}
public Ref getRefAccPayee() {
return refAccPayee;
}
public void setRefAccPayee(Ref refAccPayee) {
this.refAccPayee = refAccPayee;
}
public float getAmount() {
return amount;
}
public void setAmount(float amount) {
this.amount = amount;
}
@Override
public String getSQLTypeName() throws SQLException {
return sqlType;
}
public void readSQL(SQLInput stream, String typeName) throws SQLException {
sqlType = typeName;
tNum = stream.readInt();
issuer = stream.readRef();
refAccIssuer = stream.readRef();
payee = stream.readRef();
refAccPayee = stream.readRef();
amount = stream.readFloat();
}
/*
Ecrire dans le flot dans l'ordre.
*/
public void writeSQL(SQLOutput stream) throws SQLException {
stream.writeInt(tNum);
stream.writeRef(issuer);
stream.writeRef(refAccIssuer);
stream.writeRef(payee);
stream.writeRef(refAccPayee);
stream.writeFloat(amount);
}
}
--- Agency
package types;
import java.sql.*;
public class Agency implements SQLData {
private String sqlType;
private int agencyNo;
private String aName;
private Ref loc;
private Array listRefEmp;
private Array listRefClient;
public Agency() {
}
public Agency(String sqlType, int agencyNo, String aName, Ref loc, Array listRefEmp, Array listRefClient) {
this.sqlType = sqlType;
this.agencyNo = agencyNo;
this.aName = aName;
this.loc = loc;
this.listRefEmp = listRefEmp;
this.listRefClient = listRefClient;
}
public int getAgencyNo() {
return agencyNo;
}
public void setAgencyNo(int agencyNo) {
this.agencyNo = agencyNo;
}
public String getaName() {
return aName;
}
public void setaName(String aName) {
this.aName = aName;
}
public Ref getLoc() {
return loc;
}
public void setLoc(Ref loc) {
this.loc = loc;
}
public Array getListRefEmp() {
return listRefEmp;
}
public void setListRefEmp(Array listRefEmp) {
this.listRefEmp = listRefEmp;
}
public Array getListRefClient() {
return listRefClient;
}
public void setListRefClient(Array listRefClient) {
this.listRefClient = listRefClient;
}
@Override
public String getSQLTypeName() throws SQLException {
return sqlType;
}
@Override
public void readSQL(SQLInput stream, String typeName) throws SQLException {
this.sqlType = typeName;
this.agencyNo = stream.readInt();
this.aName = stream.readString();
this.loc = stream.readRef();
this.listRefEmp = stream.readArray();
this.listRefClient = stream.readArray();
}
@Override
public void writeSQL(SQLOutput stream) throws SQLException {
stream.writeInt(agencyNo);
stream.writeString(aName);
stream.writeRef(loc);
stream.writeArray(listRefEmp);
stream.writeArray(listRefClient);
}
}
--- client
package types;
import java.io.BufferedReader;
import java.sql.*;
public class Client implements SQLData {
private String sqlType;
private int numCli;
private String cName;
private Array prenoms;
private String job;
private float sal;
private Array listRefAccount;
private Clob project;
private Date birthDate;
private Ref refAgency;
public Client() {
}
public Client(String sqlType, int numCli, String cName, Array prenoms, String job, float sal, Array listRefAccount, Clob project, Date birthDate, Ref refAgency) {
this.sqlType = sqlType;
this.numCli = numCli;
this.cName = cName;
this.prenoms = prenoms;
this.job = job;
this.sal = sal;
this.listRefAccount = listRefAccount;
this.project = project;
this.birthDate = birthDate;
this.refAgency = refAgency;
}
public String getSqlType() {
return sqlType;
}
public void setSqlType(String sqlType) {
this.sqlType = sqlType;
}
public int getNumCli() {
return numCli;
}
public void setNumCli(int numCli) {
this.numCli = numCli;
}
public String getcName() {
return cName;
}
public void setcName(String cName) {
this.cName = cName;
}
public Array getPrenoms() {
return prenoms;
}
public void setPrenoms(Array prenoms) {
this.prenoms = prenoms;
}
public String getJob() {
return job;
}
public void setJob(String job) {
this.job = job;
}
public float getSal() {
return sal;
}
public void setSal(float sal) {
this.sal = sal;
}
public Array getListRefAccount() {
return listRefAccount;
}
public void setListRefAccount(Array listRefAccount) {
this.listRefAccount = listRefAccount;
}
public Clob getProject() {
return project;
}
public void setProject(Clob project) {
this.project = project;
}
public Date getBirthDate() {
return birthDate;
}
public void setBirthDate(Date birthDate) {
this.birthDate = birthDate;
}
public Ref getRefAgency() {
return refAgency;
}
public void setRefAgency(Ref refAgency) {
this.refAgency = refAgency;
}
/**
* Returns the fully-qualified
* name of the SQL user-defined type that this object represents.
* This method is called by the JDBC driver to get the name of the
* UDT instance that is being mapped to this instance of
* {@code SQLData}.
*
* @return the type name that was passed to the method {@code readSQL}
* when this object was constructed and populated
* @throws SQLException if there is a database access error
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
@Override
public String getSQLTypeName() throws SQLException {
return sqlType;
}
/**
* Populates this object with data read from the database.
* The implementation of the method must follow this protocol:
* <UL>
* <LI>It must read each of the attributes or elements of the SQL
* type from the given input stream. This is done
* by calling a method of the input stream to read each
* item, in the order that they appear in the SQL definition
* of the type.
* <LI>The method {@code readSQL} then
* assigns the data to appropriate fields or
* elements (of this or other objects).
* Specifically, it must call the appropriate <i>reader</i> method
* ({@code SQLInput.readString}, {@code SQLInput.readBigDecimal},
* and so on) method(s) to do the following:
* for a distinct type, read its single data element;
* for a structured type, read a value for each attribute of the SQL type.
* </UL>
* The JDBC driver initializes the input stream with a type map
* before calling this method, which is used by the appropriate
* {@code SQLInput} reader method on the stream.
*
* @param stream the {@code SQLInput} object from which to read the data for
* the value that is being custom mapped
* @param typeName the SQL type name of the value on the data stream
* @throws SQLException if there is a database access error
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see SQLInput
* @since 1.2
*/
@Override
public void readSQL(SQLInput stream, String typeName) throws SQLException {
this.sqlType = typeName;
this.numCli = stream.readInt();
this.cName = stream.readString();
this.prenoms = stream.readArray();
this.job = stream.readString();
this.sal = stream.readFloat();
this.listRefAccount = stream.readArray();
this.project = stream.readClob();
this.birthDate = stream.readDate();
this.refAgency = stream.readRef();
}
/**
* Writes this object to the given SQL data stream, converting it back to
* its SQL value in the data source.
* The implementation of the method must follow this protocol:<BR>
* It must write each of the attributes of the SQL type
* to the given output stream. This is done by calling a
* method of the output stream to write each item, in the order that
* they appear in the SQL definition of the type.
* Specifically, it must call the appropriate {@code SQLOutput} writer
* method(s) ({@code writeInt}, {@code writeString}, and so on)
* to do the following: for a Distinct Type, write its single data element;
* for a Structured Type, write a value for each attribute of the SQL type.
*
* @param stream the {@code SQLOutput} object to which to write the data for
* the value that was custom mapped
* @throws SQLException if there is a database access error
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see SQLOutput
* @since 1.2
*/
@Override
public void writeSQL(SQLOutput stream) throws SQLException {
stream.writeInt(numCli);
stream.writeString(cName);
stream.writeArray(prenoms);
stream.writeString(job);
stream.writeFloat(sal);
stream.writeArray(listRefAccount);
stream.writeClob(project);
stream.writeDate(birthDate);
stream.writeRef(refAgency);
}
public void displayClientProject() throws java.sql.SQLException, java.io.IOException {
BufferedReader clobReader;
clobReader = new BufferedReader(this.getProject().getCharacterStream());
String ligne;
System.out.println("");
System.out.println("[ <PROJECT/ ");
while ((ligne = clobReader.readLine()) != null) {
System.out.println(" " + ligne);
}
System.out.println(" /CV>] ");
System.out.println("");
}
}
-- LOCATION
package types;
import java.sql.*;
public class Location implements SQLData {
private String sqlType;
private String country;
private String city;
private String streetName;
private int streetNo;
public Location() {
}
public Location(String sqlType, String country, String city, String streetName, int streetNo) {
this.sqlType = sqlType;
this.country = country;
this.city = city;
this.streetName = streetName;
this.streetNo = streetNo;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getStreetName() {
return streetName;
}
public void setStreetName(String streetName) {
this.streetName = streetName;
}
public int getStreetNo() {
return streetNo;
}
public void setStreetNo(int streetNo) {
this.streetNo = streetNo;
}
/**
* Returns the fully-qualified
* name of the SQL user-defined type that this object represents.
* This method is called by the JDBC driver to get the name of the
* UDT instance that is being mapped to this instance of
* {@code SQLData}.
*
* @return the type name that was passed to the method {@code readSQL}
* when this object was constructed and populated
* @throws SQLException if there is a database access error
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
@Override
public String getSQLTypeName() throws SQLException {
return sqlType;
}
/**
* Populates this object with data read from the database.
* The implementation of the method must follow this protocol:
* <UL>
* <LI>It must read each of the attributes or elements of the SQL
* type from the given input stream. This is done
* by calling a method of the input stream to read each
* item, in the order that they appear in the SQL definition
* of the type.
* <LI>The method {@code readSQL} then
* assigns the data to appropriate fields or
* elements (of this or other objects).
* Specifically, it must call the appropriate <i>reader</i> method
* ({@code SQLInput.readString}, {@code SQLInput.readBigDecimal},
* and so on) method(s) to do the following:
* for a distinct type, read its single data element;
* for a structured type, read a value for each attribute of the SQL type.
* </UL>
* The JDBC driver initializes the input stream with a type map
* before calling this method, which is used by the appropriate
* {@code SQLInput} reader method on the stream.
*
* @param stream the {@code SQLInput} object from which to read the data for
* the value that is being custom mapped
* @param typeName the SQL type name of the value on the data stream
* @throws SQLException if there is a database access error
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see SQLInput
* @since 1.2
*/
@Override
public void readSQL(SQLInput stream, String typeName) throws SQLException {
this.sqlType = typeName;
this.country = stream.readString();
this.city = stream.readString();
this.streetName = stream.readString();
this.streetNo = stream.readInt();
}
/*
Ecrire dans le flot dans l'ordre.
*/
public void writeSQL(SQLOutput stream) throws SQLException {
stream.writeString(country);
stream.writeString(city);
stream.writeString(streetName);
stream.writeInt(streetNo);
}
@Override
public String toString() {
return "types.Location{" +
"country='" + country + '\'' +
", city='" + city + '\'' +
", streetName='" + streetName + '\'' +
", streetNo=" + streetNo +
'}';
}
}
--- employe
package types;
import java.io.BufferedReader;
import java.sql.*;
public class Employe implements SQLData {
private String sqlType;
private int empNo;
private String eName;
private Array prenoms;
private String job;
private float sal;
private Clob cv;
private Date birthDate;
private Date employementDate;
private Ref refAgency;
public Employe() {
}
public Employe(String sqlType, int empNo, String eName, Array prenoms, String job, float sal, Clob cv, Date birthDate, Date employementDate, Ref refAgency) {
this.sqlType = sqlType;
this.empNo = empNo;
this.eName = eName;
this.prenoms = prenoms;
this.job = job;
this.sal = sal;
this.cv = cv;
this.birthDate = birthDate;
this.employementDate = employementDate;
this.refAgency = refAgency;
}
public String getSqlType() {
return sqlType;
}
public void setSqlType(String sqlType) {
this.sqlType = sqlType;
}
public int getEmpNo() {
return empNo;
}
public void setEmpNo(int empNo) {
this.empNo = empNo;
}
public String geteName() {
return eName;
}
public void seteName(String eName) {
this.eName = eName;
}
public Array getPrenoms() {
return prenoms;
}
public void setPrenoms(Array prenoms) {
this.prenoms = prenoms;
}
public String getJob() {
return job;
}
public void setJob(String job) {
this.job = job;
}
public float getSal() {
return sal;
}
public void setSal(float sal) {
this.sal = sal;
}
public Clob getCv() {
return cv;
}
public void setCv(Clob cv) {
this.cv = cv;
}
public Date getBirthDate() {
return birthDate;
}
public void setBirthDate(Date birthDate) {
this.birthDate = birthDate;
}
public Date getEmployementDate() {
return employementDate;
}
public void setEmployementDate(Date employementDate) {
this.employementDate = employementDate;
}
public Ref getRefAgency() {
return refAgency;
}
public void setRefAgency(Ref refAgency) {
this.refAgency = refAgency;
}
/**
* Returns the fully-qualified
* name of the SQL user-defined type that this object represents.
* This method is called by the JDBC driver to get the name of the
* UDT instance that is being mapped to this instance of
* {@code SQLData}.
*
* @return the type name that was passed to the method {@code readSQL}
* when this object was constructed and populated
* @throws SQLException if there is a database access error
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
@Override
public String getSQLTypeName() throws SQLException {
return sqlType;
}
/**
* Populates this object with data read from the database.
* The implementation of the method must follow this protocol:
* <UL>
* <LI>It must read each of the attributes or elements of the SQL
* type from the given input stream. This is done
* by calling a method of the input stream to read each
* item, in the order that they appear in the SQL definition
* of the type.
* <LI>The method {@code readSQL} then
* assigns the data to appropriate fields or
* elements (of this or other objects).
* Specifically, it must call the appropriate <i>reader</i> method
* ({@code SQLInput.readString}, {@code SQLInput.readBigDecimal},
* and so on) method(s) to do the following:
* for a distinct type, read its single data element;
* for a structured type, read a value for each attribute of the SQL type.
* </UL>
* The JDBC driver initializes the input stream with a type map
* before calling this method, which is used by the appropriate
* {@code SQLInput} reader method on the stream.
*
* @param stream the {@code SQLInput} object from which to read the data for
* the value that is being custom mapped
* @param typeName the SQL type name of the value on the data stream
* @throws SQLException if there is a database access error
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see SQLInput
* @since 1.2
*/
@Override
public void readSQL(SQLInput stream, String typeName) throws SQLException {
this.sqlType = typeName;
this.empNo = stream.readInt();
this.eName = stream.readString();
this.prenoms = stream.readArray();
this.job = stream.readString();
this.sal = stream.readFloat();
this.cv = stream.readClob();
this.birthDate = stream.readDate();
this.employementDate = stream.readDate();
this.refAgency = stream.readRef();
}
/*
Ecrire dans le flot dans l'ordre.
*/
public void writeSQL(SQLOutput stream) throws SQLException {
stream.writeInt(empNo);
stream.writeString(eName);
stream.writeArray(prenoms);
stream.writeString(job);
stream.writeFloat(sal);
stream.writeClob(cv);
stream.writeDate(birthDate);
stream.writeDate(employementDate);
stream.writeRef(refAgency);
}
public void displayCV() throws java.sql.SQLException, java.io.IOException {
BufferedReader clobReader;
clobReader = new BufferedReader(this.getCv().getCharacterStream());
String ligne;
System.out.println("");
System.out.println("[ <CV/ ");
while ((ligne = clobReader.readLine()) != null) {
System.out.println(" " + ligne);
}
System.out.println(" /CV>] ");
System.out.println("");
}
@Override
public String toString() {
return "types.Employe{" +
"sqlType='" + sqlType + '\'' +
", empNo=" + empNo +
", eName='" + eName + '\'' +
", prenoms=" + prenoms +
", job='" + job + '\'' +
", sal=" + sal +
", cv=" + cv +
", birthDate=" + birthDate +
", employementDate=" + employementDate +
", refAgency=" + refAgency +
'}';
}
}