1 7 8 package com.hp.hpl.jena.db.impl; 9 10 import java.sql.PreparedStatement ; 11 import java.sql.ResultSet ; 12 import java.sql.SQLException ; 13 14 import com.hp.hpl.jena.db.IDBConnection; 15 import com.hp.hpl.jena.db.RDFRDBException; 16 17 18 23 public class Driver_PostgreSQL extends DriverRDB { 24 25 26 27 30 public Driver_PostgreSQL( ){ 31 super(); 32 33 String myPackageName = this.getClass().getPackage().getName(); 34 35 DATABASE_TYPE = "PostgreSQL"; 36 DRIVER_NAME = "org.postgresql.Driver"; 37 38 ID_SQL_TYPE = "INTEGER"; 39 URI_COMPRESS = false; 40 INDEX_KEY_LENGTH_MAX = INDEX_KEY_LENGTH = 250; 41 LONG_OBJECT_LENGTH_MAX = LONG_OBJECT_LENGTH = 250; 42 TABLE_NAME_LENGTH_MAX = 63; 43 IS_XACT_DB = true; 44 PRE_ALLOCATE_ID = true; 45 SKIP_DUPLICATE_CHECK = false; 46 SQL_FILE = "etc/postgresql.sql"; 47 QUOTE_CHAR = '\''; 48 DB_NAMES_TO_UPPER = false; 49 setTableNames(TABLE_NAME_PREFIX); 50 51 m_psetClassName = myPackageName + ".PSet_TripleStore_RDB"; 52 m_psetReifierClassName = myPackageName + ".PSet_ReifStore_RDB"; 53 54 m_lsetClassName = myPackageName + ".SpecializedGraph_TripleStore_RDB"; 55 m_lsetReifierClassName = myPackageName + ".SpecializedGraphReifier_RDB"; 56 } 57 58 61 public void setConnection( IDBConnection dbcon ) { 62 m_dbcon = dbcon; 63 64 try { 65 m_sql = new SQLCache(SQL_FILE, null, dbcon, ID_SQL_TYPE); 68 } catch (Exception e) { 69 e.printStackTrace( System.err ); 70 logger.error("Unable to set connection for Driver:", e); 71 } 72 } 73 74 78 public int graphIdAlloc ( String graphName ) { 79 DBIDInt result = null; 80 int dbid = 0; 81 try { 82 dbid = getInsertID(GRAPH_TABLE); 83 PreparedStatement ps = m_sql.getPreparedSQLStatement("insertGraph",GRAPH_TABLE); 84 ps.setInt(1,dbid); 85 ps.setString(2,graphName); 86 ps.executeUpdate(); 87 } catch (SQLException e) { 88 throw new RDFRDBException("Failed to get last inserted ID: " + e); 89 } 90 return dbid; 91 } 92 93 97 public void graphIdDealloc ( int graphId ) { 98 DBIDInt result = null; 99 try { 100 PreparedStatement ps = m_sql.getPreparedSQLStatement("deleteGraph",GRAPH_TABLE); 101 ps.setInt(1,graphId); 102 ps.executeUpdate(); 103 } catch (SQLException e) { 104 throw new RDFRDBException("Failed to delete graph ID: " + e); 105 } 106 return; 107 } 108 109 public int getInsertID ( String tableName ) { 110 DBIDInt result = null; 111 try { 112 PreparedStatement ps = m_sql.getPreparedSQLStatement("getInsertID",tableName); 113 ResultSet rs = ps.executeQuery(); 114 if (rs.next()) { 115 result = wrapDBID(rs.getObject(1)); 116 } else 117 throw new RDFRDBException("No insert ID"); 118 } catch (SQLException e) { 119 throw new RDFRDBException("Failed to insert ID: " + e); 120 } 121 return result.getIntID(); 122 } 123 124 125 132 protected void getTblParams ( String [] param ) { 133 String spoColType; 134 String headColType; 135 136 if ( LONG_OBJECT_LENGTH > 4000 ) 137 throw new RDFRDBException("Long object length specified (" + LONG_OBJECT_LENGTH + 138 ") exceeds maximum sane length of 4000."); 139 if ( INDEX_KEY_LENGTH > 4000 ) 140 throw new RDFRDBException("Index key length specified (" + INDEX_KEY_LENGTH + 141 ") exceeds maximum sane length of 4000."); 142 143 spoColType = "VARCHAR(" + LONG_OBJECT_LENGTH + ")"; 144 STRINGS_TRIMMED = false; 145 param[0] = spoColType; 146 headColType = "VARCHAR(" + INDEX_KEY_LENGTH + ")"; 147 STRINGS_TRIMMED = false; 148 param[1] = headColType; 149 param[2] = TABLE_NAME_PREFIX; 150 } 151 152 153 154 158 protected String [] getDbInitTablesParams() { 159 String [] res = new String [3]; 160 161 getTblParams (res); 162 EOS_LEN = EOS.length(); 163 164 return res; 165 } 166 174 175 protected String [] getCreateTableParams( int graphId, boolean isReif ) { 176 String [] parms = new String [3]; 177 String [] res = new String [2]; 178 179 getTblParams (parms); 180 int tblCnt = getTableCount(graphId); 181 res[0] = genTableName(graphId,tblCnt,isReif); 182 res[1] = parms[0]; 183 return res; 184 } 185 186 public String genSQLStringMatchOp_IC( String fun ) { 187 return "I" + genSQLLikeKW(); 188 } 189 190 } 191 192 218 | Popular Tags |