Presentation is loading. Please wait.

Presentation is loading. Please wait.

WiTa Datenbankanbindung: Schnittstellen, Methoden, Attribute.

Similar presentations


Presentation on theme: "WiTa Datenbankanbindung: Schnittstellen, Methoden, Attribute."— Presentation transcript:

1 WiTa Datenbankanbindung: Schnittstellen, Methoden, Attribute

2 Übersicht Schnittstellen, Methoden und Attribute für –Speichern –Laden –Hilfsstrukturen

3 Speichern

4 Interfaces –Storeable: getString() –Createable: create(), remove() –Updateable: update() Hilfsmethoden (static) –executeCommand –executeCreate Create Update Remove

5 Interface: Storeable public String getCreateString() INSERT INTO [Tabelle] ([Tab.-Spalten]) VALUES ([Attribute]) public String getUpdateString() UPDATE [Tabelle] SET [Spalte = Attribut] WHERE [Prim.-Key = Objekt-ID] public String getRemoveString() DELETE FROM [Tabelle] WHERE [Prim.-Key = Objekt-ID]

6 Interface: Createable create(): public void create() throws SQLException, ValidationException { this.validate(); executeCreate(this, this.getLogger()); } remove(): public void remove() throws SQLException { executeCommand(this.getRemoveString(), this.getLogger()); }

7 Interface: Updateable update(): public void update() throws SQLException, ValidationException { if(this.getId() == 0){ String[] error = {this+[ERROR-MSG]}; throw new ValidationException(error); } this.validate(); String[] strUpdate = {this.getUpdateString()}; executeUpdate(strUpdate, this.getLogger()); }

8 Hilfsmethode: executeCommand (3 Varianten) 1.public static void executeCommand( String sqlString, Logger logger ) 2.public static void executeCommand( String[] sqlString, Logger logger )

9 Hilfsmethode: executeCommand (3. Variante) 3.public static void executeCommand( String sqlString, Logger logger, Connection connect, boolean commit )

10 Hilfsmethode: executeCreate (2 Varianten) 1.public static int executeCreate( Storeable ObjectToStore, Logger logger ) 2.public static int executeCreate( Storeable ObjectToStore, Logger logger, Connection connect, boolean commit )

11 Laden

12 Interfaces –Restoreable: restore(ResultSet) Hilfsmethoden (static) –genericFind –calculateQuery –getMemberFromDatabase

13 Interface: Restoreable restore(ResultSet): (in BankDetail) public void restore(ResultSet source) throws SQLException { this.setId (source.getInt ("BankDetail_id") ); this.setBank (source.getString ("bank") ); this.setBankCode (source.getInt ("bankCode") ); this.setAccountNumber( source.getLong("accountNumber") ); this.ownerId = source.getInt("owner"); this.setReasonForPayment (source.getString("reasonForPayment") ); log.info(this+"restore("+ source.getClass().getName() +"): " +"restoring was successful"); }

14 Hilfsmethode: genericFind public static Collection genericFind( String queryString, String restoreableClassName, Logger logger ) Beispiel: genericFind( "SELECT * FROM Address WHERE street LIKE "+ getQuery(street), "de.uni_marburg.wita.orga.Address", log );

15 Hilfsmethode: calculateQuery public static Object calculateQuery( String sqlQuery, boolean longOrDouble, Logger logger ) Beispiel: Long nCounter = ( Long ) calculateQuery( "SELECT count(*) FROM … " …, true, log );

16 Hilfsmethode: getMemberFromDatabase public static Object getMemberFromDatabase( String sqlQuery, String restoreableObjectName, Logger logger ) Beispiel: getMemberFromDatabase( "SELECT * FROM Address WHERE id = "+ addressId, "de.uni_marburg.wita.orga.Address", log );

17 Hilfsstrukturen

18 Interfaces –SimpleIntId: Id([int]) Hilfsmethoden (static) –Connection getConnection –StringmakeStringFuzzy –StringgetCompString –StringgetQuery –String[]makeSQLString get set

19 Hilfsmethode: getQuery public static String getQuery( ) Beispiele: (String) test (Date) [DATE] (String) yyyy-MM-dd HH:mm:ss (boolean) true (String) 1 (boolean) false (String) 2 String Date boolean

20 Hilfsmethode: makeSQLString String makeSQLString( String[] fieldList, String prefix, String separator) Beispiel: fieldList = {eins,zwei,drei} prefix = Obj. separator = ; Obj.eins; Obj.zwei; Obj.drei Parameter: Rückgabe:

21 Hilfsstrukturen Hilfsattribute – final static transient String[] sqlNames Beispiel: (in BankDetail) private final static transient String[] sqlNames = { "BankDetail_id, "bank", "bankCode, "accountNumber", "owner, "reasonForPayment" }; private public

22 Hilfsstrukturen Hilfsattribute –private transient int [Attribut-Name]Id Beispiel: (in BankDetail) … private Person owner; private transient int ownerId;...


Download ppt "WiTa Datenbankanbindung: Schnittstellen, Methoden, Attribute."

Similar presentations


Ads by Google