KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > db > impl > DBPropDatabase


1 /*
2   (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3   [See end of file]
4 */

5
6 package com.hp.hpl.jena.db.impl;
7
8 import com.hp.hpl.jena.graph.*;
9 import com.hp.hpl.jena.util.iterator.*;
10 import com.hp.hpl.jena.vocabulary.DB;
11
12 import java.text.SimpleDateFormat JavaDoc;
13 import java.util.*;
14
15 /**
16  *
17  * A wrapper to assist in getting and setting DB information from
18  * a persistent store.
19  *
20  * This is written in the style of enhanced nodes - no state is
21  * stored in the DBStoreDesc, instead all state is in the
22  * underlying graph and this is just provided as a convenience.
23  *
24  * (We don't use enhanced nodes because, since we control everything
25  * in the persistent store system description, we can avoid any
26  * need to handle polymorhphism).
27  *
28  *
29  * @author csayers
30  * @version $Revision: 1.13 $
31  */

32 public class DBPropDatabase extends DBProp {
33
34     /**
35      * @since Jena 2.0
36      */

37
38     public static final Node_URI dbEngineType = (Node_URI)DB.engineType.getNode();
39     public static final Node_URI dbLayoutVersion = (Node_URI)DB.layoutVersion.getNode();
40     public static final Node_URI dbDriverVersion = (Node_URI)DB.driverVersion.getNode();
41     public static final Node_URI dbFormatDate = (Node_URI)DB.formatDate.getNode();
42     public static final Node_URI dbGraph = (Node_URI)DB.graph.getNode();
43     public static final Node_URI dbLongObjectLength = (Node_URI)DB.longObjectLength.getNode();
44     public static final Node_URI dbIndexKeyLength = (Node_URI)DB.indexKeyLength.getNode();
45     public static final Node_URI dbIsTransactionDb = (Node_URI)DB.isTransactionDb.getNode();
46     public static final Node_URI dbDoCompressURI = (Node_URI)DB.doCompressURI.getNode();
47     public static final Node_URI dbCompressURILength = (Node_URI)DB.compressURILength.getNode();
48     public static final Node_URI dbTableNamePrefix = (Node_URI)DB.tableNamePrefix.getNode();
49     
50     public static final String JavaDoc dbSystemGraphName = "SystemGraph";
51     
52     protected static SimpleDateFormat JavaDoc dateFormat = null;
53
54     public DBPropDatabase ( SpecializedGraph g, String JavaDoc engineType, String JavaDoc driverVersion,
55         String JavaDoc layoutVersion, String JavaDoc longObjectLength, String JavaDoc indexKeyLength,
56         String JavaDoc isTransactionDb, String JavaDoc doCompressURI, String JavaDoc compressURILength,
57         String JavaDoc tableNamePrefix ) {
58         super(g);
59         
60         if( dateFormat == null ) {
61             // Use ISO 8601 Date format and write all dates as UTC time
62
dateFormat = new SimpleDateFormat JavaDoc("yyyyMMdd'T'HHmmss'Z'");
63             dateFormat.setTimeZone( TimeZone.getTimeZone("GMT"));
64         }
65         
66         String JavaDoc today = dateFormat.format( new Date());
67         if( engineType != null ) putPropString(dbEngineType, engineType);
68         if( driverVersion != null ) putPropString(dbDriverVersion, driverVersion);
69         putPropString(dbLayoutVersion, layoutVersion);
70         putPropString(dbFormatDate, today);
71         putPropString(dbLongObjectLength, longObjectLength);
72         putPropString(dbIndexKeyLength, indexKeyLength);
73         putPropString(dbIsTransactionDb, isTransactionDb);
74         putPropString(dbDoCompressURI, doCompressURI);
75         putPropString(dbCompressURILength, compressURILength);
76         putPropString(dbTableNamePrefix, tableNamePrefix);
77     }
78     
79     public DBPropDatabase( SpecializedGraph g, Node n) {
80         super(g,n);
81     }
82     
83     public DBPropDatabase( SpecializedGraph g) {
84         super(g,findDBPropNode(g));
85     }
86     
87     public String JavaDoc getName() { return self.getURI(); }
88     public String JavaDoc getEngineType() { return getPropString( dbEngineType); }
89     public String JavaDoc getDriverVersion() { return getPropString( dbDriverVersion);}
90     public String JavaDoc getFormatDate() { return getPropString( dbFormatDate); }
91     public String JavaDoc getLayoutVersion() { return getPropString( dbLayoutVersion); }
92     public String JavaDoc getLongObjectLength() { return getPropString( dbLongObjectLength); }
93     public String JavaDoc getIndexKeyLength() { return getPropString( dbIndexKeyLength); }
94     public String JavaDoc getIsTransactionDb() { return getPropString( dbIsTransactionDb); }
95     public String JavaDoc getDoCompressURI() { return getPropString( dbDoCompressURI); }
96     public String JavaDoc getCompressURILength() { return getPropString( dbCompressURILength); }
97     public String JavaDoc getTableNamePrefix() { return getPropString( dbTableNamePrefix); }
98     
99     public void addGraph( DBPropGraph g ) {
100         putPropNode( dbGraph, g.getNode() );
101     }
102
103     public void removeGraph( DBPropGraph g ) {
104         SpecializedGraph.CompletionFlag complete = newComplete();
105         ClosableIterator matches = graph.find( self, dbGraph, g.getNode(), complete);
106         if( matches.hasNext() ) {
107             graph.delete( (Triple)(matches.next()), complete );
108             g.remove();
109             matches.close();
110         }
111     }
112     
113     public ExtendedIterator getAllGraphs() {
114         return
115             graph.find( self, dbGraph, null, newComplete() )
116             .mapWith( new MapToLSet() );
117     }
118     
119     public ExtendedIterator getAllGraphNames() {
120         return getAllGraphs() .mapWith( graphToName );
121     }
122
123     static final Map1 graphToName = new Map1()
124         { public Object JavaDoc map1( Object JavaDoc o) { return ((DBPropGraph) o).getName(); } };
125
126     private class MapToLSet implements Map1 {
127         public Object JavaDoc map1( Object JavaDoc o) {
128             Triple t = (Triple) o;
129             return new DBPropGraph( graph, t.getObject() );
130         }
131     }
132     
133     static Node findDBPropNode( SpecializedGraph g) {
134         ClosableIterator matches = g.find( null, dbEngineType, null, newComplete() );
135         if( matches.hasNext())
136             try { return ((Triple) matches.next()).getSubject(); }
137             finally { matches.close(); }
138         return null;
139     }
140 }
141
142 /*
143  * (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
144  * All rights reserved.
145  *
146  * Redistribution and use in source and binary forms, with or without
147  * modification, are permitted provided that the following conditions
148  * are met:
149  * 1. Redistributions of source code must retain the above copyright
150  * notice, this list of conditions and the following disclaimer.
151  * 2. Redistributions in binary form must reproduce the above copyright
152  * notice, this list of conditions and the following disclaimer in the
153  * documentation and/or other materials provided with the distribution.
154  * 3. The name of the author may not be used to endorse or promote products
155  * derived from this software without specific prior written permission.
156
157  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
158  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
159  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
160  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
161  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
162  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
163  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
164  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
165  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
166  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
167  */
Popular Tags