KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > jdbc > sql > conv > FileConverter


1
2 /*
3  * Copyright (c) 1998 - 2005 Versant Corporation
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Versant Corporation - initial API and implementation
11  */

12 package com.versant.core.jdbc.sql.conv;
13
14 import com.versant.core.jdbc.JdbcConverter;
15 import com.versant.core.jdbc.JdbcConverterFactory;
16 import com.versant.core.jdbc.JdbcTypeRegistry;
17 import com.versant.core.jdbc.metadata.JdbcColumn;
18
19 import javax.jdo.JDOFatalDataStoreException; //todo: appears only in throws clause
20
import java.sql.PreparedStatement JavaDoc;
21 import java.sql.SQLException JavaDoc;
22 import java.sql.ResultSet JavaDoc;
23 import java.io.File JavaDoc;
24
25 /**
26  * This converter converts java.io.File objects to and from SQL. It assumes
27  * that the File is stored in a column compatible with ResultSet.getString and
28  * PreparedStatement.setString.
29  * @keep-all
30  */

31 public class FileConverter extends TypeAsStringConverterBase {
32
33     public static class Factory extends NoArgJdbcConverterFactory {
34
35         private FileConverter converter;
36
37         /**
38          * Create a converter for col using args as parameters. Return null if
39          * no converter is required.
40          */

41         public JdbcConverter createJdbcConverter(JdbcColumn col, Object JavaDoc args,
42                 JdbcTypeRegistry jdbcTypeRegistry) {
43             if (converter == null) 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 JavaDoc fromString(String JavaDoc s) {
54         return new File JavaDoc(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 JavaDoc getValueType() {
62         return File JavaDoc.class;
63     }
64
65 }
66
67
Popular Tags