Lines 103-108
Link Here
|
103 |
import org.netbeans.modules.dlight.util.DLightLogger; |
103 |
import org.netbeans.modules.dlight.util.DLightLogger; |
104 |
import org.netbeans.modules.dlight.util.Range; |
104 |
import org.netbeans.modules.dlight.util.Range; |
105 |
import org.netbeans.modules.dlight.util.Util; |
105 |
import org.netbeans.modules.dlight.util.Util; |
|
|
106 |
import org.openide.util.Exceptions; |
106 |
import org.openide.util.Lookup; |
107 |
import org.openide.util.Lookup; |
107 |
import org.openide.util.NotImplementedException; |
108 |
import org.openide.util.NotImplementedException; |
108 |
|
109 |
|
Lines 114-120
Link Here
|
114 |
|
115 |
|
115 |
private static final Logger LOG = DLightLogger.getLogger(SQLStackDataStorage.class); |
116 |
private static final Logger LOG = DLightLogger.getLogger(SQLStackDataStorage.class); |
116 |
private static final CallStackEntryParser defaultParser = new DefaultStackParserImpl(); |
117 |
private static final CallStackEntryParser defaultParser = new DefaultStackParserImpl(); |
117 |
private final List<DataTableMetadata> tableMetadatas; |
118 |
private static final HashMap<Class<?>, String> classToType = new HashMap<Class<?>, String>(); |
|
|
119 |
|
120 |
private final HashMap<String, DataTableMetadata> tableMetadatas; |
118 |
private final AtomicBoolean closed = new AtomicBoolean(false); |
121 |
private final AtomicBoolean closed = new AtomicBoolean(false); |
119 |
private DBProxy dbProxy; |
122 |
private DBProxy dbProxy; |
120 |
private SQLRequestsProcessor requestsProcessor; |
123 |
private SQLRequestsProcessor requestsProcessor; |
Lines 124-131
Link Here
|
124 |
private CppSymbolDemangler demangler; |
127 |
private CppSymbolDemangler demangler; |
125 |
private ServiceInfoDataStorage serviceInfoDataStorage; |
128 |
private ServiceInfoDataStorage serviceInfoDataStorage; |
126 |
|
129 |
|
|
|
130 |
static { |
131 |
classToType.put(Byte.class, "tinyint"); // NOI18N |
132 |
classToType.put(Short.class, "smallint"); // NOI18N |
133 |
classToType.put(Integer.class, "int"); // NOI18N |
134 |
classToType.put(Long.class, "bigint"); // NOI18N |
135 |
classToType.put(Double.class, "double"); // NOI18N |
136 |
classToType.put(Float.class, "real"); // NOI18N |
137 |
classToType.put(String.class, "varchar"); // NOI18N |
138 |
classToType.put(Time.class, "bigint"); // NOI18N |
139 |
} |
140 |
|
127 |
public SQLStackDataStorage() { |
141 |
public SQLStackDataStorage() { |
128 |
tableMetadatas = new ArrayList<DataTableMetadata>(); |
142 |
tableMetadatas = new HashMap<String, DataTableMetadata>(); |
129 |
} |
143 |
} |
130 |
|
144 |
|
131 |
@Override |
145 |
@Override |
Lines 164-169
Link Here
|
164 |
dbProxy = new DBProxy(requestsProcessor, requestsProvider); |
178 |
dbProxy = new DBProxy(requestsProcessor, requestsProvider); |
165 |
|
179 |
|
166 |
initTables(); |
180 |
initTables(); |
|
|
181 |
loadSchema(); |
167 |
} |
182 |
} |
168 |
|
183 |
|
169 |
private <T extends DataFilter> Collection<T> getDataFilters(List<DataFilter> filters, Class<T> clazz) { |
184 |
private <T extends DataFilter> Collection<T> getDataFilters(List<DataFilter> filters, Class<T> clazz) { |
Lines 178-184
Link Here
|
178 |
|
193 |
|
179 |
@Override |
194 |
@Override |
180 |
public boolean hasData(DataTableMetadata data) { |
195 |
public boolean hasData(DataTableMetadata data) { |
181 |
return data.isProvidedBy(tableMetadatas); |
196 |
return data.isProvidedBy(new ArrayList<DataTableMetadata>(tableMetadatas.values())); |
182 |
} |
197 |
} |
183 |
|
198 |
|
184 |
@Override |
199 |
@Override |
Lines 198-204
Link Here
|
198 |
|
213 |
|
199 |
@Override |
214 |
@Override |
200 |
public void createTables(List<DataTableMetadata> tableMetadatas) { |
215 |
public void createTables(List<DataTableMetadata> tableMetadatas) { |
201 |
this.tableMetadatas.addAll(tableMetadatas); |
216 |
for (DataTableMetadata dataTableMetadata : tableMetadatas) { |
|
|
217 |
this.tableMetadatas.put(dataTableMetadata.getName(), dataTableMetadata); |
218 |
} |
202 |
} |
219 |
} |
203 |
|
220 |
|
204 |
// For tests ... |
221 |
// For tests ... |
Lines 269-274
Link Here
|
269 |
} |
286 |
} |
270 |
} |
287 |
} |
271 |
|
288 |
|
|
|
289 |
private void loadSchema() { |
290 |
try { |
291 |
ResultSet rs = sqlStorage.select("INFORMATION_SCHEMA.TABLES", null, // NOI18N |
292 |
"SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE LIKE 'TABLE'"); // NOI18N |
293 |
|
294 |
if (rs == null) { |
295 |
return; |
296 |
} |
297 |
|
298 |
while (rs.next()) { |
299 |
String tableName = rs.getString(1); |
300 |
loadTable(tableName); |
301 |
} |
302 |
} catch (SQLException ex) { |
303 |
Exceptions.printStackTrace(ex); |
304 |
} |
305 |
} |
306 |
|
307 |
protected Class<?> typeToClass(String type) { |
308 |
Set<Class<?>> clazzes = classToType.keySet(); |
309 |
for (Class<?> clazz : clazzes) { |
310 |
if (classToType.get(clazz).equalsIgnoreCase(type)) { |
311 |
return clazz; |
312 |
} |
313 |
} |
314 |
return String.class; |
315 |
} |
316 |
|
317 |
private void loadTable(String tableName) { |
318 |
try { |
319 |
ResultSet rs = sqlStorage.select("INFORMATION_SCHEMA.COLUMNS", null, "SELECT COLUMN_NAME, "// NOI18N |
320 |
+ "TYPE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME LIKE '" + tableName + "'");// NOI18N |
321 |
List<Column> columns = new ArrayList<Column>(); |
322 |
while (rs.next()) { |
323 |
Column c = new Column(rs.getString("COLUMN_NAME"), typeToClass(rs.getString("TYPE_NAME")));// NOI18N |
324 |
columns.add(c); |
325 |
} |
326 |
DataTableMetadata result = new DataTableMetadata(tableName, columns, null); |
327 |
// sqlStorage.loadTable(result); |
328 |
tableMetadatas.put(tableName, result); |
329 |
} catch (SQLException ex) { |
330 |
Exceptions.printStackTrace(ex); |
331 |
} |
332 |
} |
333 |
|
272 |
@Override |
334 |
@Override |
273 |
public long putStack(long contextID, List<CharSequence> stack) { |
335 |
public long putStack(long contextID, List<CharSequence> stack) { |
274 |
// Even if this stack has no any associated metrics, we need to store the |
336 |
// Even if this stack has no any associated metrics, we need to store the |
Lines 440-446
Link Here
|
440 |
Map<FunctionMetric, Object> metricValues = new HashMap<FunctionMetric, Object>(); |
502 |
Map<FunctionMetric, Object> metricValues = new HashMap<FunctionMetric, Object>(); |
441 |
for (FunctionMetric m : metrics) { |
503 |
for (FunctionMetric m : metrics) { |
442 |
try { |
504 |
try { |
443 |
rs.findColumn(m.getMetricID()); |
|
|
444 |
Object value = rs.getObject(m.getMetricID()); |
505 |
Object value = rs.getObject(m.getMetricID()); |
445 |
if (m.getMetricValueClass() == Time.class && value != null) { |
506 |
if (m.getMetricValueClass() == Time.class && value != null) { |
446 |
value = new Time(Long.valueOf(value.toString())); |
507 |
value = new Time(Long.valueOf(value.toString())); |