⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmldatabase.java

📁 导出ORACLE数据库对象DDL语句的程序
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
//			System.out.println(this.getLogsSQL);
			rs=cnn.executeQuery(this.getLogsSQL);
			
			while(rs.next()){
				String log=rs.getString(1);
				log=log+this.DATA_DIR+this.fileSeperator+(new File(rs.getString(2))).getName();
				log=log+rs.getString(3);
				logs=logs+log+",\n";	
			}			
			logs=logs.substring(0,logs.length()-2);
			rs.close();
			
		} catch (Exception e) {
			//e.printStackTrace();
			Logger.log(Logger.ERROR,e.getMessage());
			
			return null;
		}	
		
		return "LOGFILE "+logs;
	}
	
	protected String getCharacterSet(){
		JDBCPool cnn=null;
		ResultSet rs=null;
		String charset=null;
		try {
			if(JDBCPoolManager.getInstance().isDebug()) 
				System.out.println(this.getClass().toString());
				
			cnn=this.getConnPool();
			rs=cnn.executeQuery(this.getCharSetSQL);
			
			if(rs.next())	charset=rs.getString(1);	
						
			rs.close();
			
		} catch (Exception e) {
			Logger.log(Logger.ERROR,e.getMessage());
			try {
				rs.close();
				
			} catch (Exception e1) {
			}
			
			return null;
		}	
		
		return "CHARACTER SET "+charset;
	
	}	

	protected String getNationalCharacterSet(){
		JDBCPool cnn=null;
		ResultSet rs=null;
		String NationalCharset=null;
		try {
			if(JDBCPoolManager.getInstance().isDebug()) 
				System.out.println(this.getClass().toString());
				
			cnn=this.getConnPool();
			rs=cnn.executeQuery(this.getNationalCharSetSQL);
			
			if(rs.next()) NationalCharset=rs.getString(1);	
		
			rs.close();
			
		} catch (Exception e) {
			Logger.log(Logger.ERROR,e.getMessage());
			try {
				rs.close();
				
			} catch (Exception e1) {
			}
			
			return null;
		}	
		
		return "NATIONAL CHARACTER SET "+NationalCharset;
	
	}	
	
	/**
	 * Returns the tempTbs.
	 * @return String
	 */
	protected String getTempTbs() {
		JDBCPool cnn=null;
		ResultSet rs=null;
		try {
			if(JDBCPoolManager.getInstance().isDebug()) 
				System.out.println(this.getClass().toString());
				
			cnn=this.getConnPool();
			rs=cnn.executeQuery(getTempTbsSQL);
			
			if (rs.next())	tempTbsName=rs.getString(1);	
			rs.close();
			
		} catch (Exception e) {
			Logger.log(Logger.ERROR,e.getMessage());
			try {
				
			} catch (Exception e1) {
			}
			
			return null;
		}	
		if(tempTbsName==null) return null;
		String temptbs=getTbsDatFiles(tempTbsName);
		temptbs=StrUtil.deleteLineFromStr(temptbs,4);
		temptbs=StrUtil.deleteLineFromStr(temptbs,4);		
		return "DEFAULT TEMPORARY TABLESPACE "+tempTbsName+" "+temptbs.trim();
		
		/**
		XMLTablespace tempTbs=(XMLTablespace)this.getChildren(XMLNode.XML_STORAGE,XMLStorage.NAME).getChildren(XMLNode.XML_TABLESPACES,XMLTablespaces.NAME).getChildren(XMLNode.XML_TABLESPACE,tempTbsName);
		return "DEFAULT TEMPORARY TABLESPACE "+tempTbsName+" "+tempTbs.getSqlDDLWithoutName();
		**/
		
	}

	/**
	 * Returns the udnoTbs.
	 * @return String
	 */
	protected String getUndoTbs() {
		JDBCPool cnn=null;
		ResultSet rs=null;
		try {
			if(JDBCPoolManager.getInstance().isDebug()) 
				System.out.println(this.getClass().toString());
				
			cnn=this.getConnPool();
			rs=cnn.executeQuery(getUndoTbsSQL);
			
			if(rs.next())	undoTbsName=rs.getString(1);	
			rs.close();
			
		} catch (Exception e) {
			Logger.log(Logger.ERROR,e.getMessage());
			try {
				
			} catch (Exception e1) {
			}
			
			return null;
		}	
		
		if(undoTbsName==null) return null;
		
		String undotbs=getTbsDatFiles(undoTbsName);
		undotbs=StrUtil.deleteLineFromStr(undotbs,4);
		undotbs=StrUtil.deleteLineFromStr(undotbs,4);

		/**
		undotbs=undotbs.replaceAll("BLOCKSIZE ....\n","");;		
		undotbs=undotbs.replaceAll("BLOCKSIZE .....\n","");;		
		undotbs=undotbs.replaceAll("AUTOALLOCATE SEGMENT SPACE MANAGEMENT MANUAL EXTENT MANAGEMENT LOCAL","");
		**/
		return "UNDO TABLESPACE "+undoTbsName+" "+undotbs.trim();
		
		/**
		XMLTablespace undoTbs=(XMLTablespace)this.getChildren(XMLNode.XML_STORAGE,XMLStorage.NAME).getChildren(XMLNode.XML_TABLESPACES,XMLTablespaces.NAME).getChildren(XMLNode.XML_TABLESPACE,undoTbsName);
		return "UNDO TABLESPACE "+undoTbsName+" "+undoTbs.getSqlDDLWithoutName();
		**/
	}


	/**
	 * Returns the systemTbs.
	 * @return String
	 */
	protected String getSystemTbs() {
		String systbs=getTbsDatFiles(systemTbsName);
		systbs=StrUtil.deleteLineFromStr(systbs,4);
		systbs=StrUtil.deleteLineFromStr(systbs,4);
		return systbs.trim() ;
		
	}

	/**
	 * Returns the systemTbs.
	 * @return String
	 */
	protected String getTbsDatFiles(XMLTablespace tbs) {
		//XMLTablespaces tbss=(XMLTablespaces)this.getChildren(XMLNode.XML_STORAGE,XMLStorage.NAME).getChildren(XMLNode.XML_TABLESPACES,XMLTablespaces.NAME);		
		//XMLTablespace tbs=(XMLTablespace)tbss.getChildren(XMLNode.XML_TABLESPACE,tbsName);
		return tbs.getSqlDDLWithoutNameReplaceDatDir(this.DATA_DIR);
	}
	
	protected String getTbsDatFiles(String tbsName) {
		XMLStorage storage=(XMLStorage)this.getDirectChildren(XMLNode.XML_STORAGE,XMLStorage.NAME);
		Logger.log(Logger.INFO,"XMLStorage:"+storage);
		Enumeration enum=storage.getDirectChildren();		
		while(enum.hasMoreElements()){
			Logger.log(Logger.INFO,enum.nextElement().toString());
		}		
		XMLTablespaces tbss=(XMLTablespaces)storage.getDirectChildren(XMLNode.XML_TABLESPACES,XMLTablespaces.NAME);		
		Logger.log(Logger.INFO,"XMLTablespaces:"+tbss);
		XMLTablespace tbs=(XMLTablespace)tbss.getDirectChildren(XMLNode.XML_TABLESPACE,tbsName);
		Logger.log(Logger.INFO,"XMLTablespace "+tbsName+":"+tbs);		
		return tbs.getSqlDDLWithoutNameReplaceDatDir(this.DATA_DIR);
	}
	

	/**
	 * Returns the platform.
	 * @return int
	 */
	public int getPlatform() {
		return platform;
	}

	/**
	 * Sets the platform.
	 * @param platform The platform to set
	 */
	public void setPlatform() throws Exception {
		JDBCPool cnn=null;
		ResultSet rs=null;
		try {
			System.out.println("start call setPlatform");
			cnn=this.getConnPool();
			rs=cnn.executeQuery(this.getPlatformSQL);
			
			if(rs.next()){
				this.platform=WINDOWS;
				//System.out.println("flatform WINDOWS.");
			}else{
				this.platform=UNIX;
				this.fileSeperator="/";
				//System.out.println("flatform UNIX.");				
			} 
						
			rs.close();
			
			System.out.println("end call setPlatform");
		} catch (Exception e) {
			e.printStackTrace();
			Logger.log(Logger.ERROR,e.getMessage());
			throw e;
		}	
	}

	/**
	 * Returns the version.
	 * @return int
	 */
	public int getVersion() {
		return version;
	}

	private boolean setVersion9I() throws Exception{		
		JDBCPool cnn=null;
		ResultSet rs=null;
		boolean result=false;		

		System.out.println("start call setVersion9I");
		if(JDBCPoolManager.getInstance().isDebug()) 
			System.out.println(this.getClass().toString());
			
		cnn=this.getConnPool();
		rs=cnn.executeQuery(getVersionOracle9i);			
		if(rs.next()){
			this.version=VERSION_ORACLE9I;
			result=true;
		}else 	result=false;
		rs.close();
		
		System.out.println("end call setVersion9I");
		return result;
	}
	
	private boolean setVersion8I(){
		JDBCPool cnn=null;
		ResultSet rs=null;
		boolean result=false;				
		try {
			System.out.println("start call setVersion8I");
			cnn=this.getConnPool();
			rs=cnn.executeQuery(getVersionOracle8i);			

			if(rs.next()){
				this.version=VERSION_ORACLE8I;
				result=true;
			}else result=false;
			
			rs.close();
			
			return result;
		} catch (Exception e) {
			e.printStackTrace();
			Logger.log(Logger.ERROR,e.getMessage());
			return result;
		}	
	}
	
	/**
	 * Sets the version.
	 * @param version The version to set
	 */
	public void setVersion() throws Exception{
		JDBCPool cnn=null;
		
		if(!setVersion9I()){
			if(!setVersion8I()) this.version=VERSION_UNKNOWN;		
		}
	}

	/**
	 * Returns the status.
	 * @return String
	 */
	public String getStatus() {
		return status;
	}

	/**
	 * Returns the dstUrl.
	 * @return String
	 */
	public String getDstUrl() {
		return dstUrl;
	}

	/**
	 * Returns the dstUser.
	 * @return String
	 */
	public String getDstUser() {
		return dstUser;
	}

	/**
	 * Returns the srcUrl.
	 * @return String
	 */
	public String getSrcUrl() {
		return srcUrl;
	}

	/**
	 * Returns the srcUser.
	 * @return String
	 */
	public String getSrcUser() {
		return srcUser;
	}

	/**
	 * Sets the dstUrl.
	 * @param dstUrl The dstUrl to set
	 */
	public void setDstUrl(String dstUrl) {
		this.dstUrl = dstUrl;
	}

	/**
	 * Sets the dstUser.
	 * @param dstUser The dstUser to set
	 */
	public void setDstUser(String dstUser) {
		this.dstUser = dstUser;
	}
	
	
	/**
	 * Sets the srcUrl.
	 * @param srcUrl The srcUrl to set
	 */
	public void setSrcUrl(String srcUrl) {
		this.srcUrl = srcUrl;
	}

	/**
	 * Sets the srcUser.
	 * @param srcUser The srcUser to set
	 */
	public void setSrcUser(String srcUser) {
		this.srcUser = srcUser;
	}

	public String getSrcPosition(){
		int indpos=this.srcUrl.indexOf('@');
		String position=this.srcUrl.substring(indpos+1);
		Logger.log(Logger.INFO,"getSrcPosition");
		Logger.log(Logger.INFO,"srcUrl:"+this.srcUrl);
		Logger.log(Logger.INFO,"position:"+position);
		position=position+"/"+this.getSrcUser();
		return position;
	}

	public String getDstPosition(){
		int indpos=this.dstUrl.indexOf('@');
		String position=this.dstUrl.substring(indpos+1);
		Logger.log(Logger.INFO,"getDstPosition");
		Logger.log(Logger.INFO,"srcUrl:"+this.dstUrl);
		Logger.log(Logger.INFO,"position:"+position);
		position=position+"/"+this.getDstUser();
		return position;
	}

	/**
	 * @param sqlstr
	 * @return
	 */
	public ResultSet connQuery(String sqlstr) {
		ResultSet rset=null;
	
		try {
			DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver ());
		      Connection conn = DriverManager.getConnection(getUrl(), getDBUser(), getDBPassword());
		      Statement stmt = conn.createStatement (ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_READ_ONLY);
			  rset = stmt.executeQuery(sqlstr);
			} catch (Exception e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		return rset;
		}
	}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -