Source Code Cross Referenced for SYSVIEWSRowFactory.java in  » Database-DBMS » db-derby-10.2 » org » apache » derby » impl » sql » catalog » 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 » Database DBMS » db derby 10.2 » org.apache.derby.impl.sql.catalog 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:
003:           Derby - Class org.apache.derby.impl.sql.catalog.SYSVIEWSRowFactory
004:
005:           Licensed to the Apache Software Foundation (ASF) under one or more
006:           contributor license agreements.  See the NOTICE file distributed with
007:           this work for additional information regarding copyright ownership.
008:           The ASF licenses this file to you under the Apache License, Version 2.0
009:           (the "License"); you may not use this file except in compliance with
010:           the License.  You may obtain a copy of the License at
011:
012:              http://www.apache.org/licenses/LICENSE-2.0
013:
014:           Unless required by applicable law or agreed to in writing, software
015:           distributed under the License is distributed on an "AS IS" BASIS,
016:           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017:           See the License for the specific language governing permissions and
018:           limitations under the License.
019:
020:         */
021:
022:        package org.apache.derby.impl.sql.catalog;
023:
024:        import org.apache.derby.iapi.types.DataValueDescriptor;
025:
026:        import org.apache.derby.iapi.types.TypeId;
027:        import org.apache.derby.iapi.sql.dictionary.SystemColumn;
028:        import org.apache.derby.catalog.TypeDescriptor;
029:
030:        import org.apache.derby.iapi.types.DataValueFactory;
031:        import org.apache.derby.iapi.types.RowLocation;
032:
033:        import org.apache.derby.iapi.sql.dictionary.CatalogRowFactory;
034:        import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor;
035:        import org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator;
036:        import org.apache.derby.iapi.sql.dictionary.DataDictionary;
037:        import org.apache.derby.iapi.sql.dictionary.DataDictionaryContext;
038:        import org.apache.derby.iapi.sql.dictionary.TupleDescriptor;
039:        import org.apache.derby.iapi.sql.dictionary.ViewDescriptor;
040:
041:        import org.apache.derby.iapi.sql.execute.ExecutionContext;
042:        import org.apache.derby.iapi.sql.execute.ExecIndexRow;
043:        import org.apache.derby.iapi.sql.execute.ExecRow;
044:        import org.apache.derby.iapi.sql.execute.ExecutionFactory;
045:
046:        import org.apache.derby.iapi.error.StandardException;
047:
048:        import org.apache.derby.iapi.services.sanity.SanityManager;
049:
050:        import org.apache.derby.iapi.services.uuid.UUIDFactory;
051:        import org.apache.derby.catalog.UUID;
052:        import org.apache.derby.catalog.IndexDescriptor;
053:
054:        import java.util.Properties;
055:
056:        /**
057:         * Factory for creating a SYSVIEWS row.
058:         *
059:         * @author jerry
060:         */
061:
062:        public class SYSVIEWSRowFactory extends CatalogRowFactory {
063:            private static final String TABLENAME_STRING = "SYSVIEWS";
064:
065:            protected static final int SYSVIEWS_COLUMN_COUNT = 4;
066:            protected static final int SYSVIEWS_TABLEID = 1;
067:            protected static final int SYSVIEWS_VIEWDEFINITION = 2;
068:            protected static final int SYSVIEWS_CHECKOPTION = 3;
069:            protected static final int SYSVIEWS_COMPILATION_SCHEMAID = 4;
070:
071:            // Column widths
072:            protected static final int SYSVIEWS_TABLEID_WIDTH = 36;
073:
074:            protected static final int SYSVIEWS_INDEX1_ID = 0;
075:
076:            private static final int[][] indexColumnPositions = { { SYSVIEWS_TABLEID } };
077:
078:            // if you add a non-unique index allocate this array.
079:            private static final boolean[] uniqueness = null;
080:
081:            private static final String[] uuids = {
082:                    "8000004d-00d0-fd77-3ed8-000a0a0b1900" // catalog UUID
083:                    , "80000050-00d0-fd77-3ed8-000a0a0b1900" // heap UUID
084:                    , "8000004f-00d0-fd77-3ed8-000a0a0b1900" // SYSVIEWS_INDEX1
085:            };
086:
087:            /////////////////////////////////////////////////////////////////////////////
088:            //
089:            //	CONSTRUCTORS
090:            //
091:            /////////////////////////////////////////////////////////////////////////////
092:
093:            public SYSVIEWSRowFactory(UUIDFactory uuidf, ExecutionFactory ef,
094:                    DataValueFactory dvf, boolean convertIdToLower) {
095:                super (uuidf, ef, dvf, convertIdToLower);
096:                initInfo(SYSVIEWS_COLUMN_COUNT, TABLENAME_STRING,
097:                        indexColumnPositions, uniqueness, uuids);
098:            }
099:
100:            /////////////////////////////////////////////////////////////////////////////
101:            //
102:            //	METHODS
103:            //
104:            /////////////////////////////////////////////////////////////////////////////
105:
106:            /**
107:             * Make a SYSVIEWS row
108:             *
109:             * @return	Row suitable for inserting into SYSVIEWS.
110:             *
111:             * @exception   StandardException thrown on failure
112:             */
113:            public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent)
114:                    throws StandardException {
115:                DataValueDescriptor col;
116:                ExecRow row;
117:                String tableID = null;
118:                String compSchemaId = null;
119:                String viewText = null;
120:                String checkSType = null;
121:                int checkIType;
122:
123:                if (td != null) {
124:                    UUID tableUUID;
125:                    ViewDescriptor vd = (ViewDescriptor) td;
126:
127:                    /*
128:                     ** We only allocate a new UUID if the descriptor doesn't already have one.
129:                     ** For descriptors replicated from a Source system, we already have an UUID.
130:                     */
131:                    tableUUID = vd.getUUID();
132:                    if (tableUUID == null) {
133:                        tableUUID = getUUIDFactory().createUUID();
134:                        vd.setUUID(tableUUID);
135:                    }
136:                    tableID = tableUUID.toString();
137:                    viewText = vd.getViewText();
138:
139:                    /* RESOLVE - check constraints not supported yet */
140:                    checkIType = vd.getCheckOptionType();
141:
142:                    if (SanityManager.DEBUG) {
143:                        if (checkIType != ViewDescriptor.NO_CHECK_OPTION) {
144:                            SanityManager
145:                                    .THROWASSERT("checkIType expected to be "
146:                                            + ViewDescriptor.NO_CHECK_OPTION
147:                                            + ", not " + checkIType);
148:                        }
149:                    }
150:                    checkSType = "N";
151:
152:                    UUID tmpId = vd.getCompSchemaId();
153:                    compSchemaId = (tmpId == null) ? null : tmpId.toString();
154:                }
155:
156:                /* Insert info into sysviews */
157:
158:                /* RESOLVE - It would be nice to require less knowledge about sysviews
159:                 * and have this be more table driven.
160:                 */
161:
162:                /* Build the row to insert  */
163:                row = getExecutionFactory().getValueRow(SYSVIEWS_COLUMN_COUNT);
164:
165:                /* 1st column is TABLEID (UUID - char(36)) */
166:                row.setColumn(SYSVIEWS_TABLEID, dvf.getCharDataValue(tableID));
167:
168:                /* 2nd column is VIEWDEFINITION */
169:                row.setColumn(SYSVIEWS_VIEWDEFINITION, dvf
170:                        .getLongvarcharDataValue(viewText));
171:
172:                /* 3rd column is CHECKOPTION (char(1)) */
173:                row.setColumn(SYSVIEWS_CHECKOPTION, dvf
174:                        .getCharDataValue(checkSType));
175:
176:                /* 4th column is COMPILATIONSCHEMAID (UUID - char(36)) */
177:                row.setColumn(SYSVIEWS_COMPILATION_SCHEMAID, dvf
178:                        .getCharDataValue(compSchemaId));
179:
180:                return row;
181:            }
182:
183:            ///////////////////////////////////////////////////////////////////////////
184:            //
185:            //	ABSTRACT METHODS TO BE IMPLEMENTED BY CHILDREN OF CatalogRowFactory
186:            //
187:            ///////////////////////////////////////////////////////////////////////////
188:
189:            /**
190:             * Make a ViewDescriptor out of a SYSVIEWS row
191:             *
192:             * @param row a SYSVIEWS row
193:             * @param parentTupleDescriptor	Null for this kind of descriptor.
194:             * @param dd dataDictionary
195:             *
196:             * @exception   StandardException thrown on failure
197:             */
198:            public TupleDescriptor buildDescriptor(ExecRow row,
199:                    TupleDescriptor parentTupleDescriptor, DataDictionary dd)
200:                    throws StandardException {
201:                ViewDescriptor vd = null;
202:
203:                if (SanityManager.DEBUG) {
204:                    SanityManager.ASSERT(
205:                            row.nColumns() == SYSVIEWS_COLUMN_COUNT,
206:                            "Wrong number of columns for a SYSVIEWS row");
207:                }
208:
209:                DataValueDescriptor col;
210:                DataDescriptorGenerator ddg;
211:                int checkIType;
212:                String checkSType;
213:                String tableID;
214:                String compSchemaId;
215:                String viewDefinition;
216:                UUID tableUUID;
217:                UUID compSchemaUUID = null;
218:
219:                ddg = dd.getDataDescriptorGenerator();
220:
221:                /* 1st column is TABLEID (UUID - char(36)) */
222:                col = row.getColumn(SYSVIEWS_TABLEID);
223:                tableID = col.getString();
224:                tableUUID = getUUIDFactory().recreateUUID(tableID);
225:
226:                /* 2nd column is VIEWDEFINITION */
227:                col = row.getColumn(SYSVIEWS_VIEWDEFINITION);
228:                viewDefinition = col.getString();
229:
230:                /* 3rd column is CHECKOPTION (char(1)) */
231:                col = row.getColumn(SYSVIEWS_CHECKOPTION);
232:                checkSType = col.getString();
233:
234:                if (SanityManager.DEBUG) {
235:                    if (!checkSType.equals("N")) {
236:                        SanityManager
237:                                .THROWASSERT("checkSType expected to be 'N', not "
238:                                        + checkSType);
239:                    }
240:                }
241:
242:                /* RESOLVE - no check options for now */
243:                checkIType = ViewDescriptor.NO_CHECK_OPTION;
244:
245:                /* 4th column is COMPILATIONSCHEMAID (UUID - char(36)) */
246:                col = row.getColumn(SYSVIEWS_COMPILATION_SCHEMAID);
247:                compSchemaId = col.getString();
248:                if (compSchemaId != null) {
249:                    compSchemaUUID = getUUIDFactory()
250:                            .recreateUUID(compSchemaId);
251:                }
252:
253:                /* now build and return the descriptor */
254:                vd = ddg.newViewDescriptor(tableUUID, null, viewDefinition,
255:                        checkIType, compSchemaUUID);
256:                return vd;
257:            }
258:
259:            /**
260:             * Builds a list of columns suitable for creating this Catalog.
261:             *
262:             *
263:             * @return array of SystemColumn suitable for making this catalog.
264:             */
265:            public SystemColumn[] buildColumnList() {
266:                SystemColumn[] columnList = new SystemColumn[SYSVIEWS_COLUMN_COUNT];
267:
268:                columnList[0] = new SystemColumnImpl(convertIdCase("TABLEID"), // name 
269:                        SYSVIEWS_TABLEID, // column number
270:                        0, // precision
271:                        0, // scale
272:                        false, // nullability
273:                        "CHAR", // dataType
274:                        true, // built-in type
275:                        36 // maxLength
276:                );
277:                // describe columns
278:
279:                columnList[1] = new SystemColumnImpl(
280:                        convertIdCase("VIEWDEFINITION"), // column name
281:                        SYSVIEWS_VIEWDEFINITION, // column number
282:                        0, // precision
283:                        0, // scale
284:                        false, // nullability
285:                        "LONG VARCHAR", // dataType
286:                        true, // built-in type
287:                        TypeId.LONGVARCHAR_MAXWIDTH // maxLength
288:                );
289:                columnList[2] = new SystemColumnImpl(
290:                        convertIdCase("CHECKOPTION"), // column name
291:                        SYSVIEWS_CHECKOPTION,// column number
292:                        0, // precision
293:                        0, // scale
294:                        false, // nullability
295:                        "CHAR", // dataType
296:                        true, // built-in type
297:                        1 // maxLength
298:                );
299:
300:                columnList[3] = new SystemColumnImpl(
301:                        convertIdCase("COMPILATIONSCHEMAID"), // name 
302:                        SYSVIEWS_COMPILATION_SCHEMAID, // column number
303:                        0, // precision
304:                        0, // scale
305:                        false, // nullability
306:                        "CHAR", // dataType
307:                        true, // built-in type
308:                        36 // maxLength
309:                );
310:                return columnList;
311:            }
312:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.