Search in sources :

Example 6 with UserDao

use of com.serotonin.m2m2.db.dao.UserDao in project ma-modules-public by infiniteautomation.

the class Upgrade2 method upgrade.

@Override
protected void upgrade() throws Exception {
    runScript(new String[] { "alter table reportInstances add template varchar(40);", "alter table reportInstances add reportId int;", "update reportInstances set reportId=-1;", "alter table reportInstances add mapping blob;", "alter table reportInstancePoints add xid varchar(50);", "update reportInstancePoints set xid='legacyReport';" });
    ReportDao dao = ReportDao.instance;
    UserDao ud = UserDao.instance;
    List<ReportVO> reports = dao.getReports();
    List<ReportInstance> reportInstances;
    List<User> users = ud.getUsers();
    for (User u : users) {
        reportInstances = dao.getReportInstances(u.getId());
        for (ReportInstance ri : reportInstances) {
            for (ReportVO report : reports) {
                if (ri.getName().equals(report.getName())) {
                    ri.setReportId(report.getId());
                    dao.saveReportInstance(ri);
                    break;
                }
            }
        }
    }
    // Alter the column back to have no default
    Map<String, String[]> scripts = new HashMap<String, String[]>();
    scripts.put(DatabaseProxy.DatabaseType.DERBY.name(), new String[] { "alter table reportInstances alter column reportId NOT NULL; ", "alter table reportInstancePoints alter column xid NOT NULL;" });
    scripts.put(DatabaseProxy.DatabaseType.MYSQL.name(), new String[] { "ALTER TABLE reportInstances CHANGE COLUMN `reportId` `reportId` int NOT NULL;", "ALTER TABLE reportInstancePoints CHANGE COLUMN `xid` `xid` VARCHAR(50) NOT NULL;" });
    scripts.put(DatabaseProxy.DatabaseType.MSSQL.name(), new String[] { "alter table reportInstances alter column reportId int NOT NULL;", "alter table reportInstancePoints alter column xid varchar(50) NOT NULL;" });
    scripts.put(DatabaseProxy.DatabaseType.H2.name(), new String[] { "alter table reportInstances alter column reportId int NOT NULL;", "alter table reportInstancePoints alter column xid varchar(50) NOT NULL;" });
    runScript(scripts);
}
Also used : User(com.serotonin.m2m2.vo.User) UserDao(com.serotonin.m2m2.db.dao.UserDao) HashMap(java.util.HashMap) ReportVO(com.serotonin.m2m2.reports.vo.ReportVO) ReportDao(com.serotonin.m2m2.reports.ReportDao) ReportInstance(com.serotonin.m2m2.reports.vo.ReportInstance)

Aggregations

UserDao (com.serotonin.m2m2.db.dao.UserDao)6 User (com.serotonin.m2m2.vo.User)6 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)3 ReportInstance (com.serotonin.m2m2.reports.vo.ReportInstance)2 PermissionException (com.serotonin.m2m2.vo.permission.PermissionException)2 HashMap (java.util.HashMap)2 InvalidArgumentException (com.serotonin.InvalidArgumentException)1 IntStringPair (com.serotonin.db.pair.IntStringPair)1 DataPointDao (com.serotonin.m2m2.db.dao.DataPointDao)1 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)1 Translations (com.serotonin.m2m2.i18n.Translations)1 ReportDao (com.serotonin.m2m2.reports.ReportDao)1 ReportVO (com.serotonin.m2m2.reports.vo.ReportVO)1 CronTimerTrigger (com.serotonin.timer.CronTimerTrigger)1 File (java.io.File)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1