001: // jTDS JDBC Driver for Microsoft SQL Server and Sybase
002: // Copyright (C) 2004 The jTDS Project
003: //
004: // This library is free software; you can redistribute it and/or
005: // modify it under the terms of the GNU Lesser General Public
006: // License as published by the Free Software Foundation; either
007: // version 2.1 of the License, or (at your option) any later version.
008: //
009: // This library is distributed in the hope that it will be useful,
010: // but WITHOUT ANY WARRANTY; without even the implied warranty of
011: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: // Lesser General Public License for more details.
013: //
014: // You should have received a copy of the GNU Lesser General Public
015: // License along with this library; if not, write to the Free Software
016: // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: //
018: package net.sourceforge.jtds.jdbcx;
019:
020: import java.util.Hashtable;
021: import javax.naming.Context;
022: import javax.naming.Name;
023: import javax.naming.Reference;
024: import javax.naming.spi.ObjectFactory;
025:
026: import net.sourceforge.jtds.jdbc.Driver;
027: import net.sourceforge.jtds.jdbc.Messages;
028:
029: /**
030: * Description
031: *
032: * @author Alin Sinplean
033: * @since 0.3
034: * @version $Id: JtdsObjectFactory.java,v 1.25 2007/08/05 17:50:39 bheineman Exp $
035: */
036: public class JtdsObjectFactory implements ObjectFactory {
037: public Object getObjectInstance(Object refObj, Name name,
038: Context nameCtx, Hashtable env) throws Exception {
039: Reference ref = (Reference) refObj;
040:
041: if (ref.getClassName().equals(JtdsDataSource.class.getName())) {
042: JtdsDataSource ds = new JtdsDataSource();
043:
044: ds.setServerName((String) ref.get(
045: Messages.get(Driver.SERVERNAME)).getContent());
046: final Object portNumber = ref.get(
047: Messages.get(Driver.PORTNUMBER)).getContent();
048: if (portNumber != null) {
049: ds.setPortNumber(Integer.parseInt((String) portNumber));
050: }
051: ds.setDatabaseName((String) ref.get(
052: Messages.get(Driver.DATABASENAME)).getContent());
053: ds.setUser((String) ref.get(Messages.get(Driver.USER))
054: .getContent());
055: ds.setPassword((String) ref.get(
056: Messages.get(Driver.PASSWORD)).getContent());
057: ds.setCharset((String) ref
058: .get(Messages.get(Driver.CHARSET)).getContent());
059: ds.setLanguage((String) ref.get(
060: Messages.get(Driver.LANGUAGE)).getContent());
061: ds.setTds((String) ref.get(Messages.get(Driver.TDS))
062: .getContent());
063: ds.setBindAddress((String) ref.get(
064: Messages.get(Driver.BINDADDRESS)).getContent());
065: final Object serverType = ref.get(
066: Messages.get(Driver.SERVERTYPE)).getContent();
067: if (serverType != null) {
068: ds.setServerType(Integer.parseInt((String) serverType));
069: }
070: ds.setDomain((String) ref.get(Messages.get(Driver.DOMAIN))
071: .getContent());
072: ds.setUseNTLMV2((String) ref.get(
073: Messages.get(Driver.USENTLMV2)).getContent());
074: ds.setInstance((String) ref.get(
075: Messages.get(Driver.INSTANCE)).getContent());
076: final Object lastUpdateCount = ref.get(
077: Messages.get(Driver.LASTUPDATECOUNT)).getContent();
078: if (lastUpdateCount != null) {
079: ds.setLastUpdateCount("true".equals(lastUpdateCount));
080: }
081: final Object sendStringParametersAsUnicode = ref.get(
082: Messages.get(Driver.SENDSTRINGPARAMETERSASUNICODE))
083: .getContent();
084: if (sendStringParametersAsUnicode != null) {
085: ds.setSendStringParametersAsUnicode("true"
086: .equals(sendStringParametersAsUnicode));
087: }
088: final Object namedPipe = ref.get(
089: Messages.get(Driver.NAMEDPIPE)).getContent();
090: if (namedPipe != null) {
091: ds.setNamedPipe("true".equals(namedPipe));
092: }
093: ds.setMacAddress((String) ref.get(
094: Messages.get(Driver.MACADDRESS)).getContent());
095: final Object maxStatements = ref.get(
096: Messages.get(Driver.MAXSTATEMENTS)).getContent();
097: if (maxStatements != null) {
098: ds.setMaxStatements(Integer
099: .parseInt((String) maxStatements));
100: }
101: final Object packetSize = ref.get(
102: Messages.get(Driver.PACKETSIZE)).getContent();
103: if (packetSize != null) {
104: ds.setPacketSize(Integer.parseInt((String) packetSize));
105: }
106: final Object prepareSql = ref.get(
107: Messages.get(Driver.PREPARESQL)).getContent();
108: if (prepareSql != null) {
109: ds.setPrepareSql(Integer.parseInt((String) prepareSql));
110: }
111: final Object lobBuffer = ref.get(
112: Messages.get(Driver.LOBBUFFER)).getContent();
113: if (lobBuffer != null) {
114: ds.setLobBuffer(Long.parseLong((String) lobBuffer));
115: }
116: final Object loginTimeout = ref.get(
117: Messages.get(Driver.LOGINTIMEOUT)).getContent();
118: if (loginTimeout != null) {
119: ds.setLoginTimeout(Integer
120: .parseInt((String) loginTimeout));
121: }
122: final Object socketTimeout = ref.get(
123: Messages.get(Driver.SOTIMEOUT)).getContent();
124: if (socketTimeout != null) {
125: ds.setSocketTimeout(Integer
126: .parseInt((String) socketTimeout));
127: }
128: ds.setAppName((String) ref
129: .get(Messages.get(Driver.APPNAME)).getContent());
130: ds.setProgName((String) ref.get(
131: Messages.get(Driver.PROGNAME)).getContent());
132: ds.setWsid((String) ref.get(Messages.get(Driver.WSID))
133: .getContent());
134: final Object tcpNoDelay = ref.get(
135: Messages.get(Driver.TCPNODELAY)).getContent();
136: if (tcpNoDelay != null) {
137: ds.setTcpNoDelay("true".equals(tcpNoDelay));
138: }
139: final Object xaEmulation = ref.get(
140: Messages.get(Driver.XAEMULATION)).getContent();
141: if (xaEmulation != null) {
142: ds.setXaEmulation("true".equals(xaEmulation));
143: }
144: ds.setLogFile((String) ref
145: .get(Messages.get(Driver.LOGFILE)).getContent());
146: ds.setSsl((String) ref.get(Messages.get(Driver.SSL))
147: .getContent());
148: final Object batchSize = ref.get(
149: Messages.get(Driver.BATCHSIZE)).getContent();
150: if (batchSize != null) {
151: ds.setBatchSize(Integer.parseInt((String) batchSize));
152: }
153: final Object bufferDir = ref.get(
154: Messages.get(Driver.BUFFERDIR)).getContent();
155: if (bufferDir != null) {
156: ds.setBufferDir((String) bufferDir);
157: }
158: final Object bufferMaxMemory = ref.get(
159: Messages.get(Driver.BUFFERMAXMEMORY)).getContent();
160: if (bufferMaxMemory != null) {
161: ds.setBufferMaxMemory(Integer
162: .parseInt((String) bufferMaxMemory));
163: }
164: final Object bufferMinPackets = ref.get(
165: Messages.get(Driver.BUFFERMINPACKETS)).getContent();
166: if (bufferMinPackets != null) {
167: ds.setBufferMinPackets(Integer
168: .parseInt((String) bufferMinPackets));
169: }
170: final Object cacheMetaData = ref.get(
171: Messages.get(Driver.CACHEMETA)).getContent();
172: if (cacheMetaData != null) {
173: ds.setCacheMetaData("true".equals(cacheMetaData));
174: }
175: final Object useCursors = ref.get(
176: Messages.get(Driver.USECURSORS)).getContent();
177: if (useCursors != null) {
178: ds.setUseCursors("true".equals(useCursors));
179: }
180: final Object useJCIFS = ref.get(
181: Messages.get(Driver.USEJCIFS)).getContent();
182: if (useJCIFS != null) {
183: ds.setUseJCIFS("true".equals(useJCIFS));
184: }
185: final Object useLOBs = ref
186: .get(Messages.get(Driver.USELOBS)).getContent();
187: if (useLOBs != null) {
188: ds.setUseLOBs("true".equals(useLOBs));
189: }
190:
191: ds.setDescription((String) ref.get("description")
192: .getContent());
193:
194: return ds;
195: }
196:
197: return null;
198: }
199: }
|