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

📄 modelrdb.java

📁 Jena推理机
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
  (c) Copyright 2003, 2004, 2005, 2006, 2007 Hewlett-Packard Development Company, LP
  [See end of file]
*/

package com.hp.hpl.jena.db;


import com.hp.hpl.jena.rdf.model.impl.*;
import com.hp.hpl.jena.rdf.model.*;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
import com.hp.hpl.jena.enhanced.*;
import com.hp.hpl.jena.graph.*;

/** A persistent relational database implemention of the RDF API.
 *
 * <p>This implementation of the RDF API stores all its data in a relational database.</p>
 * <p> To construct a persistent RDB Model, first load the jdbc connector for 
 * your database - in this example, mysql:</p>
 * 
 * <code> 
 *    Class.forName("com.mysql.jdbc.Driver");
 * </code>
 * <p> Then create a connection to the database: </p>
 * 
 * <code> 
 *    IDBConnection conn = new DBConnection("jdbc:mysql://localhost/test", "test", "", "MySQL");
 * </code>
 * 
 * <p> Now, using that connection, you can construct Models in the database:</p>
 * <code>
 *	  Model m = ModelRDB.createModel(conn);
 * </code>
 * 
 * @author csayers (based on ModelMem written by bwm and the Jena 1 version of Model RDB by der.)
 * @version $Revision: 1.21 $
 */
public class ModelRDB extends ModelCom implements Model {    
    
    protected GraphRDB m_graphRDB = null;

    /**
     * Construct a model which is stored persistently in a Relational DataBase
     * 
     * If a model already exists in the database, then it is opened, otherwise
     * a new model with default name and formatting is inserted and opened.
     * @param dbcon a Connection specifying the database connection
     * @deprecated Since Jena 2.0, this call is not recommended - 
     * in the short-term use ModelRDB.open or ModelRDB.createModel;
     * in the longer-term use factory methods to construct persistent models.
     */
     public ModelRDB( IDBConnection dbcon) throws RDFRDBException {
		this(BuiltinPersonalities.model, new GraphRDB(dbcon, null, null, !dbcon.containsDefaultModel()));
     }


    /**
     * Construct a model which is stored persistently in a Relational DataBase
     * 
     * If a model with the specified identifier already exists in the 
     * database, then it is opened, otherwise a new model with default 
     * formatting is inserted and opened.
     * @param dbcon a Connection specifying the database connection
     * @param modelID is the identifier of an RDF model within the database.
     * The modelID "DEFAULT" is reserved and may not be used for user models.
     * @deprecated Since Jena 2.0, this call is not recommended -
     * in the short-term use ModelRDB.open or ModelRDB.createModel;
     * in the longer-term use factory methods to construct persistent models.
     */
     public ModelRDB( IDBConnection dbcon, String modelID) throws RDFRDBException {
		this(BuiltinPersonalities.model, new GraphRDB(dbcon, modelID, null, !dbcon.containsDefaultModel()));
     }


    /** 
     * A model which is stored persistently in a Relational DataBase
     * 
     * Most applications should not call the constructor - use
     * ModelRDB.createModel (to create a new model) or
     * ModelRDB.open (to open an exising model).
	 * 
     * @param p the GraphPersonality of the resulting Model
     * @param graph a GraphRDB to be exposed through the model interface
     * 
     * @since Jena 2.0
     */
    public ModelRDB(GraphPersonality p, GraphRDB graph) throws RDFRDBException {
    	super( graph, p);
    	m_graphRDB = graph;
    }
    
    public ModelRDB( GraphRDB graph ) {
        super( graph ); 
        m_graphRDB = graph; 
    }

    /**
     * Open the default model from an existing rdf database. The layout and 
     * datatype type information will be dynamically loaded from the database. 
     * 
     * @param dbcon an IDBConnection specifying the database connection
     */
    public static ModelRDB open(IDBConnection dbcon) throws RDFRDBException {
        return open(dbcon, null);
    }

    /**
     * Open an existing rdf database. The layout and datatype type information
     * will be dynamically loaded from the database.
     * Will throw an RDFDBException if the database does not seem to formated.
     * @param dbcon a IDBConnection specifying the database connection
     * @param name the name of the RDF model to open
     */
    public static ModelRDB open(IDBConnection dbcon, String name) throws RDFRDBException {
        GraphRDB graph = new GraphRDB(dbcon, name, null, GraphRDB.OPTIMIZE_AND_HIDE_ONLY_FULL_REIFICATIONS ,false);
		return new ModelRDB(BuiltinPersonalities.model, graph);
    }

    /**
     * Create a new default model on an existing database.
     * Will format the database if it has not already been formatted.
     * @param dbcon a DBConnection specifying the database connection
     * @since Jena 2.0
     */
    public static ModelRDB createModel(IDBConnection dbcon) throws RDFRDBException {
        return createModel(dbcon, null, getDefaultModelProperties(dbcon));
    }

    /**
     * Create a new model on an existing database.
     * Will format the database if it has not already been formatted.
     *
     * <p>
	 * Use the properties to optionally customize the model - this
	 * won't change the results you see when using the model interface,
	 * but it may alter the speed with which you get them or the space
	 * required by the underlying database.</p>
	 *
	 * <p>
	 * The properties must form a complete and consistent set.
	 * The easist way to get a complete and consistent set is to call
	 * getDefaultModelProperties, modify it, and then use that as an argument
	 * in the call.</p>
	 * 
     * @param dbcon a DBConnection specifying the database connection
     * @param modelProperties a Model containing customization properties
     * @since Jena 2.0
     */
    public static ModelRDB createModel(IDBConnection dbcon, Model modelProperties) throws RDFRDBException {
        return createModel(dbcon, null, modelProperties);
    }

    /**
     * Create a new model on an existing database.
     * Will format the database if it has not already been formatted.
     * @param dbcon a DBConnectionI specifying the database connection
     * @param name the name to give the newly created model.
     * The name "DEFAULT" is reserved and may not be used for user models.
     */
    public static ModelRDB createModel(IDBConnection dbcon, String name) throws RDFRDBException {
        return createModel(dbcon, name, getDefaultModelProperties(dbcon));
    }

    /**
     * Create a new model on an existing database.
     * Will format the database if it has not already been formatted.
     *
     * <p>
	 * Use the properties to optionally customize the model - this
	 * won't change the results you see when using the model interface,
	 * but it may alter the speed with which you get them or the space
	 * required by the underlying database.</p>
	 *
	 * <p>
	 * The properties must form a complete and consistent set.
	 * The easist way to get a complete and consistent set is to call
	 * getDefaultModelProperties, modify it, and then use that as an argument
	 * in the call.</p>
	 * 
     * @param dbcon a DBConnection specifying the database connection
     * @param name the name to give the newly created model.
     * The name "DEFAULT" is reserved and may not be used for user models.
     * @param modelProperties a Model containing customization properties
     * @since Jena 2.0
     */
    public static ModelRDB createModel(IDBConnection dbcon, String name, Model modelProperties) throws RDFRDBException {
    	
        GraphRDB graph;
    	if( modelProperties != null )
    		graph = new GraphRDB(dbcon, name, modelProperties.getGraph(), GraphRDB.OPTIMIZE_AND_HIDE_ONLY_FULL_REIFICATIONS ,true);
    	else
        	graph = new GraphRDB(dbcon, name, null, GraphRDB.OPTIMIZE_AND_HIDE_ONLY_FULL_REIFICATIONS, true);
        return new ModelRDB(BuiltinPersonalities.model, graph);
    }

    /**
     * Create a new database suitable for storing RDF data. In fact the database has
     * to exist since jdbc can't create an empty database from a vacuum but it can be empty
     * and this call will format it with appropriate tables and stored procedures.
     * <p>
     * The appropriate RDF-RDB driver to use is assumed to be the class Driver<DatabaseType><LayoutType>.
     * If that can't be found it defaults to looking for a property file in /etc/Driver<DatabaseType><LayoutType>.config
     * and uses that to determine the driver class and parameters.</p>
     *
     * @param dbcon a DBConnection specifying the database connection
     * @param layoutType the name of the layout style to use. Currently one of:
     * "Generic", "Hash", "MMGeneric", "MMHash", "Proc", "ThinProc".
     * @param databaseType the name of the database type. Currently one of:
     * "Interbase" "Postgresql" "Mysql" "Oracle". This may seem a little redundant
     * given that the jdbc uri implicitly contains this information but there is no
     * standard way of extracting this (esp. if the user connects via a bridge).
     * @deprecated Since Jena 2.0 this call is no longer needed - it is preferable 
     * to specify the database type when constructing the DBConnection and to modify
     * the layout by using the properties in the DBConnection.  Then use the 
     * call ModelRDB.createModel(IDBConnection)
     */
    public static ModelRDB create(IDBConnection dbcon, String layoutType, String databaseType) throws RDFRDBException {
        dbcon.setDatabaseType(databaseType);
        return createModel(dbcon, null, getDefaultModelProperties(dbcon));
    }

    /**
     * Create a new database suitable for storing RDF data. In fact the database has
     * to exist since jdbc can't create an empty database from a vacuum but it can be empty
     * and this call will format it with appropriate tables and stored procedures.
     * <p>
     * Uses a default layout format which is able to support multiple models in a single database.
     * </p>
     * @param dbcon a DBConnectionI specifying the database connection
     * @param databaseType the name of the database type. Currently one of:
     * "Interbase" "Postgresql" "Mysql" "Oracle". This may seem a little redundant
     * given that the jdbc uri implicitly contains this information but there is no
     * standard way of extracting this (esp. if the user connects via a bridge).
     * @deprecated Since Jena 2.0 this call is no longer needed - it is preferable to 

⌨️ 快捷键说明

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