У меня есть модель звездной схемы, в которой Таблица серверов содержит информацию об имени сервера. Таблица информации содержит информацию, которую я хочу для конкретного сервера. И Таблица фактических данных содержит информацию о том, какой сервер содержит какую информацию.
Server Table
Information Table
Actual Data Table
Теперь проблема, с которой я столкнулся, - я пытаюсь вставить данные в таблицу данных , используя JDBC. Но я не уверен, как мне добавить данные в таблицу фактических данных в модели звезды. Должен ли я подключаться к базе данных и вставлять ее каждый раз для каждой информации, или есть какой-то прямой способ, которым мы можем сделать это, связываясь с базой данных только один раз. Это мой код, где я получаю всю информацию для каждого сервера. И IndexData - это класс, в который я вставляю значения в базу данных Oracle.
public void fetchlog() {
InputStream is = null;
InputStream isUrl = null;
FileOutputStream fos = null;
try {
is = HttpUtil.getFile(monitorUrl);
if(monitorUrl.contains("stats.jsp") || monitorUrl.contains("monitor.jsp")) {
trimUrl = monitorUrl.replaceAll("(?<=/)(stats|monitor).jsp$", "ping");
}
isUrl = HttpUtil.getFile(trimUrl);
BufferedReader in = new BufferedReader (new InputStreamReader (is));
String line;
int i=0,j=0,k=0;
while ((line = in.readLine()) != null) {
if(line.contains("numDocs")) {
docs = in.readLine().trim();
//So should I keep on inserting into Database for each information, like this
//IndexData id = new IndexData(timeStamp, ServerName, InformationName, docs);
} else if(line.contains("indexSize")) {
indexSize = in.readLine().trim();
//For this information-- the same way?
//IndexData id = new IndexData(timeStamp, ServerName, InformationName, indexSize);
} else if(line.contains("cumulative_lookups")) {
cacheHits= in.readLine().trim();
//For this information too-- the same way?
//IndexData id = new IndexData(timeStamp, ServerName, InformationName, cacheHits);
} else if(line.contains("lastCommitTime")) {
lastCommitTime = in.readLine().trim();
//For this information too-- the same way?
//IndexData id = new IndexData(timeStamp, ServerName, InformationName, lastCommitTime );
}
BufferedReader inUrl = new BufferedReader (new InputStreamReader (isUrl));
String lineUrl;
Pattern regex = Pattern.compile("<str name=\"status\">(.*?)</str>");
while ((lineUrl = inUrl.readLine()) != null) {
System.out.println(lineUrl);
if(lineUrl.contains("str name=\"status\"")) {
Matcher regexMatcher = regex.matcher(lineUrl);
if (regexMatcher.find()) {
upDown= regexMatcher.group(1);
//For this information too-- the same way?
//IndexData id = new IndexData(timeStamp, ServerName, InformationName, upDown);
}
System.out.println("Status:- " + status);
}
}
//Or is there some other way we can insert directly into database by communicating with database only one time not multiple times for each information.
//IndexData id = new IndexData(timeStamp, ServerName, InformationName, Value);
fos = new FileOutputStream(buildTargetPath());
IOUtils.copy(is, fos);
} catch (FileNotFoundException e) {
log.error("File Exception in fetching monitor logs :" + e);
} catch (IOException e) {
log.error("Exception in fetching monitor logs :" + e);
}
}
I hope question is clear to everyone. Any suggestions will be appreciated.