Revision 47579 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.sqlite/org.gvsig.sqlite.provider/src/main/java/org/gvsig/sqlite/dal/SQLiteHelper.java
SQLiteHelper.java | ||
---|---|---|
25 | 25 |
import java.sql.Connection; |
26 | 26 |
import java.sql.ResultSet; |
27 | 27 |
import java.sql.SQLException; |
28 |
import org.apache.commons.codec.binary.Hex; |
|
28 | 29 |
import org.gvsig.expressionevaluator.GeometryExpressionBuilderHelper.GeometrySupportType; |
29 | 30 |
import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.FIELD_CONFIGURATION_NAME; |
30 | 31 |
import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.FIELD_CONFIGURATION_VALUE; |
... | ... | |
48 | 49 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory; |
49 | 50 |
import org.gvsig.fmap.dal.store.jdbc2.spi.AbstractConnectionProvider; |
50 | 51 |
import org.gvsig.fmap.dal.store.jdbc2.spi.ConnectionProvider; |
51 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCConnectionBase; |
|
52 | 52 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCHelperBase; |
53 | 53 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase; |
54 | 54 |
import org.gvsig.fmap.dal.store.jdbc2.spi.SRSSolver; |
... | ... | |
67 | 67 |
import org.gvsig.tools.dispose.DisposeUtils; |
68 | 68 |
import org.slf4j.Logger; |
69 | 69 |
import org.slf4j.LoggerFactory; |
70 |
import org.sqlite.JDBC; |
|
71 | 70 |
import org.sqlite.SQLiteConfig; |
72 | 71 |
import org.sqlite.SQLiteConfig.TransactionMode; |
73 | 72 |
import org.sqlite.SQLiteConnection; |
73 |
import org.sqlite.SQLiteOpenMode; |
|
74 | 74 |
|
75 | 75 |
@SuppressWarnings("UseSpecificCatch") |
76 | 76 |
public class SQLiteHelper extends JDBCHelperBase { |
... | ... | |
105 | 105 |
config.setSharedCache(true); |
106 | 106 |
config.enableLoadExtension(true); |
107 | 107 |
config.setTransactionMode(TransactionMode.IMMEDIATE); |
108 |
config.setOpenMode(SQLiteOpenMode.NOMUTEX); |
|
109 |
|
|
110 |
// config.setJournalMode(SQLiteConfig.JournalMode.WAL); |
|
111 |
// config.setTransactionMode(SQLiteConfig.TransactionMode.DEFERRED); |
|
108 | 112 |
// config.setSynchronous(SQLiteConfig.SynchronousMode.OFF); |
113 |
// config.setOpenMode(SQLiteOpenMode.FULLMUTEX); |
|
114 |
|
|
115 |
|
|
109 | 116 |
config.setPragma(SQLiteConfig.Pragma.CASE_SENSITIVE_LIKE, "true"); |
110 | 117 |
|
111 | 118 |
SQLiteConnection conn; |
... | ... | |
120 | 127 |
|
121 | 128 |
if (newdb) { |
122 | 129 |
String[] sqls2 = new String[]{ |
123 |
"CREATE CACHED TABLE PUBLIC.\"" + TABLE_RESOURCES_NAME + "\"(\"" + FIELD_RESOURCES_NAME + "\" VARCHAR(150) NOT NULL, \"" + FIELD_RESOURCES_RESOURCE + "\" BLOB DEFAULT NULL)", |
|
124 |
"ALTER TABLE PUBLIC.\"" + TABLE_RESOURCES_NAME + "\" ADD CONSTRAINT PUBLIC.CONSTRAINT_E PRIMARY KEY(\"" + FIELD_RESOURCES_NAME + "\")", |
|
125 |
"CREATE CACHED TABLE PUBLIC.\"" + TABLE_CONFIGURATION_NAME + "\"(\"" + FIELD_CONFIGURATION_NAME + "\" VARCHAR(200) NOT NULL, \"" + FIELD_CONFIGURATION_VALUE + "\" CLOB DEFAULT NULL)", |
|
126 |
"ALTER TABLE PUBLIC.\"" + TABLE_CONFIGURATION_NAME + "\" ADD CONSTRAINT PUBLIC.CONSTRAINT_2 PRIMARY KEY(\"" + FIELD_CONFIGURATION_NAME + "\")",}; |
|
130 |
"CREATE TABLE IF NOT EXISTS \"" + TABLE_RESOURCES_NAME + "\"(\"" + FIELD_RESOURCES_NAME + "\" VARCHAR(150) NOT NULL, \"" + FIELD_RESOURCES_RESOURCE + "\" BLOB DEFAULT NULL , PRIMARY KEY(\"" + FIELD_RESOURCES_NAME + "\"))", |
|
131 |
"CREATE TABLE IF NOT EXISTS \"" + TABLE_CONFIGURATION_NAME + "\"(\"" + FIELD_CONFIGURATION_NAME + "\" VARCHAR(200) NOT NULL, \"" + FIELD_CONFIGURATION_VALUE + "\" CLOB DEFAULT NULL, PRIMARY KEY(\"" + FIELD_CONFIGURATION_NAME + "\"))" |
|
132 |
}; |
|
127 | 133 |
for (String sql : sqls2) { |
128 | 134 |
try { |
129 | 135 |
conn.createStatement().execute(sql); |
... | ... | |
191 | 197 |
super(connectionParameters); |
192 | 198 |
this.srssolver = null; // GeopackageUtils.createSRSSolver(this); |
193 | 199 |
} |
194 |
|
|
200 |
|
|
195 | 201 |
@Override |
196 | 202 |
public synchronized JDBCConnection getConnection() throws AccessResourceException { |
197 | 203 |
try { |
... | ... | |
209 | 215 |
} |
210 | 216 |
this.connectionProvider = new ConnectionProviderImpl(connectionParameters); |
211 | 217 |
} |
212 |
JDBCConnection connection = new JDBCConnectionBase( |
|
213 |
this.transaction, |
|
214 |
this.connectionProvider.getConnection(), |
|
215 |
this.getConnectionProviderKey(connectionParameters) |
|
216 |
); |
|
218 |
JDBCConnection connection = SQLiteJDBCConnection.create(this); |
|
217 | 219 |
if (LOGGER.isDebugEnabled()) { |
218 | 220 |
LOGGER.debug("[" + JDBCUtils.getConnId(connection.get()) + "] getConnection " + connectionProvider.getStatus() + " " + connectionProvider.toString()); |
219 | 221 |
} |
... | ... | |
224 | 226 |
} |
225 | 227 |
|
226 | 228 |
@Override |
229 |
public ConnectionProvider getConnectionProvider() { |
|
230 |
if (this.connectionProvider == null) { |
|
231 |
SQLiteConnectionParameters connectionParameters = this.getConnectionParameters(); |
|
232 |
if( connectionParameters==null ) { |
|
233 |
return null; // Testing mode? |
|
234 |
} |
|
235 |
this.connectionProvider = new ConnectionProviderImpl(connectionParameters); |
|
236 |
} |
|
237 |
return this.connectionProvider; |
|
238 |
} |
|
239 |
|
|
240 |
|
|
241 |
@Override |
|
227 | 242 |
public SQLiteConnectionParameters getConnectionParameters() { |
228 | 243 |
return (SQLiteConnectionParameters) super.getConnectionParameters(); |
229 | 244 |
} |
... | ... | |
410 | 425 |
this.initialize(explorer, parameters, null); |
411 | 426 |
return explorer; |
412 | 427 |
} |
413 |
|
|
428 |
|
|
429 |
@Override |
|
430 |
public String getConnectionProviderKey(JDBCConnectionParameters connectionParameters) { |
|
431 |
return super.getConnectionProviderKey(connectionParameters); |
|
432 |
} |
|
433 |
|
|
414 | 434 |
} |
Also available in: Unified diff