Autopsy  4.12.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
SqliteEamDb.java
Go to the documentation of this file.
1 /*
2  * Central Repository
3  *
4  * Copyright 2015-2019 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.centralrepository.datamodel;
20 
21 import java.sql.Connection;
22 import java.sql.ResultSet;
23 import java.sql.SQLException;
24 import java.sql.Statement;
25 import java.util.Arrays;
26 import java.util.List;
27 import java.util.Set;
28 import java.util.concurrent.locks.ReentrantReadWriteLock;
29 import java.util.logging.Level;
30 import org.apache.commons.dbcp2.BasicDataSource;
31 import org.openide.util.NbBundle.Messages;
33 import org.sleuthkit.datamodel.TskData;
36 
42 final class SqliteEamDb extends AbstractSqlEamDb {
43 
44  private final static Logger LOGGER = Logger.getLogger(SqliteEamDb.class.getName());
45 
46  private static SqliteEamDb instance;
47 
48  private BasicDataSource connectionPool = null;
49 
50  private final SqliteEamDbSettings dbSettings;
51 
52  // While the Sqlite database should only be used for single users, it is still
53  // possible for multiple threads to attempt to write to the database simultaneously.
54  private final ReentrantReadWriteLock rwLock = new ReentrantReadWriteLock(true);
55 
64  public synchronized static SqliteEamDb getInstance() throws EamDbException {
65  if (instance == null) {
66  instance = new SqliteEamDb();
67  }
68 
69  return instance;
70  }
71 
78  private SqliteEamDb() throws EamDbException {
79  dbSettings = new SqliteEamDbSettings();
80  bulkArtifactsThreshold = dbSettings.getBulkThreshold();
81  }
82 
83  @Override
84  public void shutdownConnections() throws EamDbException {
85  try {
86  synchronized (this) {
87  if (null != connectionPool) {
88  connectionPool.close();
89  connectionPool = null; // force it to be re-created on next connect()
90  }
91  clearCaches();
92  }
93  } catch (SQLException ex) {
94  throw new EamDbException("Failed to close existing database connections.", ex); // NON-NLS
95  }
96  }
97 
98  @Override
99  public void updateSettings() {
100  synchronized (this) {
101  dbSettings.loadSettings();
102  bulkArtifactsThreshold = dbSettings.getBulkThreshold();
103  }
104  }
105 
106  @Override
107  public void saveSettings() {
108  synchronized (this) {
109  dbSettings.saveSettings();
110  }
111  }
112 
113  @Override
114  public void reset() throws EamDbException {
115  try {
116  acquireExclusiveLock();
117 
118  Connection conn = connect();
119 
120  try {
121 
122  Statement dropContent = conn.createStatement();
123  dropContent.executeUpdate("DELETE FROM organizations");
124  dropContent.executeUpdate("DELETE FROM cases");
125  dropContent.executeUpdate("DELETE FROM data_sources");
126  dropContent.executeUpdate("DELETE FROM reference_sets");
127  dropContent.executeUpdate("DELETE FROM artifact_types");
128  dropContent.executeUpdate("DELETE FROM db_info");
129 
130  String instancesTemplate = "DELETE FROM %s_instances";
131  String referencesTemplate = "DELETE FROM global_files";
132  for (CorrelationAttributeInstance.Type type : defaultCorrelationTypes) {
133  dropContent.executeUpdate(String.format(instancesTemplate, type.getDbTableName()));
134  // FUTURE: support other reference types
135  if (type.getId() == CorrelationAttributeInstance.FILES_TYPE_ID) {
136  dropContent.executeUpdate(String.format(referencesTemplate, type.getDbTableName()));
137  }
138  }
139 
140  dropContent.executeUpdate("VACUUM");
141  } catch (SQLException ex) {
142  LOGGER.log(Level.WARNING, "Failed to reset database.", ex);
143  } finally {
144  EamDbUtil.closeConnection(conn);
145  }
146 
147  dbSettings.insertDefaultDatabaseContent();
148  } finally {
149  releaseExclusiveLock();
150  }
151  }
152 
157  @Messages({"SqliteEamDb.databaseMissing.message=Central repository database missing"})
158  private void setupConnectionPool(boolean foreignKeysEnabled) throws EamDbException {
159 
160  if (dbSettings.dbFileExists() == false) {
161  throw new EamDbException(Bundle.SqliteEamDb_databaseMissing_message());
162  }
163 
164  connectionPool = new BasicDataSource();
165  connectionPool.setDriverClassName(dbSettings.getDriver());
166  connectionPool.setUrl(dbSettings.getConnectionURL());
167 
168  // tweak pool configuration
169  connectionPool.setInitialSize(50);
170  connectionPool.setMaxTotal(-1);
171  connectionPool.setMaxIdle(-1);
172  connectionPool.setMaxWaitMillis(1000);
173  connectionPool.setValidationQuery(dbSettings.getValidationQuery());
174  if (foreignKeysEnabled) {
175  connectionPool.setConnectionInitSqls(Arrays.asList("PRAGMA foreign_keys = ON"));
176  } else {
177  connectionPool.setConnectionInitSqls(Arrays.asList("PRAGMA foreign_keys = OFF"));
178  }
179  }
180 
191  @Messages({"SqliteEamDb.connectionFailedMessage.message=Error getting connection to database.",
192  "SqliteEamDb.centralRepositoryDisabled.message=Central Repository module is not enabled."})
193  @Override
194  protected Connection connect(boolean foreignKeys) throws EamDbException {
195  synchronized (this) {
196  if (!EamDb.isEnabled()) {
197  throw new EamDbException(Bundle.SqliteEamDb_centralRepositoryDisabled_message()); // NON-NLS
198  }
199  if (connectionPool == null) {
200  setupConnectionPool(foreignKeys);
201  }
202  try {
203  return connectionPool.getConnection();
204  } catch (SQLException ex) {
205  throw new EamDbException(Bundle.SqliteEamDb_connectionFailedMessage_message(), ex); // NON-NLS
206  }
207  }
208  }
209 
218  @Override
219  protected Connection connect() throws EamDbException {
220  return connect(true);
221  }
222 
223  @Override
224  protected String getConflictClause() {
225  // For sqlite, our conflict clause is part of the table schema
226  return "";
227  }
228 
237  @Override
238  public void newDbInfo(String name, String value) throws EamDbException {
239  try {
240  acquireExclusiveLock();
241  super.newDbInfo(name, value);
242  } finally {
243  releaseExclusiveLock();
244  }
245  }
246 
256  @Override
257  public String getDbInfo(String name) throws EamDbException {
258  try {
259  acquireSharedLock();
260  return super.getDbInfo(name);
261  } finally {
262  releaseSharedLock();
263  }
264  }
265 
274  @Override
275  public void updateDbInfo(String name, String value) throws EamDbException {
276  try {
277  acquireExclusiveLock();
278  super.updateDbInfo(name, value);
279  } finally {
280  releaseExclusiveLock();
281  }
282  }
283 
289  @Override
290  public CorrelationCase newCase(Case autopsyCase) throws EamDbException {
291  try {
292  acquireExclusiveLock();
293  return super.newCase(autopsyCase);
294  } finally {
295  releaseExclusiveLock();
296  }
297  }
298 
299  @Override
300  public void addDataSourceObjectId(int rowId, long dataSourceObjectId) throws EamDbException {
301  try {
302  acquireExclusiveLock();
303  super.addDataSourceObjectId(rowId, dataSourceObjectId);
304  } finally {
305  releaseExclusiveLock();
306  }
307  }
308 
316  @Override
317  public CorrelationCase newCase(CorrelationCase eamCase) throws EamDbException {
318  try {
319  acquireExclusiveLock();
320  return super.newCase(eamCase);
321  } finally {
322  releaseExclusiveLock();
323  }
324  }
325 
331  @Override
332  public void updateCase(CorrelationCase eamCase) throws EamDbException {
333  try {
334  acquireExclusiveLock();
335  super.updateCase(eamCase);
336  } finally {
337  releaseExclusiveLock();
338  }
339  }
340 
348  @Override
349  public CorrelationCase getCaseByUUID(String caseUUID) throws EamDbException {
350  try {
351  acquireSharedLock();
352  return super.getCaseByUUID(caseUUID);
353  } finally {
354  releaseSharedLock();
355  }
356  }
357 
365  @Override
366  public CorrelationCase getCaseById(int caseId) throws EamDbException {
367  try {
368  acquireSharedLock();
369  return super.getCaseById(caseId);
370  } finally {
371  releaseSharedLock();
372  }
373 
374  }
375 
381  @Override
382  public List<CorrelationCase> getCases() throws EamDbException {
383  try {
384  acquireSharedLock();
385  return super.getCases();
386  } finally {
387  releaseSharedLock();
388  }
389  }
390 
396  @Override
397  public CorrelationDataSource newDataSource(CorrelationDataSource eamDataSource) throws EamDbException {
398  try {
399  acquireExclusiveLock();
400  return super.newDataSource(eamDataSource);
401  } finally {
402  releaseExclusiveLock();
403  }
404  }
405 
415  @Override
416  public CorrelationDataSource getDataSource(CorrelationCase correlationCase, Long caseDbDataSourceId) throws EamDbException {
417  try {
418  acquireSharedLock();
419  return super.getDataSource(correlationCase, caseDbDataSourceId);
420  } finally {
421  releaseSharedLock();
422  }
423  }
424 
434  @Override
435  public CorrelationDataSource getDataSourceById(CorrelationCase correlationCase, int dataSourceId) throws EamDbException {
436  try {
437  acquireSharedLock();
438  return super.getDataSourceById(correlationCase, dataSourceId);
439  } finally {
440  releaseSharedLock();
441  }
442  }
443 
449  @Override
450  public List<CorrelationDataSource> getDataSources() throws EamDbException {
451  try {
452  acquireSharedLock();
453  return super.getDataSources();
454  } finally {
455  releaseSharedLock();
456  }
457  }
458 
467  @Override
468  public void updateDataSourceName(CorrelationDataSource eamDataSource, String newName) throws EamDbException {
469  try {
470  acquireExclusiveLock();
471  super.updateDataSourceName(eamDataSource, newName);
472  } finally {
473  releaseExclusiveLock();
474  }
475  }
476 
482  @Override
483  public void updateDataSourceMd5Hash(CorrelationDataSource eamDataSource) throws EamDbException {
484  try {
485  acquireExclusiveLock();
486  super.updateDataSourceMd5Hash(eamDataSource);
487  } finally {
488  releaseExclusiveLock();
489  }
490  }
491 
497  @Override
498  public void updateDataSourceSha1Hash(CorrelationDataSource eamDataSource) throws EamDbException {
499  try {
500  acquireExclusiveLock();
501  super.updateDataSourceSha1Hash(eamDataSource);
502  } finally {
503  releaseExclusiveLock();
504  }
505  }
506 
513  @Override
514  public void updateDataSourceSha256Hash(CorrelationDataSource eamDataSource) throws EamDbException {
515  try {
516  acquireExclusiveLock();
517  super.updateDataSourceSha256Hash(eamDataSource);
518  } finally {
519  releaseExclusiveLock();
520  }
521  }
522 
529  @Override
530  public void addArtifactInstance(CorrelationAttributeInstance eamArtifact) throws EamDbException {
531  try {
532  acquireExclusiveLock();
533  super.addArtifactInstance(eamArtifact);
534  } finally {
535  releaseExclusiveLock();
536  }
537  }
538 
539  @Override
540  public List<CorrelationAttributeInstance> getArtifactInstancesByTypeValue(CorrelationAttributeInstance.Type aType, String value) throws EamDbException, CorrelationAttributeNormalizationException {
541  try {
542  acquireSharedLock();
543  return super.getArtifactInstancesByTypeValue(aType, value);
544  } finally {
545  releaseSharedLock();
546  }
547  }
548 
549  @Override
550  public List<CorrelationAttributeInstance> getArtifactInstancesByTypeValues(CorrelationAttributeInstance.Type aType, List<String> values) throws EamDbException, CorrelationAttributeNormalizationException {
551  try {
552  acquireSharedLock();
553  return super.getArtifactInstancesByTypeValues(aType, values);
554  } finally {
555  releaseSharedLock();
556  }
557  }
558 
559  @Override
560  public List<CorrelationAttributeInstance> getArtifactInstancesByTypeValuesAndCases(CorrelationAttributeInstance.Type aType, List<String> values, List<Integer> caseIds) throws EamDbException, CorrelationAttributeNormalizationException {
561  try {
562  acquireSharedLock();
563  return super.getArtifactInstancesByTypeValuesAndCases(aType, values, caseIds);
564  } finally {
565  releaseSharedLock();
566  }
567  }
568 
581  @Override
582  public Long getCountArtifactInstancesByTypeValue(CorrelationAttributeInstance.Type aType, String value) throws EamDbException, CorrelationAttributeNormalizationException {
583  try {
584  acquireSharedLock();
585  return super.getCountArtifactInstancesByTypeValue(aType, value);
586  } finally {
587  releaseSharedLock();
588  }
589  }
590 
591  @Override
592  public int getFrequencyPercentage(CorrelationAttributeInstance corAttr) throws EamDbException, CorrelationAttributeNormalizationException {
593  try {
594  acquireSharedLock();
595  return super.getFrequencyPercentage(corAttr);
596  } finally {
597  releaseSharedLock();
598  }
599  }
600 
613  @Override
614  public Long getCountUniqueCaseDataSourceTuplesHavingTypeValue(CorrelationAttributeInstance.Type aType, String value) throws EamDbException, CorrelationAttributeNormalizationException {
615  try {
616  acquireSharedLock();
617  return super.getCountUniqueCaseDataSourceTuplesHavingTypeValue(aType, value);
618  } finally {
619  releaseSharedLock();
620  }
621  }
622 
623  @Override
624  public Long getCountUniqueDataSources() throws EamDbException {
625  try {
626  acquireSharedLock();
627  return super.getCountUniqueDataSources();
628  } finally {
629  releaseSharedLock();
630  }
631  }
632 
644  @Override
645  public Long getCountArtifactInstancesByCaseDataSource(CorrelationDataSource correlationDataSource) throws EamDbException {
646  try {
647  acquireSharedLock();
648  return super.getCountArtifactInstancesByCaseDataSource(correlationDataSource);
649  } finally {
650  releaseSharedLock();
651  }
652  }
653 
658  @Override
659  public void commitAttributeInstancesBulk() throws EamDbException {
660  try {
661  acquireExclusiveLock();
662  super.commitAttributeInstancesBulk();
663  } finally {
664  releaseExclusiveLock();
665  }
666  }
667 
671  @Override
672  public void bulkInsertCases(List<CorrelationCase> cases) throws EamDbException {
673  try {
674  acquireExclusiveLock();
675  super.bulkInsertCases(cases);
676  } finally {
677  releaseExclusiveLock();
678  }
679  }
680 
691  @Override
692  public void setAttributeInstanceKnownStatus(CorrelationAttributeInstance eamArtifact, TskData.FileKnown knownStatus) throws EamDbException {
693  try {
694  acquireExclusiveLock();
695  super.setAttributeInstanceKnownStatus(eamArtifact, knownStatus);
696  } finally {
697  releaseExclusiveLock();
698  }
699  }
700 
709  @Override
710  public Long getCountArtifactInstancesKnownBad(CorrelationAttributeInstance.Type aType, String value) throws EamDbException, CorrelationAttributeNormalizationException {
711  try {
712  acquireSharedLock();
713  return super.getCountArtifactInstancesKnownBad(aType, value);
714  } finally {
715  releaseSharedLock();
716  }
717  }
718 
731  @Override
732  public List<String> getListCasesHavingArtifactInstancesKnownBad(CorrelationAttributeInstance.Type aType, String value) throws EamDbException, CorrelationAttributeNormalizationException {
733  try {
734  acquireSharedLock();
735  return super.getListCasesHavingArtifactInstancesKnownBad(aType, value);
736  } finally {
737  releaseSharedLock();
738  }
739  }
740 
748  @Override
749  public void deleteReferenceSet(int referenceSetID) throws EamDbException {
750  try {
751  acquireExclusiveLock();
752  super.deleteReferenceSet(referenceSetID);
753  } finally {
754  releaseExclusiveLock();
755  }
756  }
757 
767  @Override
768  public boolean isValueInReferenceSet(String value, int referenceSetID, int correlationTypeID) throws EamDbException, CorrelationAttributeNormalizationException {
769  try {
770  acquireSharedLock();
771  return super.isValueInReferenceSet(value, referenceSetID, correlationTypeID);
772  } finally {
773  releaseSharedLock();
774  }
775  }
776 
785  @Override
786  public void processInstanceTable(CorrelationAttributeInstance.Type type, InstanceTableCallback instanceTableCallback) throws EamDbException {
787  try {
788  acquireSharedLock();
789  super.processInstanceTable(type, instanceTableCallback);
790  } finally {
791  releaseSharedLock();
792  }
793  }
794 
803  @Override
804  public void processInstanceTableWhere(CorrelationAttributeInstance.Type type, String whereClause, InstanceTableCallback instanceTableCallback) throws EamDbException {
805  try {
806  acquireSharedLock();
807  super.processInstanceTableWhere(type, whereClause, instanceTableCallback);
808  } finally {
809  releaseSharedLock();
810  }
811  }
812 
825  @Override
826  public boolean referenceSetExists(String referenceSetName, String version) throws EamDbException {
827  try {
828  acquireSharedLock();
829  return super.referenceSetExists(referenceSetName, version);
830  } finally {
831  releaseSharedLock();
832  }
833  }
834 
843  @Override
844  public boolean isArtifactKnownBadByReference(CorrelationAttributeInstance.Type aType, String value) throws EamDbException, CorrelationAttributeNormalizationException {
845  try {
846  acquireSharedLock();
847  return super.isArtifactKnownBadByReference(aType, value);
848  } finally {
849  releaseSharedLock();
850  }
851  }
852 
862  @Override
863  public EamOrganization newOrganization(EamOrganization eamOrg) throws EamDbException {
864  try {
865  acquireExclusiveLock();
866  return super.newOrganization(eamOrg);
867  } finally {
868  releaseExclusiveLock();
869  }
870  }
871 
879  @Override
880  public List<EamOrganization> getOrganizations() throws EamDbException {
881  try {
882  acquireSharedLock();
883  return super.getOrganizations();
884  } finally {
885  releaseSharedLock();
886  }
887  }
888 
898  @Override
899  public EamOrganization getOrganizationByID(int orgID) throws EamDbException {
900  try {
901  acquireSharedLock();
902  return super.getOrganizationByID(orgID);
903  } finally {
904  releaseSharedLock();
905  }
906  }
907 
908  @Override
909  public void updateOrganization(EamOrganization updatedOrganization) throws EamDbException {
910  try {
911  acquireExclusiveLock();
912  super.updateOrganization(updatedOrganization);
913  } finally {
914  releaseExclusiveLock();
915  }
916  }
917 
918  @Override
919  public void deleteOrganization(EamOrganization organizationToDelete) throws EamDbException {
920  try {
921  acquireExclusiveLock();
922  super.deleteOrganization(organizationToDelete);
923  } finally {
924  releaseExclusiveLock();
925  }
926  }
927 
937  @Override
938  public int newReferenceSet(EamGlobalSet eamGlobalSet) throws EamDbException {
939  try {
940  acquireExclusiveLock();
941  return super.newReferenceSet(eamGlobalSet);
942  } finally {
943  releaseExclusiveLock();
944  }
945  }
946 
956  @Override
957  public EamGlobalSet getReferenceSetByID(int referenceSetID) throws EamDbException {
958  try {
959  acquireSharedLock();
960  return super.getReferenceSetByID(referenceSetID);
961  } finally {
962  releaseSharedLock();
963  }
964  }
965 
975  @Override
976  public List<EamGlobalSet> getAllReferenceSets(CorrelationAttributeInstance.Type correlationType) throws EamDbException {
977  try {
978  acquireSharedLock();
979  return super.getAllReferenceSets(correlationType);
980  } finally {
981  releaseSharedLock();
982  }
983  }
984 
994  @Override
995  public void addReferenceInstance(EamGlobalFileInstance eamGlobalFileInstance, CorrelationAttributeInstance.Type correlationType) throws EamDbException {
996  try {
997  acquireExclusiveLock();
998  super.addReferenceInstance(eamGlobalFileInstance, correlationType);
999  } finally {
1000  releaseExclusiveLock();
1001  }
1002  }
1003 
1009  @Override
1010  public void bulkInsertReferenceTypeEntries(Set<EamGlobalFileInstance> globalInstances, CorrelationAttributeInstance.Type contentType) throws EamDbException {
1011  try {
1012  acquireExclusiveLock();
1013  super.bulkInsertReferenceTypeEntries(globalInstances, contentType);
1014  } finally {
1015  releaseExclusiveLock();
1016  }
1017  }
1018 
1029  @Override
1030  public List<EamGlobalFileInstance> getReferenceInstancesByTypeValue(CorrelationAttributeInstance.Type aType, String aValue) throws EamDbException, CorrelationAttributeNormalizationException {
1031  try {
1032  acquireSharedLock();
1033  return super.getReferenceInstancesByTypeValue(aType, aValue);
1034  } finally {
1035  releaseSharedLock();
1036  }
1037  }
1038 
1048  @Override
1049  public int newCorrelationType(CorrelationAttributeInstance.Type newType) throws EamDbException {
1050  try {
1051  acquireExclusiveLock();
1052  return super.newCorrelationType(newType);
1053  } finally {
1054  releaseExclusiveLock();
1055  }
1056  }
1057 
1067  @Override
1068  public List<CorrelationAttributeInstance.Type> getDefinedCorrelationTypes() throws EamDbException {
1069  try {
1070  acquireSharedLock();
1071  return super.getDefinedCorrelationTypes();
1072  } finally {
1073  releaseSharedLock();
1074  }
1075  }
1076 
1086  @Override
1087  public List<CorrelationAttributeInstance.Type> getEnabledCorrelationTypes() throws EamDbException {
1088  try {
1089  acquireSharedLock();
1090  return super.getEnabledCorrelationTypes();
1091  } finally {
1092  releaseSharedLock();
1093  }
1094  }
1095 
1105  @Override
1106  public List<CorrelationAttributeInstance.Type> getSupportedCorrelationTypes() throws EamDbException {
1107  try {
1108  acquireSharedLock();
1109  return super.getSupportedCorrelationTypes();
1110  } finally {
1111  releaseSharedLock();
1112  }
1113  }
1114 
1122  @Override
1123  public void updateCorrelationType(CorrelationAttributeInstance.Type aType) throws EamDbException {
1124  try {
1125  acquireExclusiveLock();
1126  super.updateCorrelationType(aType);
1127  } finally {
1128  releaseExclusiveLock();
1129  }
1130  }
1131 
1141  @Override
1142  public CorrelationAttributeInstance.Type getCorrelationTypeById(int typeId) throws EamDbException {
1143  try {
1144  acquireSharedLock();
1145  return super.getCorrelationTypeById(typeId);
1146  } finally {
1147  releaseSharedLock();
1148  }
1149  }
1150 
1156  @Override
1157  public void upgradeSchema() throws EamDbException, SQLException, IncompatibleCentralRepoException {
1158  try {
1159  acquireExclusiveLock();
1160  super.upgradeSchema();
1161  } finally {
1162  releaseExclusiveLock();
1163  }
1164  }
1165 
1177  @Override
1178  public CoordinationService.Lock getExclusiveMultiUserDbLock() throws EamDbException {
1179  // Multiple users are not supported for SQLite
1180  return null;
1181  }
1182 
1188  private void acquireExclusiveLock() {
1189  rwLock.writeLock().lock();
1190  }
1191 
1197  private void releaseExclusiveLock() {
1198  rwLock.writeLock().unlock();
1199  }
1200 
1206  private void acquireSharedLock() {
1207  rwLock.readLock().lock();
1208  }
1209 
1215  private void releaseSharedLock() {
1216  rwLock.readLock().unlock();
1217  }
1218 
1219  @Override
1220  boolean doesColumnExist(Connection conn, String tableName, String columnName) throws SQLException {
1221  final String tableInfoQueryTemplate = "PRAGMA table_info(%s)"; //NON-NLS
1222  ResultSet resultSet = null;
1223  Statement statement = null;
1224  boolean columnExists = false;
1225  try {
1226  statement = conn.createStatement();
1227  resultSet = statement.executeQuery(String.format(tableInfoQueryTemplate, tableName));
1228  while (resultSet.next()) {
1229  // the second value ( 2 ) is the column name
1230  if (resultSet.getString(2).equals(columnName)) {
1231  columnExists = true;
1232  break;
1233  }
1234  }
1235  } finally {
1236  EamDbUtil.closeResultSet(resultSet);
1237  EamDbUtil.closeStatement(statement);
1238  }
1239  return columnExists;
1240  }
1241 }

Copyright © 2012-2018 Basis Technology. Generated on: Wed Sep 18 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.