001/* 002 * JKNIV, whinstone one contract to access your database. 003 * 004 * Copyright (C) 2017, the original author or authors. 005 * 006 * This library is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 2.1 of the License. 010 * 011 * This library is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public 017 * License along with this library; if not, write to the Free Software Foundation, Inc., 018 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 019 */ 020package net.sf.jkniv.whinstone.couchdb; 021 022import java.util.Properties; 023 024import org.slf4j.Logger; 025import org.slf4j.LoggerFactory; 026 027import net.sf.jkniv.exception.HandleableException; 028import net.sf.jkniv.sqlegance.RepositoryProperty; 029import net.sf.jkniv.sqlegance.transaction.Isolation; 030import net.sf.jkniv.whinstone.commands.CommandAdapter; 031 032public class HttpConnectionFactory //implements ConnectionFactory 033{ 034 private static final Logger LOG = LoggerFactory.getLogger(HttpConnectionFactory.class); 035 private static final String AUTH_COOKIE = "Set-Cookie"; 036 private final String contextName; 037 private String url; 038 private String schema; 039 private String username; 040 private String password; 041 private CouchDbAuthenticate auth; 042 private HandleableException handlerException; 043 044 public HttpConnectionFactory(Properties props, String contextName) 045 { 046 this.url = props.getProperty(RepositoryProperty.JDBC_URL.key(), "http://127.0.0.1:5984"); 047 this.schema = props.getProperty(RepositoryProperty.JDBC_SCHEMA.key()); 048 this.username = props.getProperty(RepositoryProperty.JDBC_USER.key()); 049 this.password = props.getProperty(RepositoryProperty.JDBC_PASSWORD.key()); 050 this.auth = new CouchDbAuthenticate(this.url, this.username, this.password); 051 this.contextName = contextName; 052 } 053 054 //@Override 055 //public ConnectionFactory with(HandleableException handlerException) 056 public HttpConnectionFactory with(HandleableException handlerException) 057 { 058 this.handlerException = handlerException; 059 return this; 060 } 061 062 // @Override 063 public CommandAdapter open() 064 { 065 //String token = auth.authenticate(); 066 HttpBuilder httpBuilder = new HttpBuilder(auth, this.url, this.schema, new RequestParams(this.schema)); 067 return new HttpCookieCommandAdapter(httpBuilder, contextName); 068 } 069 070 071 //@Override 072 public CommandAdapter open(Isolation isolation) 073 { 074 LOG.warn("whinstone-cassandra doesn't support isolation attribute [{}]", isolation); 075 return open(); 076 } 077 /* 078 @Override 079 public Transactional getTransactionManager() 080 { 081 // TODO Auto-generated method stub 082 return null; 083 } 084 085 @Override 086 public String getContextName() 087 { 088 return contextName; 089 } 090 091 @Override 092 public void close(ConnectionAdapter conn) 093 { 094// try 095// { 096 conn.close(); 097// } 098// catch (SQLException e) 099// { 100// LOG.warn("Error to try close Cassandra session/cluster [{}]", conn, e); 101// } 102 } 103 104 @Override 105 public void close(PreparedStatement stmt) 106 { 107 // TODO Auto-generated method stub 108 109 } 110 111 @Override 112 public void close(Statement stmt) 113 { 114 // TODO Auto-generated method stub 115 } 116 117 @Override 118 public void close(ResultSet rs) 119 { 120 // TODO Auto-generated method stub 121 122 } 123 124 @Override 125 public void close(CallableStatement call) 126 { 127 // TODO Auto-generated method stub 128 129 } 130 131 public String getSchema() 132 { 133 return schema; 134 } 135*/ 136}