Source Code Cross Referenced for JDBC2KBUtils.java in  » Rule-Engine » Mandarax » org » mandarax » jdbc » server » 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 » Rule Engine » Mandarax » org.mandarax.jdbc.server 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.mandarax.jdbc.server;
002:
003:        import java.sql.Types;
004:        import java.util.*;
005:        import org.apache.commons.collections.iterators.FilterIterator;
006:        import org.mandarax.kernel.*;
007:        import org.mandarax.lib.LibObject;
008:        import org.mandarax.util.logging.LogCategories;
009:
010:        /**
011:         * Some utilities related to the kb - jdbc mapping. 
012:         * @author <A HREF="mailto:mandarax@jbdietrich.com">Jens Dietrich</A>
013:         * @version 3.3.2 <29 December 2004>
014:         * @since 3.0
015:         */
016:
017:        public class JDBC2KBUtils implements  LogCategories {
018:
019:            static LogicFactory lfactory = LogicFactory.getDefaultFactory();
020:
021:            /**
022:             * Get the slot name for a predicate.
023:             * @return a slot name
024:             * @param predicate a predicate
025:             * @param index an index
026:             */
027:            public static String getSlotName(Predicate predicate, int index) {
028:                return predicate.getSlotNames()[index];
029:            }
030:
031:            /**
032:             * Get the predicate with a certain name.
033:             * @return a predicate or null if such a predicate does not exist
034:             * @param kb a knowledge base
035:             * @param name a predicate name
036:             */
037:            public static Predicate getPredicate(KnowledgeBase kb, String name) {
038:                return kb.getPredicate(name);
039:            }
040:
041:            /**
042:             * Get a list of predicates that can be used as tables in SQL queries.
043:             * @return list of predicates
044:             * @param kb a knowledge base
045:             */
046:            public static Iterator getExposedPredicates(KnowledgeBase kb) {
047:                Iterator predicates = kb.predicates();
048:                org.apache.commons.collections.Predicate condition = new org.apache.commons.collections.Predicate() {
049:                    public boolean evaluate(Object obj) {
050:                        if (obj instanceof  Predicate) {
051:                            Predicate p = (Predicate) obj;
052:                            return !(LibObject.isLibPredicate(p));
053:                        }
054:                        return false;
055:                    }
056:                };
057:                Iterator filtered = new FilterIterator(predicates, condition);
058:                return filtered;
059:            }
060:
061:            /**
062:             * Get an iterator that lists all predicates found in a knowledge base.
063:             * @param predicate
064:             * @param name
065:             * @return an iterator
066:             */
067:
068:            /**
069:             * Get the slot number for a certain slot name.
070:             * @return a slot index or -1 if no slot with this name exists
071:             * @param predicate a predicate
072:             * @param name a slot name
073:             */
074:            public static int getSlotNumber(Predicate predicate, String name) {
075:                String[] slotNames = predicate.getSlotNames();
076:                for (int i = 0; i < slotNames.length; i++) {
077:                    if (name.equals(slotNames[i]))
078:                        return i;
079:                }
080:                return -1;
081:            }
082:
083:            /**
084:             * Get the list of query variables.
085:             * @param query a query
086:             * @return a list of variables
087:             */
088:            public static List getVariables(Query query) {
089:                Fact[] facts = query.getFacts();
090:                List vars = new ArrayList();
091:                if (facts.length > 1)
092:                    LogCategories.LOG_JDBC
093:                            .warn("Try to get query variables for mandarax jdnc driver for queries with more than one fact");
094:                for (int i = 0; i < facts.length; i++) {
095:                    Predicate p = facts[i].getPredicate();
096:                    Class[] structure = p.getStructure();
097:                    for (int j = 0; j < structure.length; j++) {
098:                        vars.add(lfactory.createVariableTerm(getSlotName(p, j),
099:                                structure[j]));
100:                    }
101:                }
102:                return vars;
103:            }
104:
105:            /** 
106:             * Specifies the SQL type associated with a java type.
107:             * @see java.sql.Types
108:             * @param jtype a java type
109:             * @return SQL type from java.sql.Types
110:             */
111:            public static int getTypeMapping(Class jtype) {
112:                if (jtype == String.class)
113:                    return Types.VARCHAR;
114:                else if (jtype == Integer.class)
115:                    return Types.INTEGER;
116:                else if (jtype == Double.class)
117:                    return Types.DOUBLE;
118:                else if (jtype == Float.class)
119:                    return Types.FLOAT;
120:                else if (jtype == Short.class)
121:                    return Types.SMALLINT;
122:                else if (jtype == Long.class)
123:                    return Types.BIGINT;
124:                else if (jtype == Boolean.class)
125:                    return Types.BOOLEAN;
126:                else if (jtype == java.sql.Date.class)
127:                    return Types.DATE;
128:                // warning: util.Date instance also handled as dates !!
129:                // TODO more testing and investigation of side effects
130:                else if (jtype == java.util.Date.class)
131:                    return Types.DATE;
132:                else if (jtype == java.sql.Time.class)
133:                    return Types.TIME;
134:                else if (jtype == java.sql.Timestamp.class)
135:                    return Types.TIMESTAMP;
136:                else
137:                    return Types.JAVA_OBJECT;
138:            }
139:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.