From de747313e8e58b6f3791da446d1cd80a292bd174 Mon Sep 17 00:00:00 2001 From: greatim Date: Mon, 6 Jul 2015 18:18:33 +0900 Subject: [PATCH] DATABASE: make database converter to compatamize save file make database converter to compatamize save file refactor DBTableRegistry for creating table selectively refactor project.java to manipulate save file (version control) Change-Id: Icff1f729992765587d53861979fb5cd303128814 Signed-off-by: greatim --- .../tizen/dynamicanalyzer/database/DBTable.java | 50 +-- .../dynamicanalyzer/database/DBTableRegistry.java | 43 ++- .../database/SqlConnectionManager.java | 7 +- .../database/compatible/DBConverter.java | 233 ++++++++++++++ .../database/compatible/DBSchemeConstant.java | 47 +++ .../database/compatible/IConvert.java | 56 ++++ .../compatible/SubConverter10to20Earlier.java | 144 +++++++++ .../compatible/SubConverter10to20Later.java | 353 +++++++++++++++++++++ .../dynamicanalyzer/handlers/OpenTraceHandler.java | 60 +++- .../org/tizen/dynamicanalyzer/project/AppInfo.java | 10 +- .../dynamicanalyzer/project/DeviceStatusInfo.java | 6 +- .../org/tizen/dynamicanalyzer/project/Project.java | 157 ++++++--- .../ui/toolbar/opentrace/OpenTraceDialog.java | 39 +-- .../opentrace/OpenTraceProgressManager.java | 14 +- .../ui/toolbar/opentrace/SaveFilesTable.java | 18 +- .../ui/toolbar/opentrace/TempFilesTable.java | 19 +- .../profiling/UIFunctionProfilingDataChecker.java | 3 +- .../ui/file/data/FileAccessDBTest.java | 6 +- .../ui/file/data/FileAccessorDBTest.java | 6 +- .../ui/file/data/FileApiDBTest.java | 8 +- .../ui/file/data/FileStatusDBTest.java | 6 +- .../ui/file/manager/FileDataMakerTest.java | 3 +- 22 files changed, 1145 insertions(+), 143 deletions(-) create mode 100644 org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/database/compatible/DBConverter.java create mode 100644 org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/database/compatible/DBSchemeConstant.java create mode 100644 org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/database/compatible/IConvert.java create mode 100644 org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/database/compatible/SubConverter10to20Earlier.java create mode 100644 org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/database/compatible/SubConverter10to20Later.java diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/database/DBTable.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/database/DBTable.java index 6cb7553..214f94c 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/database/DBTable.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/database/DBTable.java @@ -82,7 +82,7 @@ public abstract class DBTable implements IPreparedStatement, IResultSet { return retstr; } - public final void createTable() { + public final boolean createTable() { StringBuffer query = new StringBuffer(); query.append("create table "); query.append(getTableName()); @@ -100,7 +100,7 @@ public abstract class DBTable implements IPreparedStatement, IResultSet { query.append(CommonConstants.SEMICOLON); String queryString = query.toString(); - SqlConnectionManager.executeUpdate(queryString); + return SqlConnectionManager.executeUpdate(queryString); } public final void insertData(List> data) { @@ -123,6 +123,30 @@ public abstract class DBTable implements IPreparedStatement, IResultSet { } } + public final boolean createIndexTable() { + int size = columns.size(); + StringBuffer indexColumns = new StringBuffer(); + + for (int i = 0; i < size; i++) { + if (columns.get(i).isIndex()) { + if (indexColumns.length() > 0) { + indexColumns.append(", "); + } + indexColumns.append(columns.get(i).getName()); + } + } + + if (indexColumns.length() > 0) { + String queryString = "create index " + getTableName() + "_index on "//$NON-NLS-1$//$NON-NLS-2$ + + getTableName() + CommonConstants.OPEN_BRACKET + indexColumns.toString() + + CommonConstants.CLOSE_BRACKET; + + return SqlConnectionManager.executeUpdate(queryString); + } else { + return true; + } + } + public final List> selectAllColumnData(String option) { return selectData(null, option, this); } @@ -174,28 +198,6 @@ public abstract class DBTable implements IPreparedStatement, IResultSet { return resultdata; } - public final void createIndexTable() { - int size = columns.size(); - StringBuffer indexColumns = new StringBuffer(); - - for (int i = 0; i < size; i++) { - if (columns.get(i).isIndex()) { - if (indexColumns.length() > 0) { - indexColumns.append(", "); - } - indexColumns.append(columns.get(i).getName()); - } - } - - if (indexColumns.length() > 0) { - String queryString = "create index " + getTableName() + "_index on "//$NON-NLS-1$//$NON-NLS-2$ - + getTableName() + CommonConstants.OPEN_BRACKET + indexColumns.toString() - + CommonConstants.CLOSE_BRACKET; - - SqlConnectionManager.executeUpdate(queryString); - } - } - protected void setArrayToPreparedStatement(int index, String type, PreparedStatement prep, List rowData) { try { diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/database/DBTableRegistry.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/database/DBTableRegistry.java index 4326536..9b0458f 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/database/DBTableRegistry.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/database/DBTableRegistry.java @@ -27,29 +27,50 @@ package org.tizen.dynamicanalyzer.database; import java.util.HashMap; import java.util.Map; +import java.util.Set; // this class is manager class of all db table // all db table is registered in this class at instantiation public class DBTableRegistry { - + + private static boolean registerSwitch = true; private static Map tables = null; - + static { tables = new HashMap(); } - + + public static synchronized void registerEnabled(boolean enabled) { + registerSwitch = enabled; + } + public static synchronized void registerDBTable(DBTable table) { - tables.put(table.getTableName(), table); + if (registerSwitch) { + tables.put(table.getTableName(), table); + } } - - public static void createDBTables() { - for (Map.Entry entry : tables.entrySet()) { - DBTable table = entry.getValue(); - table.createTable(); - table.createIndexTable(); + + // create database table of given table set + // if set is null, then create all registered table + public static void createDBTables(Set tableNames) { + if (tableNames == null) { + for (Map.Entry entry : tables.entrySet()) { + DBTable table = entry.getValue(); + table.createTable(); + table.createIndexTable(); + } + } else { + for (Map.Entry entry : tables.entrySet()) { + String tableName = entry.getKey(); + if (tableNames.contains(tableName)) { + DBTable table = entry.getValue(); + table.createTable(); + table.createIndexTable(); + } + } } } - + public static DBTable getDBTable(String tablename) { return tables.get(tablename); } diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/database/SqlConnectionManager.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/database/SqlConnectionManager.java index 9e15158..f304dfd 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/database/SqlConnectionManager.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/database/SqlConnectionManager.java @@ -239,7 +239,9 @@ public class SqlConnectionManager { } } - public static void executeUpdate(String statement) { + public static boolean executeUpdate(String statement) { + boolean bret = false; + Connection conn = null; Statement sm = null; try { @@ -247,6 +249,7 @@ public class SqlConnectionManager { if (conn != null) { sm = conn.createStatement(); sm.executeUpdate(statement); + bret = true; } } catch (SQLException e) { Logger.exception(e); @@ -255,6 +258,8 @@ public class SqlConnectionManager { if (conn != null) putUpdateConnection(conn); } + + return bret; } // this method calls specific interface method of each DB table class diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/database/compatible/DBConverter.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/database/compatible/DBConverter.java new file mode 100644 index 0000000..8107b3d --- /dev/null +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/database/compatible/DBConverter.java @@ -0,0 +1,233 @@ +/* + * Dynamic Analyzer + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Jaewon Lim + * Woojin Jung + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + * + */ +package org.tizen.dynamicanalyzer.database.compatible; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.tizen.dynamicanalyzer.database.SqlConnectionManager; +import org.tizen.dynamicanalyzer.project.ProjectVersion; +import org.tizen.dynamicanalyzer.util.Logger; + +public class DBConverter implements IConvert { + private ProjectVersion version; + + private Set tables = new HashSet(); + private Map> columns = new HashMap>(); + private Map> indexColumns = new HashMap>(); + + public DBConverter(ProjectVersion version) { + this.version = version; + } + + public boolean convert() { + boolean ret = true; + + switch (version) { + case VERSION_10: + if (!(new SubConverter10to20Earlier(this).convert()) + || !(new SubConverter10to20Later(this).convert())) { + ret = false; + break; + } + /* fall through */ + case VERSION_20: + // recent version, do nothing + break; + case VERSION_UNKNOWN: + Logger.warning("Converting failed : unknown version of project"); + ret = false; + break; + } + + return ret; + } + + private void queryTableList() { + tables.clear(); + ResultSet rs = SqlConnectionManager.executeQueryRS(DBSchemeConstant.QUERY_TABLE_NAME); + if (rs != null) { + try { + while (rs.next()) { + tables.add(rs.getString(1)); + } + } catch (SQLException e) { + Logger.exception(e); + } finally { + SqlConnectionManager.releaseResultSet(rs); + } + } + } + + private void queryColumnList() { + columns.clear(); + ResultSet rs = SqlConnectionManager.executeQueryRS(DBSchemeConstant.QUERY_COLUMN_NAME); + if (rs != null) { + try { + while (rs.next()) { + String tableName = rs.getString(1); + String columnName = rs.getString(2); + + Set columnSet = columns.get(tableName); + if (columnSet == null) { + columnSet = new HashSet(); + columns.put(tableName, columnSet); + } + + columnSet.add(columnName); + } + } catch (SQLException e) { + Logger.exception(e); + } finally { + SqlConnectionManager.releaseResultSet(rs); + } + } + } + + // currently not used, but hold this code for future use + @SuppressWarnings("unused") + private void queryIndexColumList() { + indexColumns.clear(); + ResultSet rs = SqlConnectionManager + .executeQueryRS(DBSchemeConstant.QUERY_INDEX_COLUMN_NAME); + if (rs != null) { + try { + while (rs.next()) { + String tableName = rs.getString(1); + String columnName = rs.getString(2); + + Set columnForIndex = indexColumns.get(tableName); + if (columnForIndex == null) { + columnForIndex = new HashSet(); + indexColumns.put(tableName, columnForIndex); + } + + columnForIndex.add(columnName); + } + } catch (SQLException e) { + Logger.exception(e); + } finally { + SqlConnectionManager.releaseResultSet(rs); + } + } + } + + @Override + public void init() { + queryTableList(); + queryColumnList(); + } + + @Override + public Set getTables() { + return Collections.unmodifiableSet(tables); + } + + @Override + public Set getColumns(String tableName) { + Set columnList = columns.get(tableName); + if (columnList != null) { + return Collections.unmodifiableSet(columnList); + } else { + return null; + } + } + + @Override + public Set getIndexColumns(String tableName) { + Set columnList = indexColumns.get(tableName); + if (columnList != null) { + return Collections.unmodifiableSet(columnList); + } else { + return null; + } + } + + @Override + public boolean renameColumn(String tableName, String from, String to) { + String query = String.format(DBSchemeConstant.RENAME_COLUMN, tableName, from, to); + return SqlConnectionManager.executeUpdate(query); + } + + @Override + public boolean renameTable(String from, String to) { + String query = String.format(DBSchemeConstant.RENAME_TABLE, from, to); + return SqlConnectionManager.executeUpdate(query); + } + + @Override + public boolean addIndex(String tableName, String[] columnList) { + StringBuffer columns = new StringBuffer(); + for (int i = 0; i < columnList.length; i++) { + if (i != 0) { + columns.append(", "); + } + columns.append(columnList[i]); + } + + String query = String.format(DBSchemeConstant.ADD_INDEX, tableName, tableName, + columns.toString()); + return SqlConnectionManager.executeUpdate(query); + } + + @Override + public boolean dropIndex(String tableName, String indexName) { + String query = String.format(DBSchemeConstant.DROP_INDEX, indexName); + return SqlConnectionManager.executeUpdate(query); + } + + @Override + public boolean changeType(String tableName, String columnName, String type) { + String query = String.format(DBSchemeConstant.CHANGE_TYPE, tableName, columnName, type); + return SqlConnectionManager.executeUpdate(query); + } + + // add after last column + @Override + public boolean addColumn(String tableName, String columnName, String type, String defaultValue, + String option) { + String query = String.format(DBSchemeConstant.ADD_COLUMN, tableName, columnName, type, + defaultValue, option); + return SqlConnectionManager.executeUpdate(query); + } + + @Override + public boolean dropColumn(String tableName, String columnName) { + String query = String.format(DBSchemeConstant.DROP_COLUMN, tableName, columnName); + return SqlConnectionManager.executeUpdate(query); + } + + @Override + public boolean createTable(String tableName) { + // TODO : create table + return true; + } +} diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/database/compatible/DBSchemeConstant.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/database/compatible/DBSchemeConstant.java new file mode 100644 index 0000000..010cd74 --- /dev/null +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/database/compatible/DBSchemeConstant.java @@ -0,0 +1,47 @@ +/* + * Dynamic Analyzer + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Jaewon Lim + * Woojin Jung + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + * + */ +package org.tizen.dynamicanalyzer.database.compatible; + +public class DBSchemeConstant { + + /* + * queries for scheme manipulation + */ + + public static final String QUERY_TABLE_NAME = "select table_name from information_schema.tables where table_schema='PUBLIC' order by table_name"; + public static final String QUERY_COLUMN_NAME = "select table_name, column_name from information_schema.columns where table_schema='PUBLIC' order by table_name, ordinal_position"; + public static final String QUERY_INDEX_COLUMN_NAME = "select table_name, column_name from information_schema.system_indexinfo where table_schem='PUBLIC' order by table_name"; + + public static final String RENAME_TABLE = "alter table %s rename to %s"; + public static final String RENAME_COLUMN = "alter table %s alter column %s rename to %s"; + + public static final String ADD_INDEX = "create index %s_index on %s (%s)"; + public static final String DROP_INDEX = "drop index %s"; + public static final String CHANGE_TYPE = "alter table %s alter column %s set data type %s"; + public static final String ADD_COLUMN = "alter table %s add column %s %s default '%s' %s"; + public static final String DROP_COLUMN = "alter table %s drop column %s cascade"; + +} diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/database/compatible/IConvert.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/database/compatible/IConvert.java new file mode 100644 index 0000000..578d333 --- /dev/null +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/database/compatible/IConvert.java @@ -0,0 +1,56 @@ +/* + * Dynamic Analyzer + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Jaewon Lim + * Woojin Jung + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + * + */ +package org.tizen.dynamicanalyzer.database.compatible; + +import java.util.Set; + +interface IConvert { + + public void init(); + + public Set getTables(); + + public Set getColumns(String tableName); + + public Set getIndexColumns(String tableName); + + public boolean renameColumn(String tableName, String from, String to); + + public boolean renameTable(String from, String to); + + public boolean addIndex(String tableName, String[] columnList); + + public boolean dropIndex(String tableName, String indexName); + + public boolean changeType(String tableName, String columnName, String type); + + public boolean addColumn(String tableName, String columnName, String type, String defaultValue, + String option); + + public boolean dropColumn(String tableName, String columnName); + + public boolean createTable(String tableName); +} diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/database/compatible/SubConverter10to20Earlier.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/database/compatible/SubConverter10to20Earlier.java new file mode 100644 index 0000000..0079f32 --- /dev/null +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/database/compatible/SubConverter10to20Earlier.java @@ -0,0 +1,144 @@ +/* + * Dynamic Analyzer + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Jaewon Lim + * Woojin Jung + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + * + */ +package org.tizen.dynamicanalyzer.database.compatible; + +import java.util.Set; + +import org.tizen.dynamicanalyzer.database.DBConstants; +import org.tizen.dynamicanalyzer.database.DBTable; +import org.tizen.dynamicanalyzer.database.DBTableRegistry; +import org.tizen.dynamicanalyzer.ui.timeline.LifeCycleDBTable; + +/*- + * Project version 1.0 represent a database version of following SDK version + * 2.3, 2.3 rev1, 2.3 rev2, 2.3.1 + * + * We will call 2.3 and 2.3 rev1 to "earlier version" and, 2.3 rev2 and 2.3.1 to "later version" + * + * Earlier version (2.3 and 2.3 rev1) and later version (2.3 rev2, 2.3.1) have different scheme + * of database, so they have to be converted differently. Earlier version will be converted to later + * version first. + */ +class SubConverter10to20Earlier { + + /* + * constants for changes from earlier version to later version + */ + + // added columns + private static final String EARLY_THREADDATA_TABLE = "THREADDATA"; + private static final String EARLY_THREADDATA_CREATEID = "CREATETID"; + private static final String EARLY_THREADDATA_CREATEID_TYPE = DBConstants.DBTYPE_INT4; + private static final String EARLY_THREADDATA_CREATEID_DEFAULT = "-1"; + private static final String EARLY_THREADDATA_CREATEID_OPTION = DBConstants.NOT_NULL; + private static final String EARLY_THREADDATA_JOINID = "JOINTID"; + private static final String EARLY_THREADDATA_JOINID_TYPE = DBConstants.DBTYPE_INT4; + private static final String EARLY_THREADDATA_JOINID_DEFAULT = "-1"; + private static final String EARLY_THREADDATA_JOINID_OPTION = DBConstants.NOT_NULL; + + // added table + private static final String EARLY_LIFECYCLE_TABLE = "LIFE_CYCLE"; + + // added for indexing + private static final String EARLY_GLCONTEXT_TABLE = "GL_CONTEXT"; + private static final String EARLY_GLCONTEXT_SEQ = "SEQ"; + + private static final String EARLY_GLHISTORY_TABLE = "GL_HISTORY"; + private static final String EARLY_GLHISTORY_TABLE_INDEX = "GL_HISTORY_INDEX"; + private static final String EARLY_GLHISTORY_CONTEXTID = "CONTEXT_ID"; + private static final String EARLY_GLHISTORY_STATEID = "RENDER_STATE_ID"; + private static final String EARLY_GLHISTORY_CHANGESEQ = "CHANGE_SEQUENCE_NUMBER"; + + private static final String EARLY_NETWORKAPI_TABLE = "NETWORK_API"; + private static final String EARLY_NETWORKAPI_TIME = "TIME"; + + // parent converter + private IConvert converter = null; + + public SubConverter10to20Earlier(IConvert converter) { + this.converter = converter; + } + + // this method convert from earlier version to later version + public boolean convert() { + // first initialize parent converter + converter.init(); + + // add life-cycle table + Set tableList = converter.getTables(); + if (!tableList.contains(EARLY_LIFECYCLE_TABLE)) { + // this is earlier version + // add life-cycle table + DBTableRegistry.registerEnabled(false); + DBTable lifecycleTable = (DBTable) new LifeCycleDBTable(); + DBTableRegistry.registerEnabled(true); + if (!lifecycleTable.createTable() || !lifecycleTable.createIndexTable()) { + return false; + } + } else { + // this is later version already + return true; + } + + // add columns to thread data table + if (tableList.contains(EARLY_THREADDATA_TABLE)) { + // there is thread data table + if (!converter.addColumn(EARLY_THREADDATA_TABLE, EARLY_THREADDATA_CREATEID, + EARLY_THREADDATA_CREATEID_TYPE, EARLY_THREADDATA_CREATEID_DEFAULT, + EARLY_THREADDATA_CREATEID_OPTION) + || !converter.addColumn(EARLY_THREADDATA_TABLE, EARLY_THREADDATA_JOINID, + EARLY_THREADDATA_JOINID_TYPE, EARLY_THREADDATA_JOINID_DEFAULT, + EARLY_THREADDATA_JOINID_OPTION)) { + return false; + } + } + + // add index column + if (tableList.contains(EARLY_GLCONTEXT_TABLE)) { + if (!converter.addIndex(EARLY_GLCONTEXT_TABLE, new String[] { EARLY_GLCONTEXT_SEQ })) { + return false; + } + } + + if (tableList.contains(EARLY_GLHISTORY_TABLE)) { + // remove gl_history_index and create new gl_history_index + if (!converter.dropIndex(EARLY_GLHISTORY_TABLE, EARLY_GLHISTORY_TABLE_INDEX) + || !converter.addIndex(EARLY_GLHISTORY_TABLE, new String[] { + EARLY_GLHISTORY_CONTEXTID, EARLY_GLHISTORY_STATEID, + EARLY_GLHISTORY_CHANGESEQ })) { + return false; + } + } + + if (tableList.contains(EARLY_NETWORKAPI_TABLE)) { + if (!converter.addIndex(EARLY_NETWORKAPI_TABLE, new String[] { EARLY_NETWORKAPI_TIME })) { + return false; + } + } + + return true; + } +} diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/database/compatible/SubConverter10to20Later.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/database/compatible/SubConverter10to20Later.java new file mode 100644 index 0000000..c33daf3 --- /dev/null +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/database/compatible/SubConverter10to20Later.java @@ -0,0 +1,353 @@ +/* + * Dynamic Analyzer + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Jaewon Lim + * Woojin Jung + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + * + */ +package org.tizen.dynamicanalyzer.database.compatible; + +import java.util.Set; + +import org.tizen.dynamicanalyzer.database.DBTable; +import org.tizen.dynamicanalyzer.database.DBTableRegistry; +import org.tizen.dynamicanalyzer.ui.info.appStartup.AppStartupDBTable; +import org.tizen.dynamicanalyzer.ui.info.appStartup.WebAppStartupDBTable; +import org.tizen.dynamicanalyzer.ui.interactive.data.InteractiveValueDBTable; +import org.tizen.dynamicanalyzer.ui.interactive.data.InteractiveVariableDBTable; +import org.tizen.dynamicanalyzer.ui.opengl.data.DB.GLBufferSizeDBTableManager; +import org.tizen.dynamicanalyzer.ui.summary.profiling.WebProfilingDataDBTable; +import org.tizen.dynamicanalyzer.ui.timeline.calltrace.WebFunctionEntryDBTable; +import org.tizen.dynamicanalyzer.ui.timeline.calltrace.WebFunctionExitDBTable; +import org.tizen.dynamicanalyzer.util.Logger; + +/*- + * Project version 1.0 represent a database version of following SDK version + * 2.3, 2.3 rev1, 2.3 rev2, 2.3.1 + * + * We will call 2.3 and 2.3 rev1 to "earlier version" and, 2.3 rev2 and 2.3.1 to "later version" + * + * Earlier version (2.3 and 2.3 rev1) and later version (2.3 rev2, 2.3.1) have different scheme + * of database, so they have to be converted differently. Earlier version will be converted to later + * version first. + */ +class SubConverter10to20Later { + + /* + * constants for changes from later version to 2.4 + */ + + private static final String CHANGE_SEPERATOR = ">"; + private static final String TABLENAME_SEPERATOR = ":"; + + // @formatter:off + private static final String[] drop_column = { "FUNCTIONENTRY : TYPE" }; + + private static final String[] change_column_name = { + "CALLSTACKDATA : SEQNUMBER > SEQUENCE_NUMBER", + "CALLSTACKUNITS : FUNCTIONID > FUNCTION_ID", + "CALLSTACKUNITS : BINARYID > BINARY_ID", + "CALLSTACKUNITS : PCADDR > PC_ADDRESS", + "FAILEDAPIDATA : PROCESS_ID > PID", + "FILE_API_DB : ERRNO > ERROR_NUMBER", + "FILE_API_DB : ARGUMENTS_VALUE > ARGUMENT", + "FREEDATA : PROCESS_ID > PID", + "FUNCTIONENTRY : SEQNUMBER > SEQUENCE_NUMBER", + "FUNCTIONENTRY : FUNCTIONID > FUNCTION_ID", + "FUNCTIONENTRY : BINARYID > BINARY_ID", + "FUNCTIONENTRY : STARTTIME > START_TIME", + "FUNCTIONENTRY : PCADDR > START_PC_ADDRESS", + "FUNCTIONEXIT : ENTRYSEQNUMBER > ENTRY_SEQUENCE_NUMBER", + "FUNCTIONEXIT : EXITSEQNUMBER > EXIT_SEQUENCE_NUMBER", + "FUNCTIONEXIT : ENDTIME > END_TIME", + "FUNCTIONSAMPLE : SEQNUMBER > SEQUENCE_NUMBER", + "FUNCTIONSAMPLE : SAMPLETIME > SAMPLE_TIME", + "FUNCTIONSAMPLE : PCADDR > PC_ADDRESS", + "FUNCTIONSAMPLE : CPUNUM > CPU_NUMBER", + "GL_API : SEQ > SEQUENCE_NUMBER", + "GL_API : TIME > SATRT_TIME", + "GL_API : ID > API_ID", + "GL_API : ARG > ARGUMENT", + "GL_API : RET > RETURN_VALUE", + "GL_API : ERROR > ERROR_NUMBER", + "GL_API : LIB_NAME > CALLER_LIBRARY_NAME", + "GL_CONTEXT : SEQ > SEQUENCE_NUMBER", + "GL_PROGRAM : ID > PROGRAM_ID", + "GL_REDUNDANT : PARAMETER > ARGUMENT", + "GL_TEXTURE : CHANGE_SEQ > CHANGE_SEQUENCE_NUMBER", + "LEAKDATA : PROCESS_ID > PID", + "MEMORYALLOCATIONDATA : PROCESS_ID > PID", + "MEMORYALLOCATIONDATA : THREAD_ID > TID", + "NETWORK_API : SEQ > SEQUENCE_NUMBER", + "NETWORK_API : FD_VALUE > NETWORK_FD", + "NETWORK_API : TIME > API_TIME", + "NETWORK_API : ID > API_ID", + "NETWORK_API : ERROR > ERROR_NUMBER", + "NETWORK_API : ARG > ARGUMENT", + "NETWORK_API : RET > RETURN_VALUE", + "NETWORK_API : LIB_NAME > CALLER_LIBRARY_NAME", + "NETWORK_SERIES : FD_VALUE > NETWORK_FD", + "NETWORK_SERIES : ID > API_ID", + "PROFILINGCHILDDATA : PROFILINGDATAID > PROFILING_DATA_ID", + "PROFILINGDATA : PROFILINGDATAID > PROFILING_DATA_ID", + "PROFILINGDATA : FUNCTIONID > FUNCTION_ID", + "PROFILINGDATA : BINARYID > BINARY_ID", + "PROFILINGDATA : EXCOUNT > EXCLUSIVE_COUNT", + "PROFILINGDATA : INCOUNT > INCLUSIVE_COUNT", + "PROFILINGDATA : CALLCOUNT > CALL_COUNT", + "PROFILINGDATA : INCLEXETIME > INCLUSIVE_EXECUTION_TIME", + "PROFILINGDATA : EXCLEXETIME > EXCLUSIVE_EXECUTION_TIME", + "REPLAY : SEQ > SEQUENCE_NUMBER", + "SYNCAPI : SEQNUMBER > SEQUENCE_NUMBER", + "SYNCAPI : APICALLTIME > CALL_TIME", + "SYNCAPI : APIID > API_ID", + "SYNCAPI : SYNCVALUE > SYNC_VALUE", + "SYNCDATA : SYNCDATAID > SYNC_DATA_ID", + "SYNCDATA : SYNCTYPE > SYNC_TYPE", + "SYNCDATA : SYNCVALUE > SYNC_VALUE", + "SYNCDATA : ATTRIBUTETYPE > ATTRIBUTE_TYPE", + "SYNCDATA : SYNCDATATYPE > SYNC_DATA_TYPE", + "SYNCDATA : PARENTID > PARENT_ID", + "SYNCEVENT : APISEQNUMBER > SEQUENCE_NUMBER", + "SYNCEVENT : SYNCDATAID > SYNC_DATA_ID", + "SYNCEVENT : EVENTTIME > EVENT_TIME", + "SYNCEVENT : APITYPE > API_TYPE", + "SYNCEVENT : SYNCVALUE > SYNC_VALUE", + "SYNCEVENT : BLOCKENDTIME > BLOCK_END_TIME", + "THREADAPI : SEQNUMBER > SEQUENCE_NUMBER", + "THREADAPI : THREADDATAID > THREAD_DATA_ID", + "THREADAPI : APICALLTIME > CALL_TIME", + "THREADAPI : APIID > API_ID", + "THREADDATA : THREADDATAID > THREAD_DATA_ID", + "THREADDATA : THREADTYPE > THREAD_TYPE", + "THREADDATA : ATTRIBUTETYPE > ATTRIBUTE_TYPE", + "THREADDATA : STARTTIME > START_TIME", + "THREADDATA : ENDTIME > END_TIME", + "THREADDATA : FUNCTIONID > API_ID", + "THREADDATA : CLASSNAME > CLASS_NAME", + "THREADDATA : CREATETID > CREATE_TID", + "THREADDATA : JOINTID > JOIN_TID", + "THREADEVENT : THREADDATAID > THREAD_DATA_ID", + "THREADEVENT : EVENTTIME > EVENT_TIME", + "THREADEVENT : APITYPE > API_TYPE", + "THREADEVENT : EVENTTYPE > EVENT_TYPE", + "THREADEVENT : THREADTYPE > THREAD_TYPE", + "THREADEVENT : CALLERID > CALLER_ID", + "TIMELINE_TARGET_PROCESS : THREAD_ID > TID", + "WARNINGDATA : PROCESS_ID > PID", + "WARNINGDATA : THREAD_ID > TID" }; + + private static final String[] change_table_name = { + "CALLSTACKDATA > CALL_STACK_DATA", + "CALLSTACKUNITS > CALL_STACK_UNIT", + "FAILEDAPIDATA > FAILED_API_DATA", + "FILE_ACCESS_DB > FILE_ACCESS", + "FILE_ACCESSOR_DB > FILE_ACCESSOR", + "FILE_API_DB > FILE_API", + "FILE_STATUS_DB > FILE_STATUS", + "FREEDATA > FREE_DATA", + "FUNCTIONENTRY > FUNCTION_ENTRY", + "FUNCTIONEXIT > FUNCTION_EXIT", + "FUNCTIONSAMPLE > FUNCTION_SAMPLE", + "LEAKDATA > LEAK_DATA", + "MEMORYALLOCATIONDATA > MEMORY_ALLOCATION_DATA", + "PROFILINGCHILDDATA > PROFILING_CHILD_DATA", + "PROFILINGDATA > PROFILING_DATA", + "SYNCAPI > SYNC_API", + "SYNCDATA > SYNC_DATA", + "SYNCEVENT > SYNC_EVENT", + "THREADAPI > THREAD_API", + "THREADDATA > THREAD_DATA", + "THREADEVENT > THREAD_EVENT", + "WARNINGDATA > WARNING_DATA" }; + + @SuppressWarnings("unused") + private static final String[] create_table = { + "APP_STARTUP", + "GL_BUFFER_SIZE", + "INTERACTIVE_VALUE", + "INTERACTIVE_VARIABLE", + "WEB_APP_STARTUP", + "WEB_FUNCTION_ENTRY", + "WEB_FUNCTION_EXIT", + "WEB_PROFILING_DATA" }; + // @formatter:on + + // parent converter + private IConvert converter = null; + + public SubConverter10to20Later(IConvert converter) { + this.converter = converter; + } + + // this method convert from later version to 2.4 + public boolean convert() { + // first initialize parent converter + converter.init(); + + Set tables = converter.getTables(); + + if (!dropColumns(tables)) + return false; + + if (!renameColumns(tables)) + return false; + + if (!renameTables(tables)) + return false; + + if (!createTables(tables)) + return false; + + return true; + } + + private boolean renameTables(Set tables) { + for (int i = 0; i < change_table_name.length; i++) { + String[] tableNames = change_table_name[i].split(CHANGE_SEPERATOR); + if (tableNames.length == 2) { + String from = tableNames[0].trim(); + String to = tableNames[1].trim(); + + if (tables.contains(from)) { + if (!converter.renameTable(from, to)) { + return false; + } + } + } else { + Logger.error("parsing failed while converting DB (rename table)"); + } + } + + return true; + } + + private boolean renameColumns(Set tables) { + for (int i = 0; i < change_column_name.length; i++) { + String[] splitA = change_column_name[i].split(TABLENAME_SEPERATOR); + if (splitA.length == 2) { + String tableName = splitA[0].trim(); + String[] splitB = splitA[1].trim().split(CHANGE_SEPERATOR); + if (splitB.length == 2) { + String from = splitB[0].trim(); + String to = splitB[1].trim(); + + Set columns = converter.getColumns(tableName); + if (columns != null && columns.contains(from)) { + if (!converter.renameColumn(tableName, from, to)) { + return false; + } + } + } else { + Logger.error("parsing failed while converting DB (rename column)"); + } + } else { + Logger.error("parsing failed while converting DB (rename column)"); + } + } + + return true; + } + + private boolean dropColumns(Set tables) { + for (int i = 0; i < drop_column.length; i++) { + String[] splitA = drop_column[i].split(TABLENAME_SEPERATOR); + if (splitA.length == 2) { + String tableName = splitA[0].trim(); + String columnName = splitA[1].trim(); + + Set columns = converter.getColumns(tableName); + if (columns != null && columns.contains(columnName)) { + if (!converter.dropColumn(tableName, columnName)) { + return false; + } + } + } else { + Logger.error("parsing failed while converting DB (drop column)"); + } + } + + return true; + } + + private boolean createTables(Set tables) { + DBTableRegistry.registerEnabled(false); + DBTable appStartup = (DBTable) new AppStartupDBTable(); + DBTable glBufferSize = (DBTable) new GLBufferSizeDBTableManager(); + DBTable interValue = (DBTable) new InteractiveValueDBTable(); + DBTable interVariable = (DBTable) new InteractiveVariableDBTable(); + DBTable webStartup = (DBTable) new WebAppStartupDBTable(); + DBTable webFuncEntry = (DBTable) new WebFunctionEntryDBTable(); + DBTable webFuncExit = (DBTable) new WebFunctionExitDBTable(); + DBTable webProfiling = (DBTable) new WebProfilingDataDBTable(); + DBTableRegistry.registerEnabled(true); + + if (!tables.contains(appStartup.getTableName())) { + if (!appStartup.createTable() || !appStartup.createIndexTable()) { + return false; + } + } + + if (!tables.contains(glBufferSize.getTableName())) { + if (!glBufferSize.createTable() || !glBufferSize.createIndexTable()) { + return false; + } + } + + if (!tables.contains(interValue.getTableName())) { + if (!interValue.createTable() || !interValue.createIndexTable()) { + return false; + } + } + + if (!tables.contains(interVariable.getTableName())) { + if (!interVariable.createTable() || !interVariable.createIndexTable()) { + return false; + } + } + + if (!tables.contains(webStartup.getTableName())) { + if (!webStartup.createTable() || !webStartup.createIndexTable()) { + return false; + } + } + + if (!tables.contains(webFuncEntry.getTableName())) { + if (!webFuncEntry.createTable() || !webFuncEntry.createIndexTable()) { + return false; + } + } + + if (!tables.contains(webFuncExit.getTableName())) { + if (!webFuncExit.createTable() || !webFuncExit.createIndexTable()) { + return false; + } + } + + if (!tables.contains(webProfiling.getTableName())) { + if (!webProfiling.createTable() || !webProfiling.createIndexTable()) { + return false; + } + } + + return true; + } +} diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/handlers/OpenTraceHandler.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/handlers/OpenTraceHandler.java index 34a85dd..677bf0d 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/handlers/OpenTraceHandler.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/handlers/OpenTraceHandler.java @@ -38,6 +38,7 @@ import org.tizen.dynamicanalyzer.common.AnalyzerManager; import org.tizen.dynamicanalyzer.common.Global; import org.tizen.dynamicanalyzer.communicator.DeviceManager; import org.tizen.dynamicanalyzer.database.SqlConnectionManager; +import org.tizen.dynamicanalyzer.database.compatible.DBConverter; import org.tizen.dynamicanalyzer.nl.AnalyzerLabels; import org.tizen.dynamicanalyzer.project.BinaryInfo; import org.tizen.dynamicanalyzer.project.Project; @@ -71,15 +72,31 @@ public class OpenTraceHandler extends AbstractHandler { project = Global.getProject(); + // start progress dialog + OpenTraceProgressManager.getInstance().openTracePrgressStart( + AnalyzerLabels.OPEN_TRACE_PROGRESS_LOADING); + // establish db connection with new path SqlConnectionManager.closeConnection(); SqlConnectionManager.establishConnection(project.getSavePath() + File.separator + AnalyzerConstants.DATABASE_NAME); - OpenTraceProgressManager.getInstance().openTracePrgressStart( - AnalyzerLabels.OPEN_TRACE_PROGRESS_LOADING); + // convert save file for compatible database + DBConverter converter = new DBConverter(project.getVersion()); + if (!converter.convert()) { + // failed to convert for compatible database + OpenTraceProgressManager.getInstance().closeOpenTraceDialog( + AnalyzerLabels.OPEN_TRACE_PROGRESS_LOADING_FAILED); + UIAction.showWarning(AnalyzerLabels.OPEN_TRACE_PROGRESS_INVALID); + CommonAction.clear(); + return null; + } else { + // converting is succeeded + // change version of save file to current version + project.updateVersion(); + } - boolean bsuccess = project.open(project.getSavePath()); + boolean bsuccess = project.openDetail(); if (!bsuccess) { OpenTraceProgressManager.getInstance().closeOpenTraceDialog( AnalyzerLabels.OPEN_TRACE_PROGRESS_LOADING_FAILED); @@ -248,7 +265,7 @@ public class OpenTraceHandler extends AbstractHandler { } return isSuccess; } - + private boolean loadWebProfilingData() { boolean isSuccess = true; List> profilingDatas = FunctionUsageProfiler.getInstance() @@ -260,22 +277,31 @@ public class OpenTraceHandler extends AbstractHandler { for (int i = 0; i < profilingDatas.size(); i++) { List profilingData = profilingDatas.get(i); - int profilingDataID = (Integer) profilingData.get(WebProfilingDataDBTable.COLUMN.PROFILING_DATA_ID.getIndex()); - int pid = (Integer) profilingData.get(WebProfilingDataDBTable.COLUMN.PID.getIndex()); - int functionLineNumber = (Integer) profilingData.get(WebProfilingDataDBTable.COLUMN.FUNCTION_LINE_NUMBER.getIndex()); - String functionName = (String) profilingData.get(WebProfilingDataDBTable.COLUMN.FUNCTION_NAME.getIndex()); - String functionURL = (String) profilingData.get(WebProfilingDataDBTable.COLUMN.FUNCTION_URL.getIndex()); - int callCount = (Integer) profilingData.get(WebProfilingDataDBTable.COLUMN.CALL_COUNT.getIndex()); - long inElapsedTime = (Long) profilingData.get(WebProfilingDataDBTable.COLUMN.INCLUSIVE_EXECUTION_TIME.getIndex()); - long exElapsedTime = (Long) profilingData.get(WebProfilingDataDBTable.COLUMN.EXCLUSIVE_EXECUTION_TIME.getIndex()); - + int profilingDataID = (Integer) profilingData + .get(WebProfilingDataDBTable.COLUMN.PROFILING_DATA_ID.getIndex()); + int pid = (Integer) profilingData + .get(WebProfilingDataDBTable.COLUMN.PID.getIndex()); + int functionLineNumber = (Integer) profilingData + .get(WebProfilingDataDBTable.COLUMN.FUNCTION_LINE_NUMBER.getIndex()); + String functionName = (String) profilingData + .get(WebProfilingDataDBTable.COLUMN.FUNCTION_NAME.getIndex()); + String functionURL = (String) profilingData + .get(WebProfilingDataDBTable.COLUMN.FUNCTION_URL.getIndex()); + int callCount = (Integer) profilingData + .get(WebProfilingDataDBTable.COLUMN.CALL_COUNT.getIndex()); + long inElapsedTime = (Long) profilingData + .get(WebProfilingDataDBTable.COLUMN.INCLUSIVE_EXECUTION_TIME.getIndex()); + long exElapsedTime = (Long) profilingData + .get(WebProfilingDataDBTable.COLUMN.EXCLUSIVE_EXECUTION_TIME.getIndex()); + @SuppressWarnings("unchecked") - List childSeqList = (List) profilingData.get(WebProfilingDataDBTable. - COLUMN.CHILD_SEQUENCE_ARRAY.getIndex()); + List childSeqList = (List) profilingData + .get(WebProfilingDataDBTable.COLUMN.CHILD_SEQUENCE_ARRAY.getIndex()); // create WebProfilingData - WebProfilingData fupData = new WebProfilingData(profilingDataID, functionLineNumber, functionName, - functionURL, callCount, inElapsedTime, exElapsedTime, childSeqList); + WebProfilingData fupData = new WebProfilingData(profilingDataID, + functionLineNumber, functionName, functionURL, callCount, inElapsedTime, + exElapsedTime, childSeqList); // get WebProfileDataMaker WebProfileDataMaker profiler = FunctionUsageProfiler.getInstance() diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/AppInfo.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/AppInfo.java index cbc7b54..39a33d0 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/AppInfo.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/AppInfo.java @@ -410,12 +410,16 @@ public class AppInfo { PROPERTY[] property = PROPERTY.values(); int propertycount = property.length; while (null != (content = in.readLine())) { - String[] splitData = content.split(CommonConstants.EQUAL); - int size = splitData.length; - if (2 != size) { + if (content.trim().isEmpty()) { + // it means end of section break; } + String[] splitData = content.split(CommonConstants.EQUAL); + if (2 != splitData.length) { + continue; + } + String infoKey = splitData[0]; String val = splitData[1]; int i; diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/DeviceStatusInfo.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/DeviceStatusInfo.java index d3a9c3f..21bdddf 100755 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/DeviceStatusInfo.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/DeviceStatusInfo.java @@ -177,13 +177,13 @@ public class DeviceStatusInfo { public void openPrimitive(BufferedReader in) throws IOException { String content; while (null != (content = in.readLine())) { - if (content.isEmpty()) { + if (content.trim().isEmpty()) { + // it means end of section break; } String[] splitData = content.split(CommonConstants.EQUAL); - int size = splitData.length; - if (2 != size) { + if (2 != splitData.length) { continue; } diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/Project.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/Project.java index 7c14931..fb81682 100755 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/Project.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/Project.java @@ -64,7 +64,6 @@ import org.tizen.dynamicanalyzer.project.data.MemoryMapDBTable; import org.tizen.dynamicanalyzer.project.data.ProcessInfoDBTable; import org.tizen.dynamicanalyzer.util.CommonUtil; import org.tizen.dynamicanalyzer.util.Logger; -import org.tizen.dynamicanalyzer.utils.AnalyzerUtil; public class Project { private static final ProcessInfoDBTable processInfoTable; @@ -133,22 +132,30 @@ public class Project { public Project() { } - // private constructor - private Project(String infoFilePath) { - BufferedReader in = getOpenReader(infoFilePath); + // static constructor + public static Project getProjectFromFile(String savedPath) { + Project project = new Project(); + + project.setSavePath(savedPath); + BufferedReader in = project.getOpenReader(savedPath); if (in != null) { try { - openPrimitive(in); + String fail = project.openPrimitive(in); + if (fail != null) { + Logger.error("open project failed at " + fail + " information"); + return null; + } } catch (IOException e) { Logger.exception(e); + return null; } finally { CommonUtil.tryClose(in); } + } else { + return null; } - } - public static Project getProjectInfoFromFile(String infoFilePath) { - return new Project(infoFilePath); + return project; } // ******************************************************* @@ -513,7 +520,7 @@ public class Project { progress.setStageComplete(STAGE.ESTABLISH_DB); // create table - DBTableRegistry.createDBTables(); + DBTableRegistry.createDBTables(null); progress.testCancel(); progress.setStageComplete(STAGE.CREATE_DBTABLE); @@ -532,18 +539,6 @@ public class Project { // close previous database connection SqlConnectionManager.closeConnection(); - if (!isValid()) { - String sourcePath = getSavePath(); - if (null != sourcePath && !sourcePath.isEmpty()) { - boolean success = AnalyzerUtil.deleteFile(new File(sourcePath)); - if (success) { - Logger.debug("invalid project deleted!"); //$NON-NLS-1$ - } else { - Logger.debug("invalid project delete fail..."); //$NON-NLS-1$ - } - } - } - // initialize variable version = ProjectVersion.VERSION_UNKNOWN; protocolVersion = null; @@ -688,17 +683,12 @@ public class Project { } } - public boolean open(String savePath) { + public boolean openDetail() { boolean bret = true; BufferedReader in = getOpenReader(savePath); if (in != null) { try { - String fail = openPrimitive(in); - if (fail != null) { - Logger.error("open project failed at " + fail + " informatiion"); - return false; - } openTargetStatusInfo(in); openApplicationInfo(in); openFunctionInfo(); @@ -736,20 +726,40 @@ public class Project { return reader; } + private boolean gotoSection(BufferedReader in, String sectionName) { + String content; + + try { + while (null != (content = in.readLine())) { + if (content.trim().equals(sectionName)) { + return true; + } + } + } catch (IOException e) { + Logger.exception(e); + } + + return false; + } + // return open error field name // return null if open succeed private String openPrimitive(BufferedReader in) throws IOException { String ret = null; - String content = in.readLine(); - if (content != null && content.equals(PRIMITIVE_SECTION)) { + if (gotoSection(in, PRIMITIVE_SECTION)) { + String content; while (null != (content = in.readLine())) { - String[] splitData = content.split(CommonConstants.EQUAL); - int size = splitData.length; - if (2 != size) { + if (content.trim().isEmpty()) { + // it means end of section break; } + String[] splitData = content.split(CommonConstants.EQUAL); + if (2 != splitData.length) { + continue; + } + String infoKey = splitData[0]; String val = splitData[1]; if (infoKey.equals(VERSION)) { @@ -787,8 +797,7 @@ public class Project { } private void openTargetStatusInfo(BufferedReader in) throws IOException { - String content = in.readLine(); - if (content != null && content.equals(DEVICE_SECTION)) { + if (gotoSection(in, DEVICE_SECTION)) { if (targetDeviceStatusInfo == null) { targetDeviceStatusInfo = new DeviceStatusInfo(); } @@ -797,8 +806,7 @@ public class Project { } private void openApplicationInfo(BufferedReader in) throws IOException { - String content = in.readLine(); - if (content != null && content.equals(APP_SECTION)) { + if (gotoSection(in, APP_SECTION)) { if (targetApplicationInfo == null) { targetApplicationInfo = new AppInfo(); } @@ -867,4 +875,81 @@ public class Project { putProcessInformation(pinfo); } } + + public void updateVersion() { + // if already project version is recent version, then just return + if (version == ProjectVersion.VERSION_LAST) { + return; + } + + // update saved project version to recent version + setVersion(ProjectVersion.VERSION_LAST); + + BufferedReader reader = null; + BufferedWriter writer = null; + + StringBuffer savefilename = new StringBuffer(getSavePath()); + savefilename.append(File.separator).append(PathConstants.PROJECT_INFO_FILE_NAME); + + File saveFile = new File(savefilename.toString()); + if (saveFile.isFile()) { + try { + reader = new BufferedReader(new FileReader(saveFile)); + } catch (FileNotFoundException e) { + Logger.exception(e); + } + } + + List lines = new ArrayList(); + + if (reader != null) { + String content; + boolean bFoundPrimitive = false; + boolean bFoundVersion = false; + + // read from projectInfo + try { + while (null != (content = reader.readLine())) { + if (!bFoundPrimitive && content.equals(PRIMITIVE_SECTION)) { + bFoundPrimitive = true; + } else if (bFoundPrimitive && !bFoundVersion && content.startsWith(VERSION)) { + bFoundVersion = true; + content = VERSION + CommonConstants.EQUAL + getVersion(); + } else { + // do nothing + } + + lines.add(content); + } + } catch (IOException e) { + Logger.exception(e); + } finally { + CommonUtil.tryClose(reader); + } + } + + if (saveFile.isFile()) { + try { + writer = new BufferedWriter(new FileWriter(saveFile)); + } catch (IOException e) { + Logger.exception(e); + } + } + + if (writer != null) { + // write to projectInfo + try { + for (String line : lines) { + writer.write(line); + writer.newLine(); + } + + writer.flush(); + } catch (IOException e) { + Logger.exception(e); + } finally { + CommonUtil.tryClose(writer); + } + } + } } diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/opentrace/OpenTraceDialog.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/opentrace/OpenTraceDialog.java index d6f4747..73f4d3e 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/opentrace/OpenTraceDialog.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/opentrace/OpenTraceDialog.java @@ -107,8 +107,7 @@ public class OpenTraceDialog extends DAMessageBox { AnalyzerLabels.OPEN_TRACE_DLG_TRACE_DATE }; private int[] columnSizes = { 300, 200 }; private boolean[] columnVisibility = { true, true }; - int[] sortTypes = { AnalyzerConstants.SORT_TYPE_GRID, - AnalyzerConstants.SORT_TYPE_GRID }; + int[] sortTypes = { AnalyzerConstants.SORT_TYPE_GRID, AnalyzerConstants.SORT_TYPE_GRID }; public OpenTraceDialog(Shell parent) { super(parent); @@ -310,8 +309,7 @@ public class OpenTraceDialog extends DAMessageBox { openPath = PathManager.DA_TEMP_FOLDER_PATH + File.separator + selection.getText(); } else if ((Integer) selection.getData() == SAVE_FOLDER) { - openPath = PathManager.DA_SAVE_PATH + File.separator - + selection.getText(); + openPath = PathManager.DA_SAVE_PATH + File.separator + selection.getText(); } else { return; } @@ -359,8 +357,7 @@ public class OpenTraceDialog extends DAMessageBox { private String getDrawTextByScroll(String text) { String drawTest = CommonConstants.EMPTY; if (text.length() >= detailViewHSelectionIndex) { - drawTest = (String) text - .subSequence(detailViewHSelectionIndex, text.length()); + drawTest = (String) text.subSequence(detailViewHSelectionIndex, text.length()); } return drawTest; } @@ -435,8 +432,7 @@ public class OpenTraceDialog extends DAMessageBox { GridItem item = items[0]; String openPath = null; if ((Integer) item.getData() == TEMP_FOLDER) { - openPath = PathManager.DA_TEMP_FOLDER_PATH + File.separator - + item.getText(); + openPath = PathManager.DA_TEMP_FOLDER_PATH + File.separator + item.getText(); } else if ((Integer) item.getData() == SAVE_FOLDER) { openPath = PathManager.DA_SAVE_PATH + File.separator + item.getText(); } else { @@ -470,8 +466,7 @@ public class OpenTraceDialog extends DAMessageBox { String openPath = null; if ((Integer) item.getData() == TEMP_FOLDER) { - openPath = PathManager.DA_TEMP_FOLDER_PATH + File.separator - + item.getText(); + openPath = PathManager.DA_TEMP_FOLDER_PATH + File.separator + item.getText(); } else if ((Integer) item.getData() == SAVE_FOLDER) { openPath = PathManager.DA_SAVE_PATH + File.separator + item.getText(); } else { @@ -512,8 +507,7 @@ public class OpenTraceDialog extends DAMessageBox { if (!application.isEmpty() && !device.isEmpty()) { e.gc.setFont(FontResources.TABLE_CELL_FONT); - String inputText = AnalyzerLabels.OPEN_TRACE_DLG_DETAILS_APPLICATION - + application; + String inputText = AnalyzerLabels.OPEN_TRACE_DLG_DETAILS_APPLICATION + application; Point textSize = e.gc.textExtent(inputText, SWT.DRAW_MNEMONIC); int fontHeight = textSize.y + 3; int x = rect.x + 7; @@ -528,8 +522,7 @@ public class OpenTraceDialog extends DAMessageBox { e.gc.drawText(getDrawTextByScroll(inputText), x, y); y += fontHeight; - inputText = AnalyzerLabels.OPEN_TRACE_DLG_DETAILS_CREATE_TIME - + createTime; + inputText = AnalyzerLabels.OPEN_TRACE_DLG_DETAILS_CREATE_TIME + createTime; e.gc.drawText(getDrawTextByScroll(inputText), x, y); y += fontHeight; @@ -569,13 +562,15 @@ public class OpenTraceDialog extends DAMessageBox { } private boolean setDetailsInfo(String path) { - boolean isSuccess = true; - Project project = Project.getProjectInfoFromFile(path); - - createTime = project.getCreateTime(); - device = project.getDevice(); - application = project.getAppName(); - elapsedTime = project.getTotalStopTime(); - return isSuccess; + Project project = Project.getProjectFromFile(path); + if (project != null) { + createTime = project.getCreateTime(); + device = project.getDevice(); + application = project.getAppName(); + elapsedTime = project.getTotalStopTime(); + return true; + } else { + return false; + } } } diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/opentrace/OpenTraceProgressManager.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/opentrace/OpenTraceProgressManager.java index 81adde0..bbbf9fe 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/opentrace/OpenTraceProgressManager.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/opentrace/OpenTraceProgressManager.java @@ -206,9 +206,15 @@ public class OpenTraceProgressManager implements Runnable { @Override public void run() { CommonAction.clear(); - Project project = new Project(); - Global.setProject(project); - project.setSavePath(getInstance().getSavePath()); - AnalyzerUtil.executeCommand(OpenTraceHandler.ID); + + Project project = Project.getProjectFromFile(getInstance().getSavePath()); + if (project != null) { + Global.setProject(project); + AnalyzerUtil.executeCommand(OpenTraceHandler.ID); + } else { + closeOpenTraceDialog(AnalyzerLabels.OPEN_TRACE_PROGRESS_LOADING_FAILED); + UIAction.showWarning(AnalyzerLabels.OPEN_TRACE_PROGRESS_INVALID); + CommonAction.clear(); + } } } diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/opentrace/SaveFilesTable.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/opentrace/SaveFilesTable.java index 3959549..0744fb3 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/opentrace/SaveFilesTable.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/opentrace/SaveFilesTable.java @@ -39,13 +39,12 @@ import org.tizen.dynamicanalyzer.common.path.PathManager; import org.tizen.dynamicanalyzer.model.TableInput; import org.tizen.dynamicanalyzer.nl.AnalyzerLabels; import org.tizen.dynamicanalyzer.project.Project; -import org.tizen.dynamicanalyzer.project.ProjectVersion; import org.tizen.dynamicanalyzer.resources.ColorResources; import org.tizen.dynamicanalyzer.ui.widgets.table.DATableComposite; import org.tizen.dynamicanalyzer.utils.AnalyzerUtil; public class SaveFilesTable extends DATableComposite { - private boolean isVaildVersion = true; + private boolean isValidVersion = true; private static final int TRACE_NAME_INDEX = 0; private static final int DATE_INDEX = 1; public static final int VALIDATE_INDEX = 2; @@ -77,7 +76,7 @@ public class SaveFilesTable extends DATableComposite { text.add(inputText1); text.add(inputText2); - if (isVaildVersion) { + if (isValidVersion) { text.add(VALIDATE_Y); } else { text.add(VALIDATE_N); @@ -144,15 +143,12 @@ public class SaveFilesTable extends DATableComposite { } private String getCreateTime(String path) { - isVaildVersion = true; - Project project = Project.getProjectInfoFromFile(path); - - ProjectVersion version = project.getVersion(); - if (version != ProjectVersion.VERSION_LAST) { - isVaildVersion = false; + Project project = Project.getProjectFromFile(path); + if (project != null) { + isValidVersion = true; + return project.getCreateTime(); } else { - isVaildVersion = true; + return null; } - return project.getCreateTime(); } } diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/opentrace/TempFilesTable.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/opentrace/TempFilesTable.java index b70c07c..d8be9a9 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/opentrace/TempFilesTable.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/opentrace/TempFilesTable.java @@ -63,8 +63,15 @@ public class TempFilesTable extends DATableComposite { List text = new ArrayList(); String path = PathManager.DA_TEMP_FOLDER_PATH + File.separator + tempFileList.get(i); - text.add(tempFileList.get(i)); - text.add(getCreateTime(path)); + String inputText1 = tempFileList.get(i); + String inputText2 = getCreateTime(path); + + if (inputText1.isEmpty() || null == inputText2 || inputText2.isEmpty()) { + continue; + } + + text.add(inputText1); + text.add(inputText2); TableInput tableInput = new TableInput(); tableInput.setText(text); input.add(tableInput); @@ -119,7 +126,11 @@ public class TempFilesTable extends DATableComposite { } private String getCreateTime(String path) { - Project project = Project.getProjectInfoFromFile(path); - return project.getCreateTime(); + Project project = Project.getProjectFromFile(path); + if (project != null) { + return project.getCreateTime(); + } else { + return null; + } } } diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/userinterface/profiling/UIFunctionProfilingDataChecker.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/userinterface/profiling/UIFunctionProfilingDataChecker.java index 0f049d1..d0e2218 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/userinterface/profiling/UIFunctionProfilingDataChecker.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/userinterface/profiling/UIFunctionProfilingDataChecker.java @@ -281,7 +281,8 @@ public class UIFunctionProfilingDataChecker { isEmulator = true; } } catch (DeviceNotFoundException e1) { - Logger.exception(e1); + // this exception is occurred, if 'open' save file and device is not connected + Logger.warning("Device is not found"); // do not return, assume device is emulator } diff --git a/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/data/FileAccessDBTest.java b/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/data/FileAccessDBTest.java index 2568813..01e5056 100644 --- a/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/data/FileAccessDBTest.java +++ b/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/data/FileAccessDBTest.java @@ -5,7 +5,9 @@ import static org.junit.Assert.assertEquals; import java.io.File; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.HashSet; import java.util.List; +import java.util.Set; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -30,7 +32,9 @@ public class FileAccessDBTest { + AnalyzerConstants.DATABASE_NAME); accessDB = new FileAccessDB(); - DBTableRegistry.createDBTables(); + Set tableSet = new HashSet(); + tableSet.add(accessDB.getTableName()); + DBTableRegistry.createDBTables(tableSet); access = new FileAccess(1, 2, new Long(9412708),new Long(9412708), "read"); } diff --git a/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/data/FileAccessorDBTest.java b/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/data/FileAccessorDBTest.java index e310cb9..6ed5e03 100644 --- a/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/data/FileAccessorDBTest.java +++ b/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/data/FileAccessorDBTest.java @@ -5,7 +5,9 @@ import static org.junit.Assert.assertEquals; import java.io.File; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.HashSet; import java.util.List; +import java.util.Set; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -30,7 +32,9 @@ public class FileAccessorDBTest { + AnalyzerConstants.DATABASE_NAME); accessorDB = new FileAccessorDB(); - DBTableRegistry.createDBTables(); + Set tableSet = new HashSet(); + tableSet.add(accessorDB.getTableName()); + DBTableRegistry.createDBTables(tableSet); accessor = new FileAccessor(1, 2, "/temp/test1.txt", 10, 10, true); } diff --git a/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/data/FileApiDBTest.java b/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/data/FileApiDBTest.java index 024d526..c915715 100644 --- a/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/data/FileApiDBTest.java +++ b/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/data/FileApiDBTest.java @@ -8,7 +8,9 @@ import java.sql.SQLException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; +import java.util.HashSet; import java.util.List; +import java.util.Set; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -39,7 +41,11 @@ public class FileApiDBTest { apiDB = new FileApiDB(); accessorDB = new FileAccessorDB(); - DBTableRegistry.createDBTables(); + Set tableSet = new HashSet(); + tableSet.add(apiDB.getTableName()); + tableSet.add(accessorDB.getTableName()); + DBTableRegistry.createDBTables(tableSet); + // accessorId = 1, fileId = 2, pid = 10, tid = 10 accessor = new FileAccessor(1, 2, "/temp/test1.txt", 10, 10, true); event = new FileEvent(new Long(0), 1, 2, new Long(10), 1, 11, new Long(9412708), diff --git a/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/data/FileStatusDBTest.java b/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/data/FileStatusDBTest.java index 8949b4b..b867082 100644 --- a/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/data/FileStatusDBTest.java +++ b/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/data/FileStatusDBTest.java @@ -5,7 +5,9 @@ import static org.junit.Assert.assertEquals; import java.io.File; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.HashSet; import java.util.List; +import java.util.Set; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -31,7 +33,9 @@ public class FileStatusDBTest { + AnalyzerConstants.DATABASE_NAME); statusDB = new FileStatusDB(); - DBTableRegistry.createDBTables(); + Set tableSet = new HashSet(); + tableSet.add(statusDB.getTableName()); + DBTableRegistry.createDBTables(tableSet); status = new FileStatus(1, 0, new Long(9412708)); } diff --git a/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/manager/FileDataMakerTest.java b/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/manager/FileDataMakerTest.java index d8cd661..906c411 100644 --- a/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/manager/FileDataMakerTest.java +++ b/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/manager/FileDataMakerTest.java @@ -10,7 +10,6 @@ import java.util.Collection; import java.util.Date; import java.util.List; import java.util.Random; - import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -44,7 +43,7 @@ public class FileDataMakerTest { SqlConnectionManager.establishConnection(path + File.separator + AnalyzerConstants.DATABASE_NAME); - DBTableRegistry.createDBTables(); + DBTableRegistry.createDBTables(null); makeRandomObjects(); } -- 2.7.4