Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/store/IntegratorSchema.java |
— | — | @@ -0,0 +1,72 @@ |
| 2 | +package de.brightbyte.wikiword.integrator.store; |
| 3 | + |
| 4 | +import java.sql.Connection; |
| 5 | +import java.sql.SQLException; |
| 6 | + |
| 7 | +import javax.sql.DataSource; |
| 8 | + |
| 9 | +import de.brightbyte.db.DatabaseField; |
| 10 | +import de.brightbyte.db.DatabaseKey; |
| 11 | +import de.brightbyte.db.KeyType; |
| 12 | +import de.brightbyte.db.ReferenceField; |
| 13 | +import de.brightbyte.db.RelationTable; |
| 14 | +import de.brightbyte.wikiword.DatasetIdentifier; |
| 15 | +import de.brightbyte.wikiword.TweakSet; |
| 16 | +import de.brightbyte.wikiword.schema.WikiWordStoreSchema; |
| 17 | + |
| 18 | +public class IntegratorSchema extends WikiWordStoreSchema { |
| 19 | + |
| 20 | + public IntegratorSchema(DatasetIdentifier dataset, Connection connection, TweakSet tweaks, boolean useFlushQueue) throws SQLException { |
| 21 | + super(dataset, connection, tweaks, useFlushQueue); |
| 22 | + } |
| 23 | + |
| 24 | + public IntegratorSchema(DatasetIdentifier dataset, DataSource connectionInfo, TweakSet tweaks, boolean useFlushQueue) throws SQLException { |
| 25 | + super(dataset, connectionInfo, tweaks, useFlushQueue); |
| 26 | + } |
| 27 | + |
| 28 | + public RelationTable newForeignPropertyTable(String name) { |
| 29 | + RelationTable table = new RelationTable(this, name, defaultTableAttributes); |
| 30 | + |
| 31 | + table.addField( new DatabaseField(this, "external_authority", getTextType(64), null, true, null) ); |
| 32 | + table.addField( new DatabaseField(this, "external_id", getTextType(255), null, true, null) ); |
| 33 | + |
| 34 | + table.addField( new ReferenceField(this, "concept", "INT", null, false, KeyType.INDEX, "concept", "id", null ) ); |
| 35 | + table.addField( new ReferenceField(this, "concept_name", getTextType(255), null, true, KeyType.INDEX, "concept", "name", null ) ); |
| 36 | + |
| 37 | + table.addField( new DatabaseField(this, "property", getTextType(255), null, true, KeyType.INDEX) ); |
| 38 | + table.addField( new DatabaseField(this, "value", getTextType(255), null, true, null) ); |
| 39 | + table.addField( new DatabaseField(this, "qualifier", getTextType(64), null, true, null) ); |
| 40 | + |
| 41 | + table.addKey( new DatabaseKey(this, KeyType.INDEX, "concept_property", new String[] {"concept_name", "property"}) ); |
| 42 | + table.addKey( new DatabaseKey(this, KeyType.INDEX, "property_value", new String[] {"property", "value"}) ); |
| 43 | + |
| 44 | + table.addKey( new DatabaseKey(this, KeyType.INDEX, "external_property", new String[] {"external_authority", "external_id", "property"}) ); |
| 45 | + |
| 46 | + addTable(table); |
| 47 | + |
| 48 | + return table; |
| 49 | + } |
| 50 | + |
| 51 | + public RelationTable newConceptMappingTable(String name, boolean unique) { |
| 52 | + RelationTable table = new RelationTable(this, name, defaultTableAttributes); |
| 53 | + |
| 54 | + table.addField( new DatabaseField(this, "external_authority", getTextType(64), null, true, null) ); |
| 55 | + table.addField( new DatabaseField(this, "external_id", getTextType(255), null, true, null) ); |
| 56 | + table.addField( new DatabaseField(this, "external_name", getTextType(255), null, false, null) ); |
| 57 | + |
| 58 | + table.addField( new ReferenceField(this, "concept", "INT", null, false, KeyType.INDEX, "concept", "id", null ) ); |
| 59 | + table.addField( new ReferenceField(this, "concept_name", getTextType(255), null, true, KeyType.INDEX, "concept", "name", null ) ); |
| 60 | + |
| 61 | + table.addField( new DatabaseField(this, "via", getTextType(32), null, false, KeyType.INDEX ) ); |
| 62 | + table.addField( new DatabaseField(this, "weight", "FLOAT", null, false, KeyType.INDEX ) ); |
| 63 | + |
| 64 | + table.addKey( new DatabaseKey(this, KeyType.INDEX, "external_id", new String[] {"external_authority", "external_id"}) ); |
| 65 | + table.addKey( new DatabaseKey(this, KeyType.INDEX, "external_name", new String[] {"external_authority", "external_name"}) ); |
| 66 | + |
| 67 | + if (unique) table.addKey( new DatabaseKey(this, KeyType.PRIMARY, "concept_mapping", new String[] {"concept", "external_authority", "external_id"}) ); |
| 68 | + |
| 69 | + addTable(table); |
| 70 | + return table; |
| 71 | + } |
| 72 | + |
| 73 | +} |
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/store/DatabaseConceptMappingStoreBuilder.java |
— | — | @@ -0,0 +1,59 @@ |
| 2 | +package de.brightbyte.wikiword.integrator.store; |
| 3 | + |
| 4 | +import java.sql.Connection; |
| 5 | +import java.sql.SQLException; |
| 6 | + |
| 7 | +import de.brightbyte.application.Agenda; |
| 8 | +import de.brightbyte.db.Inserter; |
| 9 | +import de.brightbyte.db.RelationTable; |
| 10 | +import de.brightbyte.util.PersistenceException; |
| 11 | +import de.brightbyte.wikiword.Corpus; |
| 12 | +import de.brightbyte.wikiword.TweakSet; |
| 13 | +import de.brightbyte.wikiword.store.builder.DatabaseWikiWordStoreBuilder; |
| 14 | + |
| 15 | +public class DatabaseConceptMappingStoreBuilder extends DatabaseWikiWordStoreBuilder implements ConceptMappingStoreBuilder { |
| 16 | + |
| 17 | + protected RelationTable mappingTable; |
| 18 | + protected Inserter mappingInserter; |
| 19 | + protected IntegratorSchema integratorSchema; |
| 20 | + |
| 21 | + public DatabaseConceptMappingStoreBuilder(String table, Corpus corpus, Connection connection, TweakSet tweaks) throws SQLException, PersistenceException { |
| 22 | + this(table, new IntegratorSchema(corpus, connection, tweaks, true), tweaks, null); |
| 23 | + } |
| 24 | + |
| 25 | + protected DatabaseConceptMappingStoreBuilder(String table, IntegratorSchema integratorSchema, TweakSet tweaks, Agenda agenda) throws SQLException, PersistenceException { |
| 26 | + super(integratorSchema, tweaks, agenda); |
| 27 | + |
| 28 | + this.mappingInserter = configureTable(table, 128, 5*32); |
| 29 | + this.mappingTable = (RelationTable)mappingInserter.getTable(); |
| 30 | + } |
| 31 | + |
| 32 | + @Override |
| 33 | + public void initialize(boolean purge, boolean dropAll) throws PersistenceException { |
| 34 | + super.initialize(purge, dropAll); |
| 35 | + } |
| 36 | + |
| 37 | + @Override |
| 38 | + public void flush() throws PersistenceException { |
| 39 | + super.flush(); |
| 40 | + } |
| 41 | + |
| 42 | + public void storeMapping(String authority, String extId, String extName, int conceptId, String conceptName, String via, double weight) throws PersistenceException { |
| 43 | + try { |
| 44 | + mappingInserter.updateString("external_authority", authority); |
| 45 | + mappingInserter.updateString("external_id", extId); |
| 46 | + mappingInserter.updateInt("concept", conceptId); |
| 47 | + mappingInserter.updateString("concept_name", conceptName); |
| 48 | + mappingInserter.updateString("via", via); |
| 49 | + mappingInserter.updateDouble("weight", weight); |
| 50 | + mappingInserter.updateRow(); |
| 51 | + } catch (SQLException e) { |
| 52 | + throw new PersistenceException(e); |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + public Corpus getCorpus() { |
| 57 | + return (Corpus)database.getDataset(); |
| 58 | + } |
| 59 | + |
| 60 | +} |
\ No newline at end of file |
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/store/ForeignPropertyStoreBuilder.java |
— | — | @@ -0,0 +1,9 @@ |
| 2 | +package de.brightbyte.wikiword.integrator.store; |
| 3 | + |
| 4 | +import de.brightbyte.util.PersistenceException; |
| 5 | +import de.brightbyte.wikiword.store.WikiWordConceptStoreBase; |
| 6 | +import de.brightbyte.wikiword.store.builder.WikiWordStoreBuilder; |
| 7 | + |
| 8 | +public interface ForeignPropertyStoreBuilder extends WikiWordStoreBuilder, WikiWordConceptStoreBase { |
| 9 | + public abstract void storeProperty(String authority, String extId, int conceptId, String conceptName, String property, String value, String qualifier) throws PersistenceException; |
| 10 | +} |
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/store/DatabaseForeignPropertyStoreBuilder.java |
— | — | @@ -0,0 +1,104 @@ |
| 2 | +package de.brightbyte.wikiword.integrator.store; |
| 3 | + |
| 4 | +import java.sql.Connection; |
| 5 | +import java.sql.SQLException; |
| 6 | + |
| 7 | +import javax.sql.DataSource; |
| 8 | + |
| 9 | +import de.brightbyte.application.Agenda; |
| 10 | +import de.brightbyte.db.Inserter; |
| 11 | +import de.brightbyte.db.RelationTable; |
| 12 | +import de.brightbyte.util.PersistenceException; |
| 13 | +import de.brightbyte.wikiword.Corpus; |
| 14 | +import de.brightbyte.wikiword.DatasetIdentifier; |
| 15 | +import de.brightbyte.wikiword.TweakSet; |
| 16 | +import de.brightbyte.wikiword.store.WikiWordStoreFactory; |
| 17 | +import de.brightbyte.wikiword.store.builder.DatabaseWikiWordStoreBuilder; |
| 18 | + |
| 19 | +public class DatabaseForeignPropertyStoreBuilder extends DatabaseWikiWordStoreBuilder implements ForeignPropertyStoreBuilder { |
| 20 | + |
| 21 | + public static class Factory implements WikiWordStoreFactory<DatabaseForeignPropertyStoreBuilder> { |
| 22 | + private String table; |
| 23 | + private DataSource db; |
| 24 | + private DatasetIdentifier dataset; |
| 25 | + private TweakSet tweaks; |
| 26 | + |
| 27 | + public Factory(String table, DatasetIdentifier dataset, DataSource db, TweakSet tweaks) { |
| 28 | + super(); |
| 29 | + this.table = table; |
| 30 | + this.db = db; |
| 31 | + this.dataset = dataset; |
| 32 | + this.tweaks = tweaks; |
| 33 | + } |
| 34 | + |
| 35 | + @SuppressWarnings("unchecked") |
| 36 | + public DatabaseForeignPropertyStoreBuilder newStore() throws PersistenceException { |
| 37 | + try { |
| 38 | + return new DatabaseForeignPropertyStoreBuilder(table, dataset, db.getConnection(), tweaks); |
| 39 | + } catch (SQLException e) { |
| 40 | + throw new PersistenceException(e); |
| 41 | + } |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + protected RelationTable propertyTable; |
| 46 | + protected Inserter propertyInserter; |
| 47 | + protected IntegratorSchema integratorSchema; |
| 48 | + |
| 49 | + public DatabaseForeignPropertyStoreBuilder(String table, DatasetIdentifier dataset, Connection connection, TweakSet tweaks) throws SQLException, PersistenceException { |
| 50 | + this(table, new IntegratorSchema(dataset, connection, tweaks, true), tweaks, null); |
| 51 | + } |
| 52 | + |
| 53 | + protected DatabaseForeignPropertyStoreBuilder(String table, IntegratorSchema integratorSchema, TweakSet tweaks, Agenda agenda) throws SQLException, PersistenceException { |
| 54 | + super(integratorSchema, tweaks, agenda); |
| 55 | + |
| 56 | + this.propertyInserter = configureTable(table, 128, 5*32); |
| 57 | + this.propertyTable = (RelationTable)propertyInserter.getTable(); |
| 58 | + } |
| 59 | + |
| 60 | + @Override |
| 61 | + public void initialize(boolean purge, boolean dropAll) throws PersistenceException { |
| 62 | + super.initialize(purge, dropAll); |
| 63 | + } |
| 64 | + |
| 65 | + @Override |
| 66 | + public void flush() throws PersistenceException { |
| 67 | + super.flush(); |
| 68 | + } |
| 69 | + |
| 70 | + public void storeProperty(String authority, String extId, int conceptId, String conceptName, String property, String value, String qualifier) throws PersistenceException { |
| 71 | + try { |
| 72 | + propertyInserter.updateString("external_authority", authority); |
| 73 | + propertyInserter.updateString("external_id", extId); |
| 74 | + propertyInserter.updateInt("concept", conceptId); |
| 75 | + propertyInserter.updateString("concept_name", conceptName); |
| 76 | + propertyInserter.updateString("property", property); |
| 77 | + propertyInserter.updateString("value", value); |
| 78 | + propertyInserter.updateString("qualifier", qualifier); |
| 79 | + propertyInserter.updateRow(); |
| 80 | + } catch (SQLException e) { |
| 81 | + throw new PersistenceException(e); |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + public Corpus getCorpus() { |
| 86 | + return (Corpus)database.getDataset(); |
| 87 | + } |
| 88 | + |
| 89 | + /* |
| 90 | + public void finishAliases() throws PersistenceException { |
| 91 | + if (beginTask("DatabasePropertyStoreBuilder.finishAliases", "resolveRedirects:property")) { |
| 92 | + RelationTable aliasTable = (RelationTable)conceptStoreSchema.getTable("alias"); |
| 93 | + int n = resolveRedirects(aliasTable, propertyTable, "concept_name", idManager!=null ? "concept" : null, AliasScope.REDIRECT, 3, null, null); |
| 94 | + endTask("DatabasePropertyStoreBuilder.finishAliases", "resolveRedirects:property", n+" entries"); |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | + public void finishIdReferences() throws PersistenceException { |
| 99 | + if (idManager==null && beginTask("DatabasePropertyStoreBuilder.finishIdReferences", "buildIdLinks:property")) { |
| 100 | + int n = buildIdLinks(propertyTable, "concept_name", "concept", 1); |
| 101 | + endTask("DatabasePropertyStoreBuilder.finishIdReferences", "buildIdLinks:property", n+" references"); |
| 102 | + } |
| 103 | + } |
| 104 | + */ |
| 105 | +} |
\ No newline at end of file |
Index: trunk/WikiWord/WikiWordIntegrator/src/main/java/de/brightbyte/wikiword/integrator/store/ConceptMappingStoreBuilder.java |
— | — | @@ -0,0 +1,9 @@ |
| 2 | +package de.brightbyte.wikiword.integrator.store; |
| 3 | + |
| 4 | +import de.brightbyte.util.PersistenceException; |
| 5 | +import de.brightbyte.wikiword.store.WikiWordConceptStoreBase; |
| 6 | +import de.brightbyte.wikiword.store.builder.WikiWordStoreBuilder; |
| 7 | + |
| 8 | +public interface ConceptMappingStoreBuilder extends WikiWordStoreBuilder, WikiWordConceptStoreBase { |
| 9 | + public void storeMapping(String authority, String extId, String extName, int concept, String name, String via, double weight) throws PersistenceException; |
| 10 | +} |