Source Code Cross Referenced for DbManager.java in  » Portal » Open-Portal » com » sun » portal » search » db » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » Open Portal » com.sun.portal.search.db 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DbManager.java
003:         *
004:         * Created on February 28, 2005, 6:26 PM
005:         */
006:
007:        package com.sun.portal.search.db;
008:
009:        import com.sun.portal.search.util.*;
010:        import com.sun.portal.search.rdm.*;
011:        import com.sun.portal.search.soif.SOIF;
012:        import com.sun.portal.search.soif.SOIFOutputStream;
013:        import java.util.HashMap;
014:        import java.util.Map;
015:        import java.util.logging.Level;
016:
017:        /**
018:         * Database factory and config utility
019:         */
020:        public class DbManager {
021:            static private Map RootDbEntrymap = new HashMap();
022:
023:            private DbManager() {
024:            }
025:
026:            static public void getRootDbEntries(SToken st, SOIFOutputStream sout)
027:                    throws RDMException {
028:                int rcode = 0;
029:                Datum key, data;
030:                SOIF soif;
031:
032:                PartitionedDb rootdb = null;
033:
034:                try {
035:
036:                    rootdb = new PartitionedDb();
037:                    //rootdb = new IndexedSOIFDb();
038:                    rootdb.open(null,
039:                            SearchConfig.getValue(SearchConfig.DBDIR), "root",
040:                            RDMDb.WRCREAT, 0644);
041:                    rootdb.dump(sout);
042:                } catch (Exception e) {
043:
044:                } finally {
045:                    if (rootdb != null)
046:                        rootdb.close(st);
047:                }
048:            }
049:
050:            static public SOIF getRootDbEntry(SToken st, String dbname)
051:                    throws RDMException {
052:
053:                int rcode = 0;
054:                Datum key, data;
055:                SOIF soif;
056:
057:                soif = (SOIF) RootDbEntrymap.get(dbname);
058:                if (soif != null) {
059:                    return soif;
060:                }
061:
062:                PartitionedDb rootdb = null;
063:
064:                try {
065:
066:                    rootdb = new PartitionedDb();
067:                    //rootdb = new IndexedSOIFDb();
068:                    rootdb.open(null,
069:                            SearchConfig.getValue(SearchConfig.DBDIR), "root",
070:                            RDMDb.WRCREAT, 0644);
071:
072:                    key = new Datum(dbname);
073:                    key = DbUtil.key_create(dbname);
074:                    data = new Datum();
075:
076:                    rcode = rootdb.fetch(st, key, data, 0, null);
077:
078:                    /*
079:                    if (rcode == Db.DB_NOTFOUND && (rw & RDMDb.WRCREAT) != 0) {
080:                        // should we really create an empty db entry here???
081:                        // XXX partitioned db is not using this mechanism...
082:                        try {
083:                    SearchLogger.getLogger().log(Level.FINE, "PSSH_CSPSB0041", dbname );
084:                            soif = new SOIF(PartitionedDb.DBASE, dbname);
085:                     
086:                            data.set_data(soif.toByteArray(SOIFDb.ENCODING));
087:                            key = new Datum(dbname);
088:                            key = DbUtil.key_create(dbname);
089:                            rootdb.store(st, key, data, 0, null);   // XXX do we need a txn arg?
090:                            rcode = rootdb.fetch(st, key, data, 0, null);	// refetch the db meta data
091:                        }
092:                        catch (Exception e) {
093:                    SearchLogger.getLogger().log(Level.WARNING, "PSSH_CSPSB0043", dbname );
094:                            //CSxLog.error(1, 1, "Failed to create db: " + dbname, e);
095:                            throw new RDMException("Failed to create db: " + dbname);
096:                        }
097:                    }
098:                    else if (rcode != 0)
099:                        throw new RDMException(new DbException("Failed to open db", rcode));
100:                     */
101:
102:                    //if (rcode != 0)
103:                    //throw new RDMException("Failed to open db, " + dbname + " err=" + rcode);
104:                    if (rcode == RDMDb.DB_NOTFOUND)
105:                        return null;
106:
107:                    soif = new SOIF(data.get_data(), SOIFDb.ENCODING);
108:                    RootDbEntrymap.put(dbname, soif);
109:                } catch (Exception e) {
110:                    if (!(e instanceof  RDMException))
111:                        e = new RDMException(e.getMessage());
112:                    throw (RDMException) e;
113:                } finally {
114:                    if (rootdb != null)
115:                        rootdb.close(st);
116:                }
117:
118:                return soif;
119:
120:            }
121:
122:            /**
123:             * A database factory - opens dbs according to their class in their root db entry.
124:             * Use this mechanism when you don't already have a db object and don't know the db class.
125:             */
126:            public static RDMDb dbOpen(SToken st, String dbname, int rw)
127:                    throws Exception {
128:                String dbdir = SearchConfig.getValue(SearchConfig.DBDIR);
129:                if (dbdir == null) {
130:                    SearchLogger.getLogger().log(Level.WARNING,
131:                            "PSSH_CSPSB0083", SearchConfig.DBDIR);
132:                    return null;
133:                }
134:
135:                // Get the db class from rootdb if present
136:
137:                // XXX we should pass the entire config soif to the native db constructor instead
138:                // of having each db having to haul it out of rootdb again...
139:
140:                RDMDb db;
141:                SOIF dbsoif = null; // root db entry for this db
142:                String dbClass = null;
143:
144:                if (dbname.equalsIgnoreCase("taxonomy"))
145:                    dbClass = "com.sun.portal.search.db.SearchOnlyDb"; // XXX this will switch to TaxonomyDb at some point
146:                else {
147:                    dbsoif = getRootDbEntry(st, dbname);
148:                    if (dbsoif != null)
149:                        dbClass = dbsoif.getValue("class");
150:                    if (dbClass == null)
151:                        dbClass = "com.sun.portal.search.db.IndexedSOIFDb"; // the default db class
152:                }
153:
154:                Class dbc;
155:                try {
156:                    try {
157:                        // try the current class loader first
158:                        dbc = Class.forName(dbClass, true, Thread
159:                                .currentThread().getContextClassLoader());
160:                    } catch (ClassNotFoundException e) {
161:                        // try the global class loader
162:                        dbc = Class.forName(dbClass);
163:                    }
164:                } catch (Exception e) {
165:                    SearchLogger.getLogger().log(Level.WARNING,
166:                            "PSSH_CSPSB0085", dbClass);
167:                    return null;
168:                }
169:                db = (RDMDb) dbc.newInstance();
170:                SearchLogger.getLogger().log(Level.FINE, "PSSH_CSPSB0086",
171:                        dbname);
172:                db.open(st, dbdir, dbname, rw, 0644);
173:                return db;
174:            }
175:
176:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.