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

📄 pset_reifstore_rdb.java

📁 Jena推理机
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			return r;
		}
		
	}

	/* (non-Javadoc)
		*  return (distinct) nodes which reify something (have any fragment)
		*/

	public ExtendedIterator findReifNodes(Node stmtURI, IDBID graphID) {
		String astName = getTblName();
		String gid = graphID.getID().toString();
		ResultSetIterator result = new ResultSetNodeIterator();
		int argc = 1;
		PreparedStatement ps = null;
		boolean notFound = false;

		String stmtStr =
			stmtURI == null ? "selectReifNode" : "selectReifNodeN";
		try {
			ps = m_sql.getPreparedSQLStatement(stmtStr, getTblName());

			if (stmtURI != null) {
				String stmt_uri = m_driver.nodeToRDBString(stmtURI,false);
				if ( stmtURI == null ) notFound = true;
				else ps.setString(argc++, stmt_uri);
			}

			ps.setString(argc, gid);

		} catch (Exception e) {
			notFound = true;
			logger.warn( "Getting prepared statement for " + stmtStr + " Caught exception ", e);
            throw new JenaException("Exception during database access", e);    // Rethrow in case there is a recovery option
		}

		if ( notFound )
			result.close();
		else try {
			result = m_sql.executeSQL(ps, stmtStr, result);
		} catch (Exception e) {
			logger.debug("find encountered exception ", e);
            throw new JenaException("Exception during database access", e);    // Rethrow in case there is a recovery option
		}
		return result;
	}

	public void storeFrag(
		Node stmtURI,
		Triple frag,
		ReificationStatementMask fragMask,
		IDBID my_GID) {
		Node subj = fragMask.hasSubj() ? frag.getObject() : Node.NULL;
		Node prop = fragMask.hasPred() ? frag.getObject() : Node.NULL;
		Node obj = fragMask.hasObj() ? frag.getObject() : Node.NULL;
		Triple t = Triple.create(subj, prop, obj);
		storeTripleAR(t, my_GID, stmtURI, fragMask.hasType(), false, null);
	}

	public void updateOneFrag(
		Node stmtURI,
		Triple frag,
		ReificationStatementMask fragMask,
		boolean nullify,
		IDBID my_GID) {
			
			String stmtStr = null;
			Node val = null;
			int argc = 1;
			String argStr;
			
			if ( !fragMask.hasOneBit() )
				throw new JenaException("Reification can only update one column");
			PreparedStatement ps = null;

			if ( fragMask.hasSubj() ) {
				stmtStr = "updateReifiedS";
				if ( !nullify ) val = frag.getObject();
			} else if ( fragMask.hasPred() ) {
				stmtStr = "updateReifiedP";
				if ( !nullify ) val = frag.getObject();
			} else if ( fragMask.hasObj() ) {
				stmtStr = "updateReifiedO";
				if ( !nullify ) val = frag.getObject();
			} else if ( fragMask.hasType() ) {
				stmtStr = "updateReifiedT";
			} 
				
			try {
			try {
				ps = m_sql.getPreparedSQLStatement(stmtStr, getTblName());
				ps.clearParameters();
				if ( fragMask.hasSubj() || fragMask.hasPred() || fragMask.hasObj() ) {
					if (nullify)
						ps.setNull(argc++,java.sql.Types.VARCHAR);
					else {
						argStr = m_driver.nodeToRDBString(val,true);
						if ( argStr == null )
							throw new RDFRDBException("Invalid update argument: " + val.toString());
						ps.setString(argc++,argStr);
					}
				} else {
					// update hasType field
					if ( nullify )
						ps.setString(argc++," ");  // not nullable
					else
						ps.setString(argc++,"T");
				}
				argStr = m_driver.nodeToRDBString(stmtURI,true);
				if ( argStr == null )
					throw new RDFRDBException("Invalid update statement URI: " + stmtURI.toString());
				ps.setString(argc++,argStr);

				ps.setString(argc++,my_GID.getID().toString());
			} catch (Exception e) {
				logger.warn( "Getting prepared statement for "	+ stmtStr + " Caught exception ", e);
                throw new JenaException("Exception during database access", e);    // Rethrow in case there is a recovery option
			}
			try {
	  			ps.executeUpdate();
 			 } catch (SQLException e1) {
				 logger.error("SQLException caught during reification update" + e1.getErrorCode(), e1);
                throw new JenaException("Exception during database access", e1);    // Rethrow in case there is a recovery option
 			}} finally {
 			 	if(ps!=null)m_sql.returnPreparedSQLStatement(ps);
 			}
		}

	public void nullifyFrag(Node stmtURI, ReificationStatementMask fragMask, IDBID my_GID) {
		updateOneFrag(stmtURI,null,fragMask,true,my_GID);
	}
	
	public void updateFrag(
		Node stmtURI,
		Triple frag,
		ReificationStatementMask fragMask,
		IDBID my_GID) {		
			updateOneFrag(stmtURI,frag,fragMask,false,my_GID);
		}

	public ResultSetReifIterator findFrag(
		Node stmtURI,
		Triple frag,
		ReificationStatementMask fragMask,
		IDBID my_GID) {
			
			String stmtStr = null;
			Node val = null;
			int argc = 1;
			ResultSetReifIterator result =
				new ResultSetReifIterator(this, true, my_GID);
			boolean notFound = false;
			String argStr;
			
			Node_Literal litNode = null;
			LiteralLabel ll = null;
			String lval = null;
			boolean litIsPlain = false;
			boolean objIsURI = false;

		
			if ( !fragMask.hasOneBit() )
				throw new JenaException("Reification can only find one column");
			PreparedStatement ps = null;

			val = frag.getObject();
			if ( fragMask.hasSubj() ) {
				stmtStr = "selectReifiedNS";
			} else if ( fragMask.hasPred() ) {
				stmtStr = "selectReifiedNP";
			} else if ( fragMask.hasObj() ) {
				stmtStr = "selectReifiedNO";
			} else if ( fragMask.hasType() ) {
				stmtStr = "selectReifiedNT";
			}
				
			try {
				ps = m_sql.getPreparedSQLStatement(stmtStr, getTblName());
				ps.clearParameters();
				argStr = m_driver.nodeToRDBString(stmtURI,false);
				if ( argStr == null ) notFound = true;
				else ps.setString(argc++,argStr);
				if ( fragMask.hasSubj() || fragMask.hasPred() || fragMask.hasObj()) {
					argStr = m_driver.nodeToRDBString(val,false);
					if ( argStr == null ) notFound = true;
					else ps.setString(argc++,argStr);
				} else {
					// find on hasType field
					ps.setString(argc++,"T");
				}
				ps.setString(argc,my_GID.getID().toString());
				
			} catch (Exception e) {
				logger.warn( "Getting prepared statement for " + stmtStr + " Caught exception ", e);
	            throw new JenaException("Exception during database access", e);    // Rethrow in case there is a recovery option
			}

			if ( notFound )
				result.close();
			else
			try {
				m_sql.executeSQL(ps, stmtStr, result);
			} catch (Exception e) {
				logger.debug("find encountered exception ", e);
                throw new JenaException("Exception during database access", e);    // Rethrow in case there is a recovery option
			}
		return result;
	}
	
	public void deleteFrag(
		Triple frag,
		ReificationStatementMask fragMask,
		IDBID my_GID) {
			
			if ( !fragMask.hasOneBit() )
				throw new JenaException("Can only delete one fragment");
			int argc = 1;
		
			PreparedStatement ps = null;
			String stmtStr = "deleteReified";
			if ( fragMask.hasSubj() )
				stmtStr += "S";
			else if ( fragMask.hasPred() )
				stmtStr += "P";
			else if ( fragMask.hasObj() )
				stmtStr += "O";
			else if ( fragMask.hasType() )
				stmtStr += "T";
			else
				throw new JenaException("Unspecified reification fragment in deleteFrag");

			Node val = frag.getObject();
			String argStr = m_driver.nodeToRDBString(val,false);
			Node stmtURI = frag.getSubject();
			String uriStr = m_driver.nodeToRDBString(stmtURI,false);
							
			try {
			try {
				ps = m_sql.getPreparedSQLStatement(stmtStr, getTblName());
				ps.clearParameters();
				
				if ( fragMask.hasSubj() )
					ps.setString(argc++,argStr);
				else if ( fragMask.hasPred() )
					ps.setString(argc++,argStr);
				else if ( fragMask.hasObj() )
					ps.setString(argc++,argStr);
				ps.setString(argc++,my_GID.getID().toString());
				ps.setString(argc,uriStr);
				
			} catch (Exception e) {
				logger.warn( "Getting prepared statement for " + stmtStr + " Caught exception ", e);
	            throw new JenaException("Exception during database access", e);    // Rethrow in case there is a recovery option
			}
			try {
				ps.executeUpdate();
			} catch (Exception e) {
				logger.debug("deleteFrag encountered exception ", e);
                throw new JenaException("Exception during database access", e);    // Rethrow in case there is a recovery option
			}}finally { 
				if(ps!=null)m_sql.returnPreparedSQLStatement(ps);
			}
		return;
	}
}
	/*
	 *  (c) Copyright 2003, 2004, 2005, 2006, 2007 Hewlett-Packard Development Company, LP
	 *  All rights reserved.
	 *
	 * Redistribution and use in source and binary forms, with or without
	 * modification, are permitted provided that the following conditions
	 * are met:
	 * 1. Redistributions of source code must retain the above copyright
	 *    notice, this list of conditions and the following disclaimer.
	 * 2. Redistributions in binary form must reproduce the above copyright
	 *    notice, this list of conditions and the following disclaimer in the
	 *    documentation and/or other materials provided with the distribution.
	 * 3. The name of the author may not be used to endorse or promote products
	 *    derived from this software without specific prior written permission.
	
	 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
	 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
	 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
	 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
	 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
	 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
	 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
	 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
	 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
	 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
	 */
 

⌨️ 快捷键说明

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