protected KiWiNamespace constructNamespaceFromDatabase(ResultSet row) throws SQLException { KiWiNamespace result = new KiWiNamespace(row.getString("prefix"),row.getString("uri")); result.setId(row.getLong("id")); result.setCreated(new Date(row.getTimestamp("createdAt").getTime())); if(!namespacePrefixCache.containsKey(result.getPrefix())) { namespacePrefixCache.put(result.getPrefix(), result); } if(!namespaceUriCache.containsKey(result.getUri())) { namespaceUriCache.put(result.getUri(), result); } return result; }
/** * Store the namespace passed as argument in the database. The database might enfore unique constraints and * thus throw an exception in case the prefix or URI is already used. * * @param namespace the namespace to store * @throws SQLException the prefix or URI is already used, or a database error occurred */ public void storeNamespace(KiWiNamespace namespace) throws SQLException { // TODO: add unique constraints to table if (namespace.getId() >= 0) { log.warn("trying to store namespace which is already persisted: {}",namespace); return; } requireJDBCConnection(); namespace.setId(getNextSequence()); PreparedStatement insertNamespace = getPreparedStatement("store.namespace"); insertNamespace.setLong(1,namespace.getId()); insertNamespace.setString(2,namespace.getPrefix()); insertNamespace.setString(3,namespace.getUri()); insertNamespace.setTimestamp(4,new Timestamp(namespace.getCreated().getTime())); insertNamespace.executeUpdate(); namespacePrefixCache.put(namespace.getPrefix(), namespace); namespaceUriCache.put(namespace.getUri(),namespace); }
/** * Delete the namespace passed as argument from the database and from the caches. * @param namespace the namespace to delete * @throws SQLException in case a database error occurred */ public void deleteNamespace(KiWiNamespace namespace) throws SQLException { if (namespace.getId() < 0) { log.warn("trying to remove namespace which is not persisted: {}",namespace); return; } requireJDBCConnection(); PreparedStatement deleteNamespace = getPreparedStatement("delete.namespace"); deleteNamespace.setLong(1, namespace.getId()); deleteNamespace.executeUpdate(); namespacePrefixCache.remove(namespace.getPrefix()); namespaceUriCache.remove(namespace.getUri()); }
@Override protected void setNamespaceInternal(String prefix, String name) throws SailException { try { // check if the namespace prefix already exists; if yes and unequal, then delete first KiWiNamespace result = databaseConnection.loadNamespaceByPrefix(prefix); if(result != null) { if(!result.getUri().equals(name)) { databaseConnection.deleteNamespace(result); databaseConnection.storeNamespace(new KiWiNamespace(prefix,name)); } } else { databaseConnection.storeNamespace(new KiWiNamespace(prefix,name)); } } catch (SQLException e) { throw new SailException("database error while updating namespace",e); } }
@Override protected String getNamespaceInternal(String prefix) throws SailException { try { KiWiNamespace result = databaseConnection.loadNamespaceByPrefix(prefix); if(result != null) { return result.getUri(); } return null; } catch (SQLException e) { throw new SailException("database error while querying namespaces",e); } }
KiWiConnection connection = persistence.getConnection(); try { KiWiNamespace ns1 = new KiWiNamespace("ns1", "http://localhost/ns1/"); KiWiNamespace ns2 = new KiWiNamespace("ns2", "http://localhost/ns2/");
@Override protected void setNamespaceInternal(String prefix, String name) throws SailException { try { // check if the namespace prefix already exists; if yes and unequal, then delete first KiWiNamespace result = databaseConnection.loadNamespaceByPrefix(prefix); if(result != null) { if(!result.getUri().equals(name)) { databaseConnection.deleteNamespace(result); databaseConnection.storeNamespace(new KiWiNamespace(prefix,name)); } } else { databaseConnection.storeNamespace(new KiWiNamespace(prefix,name)); } } catch (SQLException e) { throw new SailException("database error while updating namespace",e); } }
/** * Delete the namespace passed as argument from the database and from the caches. * @param namespace the namespace to delete * @throws SQLException in case a database error occurred */ public void deleteNamespace(KiWiNamespace namespace) throws SQLException { if (namespace.getId() < 0) { log.warn("trying to remove namespace which is not persisted: {}",namespace); return; } requireJDBCConnection(); PreparedStatement deleteNamespace = getPreparedStatement("delete.namespace"); deleteNamespace.setLong(1, namespace.getId()); deleteNamespace.executeUpdate(); namespacePrefixCache.remove(namespace.getPrefix()); namespaceUriCache.remove(namespace.getUri()); }
@Override protected String getNamespaceInternal(String prefix) throws SailException { try { KiWiNamespace result = databaseConnection.loadNamespaceByPrefix(prefix); if(result != null) { return result.getUri(); } return null; } catch (SQLException e) { throw new SailException("database error while querying namespaces",e); } }
protected KiWiNamespace constructNamespaceFromDatabase(ResultSet row) throws SQLException { KiWiNamespace result = new KiWiNamespace(row.getString("prefix"),row.getString("uri")); result.setId(row.getLong("id")); result.setCreated(new Date(row.getTimestamp("createdAt").getTime())); if(!namespacePrefixCache.containsKey(result.getPrefix())) { namespacePrefixCache.put(result.getPrefix(), result); } if(!namespaceUriCache.containsKey(result.getUri())) { namespaceUriCache.put(result.getUri(), result); } return result; }
/** * Handles a namespace declaration/definition. A namespace declaration * associates a (short) prefix string with the namespace's URI. The prefix * for default namespaces, which do not have an associated prefix, are * represented as empty strings. * * @param prefix The prefix for the namespace, or an empty string in case of a * default namespace. * @param uri The URI that the prefix maps to. * @throws org.openrdf.rio.RDFHandlerException * If the RDF handler has encountered an unrecoverable error. */ @Override public void handleNamespace(String prefix, String uri) throws RDFHandlerException { if(!config.isIgnoreNamespaces()) { try { KiWiNamespace result = connection.loadNamespaceByPrefix(prefix); if(result != null) { if(!result.getUri().equals(uri)) { connection.deleteNamespace(result); connection.storeNamespace(new KiWiNamespace(prefix,uri)); } } else { connection.storeNamespace(new KiWiNamespace(prefix,uri)); } } catch (SQLException e) { throw new RDFHandlerException(e); } } }
/** * Store the namespace passed as argument in the database. The database might enfore unique constraints and * thus throw an exception in case the prefix or URI is already used. * * @param namespace the namespace to store * @throws SQLException the prefix or URI is already used, or a database error occurred */ public void storeNamespace(KiWiNamespace namespace) throws SQLException { // TODO: add unique constraints to table if (namespace.getId() >= 0) { log.warn("trying to store namespace which is already persisted: {}",namespace); return; } requireJDBCConnection(); namespace.setId(getNextSequence()); PreparedStatement insertNamespace = getPreparedStatement("store.namespace"); insertNamespace.setLong(1,namespace.getId()); insertNamespace.setString(2,namespace.getPrefix()); insertNamespace.setString(3,namespace.getUri()); insertNamespace.setTimestamp(4,new Timestamp(namespace.getCreated().getTime())); insertNamespace.executeUpdate(); namespacePrefixCache.put(namespace.getPrefix(), namespace); namespaceUriCache.put(namespace.getUri(),namespace); }
@Override public String getNamespace(String prefix) throws SailException { try { KiWiNamespace result = databaseConnection.loadNamespaceByPrefix(prefix); if(result != null) { return result.getUri(); } else { return null; } } catch (SQLException e) { throw new SailException("database error while querying namespaces",e); } }
/** * Handles a namespace declaration/definition. A namespace declaration * associates a (short) prefix string with the namespace's URI. The prefix * for default namespaces, which do not have an associated prefix, are * represented as empty strings. * * @param prefix The prefix for the namespace, or an empty string in case of a * default namespace. * @param uri The URI that the prefix maps to. * @throws org.openrdf.rio.RDFHandlerException * If the RDF handler has encountered an unrecoverable error. */ @Override public void handleNamespace(String prefix, String uri) throws RDFHandlerException { if(!config.isIgnoreNamespaces()) { try { KiWiNamespace result = connection.loadNamespaceByPrefix(prefix); if(result != null) { if(!result.getUri().equals(uri)) { connection.deleteNamespace(result); connection.storeNamespace(new KiWiNamespace(prefix,uri)); } } else { connection.storeNamespace(new KiWiNamespace(prefix,uri)); } } catch (SQLException e) { throw new RDFHandlerException(e); } } }