Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/DatabaseFeatureStore.java |
— | — | @@ -12,6 +12,7 @@ |
13 | 13 | import de.brightbyte.db.EntityTable; |
14 | 14 | import de.brightbyte.db.QueryDataSet; |
15 | 15 | import de.brightbyte.db.RelationTable; |
| 16 | +import de.brightbyte.db.TemporaryTableDataSet; |
16 | 17 | import de.brightbyte.util.PersistenceException; |
17 | 18 | import de.brightbyte.wikiword.TweakSet; |
18 | 19 | import de.brightbyte.wikiword.model.WikiWordConcept; |
— | — | @@ -105,15 +106,49 @@ |
106 | 107 | return v; |
107 | 108 | } |
108 | 109 | |
109 | | - public DataSet<WikiWordConceptFeatures> getNeighbourhoodFeatures(int concept) throws PersistenceException { |
110 | | - String sql = "SELECT X.concept as concept, X.feature as feature, X.normal_value as value "; |
111 | | - sql += " FROM " + featureTable.getSQLName() + " as X "; |
112 | | - sql += " JOIN "+featureTable.getSQLName()+" as N ON N.feature = C.id "; |
113 | | - sql += " JOIN "+featureTable.getSQLName()+" as F ON F.feature = N.concept "; |
| 110 | + public DataSet<WikiWordConceptFeatures> getNeighbourhoodFeatures(final int concept) throws PersistenceException { |
| 111 | + /* |
| 112 | + String sql = "SELECT C.id as concept, C.name as name, X.feature as feature, X.normal_weight as value "; |
| 113 | + sql += " FROM " + featureTable.getSQLName() + " as X force key (PRIMARY) "; |
| 114 | + sql += " JOIN "+featureTable.getSQLName()+" as N force key (PRIMARY) ON N.feature = X.concept "; |
| 115 | + sql += " JOIN "+featureTable.getSQLName()+" as F force key (feature) ON F.feature = N.concept "; |
| 116 | + sql += " JOIN "+conceptTable.getSQLName()+" as C force key (PRIMARY) ON C.id = X.concept "; |
114 | 117 | sql += " WHERE F.concept = "+concept; |
115 | | - sql += " ORDER BY C.id"; |
| 118 | + sql += " ORDER BY X.concept"; |
116 | 119 | |
117 | 120 | return new QueryDataSet<WikiWordConceptFeatures>(database, getConceptFeaturesFactory(), "getNeighbourhoodFeatures", sql, false); |
| 121 | + */ |
| 122 | + return new TemporaryTableDataSet<WikiWordConceptFeatures>(database, getConceptFeaturesFactory()) { |
| 123 | + |
| 124 | + @Override |
| 125 | + public Cursor<WikiWordConceptFeatures> cursor() throws PersistenceException { |
| 126 | + try { |
| 127 | + String n = database.createTemporaryTable("id integer not null, name varchar(255) default null, primary key (id)"); |
| 128 | + String sql = "INSERT IGNORE INTO "+n+" (id) "; |
| 129 | + sql += " SELECT N.feature as id "; |
| 130 | + sql += " FROM "+featureTable.getSQLName()+" AS F "; |
| 131 | + sql += " JOIN "+featureTable.getSQLName()+" AS N ON F.feature = N.concept "; |
| 132 | + sql += " WHERE F.concept = "+concept; |
| 133 | + |
| 134 | + database.executeUpdate("getNeighbourhoodFeatures#neighbours", sql); |
| 135 | + |
| 136 | + sql = "UPDATE "+n+" as N "; |
| 137 | + sql+= " JOIN "+conceptTable.getSQLName()+" AS C ON C.id = N.id "; |
| 138 | + sql+= " SET N.name = C.name "; |
| 139 | + |
| 140 | + database.executeUpdate("getNeighbourhoodFeatures#names", sql); |
| 141 | + |
| 142 | + sql = "SELECT N.id as concept, N.name as name, X.feature as feature, X.normal_weight as value "; |
| 143 | + sql+= " FROM "+n+" AS N "; |
| 144 | + sql+= " JOIN "+featureTable.getSQLName()+" as X ON X.concept = N.id "; |
| 145 | + |
| 146 | + ResultSet rs = database.executeQuery("getNeighbourhoodFeatures#features", sql); |
| 147 | + return new TemporaryTableDataSet.Cursor<WikiWordConceptFeatures>(rs, factory, database, new String[] { n }, database.getLogOutput() ); |
| 148 | + } catch (SQLException e) { |
| 149 | + throw new PersistenceException(e); |
| 150 | + } |
| 151 | + } |
| 152 | + }; |
118 | 153 | } |
119 | 154 | |
120 | 155 | private DatabaseDataSet.Factory<WikiWordConceptFeatures> getConceptFeaturesFactory() { |