웹기반 HMI ScadaBR의 데이터베이스 스키마는 사용자가 톰캣 서버를 가동하여 서블릿 컨텍스트가 전달되는 시점에 테이블 존재 여부를 검사하여 없을때 테이블 스키마를 자동 생성합니다.
MangoContextListener 클래스를 통해서 databaseInitialize 함수를 실행하고 이때 BasePooledAccess를 상속한 데이터베이스 종류별 클래스를 통해서 테이블 검사와 스키마 생성 작업을 수행합니다. 다음의 코드는 MySQLAccess.java의 일부로 users 테이블에 대해서 간단한 쿼리를 수행하고 테이블이 없으면 "/WEB-INF/db/createTables-mysql.sql"에 저장한 스키마 일괄 생성 스크립트를 수행하는 것을 확인할 수 있습니다. 스키마 생성을 위한 SQL 스크립트는 WEB-INF/db 폴더에 createTables-mysql.sql, createTables-derby.sql 등으로 생성되어 있으므로 참조합니다.
protected boolean newDatabaseCheck(ExtendedJdbcTemplate ejt) {
try {
ejt.execute("select count(*) from users");
}
catch (DataAccessException e) {
if (e.getCause() instanceof SQLException) {
SQLException se = (SQLException) e.getCause();
if ("42S02".equals(se.getSQLState())) {
// This state means a missing table. Assume that the schema needs to be created.
createSchema("/WEB-INF/db/createTables-mysql.sql");
return true;
}
}
throw e;
}
return false;
}
설치 시점에 데이터베이스만 생성하고 데이터베이스 이름과 사용자아이디/비밀번호를 env.properties에 설정해놓으면 위에서 설명한 과정을 통해서 스키마를 자동 생성합니다.ScadaBR의 데이터베이스 스키마는 아래와 같습니다.
위의 스키마 도표에서 확인 할 수 있듯이 테이블간에 외래키 참조 제약으로 묶여 있다는 특성이 있고 그 중심에 users, datasources/datapoints, reportinstances 테이블이 있음을 확인 할 수 있습니다. 데이터베이스의 인코딩은 UTF-8로 운용하고 스키마 생성시에 자동 설정합니다.
다음은 테이블 단위의 상세 스키마 내역입니다.
compoundeventdetectors
Column |
Type |
Null |
Default |
Comments |
MIME |
id |
int(11) |
No |
xid |
varchar(50) |
No |
name |
varchar(100) |
Yes |
NULL |
alarmLevel |
int(11) |
No |
returnToNormal |
char(1) |
No |
disabled |
char(1) |
No |
conditionText |
varchar(256) |
No |
datapoints
Column |
Type |
Null |
Default |
Links to |
Comments |
MIME |
id |
int(11) |
No |
xid |
varchar(50) |
No |
dataSourceId |
int(11) |
No |
datasources -> id |
data |
longblob |
No |
datapointusers
Column |
Type |
Null |
Default |
Links to |
Comments |
MIME |
dataPointId |
int(11) |
No |
datapoints -> id |
userId |
int(11) |
No |
users -> id |
permission |
int(11) |
No |
datasources
Column |
Type |
Null |
Default |
Comments |
MIME |
id |
int(11) |
No |
xid |
varchar(50) |
No |
name |
varchar(40) |
No |
dataSourceType |
int(11) |
No |
data |
longblob |
No |
datasourceusers
Column |
Type |
Null |
Default |
Links to |
Comments |
MIME |
dataSourceId |
int(11) |
No |
datasources -> id |
userId |
int(11) |
No |
users -> id |
eventhandlers
Column |
Type |
Null |
Default |
Comments |
MIME |
id |
int(11) |
No |
xid |
varchar(50) |
No |
alias |
varchar(255) |
Yes |
NULL |
eventTypeId |
int(11) |
No |
eventTypeRef1 |
int(11) |
No |
eventTypeRef2 |
int(11) |
No |
data |
longblob |
No |
events
Column |
Type |
Null |
Default |
Links to |
Comments |
MIME |
id |
int(11) |
No |
typeId |
int(11) |
No |
typeRef1 |
int(11) |
No |
typeRef2 |
int(11) |
No |
activeTs |
bigint(20) |
No |
rtnApplicable |
char(1) |
No |
rtnTs |
bigint(20) |
Yes |
NULL |
rtnCause |
int(11) |
Yes |
NULL |
alarmLevel |
int(11) |
No |
message |
longtext |
Yes |
NULL |
ackTs |
bigint(20) |
Yes |
NULL |
ackUserId |
int(11) |
Yes |
NULL |
users -> id |
alternateAckSource |
int(11) |
Yes |
NULL |
flexprojects
Column |
Type |
Null |
Default |
Comments |
MIME |
id |
int(11) |
No |
name |
varchar(40) |
No |
description |
varchar(1024) |
Yes |
NULL |
xmlConfig |
varchar(16384) |
No |
mailinglistinactive
Column |
Type |
Null |
Default |
Links to |
Comments |
MIME |
mailingListId |
int(11) |
No |
mailinglists -> id |
inactiveInterval |
int(11) |
No |
mailinglistmembers
Column |
Type |
Null |
Default |
Links to |
Comments |
MIME |
mailingListId |
int(11) |
No |
mailinglists -> id |
typeId |
int(11) |
No |
userId |
int(11) |
Yes |
NULL |
address |
varchar(255) |
Yes |
NULL |
mailinglists
Column |
Type |
Null |
Default |
Comments |
MIME |
id |
int(11) |
No |
xid |
varchar(50) |
No |
name |
varchar(40) |
No |
maintenanceevents
Column |
Type |
Null |
Default |
Links to |
Comments |
MIME |
id |
int(11) |
No |
xid |
varchar(50) |
No |
dataSourceId |
int(11) |
No |
datasources -> id |
alias |
varchar(255) |
Yes |
NULL |
alarmLevel |
int(11) |
No |
scheduleType |
int(11) |
No |
disabled |
char(1) |
No |
activeYear |
int(11) |
Yes |
NULL |
activeMonth |
int(11) |
Yes |
NULL |
activeDay |
int(11) |
Yes |
NULL |
activeHour |
int(11) |
Yes |
NULL |
activeMinute |
int(11) |
Yes |
NULL |
activeSecond |
int(11) |
Yes |
NULL |
activeCron |
varchar(25) |
Yes |
NULL |
inactiveYear |
int(11) |
Yes |
NULL |
inactiveMonth |
int(11) |
Yes |
NULL |
inactiveDay |
int(11) |
Yes |
NULL |
inactiveHour |
int(11) |
Yes |
NULL |
inactiveMinute |
int(11) |
Yes |
NULL |
inactiveSecond |
int(11) |
Yes |
NULL |
inactiveCron |
varchar(25) |
Yes |
NULL |
mangoviews
Column |
Type |
Null |
Default |
Links to |
Comments |
MIME |
id |
int(11) |
No |
xid |
varchar(50) |
No |
name |
varchar(100) |
No |
background |
varchar(255) |
Yes |
NULL |
userId |
int(11) |
No |
users -> id |
anonymousAccess |
int(11) |
No |
data |
longblob |
No |
mangoviewusers
Column |
Type |
Null |
Default |
Links to |
Comments |
MIME |
mangoViewId |
int(11) |
No |
mangoviews -> id |
userId |
int(11) |
No |
users -> id |
accessType |
int(11) |
No |
pointeventdetectors
Column |
Type |
Null |
Default |
Links to |
Comments |
MIME |
id |
int(11) |
No |
xid |
varchar(50) |
No |
alias |
varchar(255) |
Yes |
NULL |
dataPointId |
int(11) |
No |
datapoints -> id |
detectorType |
int(11) |
No |
alarmLevel |
int(11) |
No |
stateLimit |
double |
Yes |
NULL |
duration |
int(11) |
Yes |
NULL |
durationType |
int(11) |
Yes |
NULL |
binaryState |
char(1) |
Yes |
NULL |
multistateState |
int(11) |
Yes |
NULL |
changeCount |
int(11) |
Yes |
NULL |
alphanumericState |
varchar(128) |
Yes |
NULL |
weight |
double |
Yes |
NULL |
pointhierarchy
Column |
Type |
Null |
Default |
Comments |
MIME |
id |
int(11) |
No |
parentId |
int(11) |
Yes |
NULL |
name |
varchar(100) |
Yes |
NULL |
pointlinks
Column |
Type |
Null |
Default |
Comments |
MIME |
id |
int(11) |
No |
xid |
varchar(50) |
No |
sourcePointId |
int(11) |
No |
targetPointId |
int(11) |
No |
script |
longtext |
Yes |
NULL |
eventType |
int(11) |
No |
disabled |
char(1) |
No |
pointvalueannotations
Column |
Type |
Null |
Default |
Links to |
Comments |
MIME |
pointValueId |
bigint(20) |
No |
pointvalues -> id |
textPointValueShort |
varchar(128) |
Yes |
NULL |
textPointValueLong |
longtext |
Yes |
NULL |
sourceType |
smallint(6) |
Yes |
NULL |
sourceId |
int(11) |
Yes |
NULL |
pointvalues
Column |
Type |
Null |
Default |
Links to |
Comments |
MIME |
id |
bigint(20) |
No |
dataPointId |
int(11) |
No |
datapoints -> id |
dataType |
int(11) |
No |
pointValue |
double |
Yes |
NULL |
ts |
bigint(20) |
No |
publishers
Column |
Type |
Null |
Default |
Comments |
MIME |
id |
int(11) |
No |
xid |
varchar(50) |
No |
data |
longblob |
No |
reportinstancedata
Column |
Type |
Null |
Default |
Links to |
Comments |
MIME |
pointValueId |
bigint(20) |
No |
reportInstancePointId |
int(11) |
No |
reportinstancepoints -> id |
pointValue |
double |
Yes |
NULL |
ts |
bigint(20) |
No |
reportinstancedataannotations
Column |
Type |
Null |
Default |
Comments |
MIME |
pointValueId |
bigint(20) |
No |
reportInstancePointId |
int(11) |
No |
textPointValueShort |
varchar(128) |
Yes |
NULL |
textPointValueLong |
longtext |
Yes |
NULL |
sourceValue |
varchar(128) |
Yes |
NULL |
reportinstanceevents
Column |
Type |
Null |
Default |
Links to |
Comments |
MIME |
eventId |
int(11) |
No |
reportInstanceId |
int(11) |
No |
reportinstances -> id |
typeId |
int(11) |
No |
typeRef1 |
int(11) |
No |
typeRef2 |
int(11) |
No |
activeTs |
bigint(20) |
No |
rtnApplicable |
char(1) |
No |
rtnTs |
bigint(20) |
Yes |
NULL |
rtnCause |
int(11) |
Yes |
NULL |
alarmLevel |
int(11) |
No |
message |
longtext |
Yes |
NULL |
ackTs |
bigint(20) |
Yes |
NULL |
ackUsername |
varchar(40) |
Yes |
NULL |
alternateAckSource |
int(11) |
Yes |
NULL |
reportinstancepoints
Column |
Type |
Null |
Default |
Links to |
Comments |
MIME |
id |
int(11) |
No |
reportInstanceId |
int(11) |
No |
reportinstances -> id |
dataSourceName |
varchar(40) |
No |
pointName |
varchar(100) |
No |
dataType |
int(11) |
No |
startValue |
varchar(4096) |
Yes |
NULL |
textRenderer |
longblob |
Yes |
NULL |
colour |
varchar(6) |
Yes |
NULL |
consolidatedChart |
char(1) |
Yes |
NULL |
reportinstances
Column |
Type |
Null |
Default |
Links to |
Comments |
MIME |
id |
int(11) |
No |
userId |
int(11) |
No |
users -> id |
name |
varchar(100) |
No |
includeEvents |
int(11) |
No |
includeUserComments |
char(1) |
No |
reportStartTime |
bigint(20) |
No |
reportEndTime |
bigint(20) |
No |
runStartTime |
bigint(20) |
Yes |
NULL |
runEndTime |
bigint(20) |
Yes |
NULL |
recordCount |
int(11) |
Yes |
NULL |
preventPurge |
char(1) |
Yes |
NULL |
reportinstanceusercomments
Column |
Type |
Null |
Default |
Links to |
Comments |
MIME |
reportInstanceId |
int(11) |
No |
reportinstances -> id |
username |
varchar(40) |
Yes |
NULL |
commentType |
int(11) |
No |
typeKey |
int(11) |
No |
ts |
bigint(20) |
No |
commentText |
varchar(1024) |
No |
reports
Column |
Type |
Null |
Default |
Links to |
Comments |
MIME |
id |
int(11) |
No |
userId |
int(11) |
No |
users -> id |
name |
varchar(100) |
No |
data |
longblob |
No |
scheduledevents
Column |
Type |
Null |
Default |
Comments |
MIME |
id |
int(11) |
No |
xid |
varchar(50) |
No |
alias |
varchar(255) |
Yes |
NULL |
alarmLevel |
int(11) |
No |
scheduleType |
int(11) |
No |
returnToNormal |
char(1) |
No |
disabled |
char(1) |
No |
activeYear |
int(11) |
Yes |
NULL |
activeMonth |
int(11) |
Yes |
NULL |
activeDay |
int(11) |
Yes |
NULL |
activeHour |
int(11) |
Yes |
NULL |
activeMinute |
int(11) |
Yes |
NULL |
activeSecond |
int(11) |
Yes |
NULL |
activeCron |
varchar(25) |
Yes |
NULL |
inactiveYear |
int(11) |
Yes |
NULL |
inactiveMonth |
int(11) |
Yes |
NULL |
inactiveDay |
int(11) |
Yes |
NULL |
inactiveHour |
int(11) |
Yes |
NULL |
inactiveMinute |
int(11) |
Yes |
NULL |
inactiveSecond |
int(11) |
Yes |
NULL |
inactiveCron |
varchar(25) |
Yes |
NULL |
scripts
Column |
Type |
Null |
Default |
Links to |
Comments |
MIME |
id |
int(11) |
No |
userId |
int(11) |
No |
users -> id |
xid |
varchar(50) |
No |
name |
varchar(40) |
No |
script |
varchar(16384) |
No |
data |
longblob |
No |
systemsettings
Column |
Type |
Null |
Default |
Comments |
MIME |
settingName |
varchar(32) |
No |
settingValue |
longtext |
Yes |
NULL |
usercomments
Column |
Type |
Null |
Default |
Links to |
Comments |
MIME |
userId |
int(11) |
Yes |
NULL |
users -> id |
commentType |
int(11) |
No |
typeKey |
int(11) |
No |
ts |
bigint(20) |
No |
commentText |
varchar(1024) |
No |
userevents
Column |
Type |
Null |
Default |
Links to |
Comments |
MIME |
eventId |
int(11) |
No |
events -> id |
userId |
int(11) |
No |
users -> id |
silenced |
char(1) |
No |
users
Column |
Type |
Null |
Default |
Comments |
MIME |
id |
int(11) |
No |
username |
varchar(40) |
No |
password |
varchar(30) |
No |
email |
varchar(255) |
No |
phone |
varchar(40) |
Yes |
NULL |
admin |
char(1) |
No |
disabled |
char(1) |
No |
lastLogin |
bigint(20) |
Yes |
NULL |
selectedWatchList |
int(11) |
Yes |
NULL |
homeUrl |
varchar(255) |
Yes |
NULL |
receiveAlarmEmails |
int(11) |
No |
receiveOwnAuditEvents |
char(1) |
No |
watchlistpoints
Column |
Type |
Null |
Default |
Links to |
Comments |
MIME |
watchListId |
int(11) |
No |
watchlists -> id |
dataPointId |
int(11) |
No |
datapoints -> id |
sortOrder |
int(11) |
No |
watchlists
Column |
Type |
Null |
Default |
Links to |
Comments |
MIME |
id |
int(11) |
No |
xid |
varchar(50) |
No |
userId |
int(11) |
No |
users -> id |
name |
varchar(50) |
Yes |
NULL |
watchlistusers
Column |
Type |
Null |
Default |
Links to |
Comments |
MIME |
watchListId |
int(11) |
No |
watchlists -> id |
userId |
int(11) |
No |
users -> id |
accessType |
int(11) |
No |
(주)동운시스템 전화 041-358-3760
동운 HMI 소개 바로가기
[온라인 문의 및 견적요청]