diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..5879927 --- /dev/null +++ b/build.gradle @@ -0,0 +1,58 @@ +apply plugin: 'java' +apply plugin: 'eclipse' +apply plugin: 'application' + +mainClassName = 'com.filbertkm.importer.Importer' + +sourceCompatibility = 1.7 +targetCompatibility = 1.7 + +def env = System.getenv() + +def cmdBranch = "git rev-parse --abbrev-ref HEAD" +def procBranch = cmdBranch.execute() +def gitBranch = procBranch.text.trim() + +def cmdVersion = "git rev-parse HEAD" +def procVersion = cmdVersion.execute() +def gitRevision = procVersion.text.trim() + +// basic setup for the script to run +buildscript { + + dependencies { + repositories { + mavenCentral() + } + } +} + +jar { + manifest { + attributes("Main-Class": "${mainClassName}", + "Git-Branch": ((null != gitBranch) ? gitBranch : ""), + "Git-Revision": ((null != gitRevision) ? gitRevision : "")) + } + from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } +} + +// instruct Gradle to look in mavenCentral repository first, then the /lib directory +repositories { + mavenCentral() + flatDir { dirs 'lib' } +} + +dependencies { + compile "org.wikidata.wdtk:wdtk-datamodel:0.4.0" + compile "org.wikidata.wdtk:wdtk-dumpfiles:0.4.0" + compile "org.slf4j:slf4j-log4j12:1.7.6" + compile "args4j:args4j:2.32" + compile "org.postgresql:postgresql:9.3-1103-jdbc41" + compile "com.fasterxml.jackson.core:jackson-core:2.5.3" + compile "com.fasterxml.jackson.core:jackson-annotations:2.5.3" + compile "com.fasterxml.jackson.core:jackson-databind:2.5.3" +} + +test { + jvmArgs "-XX:-UseSplitVerifier" +} diff --git a/sql/index.sql b/sql/index.sql new file mode 100644 index 0000000..6b94e53 --- /dev/null +++ b/sql/index.sql @@ -0,0 +1,8 @@ +create index idx_label on label using btree (entity_id); +create index idx_alias on alias using btree (entity_id); +create index idx_description on description using btree (entity_id); +create index idx_claim_coordinate on claim_coordinate using btree (entity_id); +create index idx_claim_datetime on claim_datetime using btree (entity_id); +create index idx_claim_entity on claim_entity using btree (entity_id); +create index idx_claim_string on claim_string using btree (entity_id); +create index idx_sitelink on sitelink using btree (entity_id); diff --git a/sql/schema.sql b/sql/schema.sql index bd5ba96..4bf84a4 100644 --- a/sql/schema.sql +++ b/sql/schema.sql @@ -1,34 +1,71 @@ +CREATE TABLE label( + id serial PRIMARY KEY, + entity_id TEXT NOT NULL, + label_language TEXT, + label_text TEXT +); + +CREATE TABLE alias( + id serial PRIMARY KEY, + entity_id TEXT NOT NULL, + alias_language TEXT, + alias_text TEXT +); + +CREATE TABLE description( + id serial PRIMARY KEY, + entity_id TEXT NOT NULL, + description_language TEXT, + description_text TEXT +); + +CREATE TABLE sitelink( + id serial PRIMARY KEY, + entity_id TEXT NOT NULL, + site_key TEXT, + page_title TEXT +); + CREATE EXTENSION IF NOT EXISTS postgis; -CREATE EXTENSION IF NOT EXISTS hstore; -CREATE TABLE coordinates( +CREATE TABLE claim_coordinate( id serial PRIMARY KEY, entity_id TEXT NOT NULL, + property_id TEXT NOT NULL, globe TEXT default NULL, precision double precision, latitude double precision, longitude double precision ); -SELECT AddGeometryColumn ('public', 'coordinates', 'geom', 4326, 'POINT', 2); +SELECT AddGeometryColumn ('public', 'claim_coordinate', 'geom', 4326, 'POINT', 2); -CREATE TABLE value_snaks( +CREATE TABLE claim_datetime( id serial PRIMARY KEY, - entity_id VARCHAR, - values HSTORE + entity_id TEXT NOT NULL, + property_id TEXT NOT NULL, + calendar TEXT default NULL, + year text, + month text, + day text, + hour text, + minute text, + second text, + precision text, + tolerance_before text, + tolerance_after text ); -CREATE TABLE terms( +CREATE TABLE claim_entity( id serial PRIMARY KEY, - entity_id TEXT NOT NULL, - term_type TEXT, - term_language TEXT, - term_text TEXT + entity_id VARCHAR, + property_id VARCHAR, + value TEXT ); -CREATE TABLE descriptions( +CREATE TABLE claim_string( id serial PRIMARY KEY, - entity_id TEXT NOT NULL, - term_language TEXT, - term_text TEXT + entity_id VARCHAR, + property_id VARCHAR, + value TEXT ); diff --git a/src/com/filbertkm/importer/JsonDumpProcessor.java b/src/com/filbertkm/importer/JsonDumpProcessor.java deleted file mode 100644 index a5bd5ea..0000000 --- a/src/com/filbertkm/importer/JsonDumpProcessor.java +++ /dev/null @@ -1,230 +0,0 @@ -package com.filbertkm.importer; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.SQLException; -import java.sql.Types; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import org.apache.log4j.ConsoleAppender; -import org.apache.log4j.Level; -import org.apache.log4j.Logger; -import org.apache.log4j.PatternLayout; -import org.wikidata.wdtk.datamodel.interfaces.EntityDocumentProcessor; -import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue; -import org.wikidata.wdtk.datamodel.interfaces.GlobeCoordinatesValue; -import org.wikidata.wdtk.datamodel.interfaces.ItemDocument; -import org.wikidata.wdtk.datamodel.interfaces.MonolingualTextValue; -import org.wikidata.wdtk.datamodel.interfaces.PropertyDocument; -import org.wikidata.wdtk.datamodel.interfaces.Statement; -import org.wikidata.wdtk.datamodel.interfaces.StatementGroup; -import org.wikidata.wdtk.datamodel.interfaces.StringValue; -import org.wikidata.wdtk.datamodel.interfaces.Value; -import org.wikidata.wdtk.datamodel.interfaces.ValueSnak; - -public class JsonDumpProcessor implements EntityDocumentProcessor { - - private static final Logger logger = Logger.getLogger(Importer.class); - - private static final String HSTORE_SEPARATOR_TOKEN = "=>"; - - private Connection conn; - - public JsonDumpProcessor(Connection conn) { - this.conn = conn; - } - - public void processItemDocument(ItemDocument itemDocument) { - String itemId = itemDocument.getEntityId().getId(); - logger.info("Processing: " + itemId); - - extractTerms(itemDocument); - extractSnaks(itemDocument); - } - - private void extractTerms(ItemDocument itemDocument) { - extractLabels(itemDocument); - extractAliases(itemDocument); - extractDescriptions(itemDocument); - } - - private void extractLabels(ItemDocument itemDocument) { - Map labels = itemDocument.getLabels(); - - for (Map.Entry label : labels.entrySet()) { - addTermToDatabase( - itemDocument.getEntityId().getId(), - "label", - label.getValue().getLanguageCode(), - label.getValue().getText() - ); - } - } - - private void extractAliases(ItemDocument itemDocument) { - Map> aliases = itemDocument.getAliases(); - - for (Map.Entry> aliasMap : aliases.entrySet()) { - List languageAliases = aliasMap.getValue(); - - for (MonolingualTextValue alias : languageAliases) { - addTermToDatabase( - itemDocument.getEntityId().getId(), - "alias", - alias.getLanguageCode(), - alias.getText() - ); - } - } - } - - private void extractDescriptions(ItemDocument itemDocument) { - Map descriptions = itemDocument.getDescriptions(); - - String query = "INSERT INTO descriptions (entity_id, term_language, term_text)" - + " VALUES(?, ?, ?)"; - - for (Map.Entry description : descriptions.entrySet()) { - try { - PreparedStatement pst = this.conn.prepareStatement(query); - pst.setString(1, itemDocument.getEntityId().getId()); - pst.setString(3, description.getValue().getLanguageCode()); - pst.setString(4, description.getValue().getText()); - - pst.executeUpdate(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - } - - private void addTermToDatabase(String itemId, String termType, String languageCode, String text) { - String query = "INSERT INTO terms (entity_id, term_type, term_language, term_text)" - + " VALUES(?, ?, ?, ?)"; - - try { - PreparedStatement pst = this.conn.prepareStatement(query); - pst.setString(1, itemId); - pst.setString(2, termType); - pst.setString(3, languageCode); - pst.setString(4, text); - - pst.executeUpdate(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - - private void extractSnaks(ItemDocument itemDocument) { - ArrayList snaks = new ArrayList<>(); - - for (StatementGroup statementGroup : itemDocument.getStatementGroups()) { - String propertyId = statementGroup.getProperty().getId(); - - for (Statement statement : statementGroup.getStatements()) { - if (statement.getClaim().getMainSnak() instanceof ValueSnak) { - Value value = ((ValueSnak) statement.getClaim().getMainSnak()).getValue(); - - if (value instanceof GlobeCoordinatesValue) { - GlobeCoordinatesValue coordinates = (GlobeCoordinatesValue)value; - this.insertCoordinates(itemDocument, coordinates); - } else if (value instanceof EntityIdValue) { - EntityIdValue entityIdValue = (EntityIdValue)value; - snaks.add(this.buildEntityIdValueSnak(propertyId, entityIdValue)); - } else if (value instanceof StringValue) { - StringValue stringValue = (StringValue)value; - snaks.add(this.buildValueSnak(propertyId, stringValue.getString())); - } - } - } - } - - insertValueSnaks(itemDocument, snaks); - } - - private void insertCoordinates(ItemDocument itemDocument, GlobeCoordinatesValue value) { - String query = "INSERT INTO coordinates (entity_id, globe, precision, latitude, longitude)" - + " VALUES(?, ?, ?, ?, ?)"; - - try { - PreparedStatement pst = this.conn.prepareStatement(query); - pst.setString(1, itemDocument.getEntityId().getId()); - pst.setString(2, value.getGlobe()); - pst.setDouble(3, value.getPrecision()); - pst.setDouble(4, value.getLatitude()); - pst.setDouble(5, value.getLongitude()); - - pst.executeUpdate(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - - private String buildEntityIdValueSnak(String propertyId, EntityIdValue value) { - return this.buildValueSnak( - propertyId, - value.getId() - ); - } - - private String buildValueSnak(String propertyId, String value) { - final StringBuilder builder = new StringBuilder(); - builder.append(propertyId); - builder.append(HSTORE_SEPARATOR_TOKEN); - builder.append("\""); - builder.append(value); - builder.append("\""); - - return builder.toString(); - } - - private void insertValueSnaks(ItemDocument itemDocument, ArrayList snaks) { - String query = "INSERT INTO value_snaks (entity_id, values) VALUES(?,?)"; - - try { - PreparedStatement pst = this.conn.prepareStatement(query); - pst.setString(1, itemDocument.getEntityId().getId()); - pst.setObject(2, buildSnaksString(snaks), Types.OTHER); - System.out.println(pst.toString()); - pst.executeUpdate(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - - private String buildSnaksString(ArrayList snaks) { - String snakString = ""; - - for (int i = 0; i < snaks.size() - 1; i++) { - if ( i == 0 ) { - snakString = snakString + snaks.get(i); - } else { - snakString = snakString + ", " + snaks.get(i); - } - } - - return snakString; - } - - public void processPropertyDocument(PropertyDocument arg0) { - // TODO Auto-generated method stub - - } - - public static void configureLogging() { - // Create the appender that will write log messages to the console. - ConsoleAppender consoleAppender = new ConsoleAppender(); - // Define the pattern of log messages. - // Insert the string "%c{1}:%L" to also show class name and line. - String pattern = "%d{yyyy-MM-dd HH:mm:ss} %-5p - %m%n"; - consoleAppender.setLayout(new PatternLayout(pattern)); - // Change to Level.ERROR for fewer messages: - consoleAppender.setThreshold(Level.INFO); - - consoleAppender.activateOptions(); - Logger.getRootLogger().addAppender(consoleAppender); - } - -} diff --git a/src/com/filbertkm/importer/Configuration.java b/src/main/java/com/filbertkm/importer/Configuration.java similarity index 82% rename from src/com/filbertkm/importer/Configuration.java rename to src/main/java/com/filbertkm/importer/Configuration.java index a0e8190..e445d3b 100644 --- a/src/com/filbertkm/importer/Configuration.java +++ b/src/main/java/com/filbertkm/importer/Configuration.java @@ -4,6 +4,9 @@ public class Configuration { + @Option(name = "-dbhost", usage = "database host", required = true) + private String dbhost; + @Option(name = "-dbuser", usage = "database user", required = true) private String dbuser; @@ -16,6 +19,10 @@ public class Configuration { @Option(name = "-dumpdir", usage = "dump directory", required = true) private String dumpdir; + public String getDBHost() { + return dbhost; + } + public String getDbUser() { return dbuser; } diff --git a/src/com/filbertkm/importer/Importer.java b/src/main/java/com/filbertkm/importer/Importer.java similarity index 84% rename from src/com/filbertkm/importer/Importer.java rename to src/main/java/com/filbertkm/importer/Importer.java index b9eeb1b..d3a2156 100644 --- a/src/com/filbertkm/importer/Importer.java +++ b/src/main/java/com/filbertkm/importer/Importer.java @@ -13,6 +13,8 @@ public class Importer { private Connection conn; + private String dbHost; + private String dbUser; private String dbName; @@ -26,7 +28,7 @@ public static void main(String[] args) { try { parser.parseArgument(args); - Importer importer = new Importer(config.getDbUser(), config.getDbName(), config.getDbPass()); + Importer importer = new Importer(config.getDBHost(), config.getDbUser(), config.getDbName(), config.getDbPass()); importer.process("wikidatawiki", config.getDumpDir()); } catch (CmdLineException e) { // omg! @@ -37,7 +39,8 @@ public static void main(String[] args) { System.out.println("done"); } - public Importer(String dbUser, String dbName, String dbPass) { + public Importer(String dbHost, String dbUser, String dbName, String dbPass) { + this.dbHost = dbHost; this.dbUser = dbUser; this.dbName = dbName; this.dbPass = dbPass; @@ -54,6 +57,7 @@ public void process(String wikiId, String dumpDirectory) { dumpProcessingController.setDownloadDirectory(dumpDirectory); dumpProcessingController.registerEntityDocumentProcessor(jsonDumpProcessor, null, true); dumpProcessingController.processMostRecentJsonDump(); + jsonDumpProcessor.flush(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -64,7 +68,7 @@ private Connection getConnection() { if (this.conn == null) { try { this.conn = DriverManager.getConnection( - "jdbc:postgresql://127.0.0.1:5432/" + this.dbName, + "jdbc:postgresql://" + this.dbHost + ":5432/" + this.dbName, this.dbUser, this.dbPass ); diff --git a/src/main/java/com/filbertkm/importer/JsonDumpProcessor.java b/src/main/java/com/filbertkm/importer/JsonDumpProcessor.java new file mode 100644 index 0000000..8de21e2 --- /dev/null +++ b/src/main/java/com/filbertkm/importer/JsonDumpProcessor.java @@ -0,0 +1,299 @@ +package com.filbertkm.importer; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.util.List; +import java.util.Map; + +import org.apache.log4j.ConsoleAppender; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.apache.log4j.PatternLayout; +import org.wikidata.wdtk.datamodel.interfaces.EntityDocumentProcessor; +import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue; +import org.wikidata.wdtk.datamodel.interfaces.GlobeCoordinatesValue; +import org.wikidata.wdtk.datamodel.interfaces.ItemDocument; +import org.wikidata.wdtk.datamodel.interfaces.MonolingualTextValue; +import org.wikidata.wdtk.datamodel.interfaces.PropertyDocument; +import org.wikidata.wdtk.datamodel.interfaces.SiteLink; +import org.wikidata.wdtk.datamodel.interfaces.Statement; +import org.wikidata.wdtk.datamodel.interfaces.StatementDocument; +import org.wikidata.wdtk.datamodel.interfaces.StatementGroup; +import org.wikidata.wdtk.datamodel.interfaces.StringValue; +import org.wikidata.wdtk.datamodel.interfaces.TermedDocument; +import org.wikidata.wdtk.datamodel.interfaces.TimeValue; +import org.wikidata.wdtk.datamodel.interfaces.Value; +import org.wikidata.wdtk.datamodel.interfaces.ValueSnak; + +public class JsonDumpProcessor implements EntityDocumentProcessor { + + private static final Logger logger = Logger.getLogger(Importer.class); + + private Connection conn; + + private PreparedStatement pstInsertLabel; + private PreparedStatement pstInsertAlias; + private PreparedStatement pstInsertDescription; + private PreparedStatement pstInsertSiteLink; + private PreparedStatement pstInsertClauseCoordinates; + private PreparedStatement pstInsertClauseDateTime; + private PreparedStatement pstInsertClauseEntity; + private PreparedStatement pstInsertClauseString; + + private int documentCount = 0; + private int documentBatchSize = 1000; + + public JsonDumpProcessor(Connection conn) { + this.conn = conn; + + try { + String queryInsertLabel = "INSERT INTO label (entity_id, label_language, label_text)" + + " VALUES(?, ?, ?)"; + pstInsertLabel = this.conn.prepareStatement(queryInsertLabel); + + String queryInsertAlias = "INSERT INTO alias (entity_id, alias_language, alias_text)" + + " VALUES(?, ?, ?)"; + pstInsertAlias = this.conn.prepareStatement(queryInsertAlias); + + String queryInsertDescriptions = "INSERT INTO description (entity_id, description_language, description_text)" + + " VALUES(?, ?, ?)"; + pstInsertDescription = this.conn.prepareStatement(queryInsertDescriptions); + + String queryInsertSiteLink = "INSERT INTO sitelink (entity_id, site_key, page_title)" + + " VALUES(?, ?, ?)"; + pstInsertSiteLink = this.conn.prepareStatement(queryInsertSiteLink); + + String queryInsertClauseCoordinates = "INSERT INTO claim_coordinate (entity_id, property_id, globe, precision, latitude, longitude)" + + " VALUES(?, ?, ?, ?, ?, ?)"; + pstInsertClauseCoordinates = this.conn.prepareStatement(queryInsertClauseCoordinates); + + String queryInsertClauseDateTime = "INSERT INTO claim_datetime (entity_id, property_id, calendar, year, month, day, hour, minute, second, precision, tolerance_before, tolerance_after)" + + " VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + pstInsertClauseDateTime = this.conn.prepareStatement(queryInsertClauseDateTime); + + String queryInsertClauseEntity = "INSERT INTO claim_entity (entity_id, property_id, value) VALUES (?,?,?)"; + pstInsertClauseEntity = this.conn.prepareStatement(queryInsertClauseEntity); + + String queryInsertClauseString = "INSERT INTO claim_string (entity_id, property_id, value) VALUES (?,?,?)"; + pstInsertClauseString = this.conn.prepareStatement(queryInsertClauseString); + + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public void processItemDocument(ItemDocument itemDocument) { + String itemId = itemDocument.getEntityId().getId(); + logger.info("Processing: " + itemId); + + extractLabels(itemDocument); + extractAliases(itemDocument); + extractDescriptions(itemDocument); + extractSiteLinks(itemDocument); + extractClaims(itemDocument); + + flushBatch(); + } + + public void processPropertyDocument(PropertyDocument propertyDoc) { + String itemId = propertyDoc.getEntityId().getId(); + logger.info("Processing: " + itemId); + + extractLabels(propertyDoc); + extractAliases(propertyDoc); + extractDescriptions(propertyDoc); + extractClaims(propertyDoc); + + flushBatch(); + } + + private void flushBatch() { + documentCount++; + if (documentCount > documentBatchSize) { + flush(); + } + } + + public void flush() { + try { + pstInsertLabel.executeBatch(); + pstInsertAlias.executeBatch(); + pstInsertDescription.executeBatch(); + pstInsertSiteLink.executeBatch(); + pstInsertClauseCoordinates.executeBatch(); + pstInsertClauseDateTime.executeBatch(); + pstInsertClauseEntity.executeBatch(); + pstInsertClauseString.executeBatch(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + private void extractLabels(TermedDocument itemDocument) { + Map labels = itemDocument.getLabels(); + + for (Map.Entry label : labels.entrySet()) { + try { + pstInsertLabel.setString(1, itemDocument.getEntityId().getId()); + pstInsertLabel.setString(2, label.getValue().getLanguageCode()); + pstInsertLabel.setString(3, label.getValue().getText()); + pstInsertLabel.addBatch(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + + private void extractAliases(TermedDocument itemDocument) { + Map> aliases = itemDocument.getAliases(); + + for (Map.Entry> aliasMap : aliases.entrySet()) { + List languageAliases = aliasMap.getValue(); + + for (MonolingualTextValue alias : languageAliases) { + + try { + pstInsertAlias.setString(1, itemDocument.getEntityId().getId()); + pstInsertAlias.setString(2, alias.getLanguageCode()); + pstInsertAlias.setString(3, alias.getText()); + pstInsertAlias.addBatch(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + } + + private void extractDescriptions(TermedDocument itemDocument) { + Map descriptions = itemDocument.getDescriptions(); + + for (Map.Entry description : descriptions.entrySet()) { + try { + pstInsertDescription.setString(1, itemDocument.getEntityId().getId()); + pstInsertDescription.setString(2, description.getValue().getLanguageCode()); + pstInsertDescription.setString(3, description.getValue().getText()); + pstInsertDescription.addBatch(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + + private void extractSiteLinks(ItemDocument itemDocument) { + Map sitelinks = itemDocument.getSiteLinks(); + + for (Map.Entry sitelink : sitelinks.entrySet()) { + try { + pstInsertSiteLink.setString(1, itemDocument.getEntityId().getId()); + pstInsertSiteLink.setString(2, sitelink.getValue().getSiteKey()); + pstInsertSiteLink.setString(3, sitelink.getValue().getPageTitle()); + // getBadges + pstInsertSiteLink.addBatch(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + + private void extractClaims(StatementDocument itemDocument) { + + for (StatementGroup statementGroup : itemDocument.getStatementGroups()) { + String propertyId = statementGroup.getProperty().getId(); + + for (Statement statement : statementGroup.getStatements()) { + if (statement.getClaim().getMainSnak() instanceof ValueSnak) { + Value value = ((ValueSnak) statement.getClaim().getMainSnak()).getValue(); + + if (value instanceof GlobeCoordinatesValue) { + GlobeCoordinatesValue coordinates = (GlobeCoordinatesValue)value; + insertCoordinates(itemDocument, propertyId, coordinates); + } else if (value instanceof TimeValue) { + TimeValue timeValue = (TimeValue)value; + insertDateTime(itemDocument, propertyId, timeValue); + } else if (value instanceof EntityIdValue) { + EntityIdValue entityIdValue = (EntityIdValue)value; + insertEntity(itemDocument, propertyId, entityIdValue.getId()); + } else if (value instanceof StringValue) { + StringValue stringValue = (StringValue)value; + insertString(itemDocument, propertyId, stringValue.getString()); + } + } + } + } + } + + private void insertCoordinates(StatementDocument itemDocument, String propertyId, GlobeCoordinatesValue value) { + + try { + pstInsertClauseCoordinates.setString(1, itemDocument.getEntityId().getId()); + pstInsertClauseCoordinates.setString(2, propertyId); + pstInsertClauseCoordinates.setString(3, value.getGlobe()); + pstInsertClauseCoordinates.setDouble(4, value.getPrecision()); + pstInsertClauseCoordinates.setDouble(5, value.getLatitude()); + pstInsertClauseCoordinates.setDouble(6, value.getLongitude()); + pstInsertClauseCoordinates.addBatch(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + private void insertDateTime(StatementDocument itemDocument, String propertyId, TimeValue value) { + try { + pstInsertClauseDateTime.setString(1, itemDocument.getEntityId().getId()); + pstInsertClauseDateTime.setString(2, propertyId); + pstInsertClauseDateTime.setString(3, value.getPreferredCalendarModel()); + pstInsertClauseDateTime.setDouble(4, value.getYear()); + pstInsertClauseDateTime.setDouble(5, value.getMonth()); + pstInsertClauseDateTime.setDouble(6, value.getDay()); + pstInsertClauseDateTime.setDouble(7, value.getHour()); + pstInsertClauseDateTime.setDouble(8, value.getMinute()); + pstInsertClauseDateTime.setDouble(9, value.getSecond()); + pstInsertClauseDateTime.setDouble(10, value.getPrecision()); + pstInsertClauseDateTime.setDouble(11, value.getBeforeTolerance()); + pstInsertClauseDateTime.setDouble(12, value.getAfterTolerance()); + pstInsertClauseDateTime.addBatch(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + private void insertString(StatementDocument itemDocument, String propertyId, String value) { + + try { + pstInsertClauseString.setString(1, itemDocument.getEntityId().getId()); + pstInsertClauseString.setString(2, propertyId); + pstInsertClauseString.setString(3, value); + pstInsertClauseString.addBatch(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + private void insertEntity(StatementDocument itemDocument, String propertyId, String value) { + + try { + pstInsertClauseEntity.setString(1, itemDocument.getEntityId().getId()); + pstInsertClauseEntity.setString(2, propertyId); + pstInsertClauseEntity.setString(3, value); + pstInsertClauseEntity.addBatch(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public static void configureLogging() { + // Create the appender that will write log messages to the console. + ConsoleAppender consoleAppender = new ConsoleAppender(); + // Define the pattern of log messages. + // Insert the string "%c{1}:%L" to also show class name and line. + String pattern = "%d{yyyy-MM-dd HH:mm:ss} %-5p - %m%n"; + consoleAppender.setLayout(new PatternLayout(pattern)); + // Change to Level.ERROR for fewer messages: + consoleAppender.setThreshold(Level.INFO); + + consoleAppender.activateOptions(); + Logger.getRootLogger().addAppender(consoleAppender); + } + +}