📄 basicdatabase.java
字号:
/** @exception StandardException Thrown on error */ public RuleBasedCollator getCollator() throws StandardException { RuleBasedCollator retval = ruleBasedCollator; if (retval == null) { if (databaseLocale != null) { retval = ruleBasedCollator = (RuleBasedCollator) Collator.getInstance(databaseLocale); } else { throw noLocale(); } } return retval; } /** @exception StandardException Thrown on error */ public DateFormat getDateFormat() throws StandardException { if (databaseLocale != null) { if (dateFormat == null) { dateFormat = DateFormat.getDateInstance(DateFormat.LONG, databaseLocale); } return dateFormat; } throw noLocale(); } /** @exception StandardException Thrown on error */ public DateFormat getTimeFormat() throws StandardException { if (databaseLocale != null) { if (timeFormat == null) { timeFormat = DateFormat.getTimeInstance(DateFormat.LONG, databaseLocale); } return timeFormat; } throw noLocale(); } /** @exception StandardException Thrown on error */ public DateFormat getTimestampFormat() throws StandardException { if (databaseLocale != null) { if (timestampFormat == null) { timestampFormat = DateFormat.getDateTimeInstance( DateFormat.LONG, DateFormat.LONG, databaseLocale); } return timestampFormat; } throw noLocale(); } private static StandardException noLocale() { return StandardException.newException(SQLState.NO_LOCALE); } public void setLocale(Locale locale) { databaseLocale = locale; dateFormat = null; timeFormat = null; timestampFormat = null; } /** Is the database active (open). */ public boolean isActive() { return active; } /* * class interface */ public BasicDatabase() { lastToBoot = true; } protected UUID makeDatabaseID(boolean create, Properties startParams) throws StandardException { TransactionController tc = af.getTransaction( ContextService.getFactory().getCurrentContextManager()); String upgradeID = null; UUID databaseID; if ((databaseID = (UUID) tc.getProperty(DataDictionary.DATABASE_ID)) == null) { // no property defined in the Transaction set // this could be an upgrade, see if it's stored in the service set UUIDFactory uuidFactory = Monitor.getMonitor().getUUIDFactory(); upgradeID = startParams.getProperty(DataDictionary.DATABASE_ID); if (upgradeID == null ) { // just create one databaseID = uuidFactory.createUUID(); } else { databaseID = uuidFactory.recreateUUID(upgradeID); } tc.setProperty(DataDictionary.DATABASE_ID, databaseID, true); } // Remove the database identifier from the service.properties // file only if we upgraded it to be stored in the transactional // property set. if (upgradeID != null) startParams.remove(DataDictionary.DATABASE_ID); tc.commit(); tc.destroy(); return databaseID; } /** * Drop all Stored Prepared Statements that * have been created for JDBC MetaData queries. * Does NOT commit the current transaction * upon completation. * * @exception SQLException on error, most likely * a deadlock or timeout. */ public void dropAllJDBCMetaDataSPSes() throws SQLException { try { LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC(); DataDictionary dd = lcc.getDataDictionary(); TransactionController tc = lcc.getTransactionExecute(); /* ** Inform the data dictionary we are going ** to perform some DDL */ dd.startWriting(lcc); for (java.util.ListIterator li = dd.getAllSPSDescriptors().listIterator(); li.hasNext(); ) { SPSDescriptor spsd = (SPSDescriptor) li.next(); /* ** Is it in SYS? if so, zap it. Can't drop metadata SPS in SYSIBM, JCC depends on it. */ if (spsd.getSchemaDescriptor().isSystemSchema() && !spsd.getSchemaDescriptor().isSYSIBM()) { dd.dropSPSDescriptor(spsd, tc); dd.dropDependentsStoredDependencies(spsd.getUUID(), tc); } } } catch (StandardException se) { throw PublicAPI.wrapStandardException(se); } } /* ** Return an Object instead of a ResourceAdapter ** so that XA classes are only used where needed; ** caller must cast to ResourceAdapter. */ public Object getResourceAdapter() { return resourceAdapter; } /* ** Methods of PropertySetCallback */ public void init(boolean dbOnly, Dictionary p) { // not called yet ... } /** @see PropertySetCallback#validate @exception StandardException Thrown on error. */ public boolean validate(String key, Serializable value, Dictionary p) throws StandardException { // //Disallow setting static creation time only configuration properties if (key.equals(EngineType.PROPERTY)) throw StandardException.newException(SQLState.PROPERTY_UNSUPPORTED_CHANGE, key, value); // only interested in the classpath if (!key.equals(Property.DATABASE_CLASSPATH)) return false; String newClasspath = (String) value; String[][] dbcp = null; //The parsed dbclasspath if (newClasspath != null) { // parse it when it is set to ensure only valid values // are written to the actual conglomerate. dbcp = IdUtil.parseDbClassPath(newClasspath, normalizeToUpper); } DataDictionaryContext ddc = (DataDictionaryContext)ContextService.getContext(DataDictionaryContext.CONTEXT_ID); if (SanityManager.DEBUG) if (ddc == null) SanityManager.THROWASSERT("Class path change with no connection"); DataDictionary dd = ddc.getDataDictionary(); // //Verify that all jar files on the database classpath are in the data dictionary. if (dbcp != null) { for (int ix=0;ix<dbcp.length;ix++) { SchemaDescriptor sd = dd.getSchemaDescriptor(dbcp[ix][IdUtil.DBCP_SCHEMA_NAME], null, false); FileInfoDescriptor fid = null; if (sd != null) fid = dd.getFileInfoDescriptor(sd,dbcp[ix][IdUtil.DBCP_SQL_JAR_NAME]); if (fid == null){ throw StandardException.newException(SQLState.LANG_DB_CLASS_PATH_HAS_MISSING_JAR , IdUtil.mkQualifiedName(dbcp[ix])); } } } return true; } /** @see PropertySetCallback#apply @exception StandardException Thrown on error. */ public Serviceable apply(String key, Serializable value, Dictionary p) throws StandardException { // only interested in the classpath if (!key.equals(Property.DATABASE_CLASSPATH)) return null; // only do the change dynamically if we are already // a per-database classapath. if (cfDB != null) { DataDictionaryContext ddc = (DataDictionaryContext)ContextService.getContext(DataDictionaryContext.CONTEXT_ID); if (SanityManager.DEBUG) if (ddc == null) SanityManager.THROWASSERT("Class path change with no connection"); DataDictionary dd = ddc.getDataDictionary(); // // Invalidate stored plans. dd.invalidateAllSPSPlans(); String newClasspath = (String) value; if (newClasspath == null) newClasspath = ""; cfDB.notifyModifyClasspath(newClasspath); } return null; } /** @see PropertySetCallback#map */ public Serializable map(String key,Serializable value,Dictionary p) { return null; } /* * methods specific to this class */ protected void createFinished() throws StandardException { // find the access factory and tell it that database creation has // finished af.createFinished(); } protected String getClasspath(Properties startParams) { String cp = PropertyUtil.getPropertyFromSet(startParams, Property.DATABASE_CLASSPATH); if (cp == null) cp = PropertyUtil.getSystemProperty(Property.DATABASE_CLASSPATH, ""); return cp; } protected void bootClassFactory(boolean create, Properties startParams) throws StandardException { String classpath = getClasspath(startParams); // parse the class path and allow 2 part names. boolean normalizeToUpper = true; String[][] elements = IdUtil.parseDbClassPath(classpath, normalizeToUpper); startParams.put(Property.BOOT_DB_CLASSPATH, classpath); cfDB = (ClassFactory) Monitor.bootServiceModule(create, this, org.apache.derby.iapi.reference.Module.ClassFactory, startParams); } /* ** Methods to allow sub-classes to offer alternate implementations. */ protected TransactionController getConnectionTransaction(ContextManager cm) throws StandardException { // start a local transaction return af.getTransaction(cm); } protected AuthenticationService bootAuthenticationService(boolean create, Properties props) throws StandardException { return (AuthenticationService) Monitor.bootServiceModule(create, this, AuthenticationService.MODULE, props); } protected void bootValidation(boolean create, Properties startParams) throws StandardException { pf = (PropertyFactory) Monitor.bootServiceModule(create, this, org.apache.derby.iapi.reference.Module.PropertyFactory, startParams); } protected void bootStore(boolean create, Properties startParams) throws StandardException { af = (AccessFactory) Monitor.bootServiceModule(create, this, AccessFactory.MODULE, startParams); } protected Properties getAllDatabaseProperties() throws StandardException { TransactionController tc = af.getTransaction( ContextService.getFactory().getCurrentContextManager()); Properties dbProps = tc.getProperties(); tc.commit(); tc.destroy(); return dbProps; } protected void bootResourceAdapter(boolean create, Properties startParams) { // Boot resource adapter - only if we are running Java 2 or // beyondwith JDBC20 extension, JTA and JNDI classes in the classpath // // assume if it doesn't boot it was because the required // classes were missing, and continue without it. // Done this way to work around Chai's need to preload // classes. // Assume both of these classes are in the class path. // Assume we may need a ResourceAdapter since we don't know how // this database is going to be used. try { resourceAdapter = Monitor.bootServiceModule(create, this, org.apache.derby.iapi.reference.Module.ResourceAdapter, allParams); } catch (StandardException mse) { // OK, resourceAdapter is an optional module } } protected void pushClassFactoryContext(ContextManager cm, ClassFactory cf) { new StoreClassFactoryContext(cm, cf, af, this); } /* ** Methods of JarReader */ public Object readJarFile(String schemaName, String sqlName) throws StandardException { DataDictionaryContext ddc = (DataDictionaryContext) ContextService.getContext(DataDictionaryContext.CONTEXT_ID); DataDictionary dd = ddc.getDataDictionary(); SchemaDescriptor sd = dd.getSchemaDescriptor(schemaName, null, true); FileInfoDescriptor fid = dd.getFileInfoDescriptor(sd,sqlName); if (fid == null) throw StandardException.newException(SQLState.LANG_FILE_DOES_NOT_EXIST, sqlName,schemaName); long generationId = fid.getGenerationId(); FileResource fr = af.getTransaction(ddc.getContextManager()).getFileHandler(); String externalName = org.apache.derby.impl.sql.execute.JarDDL.mkExternalName(schemaName, sqlName, fr.getSeparatorChar()); Object f = fr.getAsFile(externalName, generationId); if (f instanceof java.io.File) return f; try { return fr.getAsStream(externalName, generationId); } catch (java.io.IOException ioe) { throw StandardException.newException(SQLState.LANG_FILE_ERROR, ioe.toString(),ioe); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -