Skip to content

Method: handleCall(CallableStatement, int)

1: package de.fhdw.wtf.persistence.utils;
2:
3: import java.sql.CallableStatement;
4: import java.sql.SQLException;
5:
6: import de.fhdw.wtf.persistence.exception.NotValidInputException;
7: import de.fhdw.wtf.persistence.meta.Object;
8: import de.fhdw.wtf.persistence.meta.StringValue;
9:
10: /**
11: * Wrapper for a String for a Database-Query.
12: */
13: public class DBConnectionStringHandler implements DBConnectionObjectHandler {
14:         
15:         private final String string;
16:         
17:         @Override
18:         public String getObjectTypeString() {
19:                 return "Str";
20:         }
21:         
22:         @Override
23:         public void handleCall(final CallableStatement call, final int parameterIndex) throws SQLException {
24:                 call.setString(parameterIndex, this.string);
25:         }
26:         
27:         @Override
28:         public Object getObject() {
29:                 return new StringValue(this.string);
30:         }
31:         
32:         /**
33:          * creates a wrapper for a string for a database connection.
34:          *
35:          * @param string
36:          * the wrapped string
37:          * @throws NotValidInputException
38:          * throws when the given string is null
39:          */
40:         public DBConnectionStringHandler(final String string) throws NotValidInputException {
41:                 super();
42:                 
43:                 if (string == null) {
44:                         throw new NotValidInputException("string");
45:                 }
46:                 
47:                 this.string = string;
48:         }
49: }