01: /*
02: * Copyright (c) 1998 - 2005 Versant Corporation
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * Versant Corporation - initial API and implementation
10: */
11: package com.versant.core.jdbc.sql.conv;
12:
13: import com.versant.core.jdbc.JdbcConverter;
14: import com.versant.core.jdbc.JdbcConverterFactory;
15: import com.versant.core.jdbc.JdbcTypeRegistry;
16: import com.versant.core.jdbc.metadata.JdbcColumn;
17:
18: import javax.jdo.JDOFatalDataStoreException; //todo: appears only in throws clause
19: import java.sql.PreparedStatement;
20: import java.sql.SQLException;
21: import java.sql.ResultSet;
22: import java.io.File;
23:
24: /**
25: * This converter converts java.io.File objects to and from SQL. It assumes
26: * that the File is stored in a column compatible with ResultSet.getString and
27: * PreparedStatement.setString.
28: * @keep-all
29: */
30: public class FileConverter extends TypeAsStringConverterBase {
31:
32: public static class Factory extends NoArgJdbcConverterFactory {
33:
34: private FileConverter converter;
35:
36: /**
37: * Create a converter for col using args as parameters. Return null if
38: * no converter is required.
39: */
40: public JdbcConverter createJdbcConverter(JdbcColumn col,
41: Object args, JdbcTypeRegistry jdbcTypeRegistry) {
42: if (converter == null)
43: converter = new FileConverter();
44: return converter;
45: }
46:
47: }
48:
49: /**
50: * Create an instance of our type from a String.
51: * @param s String to use (never null)
52: */
53: protected Object fromString(String s) {
54: return new File(s);
55: }
56:
57: /**
58: * Get the type of our expected value objects (e.g. java.util.Locale
59: * for a converter for Locale's).
60: */
61: public Class getValueType() {
62: return File.class;
63: }
64:
65: }
|