Wikitty-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
April 2011
- 6 participants
- 99 discussions
r853 - in trunk: wikitty-api/src/main/java/org/nuiton/wikitty/services wikitty-jdbc/src/main/java/org/nuiton/wikitty/jdbc
by bpoussin@users.nuiton.org 30 Apr '11
by bpoussin@users.nuiton.org 30 Apr '11
30 Apr '11
Author: bpoussin
Date: 2011-04-30 14:23:38 +0200 (Sat, 30 Apr 2011)
New Revision: 853
Url: http://nuiton.org/repositories/revision/wikitty/853
Log:
retour en arriere, apres relecture des spec JTA, on peut bien ferme les connexions des qu'on en a plus besoin (donc avant les commit/rollback) c'est le role du fournisseur de connexion de savoir si elle est dans une transaction ou non et de rellement la fermer ou non.
Donc pour chaque getConnection ou doit avoir un finally{ close }
Modified:
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyTransaction.java
trunk/wikitty-jdbc/src/main/java/org/nuiton/wikitty/jdbc/WikittyExtensionStorageJDBC.java
trunk/wikitty-jdbc/src/main/java/org/nuiton/wikitty/jdbc/WikittyJDBCUtil.java
trunk/wikitty-jdbc/src/main/java/org/nuiton/wikitty/jdbc/WikittyStorageJDBC.java
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyTransaction.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyTransaction.java 2011-04-29 18:22:17 UTC (rev 852)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyTransaction.java 2011-04-30 12:23:38 UTC (rev 853)
@@ -51,8 +51,6 @@
/** permet d'attacher n'importe quoi a une transaction */
protected Map<Object, Object> tagValues;
- /** les connections a ferme apres un commit ou rollback */
- protected LinkedList<Connection> enlistedConnections = new LinkedList<Connection>();
/** if true begin has been called for this transaction */
protected boolean started = false;
@@ -87,13 +85,6 @@
tagValues.put(tag, value);
}
- public void addEnlistedConnection(Connection enlistedConnection) {
- if (!isStarted()) {
- throw new WikittyException("You can't add connection in transaction when transaction is not begin");
- }
- this.enlistedConnections.add(enlistedConnection);
- }
-
public boolean isStarted() {
return started;
}
@@ -137,8 +128,6 @@
setStarted(false);
} catch (Exception eee) {
throw new WikittyException("Error on commit JTA transaction", eee);
- } finally {
- close();
}
}
@@ -155,43 +144,8 @@
setStarted(false);
} catch (Exception eee) {
throw new WikittyException("Error on roolback JTA transaction", eee);
- } finally {
- close();
}
}
- /**
- * Close all enlisted connection, this method is automaticaly call after
- * commit or rollback.
- *
- * A priori normalement cela devrait etre fait automatiquement par dbcp
- * avec le commit/rollback mais ce n'est pas le cas
- * {@link org.apache.commons.dbcp.managed.ManagedConnection#transactionComplete()}
- * ou bien qu'on puisse la fermer a la main comme on fait ici, mais on tombe
- * sur des NPE :(
- *
- * Et si on ne les closes pas on arrive tout de suite a 160 connexion
- * active rien que pour les tests :(
- */
- public void close() {
- Connection c;
- while ((c = enlistedConnections.poll()) != null) {
- try {
- if (!c.isClosed()) {
- c.close();
- }
- } catch (Exception eee) {
- if (log.isDebugEnabled()) {
- // Il y a des bugs dans dbcp, avec la delegation des
- // connections, il arrive que la connection sous jacente soit
- // null et dans ce cas si on fait des appels sur c
- // pour savoir s'il faut ou non ferme la connexion
- // on a un NPE.
- // Donc on met seulement en debug le log au lieu de warn.
- log.debug("Can't close connection", eee);
- }
- }
- }
- }
}
Modified: trunk/wikitty-jdbc/src/main/java/org/nuiton/wikitty/jdbc/WikittyExtensionStorageJDBC.java
===================================================================
--- trunk/wikitty-jdbc/src/main/java/org/nuiton/wikitty/jdbc/WikittyExtensionStorageJDBC.java 2011-04-29 18:22:17 UTC (rev 852)
+++ trunk/wikitty-jdbc/src/main/java/org/nuiton/wikitty/jdbc/WikittyExtensionStorageJDBC.java 2011-04-30 12:23:38 UTC (rev 853)
@@ -137,7 +137,11 @@
statement.execute(jdbcQuery.getProperty(QUERY_CREATION_EXTENSION_DATA));
} catch (Exception eee) {
throw new WikittyException("Can't create table for extension storage", eee);
+ } finally {
+ WikittyJDBCUtil.closeQuietly(connection);
}
+ } finally {
+ WikittyJDBCUtil.closeQuietly(connectionTest);
}
}
@@ -189,6 +193,8 @@
return result;
} catch (SQLException eee) {
throw new WikittyException("Can't store extension", eee);
+ } finally {
+ WikittyJDBCUtil.closeQuietly(connection);
}
}
@@ -228,6 +234,8 @@
return result;
} catch (SQLException eee) {
throw new WikittyException("Can't delete extension", eee);
+ } finally {
+ WikittyJDBCUtil.closeQuietly(connection);
}
}
@@ -246,6 +254,8 @@
return result;
} catch (SQLException eee) {
throw new WikittyException("Can't test extension existance",eee);
+ } finally {
+ WikittyJDBCUtil.closeQuietly(connection);
}
}
@@ -267,6 +277,8 @@
return result;
} catch (SQLException eee) {
throw new WikittyException("Can't retrieve all extensions id", eee);
+ } finally {
+ WikittyJDBCUtil.closeQuietly(connection);
}
}
@@ -292,6 +304,8 @@
} catch (SQLException eee) {
throw new WikittyException(String.format(
"Can't retrieve all extensions required by %s", extensionName), eee);
+ } finally {
+ WikittyJDBCUtil.closeQuietly(connection);
}
}
@@ -327,6 +341,8 @@
lastVersion = tmp;
} catch (SQLException eee) {
throw new WikittyException("Can't get last version of extensions", eee);
+ } finally {
+ WikittyJDBCUtil.closeQuietly(connection);
}
}
String result = lastVersion.get(extName);
@@ -385,6 +401,8 @@
} catch (SQLException eee) {
throw new WikittyException(String.format("Can't load extension %s", id), eee);
+ } finally {
+ WikittyJDBCUtil.closeQuietly(connection);
}
}
return result;
@@ -401,6 +419,8 @@
return result;
} catch (Exception eee) {
throw new WikittyException("Can't clear all extension", eee);
+ } finally {
+ WikittyJDBCUtil.closeQuietly(connection);
}
}
}
Modified: trunk/wikitty-jdbc/src/main/java/org/nuiton/wikitty/jdbc/WikittyJDBCUtil.java
===================================================================
--- trunk/wikitty-jdbc/src/main/java/org/nuiton/wikitty/jdbc/WikittyJDBCUtil.java 2011-04-29 18:22:17 UTC (rev 852)
+++ trunk/wikitty-jdbc/src/main/java/org/nuiton/wikitty/jdbc/WikittyJDBCUtil.java 2011-04-30 12:23:38 UTC (rev 853)
@@ -233,6 +233,8 @@
* This connection is not configured, returned connection is just create connection
* Don't use this method, use getConnection that change auto commit to false
*
+ * This connection must be close be the asker after used
+ *
* @param conf configuration
* @return a new Connection (db transaction)
*/
@@ -306,9 +308,7 @@
WikittyManagedDataSource dataSource = dataSources.get(jdbcUrl);
Connection connection = dataSource.getConnection();
- // ne surtout pas oublie d'ajouter la connection pour quelle soit
- // bien fermee apres un commit ou un rollback
- tx.addEnlistedConnection(connection);
+
return connection;
} catch(Exception eee) {
@@ -322,26 +322,26 @@
}
}
- // REMOVED because, we must used WikittyTransaction with jta management
-// /**
-// * Closes a connection.
-// *
-// * @param connection the connection to close
-// */
-// public static void closeQuietly(Connection connection) {
-// try {
-// if (connection != null) {
-// // delegate close can throw NPE
-// // so this is necessary to catch all Exceptions
-// connection.close();
-// }
-// } catch (Exception e) {
-// log.error("Exception while closing connection", e);
-// }
-// }
+ /**
+ * Closes a connection.
+ *
+ * @param connection the connection to close
+ */
+ public static void closeQuietly(Connection connection) {
+ try {
+ if (connection != null) {
+ // delegate close can throw NPE
+ // so this is necessary to catch all Exceptions
+ connection.close();
+ }
+ } catch (Exception e) {
+ log.error("Exception while closing connection", e);
+ }
+ }
/**
* Get a new connection instance (i.e. it opens a new transaction).
+ * This connection must be close be the asker after used
*
* @return a new Connection (db transaction)
* @throws SQLException if the connection fails
Modified: trunk/wikitty-jdbc/src/main/java/org/nuiton/wikitty/jdbc/WikittyStorageJDBC.java
===================================================================
--- trunk/wikitty-jdbc/src/main/java/org/nuiton/wikitty/jdbc/WikittyStorageJDBC.java 2011-04-29 18:22:17 UTC (rev 852)
+++ trunk/wikitty-jdbc/src/main/java/org/nuiton/wikitty/jdbc/WikittyStorageJDBC.java 2011-04-30 12:23:38 UTC (rev 853)
@@ -166,7 +166,11 @@
statement.execute(jdbcQuery.getProperty(QUERY_CREATION_WIKITTY_DATA));
} catch (Exception eee) {
throw new WikittyException("Can't create table for wikitty storage", eee);
+ } finally {
+ WikittyJDBCUtil.closeQuietly(connection);
}
+ } finally {
+ WikittyJDBCUtil.closeQuietly(connectionTest);
}
}
@@ -194,8 +198,11 @@
// column but can't store binary. If binary is not used there is
// no probleme
log.fatal("Can add column to store binary field. You can't use binary", eee);
-// throw new WikittyException("Can't create table for wikitty storage", eee);
+ } finally {
+ WikittyJDBCUtil.closeQuietly(connection);
}
+ } finally {
+ WikittyJDBCUtil.closeQuietly(connectionTest);
}
}
@@ -353,6 +360,8 @@
throw eee;
} catch (Exception eee) {
throw new WikittyException("Can't store wikitty", eee);
+ } finally {
+ WikittyJDBCUtil.closeQuietly(connection);
}
}
@@ -371,6 +380,8 @@
return result;
} catch (SQLException eee) {
throw new WikittyException("Can't test wikitty existance", eee);
+ } finally {
+ WikittyJDBCUtil.closeQuietly(connection);
}
}
@@ -394,6 +405,8 @@
}
} catch (SQLException eee) {
throw new WikittyException("Can't test if wikitty is already deleted", eee);
+ } finally {
+ WikittyJDBCUtil.closeQuietly(connection);
}
}
@@ -429,6 +442,8 @@
} catch (SQLException eee) {
throw new WikittyException(String.format(
"Can't restore wikitty '%s'", id), eee);
+ } finally {
+ WikittyJDBCUtil.closeQuietly(connection);
}
}
@@ -451,6 +466,8 @@
return result;
} catch (SQLException eee) {
throw new WikittyException("Can't delete wikitty", eee);
+ } finally {
+ WikittyJDBCUtil.closeQuietly(connection);
}
}
@@ -473,6 +490,8 @@
}
} catch (SQLException eee) {
throw new WikittyException("Can't scan whole wikitty", eee);
+ } finally {
+ WikittyJDBCUtil.closeQuietly(connection);
}
}
@@ -625,6 +644,8 @@
return result;
} catch (SQLException eee) {
throw new WikittyException("Can't clear wikitty data", eee);
+ } finally {
+ WikittyJDBCUtil.closeQuietly(connection);
}
}
@@ -647,6 +668,8 @@
} catch (SQLException eee) {
result = new DataStatistic();
log.warn("Can't retrieve statisticn data", eee);
+ } finally {
+ WikittyJDBCUtil.closeQuietly(connection);
}
return result;
}
1
0
r852 - in trunk: wikitty-api/src/main/java/org/nuiton/wikitty wikitty-api/src/main/java/org/nuiton/wikitty/services wikitty-jdbc/src/main/java/org/nuiton/wikitty/jdbc
by bpoussin@users.nuiton.org 29 Apr '11
by bpoussin@users.nuiton.org 29 Apr '11
29 Apr '11
Author: bpoussin
Date: 2011-04-29 20:22:17 +0200 (Fri, 29 Apr 2011)
New Revision: 852
Url: http://nuiton.org/repositories/revision/wikitty/852
Log:
Anomalie #1492: Refactor transaction management
Added:
trunk/wikitty-jdbc/src/main/java/org/nuiton/wikitty/jdbc/WikittyManagedDataSource.java
Modified:
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyConfigOption.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceStorage.java
trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyTransaction.java
trunk/wikitty-jdbc/src/main/java/org/nuiton/wikitty/jdbc/WikittyExtensionStorageJDBC.java
trunk/wikitty-jdbc/src/main/java/org/nuiton/wikitty/jdbc/WikittyJDBCUtil.java
trunk/wikitty-jdbc/src/main/java/org/nuiton/wikitty/jdbc/WikittyStorageJDBC.java
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyConfigOption.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyConfigOption.java 2011-04-29 18:16:47 UTC (rev 851)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyConfigOption.java 2011-04-29 18:22:17 UTC (rev 852)
@@ -96,7 +96,7 @@
WIKITTY_STORAGE_JDBC_XADATASOURCE(
"wikitty.storage.jdbc.xadatasource",
n_("JDBC xadatasource driver"),
- "org.h2.jdbcx.JdbcDataSource",
+ null, // no default XA otherwize we must set it to empty in all config file
String.class, false, false),
WIKITTY_STORAGE_JDBC_XADATASOURCE_H2_URL(
"wikitty.storage.jdbc.xadatasource.org.h2.jdbcx.JdbcDataSource.URL",
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceStorage.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceStorage.java 2011-04-29 18:16:47 UTC (rev 851)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceStorage.java 2011-04-29 18:22:17 UTC (rev 852)
@@ -1178,7 +1178,7 @@
txBeginHere = true;
}
- boolean result = getWikittyStorage().exists(null, wikittyId);
+ boolean result = getWikittyStorage().exists(tx, wikittyId);
if (txBeginHere) {
tx.commit();
Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyTransaction.java
===================================================================
--- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyTransaction.java 2011-04-29 18:16:47 UTC (rev 851)
+++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyTransaction.java 2011-04-29 18:22:17 UTC (rev 852)
@@ -24,8 +24,14 @@
*/
package org.nuiton.wikitty.services;
+import java.sql.Connection;
+import java.sql.SQLException;
import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import javax.transaction.Status;
import javax.transaction.TransactionManager;
import javax.transaction.UserTransaction;
@@ -45,6 +51,8 @@
/** permet d'attacher n'importe quoi a une transaction */
protected Map<Object, Object> tagValues;
+ /** les connections a ferme apres un commit ou rollback */
+ protected LinkedList<Connection> enlistedConnections = new LinkedList<Connection>();
/** if true begin has been called for this transaction */
protected boolean started = false;
@@ -79,6 +87,13 @@
tagValues.put(tag, value);
}
+ public void addEnlistedConnection(Connection enlistedConnection) {
+ if (!isStarted()) {
+ throw new WikittyException("You can't add connection in transaction when transaction is not begin");
+ }
+ this.enlistedConnections.add(enlistedConnection);
+ }
+
public boolean isStarted() {
return started;
}
@@ -122,6 +137,8 @@
setStarted(false);
} catch (Exception eee) {
throw new WikittyException("Error on commit JTA transaction", eee);
+ } finally {
+ close();
}
}
@@ -138,7 +155,43 @@
setStarted(false);
} catch (Exception eee) {
throw new WikittyException("Error on roolback JTA transaction", eee);
+ } finally {
+ close();
}
}
+
+ /**
+ * Close all enlisted connection, this method is automaticaly call after
+ * commit or rollback.
+ *
+ * A priori normalement cela devrait etre fait automatiquement par dbcp
+ * avec le commit/rollback mais ce n'est pas le cas
+ * {@link org.apache.commons.dbcp.managed.ManagedConnection#transactionComplete()}
+ * ou bien qu'on puisse la fermer a la main comme on fait ici, mais on tombe
+ * sur des NPE :(
+ *
+ * Et si on ne les closes pas on arrive tout de suite a 160 connexion
+ * active rien que pour les tests :(
+ */
+ public void close() {
+ Connection c;
+ while ((c = enlistedConnections.poll()) != null) {
+ try {
+ if (!c.isClosed()) {
+ c.close();
+ }
+ } catch (Exception eee) {
+ if (log.isDebugEnabled()) {
+ // Il y a des bugs dans dbcp, avec la delegation des
+ // connections, il arrive que la connection sous jacente soit
+ // null et dans ce cas si on fait des appels sur c
+ // pour savoir s'il faut ou non ferme la connexion
+ // on a un NPE.
+ // Donc on met seulement en debug le log au lieu de warn.
+ log.debug("Can't close connection", eee);
+ }
+ }
+ }
+ }
}
Modified: trunk/wikitty-jdbc/src/main/java/org/nuiton/wikitty/jdbc/WikittyExtensionStorageJDBC.java
===================================================================
--- trunk/wikitty-jdbc/src/main/java/org/nuiton/wikitty/jdbc/WikittyExtensionStorageJDBC.java 2011-04-29 18:16:47 UTC (rev 851)
+++ trunk/wikitty-jdbc/src/main/java/org/nuiton/wikitty/jdbc/WikittyExtensionStorageJDBC.java 2011-04-29 18:22:17 UTC (rev 852)
@@ -96,40 +96,57 @@
public WikittyExtensionStorageJDBC(ApplicationConfig config) {
this.config = config;
jdbcQuery = WikittyJDBCUtil.loadQuery(config);
- Connection connectionTest = WikittyJDBCUtil.getConnection(config);
+
+ WikittyTransaction tx = WikittyTransaction.get();
+ boolean txBeginHere = false;
try {
+ if (!tx.isStarted()) {
+ tx.begin();
+ txBeginHere = true;
+ }
+
+ createDatabase(tx);
+
+ if (txBeginHere) {
+ tx.commit();
+ }
+ } catch (WikittyException eee) {
+ if (tx != null && tx.isStarted()) {
+ tx.rollback();
+ }
+ throw eee;
+ }
+ }
+
+ protected void createDatabase(WikittyTransaction tx) {
+ Connection connectionTest = WikittyJDBCUtil.getConnection(tx, config);
+ try {
// If test of existance work, no exception and do nothing
// if exception try to create databse
Statement statementTest = connectionTest.createStatement();
statementTest.execute(jdbcQuery.getProperty(QUERY_CREATION_EXTENSION_ADMIN_TEST));
statementTest.execute(jdbcQuery.getProperty(QUERY_CREATION_EXTENSION_DATA_TEST));
- } catch(SQLException silentError) {
+ } catch(Exception silentError) {
if (log.isInfoEnabled()) {
log.info("try to create extension database");
}
- Connection connection = WikittyJDBCUtil.getConnection(config);
+ Connection connection = WikittyJDBCUtil.getConnection(tx, config);
try {
Statement statement = connection.createStatement();
statement.execute(jdbcQuery.getProperty(QUERY_CREATION_EXTENSION_ADMIN));
- statement.execute(jdbcQuery.getProperty(QUERY_CREATION_EXTENSION_DATA));
- WikittyJDBCUtil.commitJDBCConnection(connection);
- } catch (SQLException eee) {
- WikittyJDBCUtil.rollbackJDBCConnection(connection);
+ statement.execute(jdbcQuery.getProperty(QUERY_CREATION_EXTENSION_DATA));
+ } catch (Exception eee) {
throw new WikittyException("Can't create table for extension storage", eee);
- } finally {
- WikittyJDBCUtil.closeQuietly(connection);
}
- } finally {
- WikittyJDBCUtil.closeQuietly(connectionTest);
}
}
-
+
@Override
- public WikittyEvent store(WikittyTransaction transaction,
+ public WikittyEvent store(WikittyTransaction tx,
Collection<WikittyExtension> extensions)
throws WikittyException {
WikittyEvent result = new WikittyEvent(this);
- Connection connection = WikittyJDBCUtil.getConnection(config);
+ Connection connection = WikittyJDBCUtil.getConnection(tx, config);
try {
for (WikittyExtension ext : extensions) {
// extension id is extension name with version
@@ -172,14 +189,12 @@
return result;
} catch (SQLException eee) {
throw new WikittyException("Can't store extension", eee);
- } finally {
- WikittyJDBCUtil.closeQuietly(connection);
}
}
@Override
- public WikittyEvent delete(WikittyTransaction transaction, Collection<String> extNames) {
- Connection connection = WikittyJDBCUtil.getConnection(config);
+ public WikittyEvent delete(WikittyTransaction tx, Collection<String> extNames) {
+ Connection connection = WikittyJDBCUtil.getConnection(tx, config);
try {
WikittyEvent result = new WikittyEvent(this);
@@ -213,14 +228,12 @@
return result;
} catch (SQLException eee) {
throw new WikittyException("Can't delete extension", eee);
- } finally {
- WikittyJDBCUtil.closeQuietly(connection);
}
}
@Override
- public boolean exists(WikittyTransaction transaction, String id) {
- Connection connection = WikittyJDBCUtil.getConnection(config);
+ public boolean exists(WikittyTransaction tx, String id) {
+ Connection connection = WikittyJDBCUtil.getConnection(tx, config);
try {
//select the data with teh id "id" in the admin table
String q = String.format(jdbcQuery.getProperty(QUERY_SELECT_WHERE),
@@ -233,14 +246,12 @@
return result;
} catch (SQLException eee) {
throw new WikittyException("Can't test extension existance",eee);
- } finally {
- WikittyJDBCUtil.closeQuietly(connection);
}
}
@Override
- public List<String> getAllExtensionIds(WikittyTransaction transaction) {
- Connection connection = WikittyJDBCUtil.getConnection(config);
+ public List<String> getAllExtensionIds(WikittyTransaction tx) {
+ Connection connection = WikittyJDBCUtil.getConnection(tx, config);
try {
List<String> result = new ArrayList<String>();
Statement statement = connection.createStatement();
@@ -256,15 +267,13 @@
return result;
} catch (SQLException eee) {
throw new WikittyException("Can't retrieve all extensions id", eee);
- } finally {
- WikittyJDBCUtil.closeQuietly(connection);
}
}
@Override
- public List<String> getAllExtensionsRequires(WikittyTransaction transaction,
+ public List<String> getAllExtensionsRequires(WikittyTransaction tx,
String extensionName) {
- Connection connection = WikittyJDBCUtil.getConnection(config);
+ Connection connection = WikittyJDBCUtil.getConnection(tx, config);
try {
List<String> result = new ArrayList<String>();
String q = String.format(jdbcQuery.getProperty(QUERY_SELECT_WHERE),
@@ -283,8 +292,6 @@
} catch (SQLException eee) {
throw new WikittyException(String.format(
"Can't retrieve all extensions required by %s", extensionName), eee);
- } finally {
- WikittyJDBCUtil.closeQuietly(connection);
}
}
@@ -295,12 +302,12 @@
* doesn't exist
*/
@Override
- public String getLastVersion(WikittyTransaction transaction,
+ public String getLastVersion(WikittyTransaction tx,
String extName) {
if (lastVersion == null) {
// create cache for futur call
Map<String, String> tmp = new HashMap<String, String>();
- Connection connection = WikittyJDBCUtil.getConnection(config);
+ Connection connection = WikittyJDBCUtil.getConnection(tx, config);
try {
Statement statement = connection.createStatement();
//get all extensions names and versions
@@ -320,8 +327,6 @@
lastVersion = tmp;
} catch (SQLException eee) {
throw new WikittyException("Can't get last version of extensions", eee);
- } finally {
- WikittyJDBCUtil.closeQuietly(connection);
}
}
String result = lastVersion.get(extName);
@@ -329,12 +334,12 @@
}
@Override
- public WikittyExtension restore(WikittyTransaction transaction, String name, String version)
+ public WikittyExtension restore(WikittyTransaction tx, String name, String version)
throws WikittyException {
String id = WikittyExtension.computeId(name, version);
WikittyExtension result = extensionCache.get(id);
if (result == null) {
- Connection connection = WikittyJDBCUtil.getConnection(config);
+ Connection connection = WikittyJDBCUtil.getConnection(tx, config);
try {
//get the data with the id "id" in the admin table
@@ -380,16 +385,14 @@
} catch (SQLException eee) {
throw new WikittyException(String.format("Can't load extension %s", id), eee);
- } finally {
- WikittyJDBCUtil.closeQuietly(connection);
}
}
return result;
}
@Override
- public WikittyEvent clear(WikittyTransaction transaction) {
- Connection connection = WikittyJDBCUtil.getConnection(config);
+ public WikittyEvent clear(WikittyTransaction tx) {
+ Connection connection = WikittyJDBCUtil.getConnection(tx, config);
try {
lastVersion = null;
WikittyJDBCUtil.doQuery(connection, jdbcQuery.getProperty(QUERY_CLEAR_EXTENSION));
@@ -398,8 +401,6 @@
return result;
} catch (Exception eee) {
throw new WikittyException("Can't clear all extension", eee);
- } finally {
- WikittyJDBCUtil.closeQuietly(connection);
}
}
}
Modified: trunk/wikitty-jdbc/src/main/java/org/nuiton/wikitty/jdbc/WikittyJDBCUtil.java
===================================================================
--- trunk/wikitty-jdbc/src/main/java/org/nuiton/wikitty/jdbc/WikittyJDBCUtil.java 2011-04-29 18:16:47 UTC (rev 851)
+++ trunk/wikitty-jdbc/src/main/java/org/nuiton/wikitty/jdbc/WikittyJDBCUtil.java 2011-04-29 18:22:17 UTC (rev 852)
@@ -45,7 +45,6 @@
import javax.transaction.TransactionManager;
import org.apache.commons.beanutils.BeanMap;
import org.apache.commons.beanutils.BeanUtils;
-import org.apache.commons.dbcp.managed.BasicManagedDataSource;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
@@ -54,6 +53,7 @@
import org.nuiton.util.ApplicationConfig;
import org.nuiton.wikitty.WikittyConfigOption;
import org.nuiton.wikitty.WikittyException;
+import org.nuiton.wikitty.services.WikittyTransaction;
/**
*
@@ -223,8 +223,8 @@
return result;
}
- private static Map<String, BasicManagedDataSource> dataSources =
- new HashMap<String, BasicManagedDataSource>();
+ private static Map<String, WikittyManagedDataSource> dataSources =
+ new HashMap<String, WikittyManagedDataSource>();
/**
* Get a new connection instance (i.e. it opens a new transaction) plug on
@@ -236,7 +236,12 @@
* @param conf configuration
* @return a new Connection (db transaction)
*/
- public static synchronized Connection getConnectionUnconfigured(ApplicationConfig conf) {
+ public static synchronized Connection getConnectionUnconfigured(
+ WikittyTransaction tx, ApplicationConfig conf) {
+ if (tx == null) {
+ throw new IllegalArgumentException("WikittyTransaction must not be null");
+ }
+
String driver = conf.getOption(
WikittyConfigOption.WIKITTY_STORAGE_JDBC_DRIVER.getKey());
String host = conf.getOption(
@@ -249,16 +254,13 @@
String xaDataSourceClassName = conf.getOption(
WikittyConfigOption.WIKITTY_STORAGE_JDBC_XADATASOURCE.getKey());
try {
- TransactionManager transactionManager =
- com.arjuna.ats.jta.TransactionManager.transactionManager();
-
String jdbcUrl = String.format("%s:%s@%s", username, password, host);
if (!dataSources.containsKey(jdbcUrl)) {
log.info("Creating BasicManagedDataSource for: " + jdbcUrl);
// Create datasource
- BasicManagedDataSource dataSource = new BasicManagedDataSource();
+ WikittyManagedDataSource dataSource = new WikittyManagedDataSource();
// if xadatasource
if(StringUtils.isNotEmpty(xaDataSourceClassName)) {
@@ -295,13 +297,18 @@
dataSource.setUrl(host);
dataSource.setUsername(username);
dataSource.setPassword(password);
- dataSource.setTransactionManager(transactionManager);
+ TransactionManager tm = tx.getTransactionManager();
+ dataSource.setTransactionManager(tm);
+
dataSources.put(jdbcUrl, dataSource);
}
- BasicManagedDataSource dataSource = dataSources.get(jdbcUrl);
+ WikittyManagedDataSource dataSource = dataSources.get(jdbcUrl);
Connection connection = dataSource.getConnection();
+ // ne surtout pas oublie d'ajouter la connection pour quelle soit
+ // bien fermee apres un commit ou un rollback
+ tx.addEnlistedConnection(connection);
return connection;
} catch(Exception eee) {
@@ -315,22 +322,23 @@
}
}
- /**
- * Closes a connection.
- *
- * @param connection the connection to close
- */
- public static void closeQuietly(Connection connection) {
- try {
- if (connection != null) {
- // delegate close can throw NPE
- // so this is necessary to catch all Exceptions
- connection.close();
- }
- } catch (Exception e) {
- log.error("Exception while closing connection", e);
- }
- }
+ // REMOVED because, we must used WikittyTransaction with jta management
+// /**
+// * Closes a connection.
+// *
+// * @param connection the connection to close
+// */
+// public static void closeQuietly(Connection connection) {
+// try {
+// if (connection != null) {
+// // delegate close can throw NPE
+// // so this is necessary to catch all Exceptions
+// connection.close();
+// }
+// } catch (Exception e) {
+// log.error("Exception while closing connection", e);
+// }
+// }
/**
* Get a new connection instance (i.e. it opens a new transaction).
@@ -338,9 +346,10 @@
* @return a new Connection (db transaction)
* @throws SQLException if the connection fails
*/
- public static synchronized Connection getConnection(ApplicationConfig config) {
+ public static synchronized Connection getConnection(
+ WikittyTransaction tx, ApplicationConfig config) {
try {
- Connection connection = getConnectionUnconfigured(config);
+ Connection connection = getConnectionUnconfigured(tx, config);
if (connection.getAutoCommit()) {
connection.setAutoCommit(false);
}
@@ -351,45 +360,46 @@
}
}
- /**
- * Closes a connection (i.e. transaction) and commit data.
- *
- * @param connection the connection to close and commit
- */
- public static void commitJDBCConnection(Connection connection) {
- try {
- connection.commit();
- } catch(SQLException eee) {
- throw new WikittyException("Can't commit transaction", eee);
- } finally {
- try {
- connection.close();
- } catch(SQLException eee) {
- throw new WikittyException("Can't close connection", eee);
- }
- }
- }
+ // REMOVED because, we must used WikittyTransaction with jta management
+// /**
+// * Closes a connection (i.e. transaction) and commit data.
+// *
+// * @param connection the connection to close and commit
+// */
+// public static void commitJDBCConnection(Connection connection) {
+// try {
+// connection.commit();
+// } catch(SQLException eee) {
+// throw new WikittyException("Can't commit transaction", eee);
+// } finally {
+// try {
+// connection.close();
+// } catch(SQLException eee) {
+// throw new WikittyException("Can't close connection", eee);
+// }
+// }
+// }
+//
+// /**
+// * Closes a connection (i.e. transaction) and rollback data.
+// *
+// * @param connection the connection to close and rollback
+// */
+// public static void rollbackJDBCConnection(Connection connection) {
+// try {
+// connection.rollback();
+// } catch(SQLException eee) {
+// throw new WikittyException("Can't rollback transaction", eee);
+// } finally {
+// try {
+// connection.close();
+// } catch(SQLException eee) {
+// throw new WikittyException("Can't close connection", eee);
+// }
+// }
+// }
/**
- * Closes a connection (i.e. transaction) and rollback data.
- *
- * @param connection the connection to close and rollback
- */
- public static void rollbackJDBCConnection(Connection connection) {
- try {
- connection.rollback();
- } catch(SQLException eee) {
- throw new WikittyException("Can't rollback transaction", eee);
- } finally {
- try {
- connection.close();
- } catch(SQLException eee) {
- throw new WikittyException("Can't close connection", eee);
- }
- }
- }
-
- /**
* Execute query.
*
* @param connection connection to use
Added: trunk/wikitty-jdbc/src/main/java/org/nuiton/wikitty/jdbc/WikittyManagedDataSource.java
===================================================================
--- trunk/wikitty-jdbc/src/main/java/org/nuiton/wikitty/jdbc/WikittyManagedDataSource.java (rev 0)
+++ trunk/wikitty-jdbc/src/main/java/org/nuiton/wikitty/jdbc/WikittyManagedDataSource.java 2011-04-29 18:22:17 UTC (rev 852)
@@ -0,0 +1,88 @@
+package org.nuiton.wikitty.jdbc;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import org.apache.commons.dbcp.managed.BasicManagedDataSource;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.pool.impl.GenericObjectPool;
+
+/**
+ * Extends BasicManagedDataSource to permit setWhenExhaustedAction configuration
+ * on GenericObjectPool internal field and change default action to Grow when
+ * exhausted
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class WikittyManagedDataSource extends BasicManagedDataSource {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(WikittyManagedDataSource.class);
+
+ /**
+ * nombre de connexions actives simultanement qui affiche un message
+ * lorsqu'un message est affiche ce nombre est multiplie par 2 pour le
+ * prochain message
+ */
+ protected int warnConnectionCount = 10;
+ protected byte whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_GROW;
+
+ /**
+ *
+ * @return whenExhaustedAction
+ *
+ * @see GenericObjectPool#WHEN_EXHAUSTED_BLOCK
+ * @see GenericObjectPool#WHEN_EXHAUSTED_FAIL
+ * @see GenericObjectPool#WHEN_EXHAUSTED_GROW
+ */
+ public byte getWhenExhaustedAction() {
+ byte result = whenExhaustedAction;
+ if (connectionPool != null) {
+ connectionPool.getWhenExhaustedAction();
+ }
+ return result;
+ }
+
+ /**
+ * Change whenExhaustedAction of connectionPool
+ *
+ * @param whenExhaustedAction
+ * @see GenericObjectPool#WHEN_EXHAUSTED_BLOCK
+ * @see GenericObjectPool#WHEN_EXHAUSTED_FAIL
+ * @see GenericObjectPool#WHEN_EXHAUSTED_GROW
+ */
+ public void setWhenExhaustedAction(byte whenExhaustedAction) {
+ this.whenExhaustedAction = whenExhaustedAction;
+ if (connectionPool != null) {
+ connectionPool.setWhenExhaustedAction(whenExhaustedAction);
+ }
+ }
+
+ @Override
+ protected void createConnectionPool() {
+ super.createConnectionPool();
+ connectionPool.setWhenExhaustedAction(whenExhaustedAction);
+ }
+
+ @Override
+ public Connection getConnection() throws SQLException {
+ Connection result = super.getConnection();
+
+ int active = connectionPool.getNumActive();
+ if (active > warnConnectionCount) {
+ int idle = connectionPool.getNumIdle();
+ warnConnectionCount = warnConnectionCount * 2;
+
+ log.warn(String.format(
+ "Too many database connection open active:%s idle:%s",
+ active, idle));
+ }
+
+ return result;
+ }
+
+}
Modified: trunk/wikitty-jdbc/src/main/java/org/nuiton/wikitty/jdbc/WikittyStorageJDBC.java
===================================================================
--- trunk/wikitty-jdbc/src/main/java/org/nuiton/wikitty/jdbc/WikittyStorageJDBC.java 2011-04-29 18:16:47 UTC (rev 851)
+++ trunk/wikitty-jdbc/src/main/java/org/nuiton/wikitty/jdbc/WikittyStorageJDBC.java 2011-04-29 18:22:17 UTC (rev 852)
@@ -118,42 +118,55 @@
this.config = config;
this.extensionStorage = extensionStorage;
jdbcQuery = WikittyJDBCUtil.loadQuery(config);
- checkTableOrCreation();
+
+ WikittyTransaction tx = WikittyTransaction.get();
+ boolean txBeginHere = false;
+ try {
+ if (!tx.isStarted()) {
+ tx.begin();
+ txBeginHere = true;
+ }
- // all time use alter after creation for binaryValue column because
- // this datatype is not portable
- checkColumnBinaryOrAlter();
+ checkTableOrCreation(tx);
+
+ // all time use alter after creation for binaryValue column because
+ // this datatype is not portable
+ checkColumnBinaryOrAlter(tx);
+
+ if (txBeginHere) {
+ tx.commit();
+ }
+ } catch (WikittyException eee) {
+ if (tx != null && tx.isStarted()) {
+ tx.rollback();
+ }
+ throw eee;
+ }
}
/**
* test table existance or create them if necessary
*/
- protected void checkTableOrCreation() {
- Connection connectionTest = WikittyJDBCUtil.getConnection(config);
+ protected void checkTableOrCreation(WikittyTransaction tx) {
+ Connection connectionTest = WikittyJDBCUtil.getConnection(tx, config);
try {
// If test of existance work, no exception and do nothing
// if exception try to create databse
Statement statementTest = connectionTest.createStatement();
statementTest.execute(jdbcQuery.getProperty(QUERY_CREATION_WIKITTY_ADMIN_TEST));
statementTest.execute(jdbcQuery.getProperty(QUERY_CREATION_WIKITTY_DATA_TEST));
- } catch (SQLException silentError) {
+ } catch (Exception silentError) {
if (log.isInfoEnabled()) {
log.info("try to create wikitty database");
}
- Connection connection = WikittyJDBCUtil.getConnection(config);
+ Connection connection = WikittyJDBCUtil.getConnection(tx, config);
try {
Statement statement = connection.createStatement();
statement.execute(jdbcQuery.getProperty(QUERY_CREATION_WIKITTY_ADMIN));
statement.execute(jdbcQuery.getProperty(QUERY_CREATION_WIKITTY_DATA));
- WikittyJDBCUtil.commitJDBCConnection(connection);
- } catch (SQLException eee) {
- WikittyJDBCUtil.rollbackJDBCConnection(connection);
+ } catch (Exception eee) {
throw new WikittyException("Can't create table for wikitty storage", eee);
- } finally {
- WikittyJDBCUtil.closeQuietly(connection);
}
- } finally {
- WikittyJDBCUtil.closeQuietly(connectionTest);
}
}
@@ -161,34 +174,28 @@
* Add binary column if necessary
* If add can be done, wikitty work for all, except binary type
*/
- protected void checkColumnBinaryOrAlter() {
- Connection connectionTest = WikittyJDBCUtil.getConnection(config);
+ protected void checkColumnBinaryOrAlter(WikittyTransaction tx) {
+ Connection connectionTest = WikittyJDBCUtil.getConnection(tx, config);
try {
// If test of existance work, no exception and do nothing
- // if exception try to create databse
+ // if exception try to create binary column
Statement statementTest = connectionTest.createStatement();
statementTest.execute(jdbcQuery.getProperty(QUERY_CREATION_WIKITTY_DATA_TEST_BINARY));
- } catch (SQLException silentError) {
+ } catch (Exception silentError) {
if (log.isInfoEnabled()) {
log.info("try to alter wikitty database to add binary column");
}
- Connection connection = WikittyJDBCUtil.getConnection(config);
+ Connection connection = WikittyJDBCUtil.getConnection(tx, config);
try {
Statement statement = connection.createStatement();
statement.execute(jdbcQuery.getProperty(QUERY_CREATION_WIKITTY_DATA_ALTER_BINARY));
- WikittyJDBCUtil.commitJDBCConnection(connection);
- } catch (SQLException eee) {
- WikittyJDBCUtil.rollbackJDBCConnection(connection);
+ } catch (Exception eee) {
// no exception just log fatal, wikitty can work without this
// column but can't store binary. If binary is not used there is
// no probleme
log.fatal("Can add column to store binary field. You can't use binary", eee);
// throw new WikittyException("Can't create table for wikitty storage", eee);
- } finally {
- WikittyJDBCUtil.closeQuietly(connection);
}
- } finally {
- WikittyJDBCUtil.closeQuietly(connectionTest);
}
}
@@ -217,9 +224,9 @@
}
@Override
- public WikittyEvent store(WikittyTransaction transaction,
+ public WikittyEvent store(WikittyTransaction tx,
Collection<Wikitty> wikitties, boolean force) throws WikittyException {
- Connection connection = WikittyJDBCUtil.getConnection(config);
+ Connection connection = WikittyJDBCUtil.getConnection(tx, config);
try {
WikittyEvent result = new WikittyEvent(this);
for (Wikitty wikitty : wikitties) {
@@ -346,14 +353,12 @@
throw eee;
} catch (Exception eee) {
throw new WikittyException("Can't store wikitty", eee);
- } finally {
- WikittyJDBCUtil.closeQuietly(connection);
}
}
@Override
- public boolean exists(WikittyTransaction transaction, String id) {
- Connection connection = WikittyJDBCUtil.getConnection(config);
+ public boolean exists(WikittyTransaction tx, String id) {
+ Connection connection = WikittyJDBCUtil.getConnection(tx, config);
try {
//select the data with the id "id" in the admin table
String q = String.format(jdbcQuery.getProperty(QUERY_SELECT_WHERE), COL_ID,
@@ -366,14 +371,12 @@
return result;
} catch (SQLException eee) {
throw new WikittyException("Can't test wikitty existance", eee);
- } finally {
- WikittyJDBCUtil.closeQuietly(connection);
}
}
@Override
- public boolean isDeleted(WikittyTransaction transaction, String id) {
- Connection connection = WikittyJDBCUtil.getConnection(config);
+ public boolean isDeleted(WikittyTransaction tx, String id) {
+ Connection connection = WikittyJDBCUtil.getConnection(tx, config);
try {
//select the data with the id "id" in the admin table
String q = String.format(jdbcQuery.getProperty(QUERY_SELECT_WHERE),
@@ -391,15 +394,13 @@
}
} catch (SQLException eee) {
throw new WikittyException("Can't test if wikitty is already deleted", eee);
- } finally {
- WikittyJDBCUtil.closeQuietly(connection);
}
}
@Override
- public Wikitty restore(WikittyTransaction transaction,
+ public Wikitty restore(WikittyTransaction tx,
String id, String... fqFieldName) throws WikittyException {
- Connection connection = WikittyJDBCUtil.getConnection(config);
+ Connection connection = WikittyJDBCUtil.getConnection(tx, config);
try {
//select the data with the id "id" in the admin table
String q = String.format(jdbcQuery.getProperty(
@@ -418,7 +419,7 @@
sta.setString(1, id);
ResultSet dataResultSet = sta.executeQuery();
- Wikitty result = constructWikitty(transaction, id, version, extensionList,
+ Wikitty result = constructWikitty(tx, id, version, extensionList,
dataResultSet, fqFieldName);
return result;
} else {
@@ -428,20 +429,18 @@
} catch (SQLException eee) {
throw new WikittyException(String.format(
"Can't restore wikitty '%s'", id), eee);
- } finally {
- WikittyJDBCUtil.closeQuietly(connection);
}
}
@Override
- public WikittyEvent delete(WikittyTransaction transaction, Collection<String> ids) throws WikittyException {
- Connection connection = WikittyJDBCUtil.getConnection(config);
+ public WikittyEvent delete(WikittyTransaction tx, Collection<String> ids) throws WikittyException {
+ Connection connection = WikittyJDBCUtil.getConnection(tx, config);
try {
WikittyEvent result = new WikittyEvent(this);
Date now = new Date();
for (String id : ids) {
- if (exists(transaction, id) && !isDeleted(transaction, id)) {
+ if (exists(tx, id) && !isDeleted(tx, id)) {
// addVersionUpdate delete date field
WikittyJDBCUtil.doQuery(connection, jdbcQuery.getProperty(
QUERY_DELETE_WIKITTY_ADMIN), id);
@@ -452,14 +451,12 @@
return result;
} catch (SQLException eee) {
throw new WikittyException("Can't delete wikitty", eee);
- } finally {
- WikittyJDBCUtil.closeQuietly(connection);
}
}
@Override
- public void scanWikitties(WikittyTransaction transaction, Scanner scanner) {
- Connection connection = WikittyJDBCUtil.getConnection(config);
+ public void scanWikitties(WikittyTransaction tx, Scanner scanner) {
+ Connection connection = WikittyJDBCUtil.getConnection(tx, config);
try {
Statement statement = connection.createStatement();
@@ -476,8 +473,6 @@
}
} catch (SQLException eee) {
throw new WikittyException("Can't scan whole wikitty", eee);
- } finally {
- WikittyJDBCUtil.closeQuietly(connection);
}
}
@@ -491,7 +486,8 @@
* @param fqFieldName minimum field to restore
* @return
*/
- protected Wikitty constructWikitty(WikittyTransaction transaction, String id, String version, String extensionList,
+ protected Wikitty constructWikitty(WikittyTransaction tx,
+ String id, String version, String extensionList,
ResultSet resultSet, String... fqFieldName) throws SQLException {
Set<String> acceptedField = new HashSet<String>(Arrays.asList(fqFieldName));
Wikitty result = new WikittyImpl(id);
@@ -501,7 +497,8 @@
String extName = WikittyExtension.computeName(ext);
String extVersion = WikittyExtension.computeVersion(ext);
- WikittyExtension extension = extensionStorage.restore(transaction, extName, extVersion);
+ WikittyExtension extension =
+ extensionStorage.restore(tx, extName, extVersion);
result.addExtension(extension);
}
}
@@ -619,8 +616,8 @@
}
@Override
- public WikittyEvent clear(WikittyTransaction transaction) {
- Connection connection = WikittyJDBCUtil.getConnection(config);
+ public WikittyEvent clear(WikittyTransaction tx) {
+ Connection connection = WikittyJDBCUtil.getConnection(tx, config);
try {
WikittyJDBCUtil.doQuery(connection, jdbcQuery.getProperty(QUERY_CLEAR_WIKITTY));
WikittyEvent result = new WikittyEvent(this);
@@ -628,15 +625,13 @@
return result;
} catch (SQLException eee) {
throw new WikittyException("Can't clear wikitty data", eee);
- } finally {
- WikittyJDBCUtil.closeQuietly(connection);
}
}
@Override
- public DataStatistic getDataStatistic(WikittyTransaction transaction) {
+ public DataStatistic getDataStatistic(WikittyTransaction tx) {
DataStatistic result;
- Connection connection = WikittyJDBCUtil.getConnection(config);
+ Connection connection = WikittyJDBCUtil.getConnection(tx, config);
try {
Statement statement = connection.createStatement();
@@ -652,8 +647,6 @@
} catch (SQLException eee) {
result = new DataStatistic();
log.warn("Can't retrieve statisticn data", eee);
- } finally {
- WikittyJDBCUtil.closeQuietly(connection);
}
return result;
}
1
0
r851 - trunk/wikitty-solr/src/main/java/org/nuiton/wikitty/storage/solr
by bpoussin@users.nuiton.org 29 Apr '11
by bpoussin@users.nuiton.org 29 Apr '11
29 Apr '11
Author: bpoussin
Date: 2011-04-29 20:16:47 +0200 (Fri, 29 Apr 2011)
New Revision: 851
Url: http://nuiton.org/repositories/revision/wikitty/851
Log:
ajout de commentaires d'explication
Modified:
trunk/wikitty-solr/src/main/java/org/nuiton/wikitty/storage/solr/SolrResource.java
Modified: trunk/wikitty-solr/src/main/java/org/nuiton/wikitty/storage/solr/SolrResource.java
===================================================================
--- trunk/wikitty-solr/src/main/java/org/nuiton/wikitty/storage/solr/SolrResource.java 2011-04-29 15:58:21 UTC (rev 850)
+++ trunk/wikitty-solr/src/main/java/org/nuiton/wikitty/storage/solr/SolrResource.java 2011-04-29 18:16:47 UTC (rev 851)
@@ -58,8 +58,11 @@
static private Log log = LogFactory.getLog(SolrResource.class);
protected SolrServer solrServer;
- // FIXME poussin 20110131 est-ce vraiment util d'utiliser des ThreadLocal ?
- // WikittyTransaction est deja un ThreadLocal
+ // On utilise des ThreadLocal pour que chaque thread s'executant ait un
+ // 'context' non partage avec les autres, et que si l'on commit un
+ // seul ces documents soient commite et pas ceux des autres aussi en cours
+ // TODO poussin 20110429 peut-etre revoir ca, pour utilise le threadLocal
+ // de WikittyTransaction pour stocker ces infos
protected ThreadLocal<Map<String, SolrInputDocument>> addedDocs;
protected ThreadLocal<List<String>> deletedDocs;
1
0
Author: mfortun
Date: 2011-04-29 17:58:21 +0200 (Fri, 29 Apr 2011)
New Revision: 850
Url: http://nuiton.org/repositories/revision/wikitty/850
Log:
* cosmetic changes
Modified:
trunk/wikitty-publication/src/site/rst/sync.rst
Modified: trunk/wikitty-publication/src/site/rst/sync.rst
===================================================================
--- trunk/wikitty-publication/src/site/rst/sync.rst 2011-04-29 13:25:31 UTC (rev 849)
+++ trunk/wikitty-publication/src/site/rst/sync.rst 2011-04-29 15:58:21 UTC (rev 850)
@@ -10,17 +10,17 @@
-------------------------------------
Cette nouvelle approche du module wikitty publication, basé sur Rsync, et plus
-un "simple" système de commit/update/import/delete/relocate comme svn, est motivé
-par l'aspect plus généraliste que celà apporte.
+un "simple" système de commit/update/import/delete/relocate comme svn, est
+motivé par l'aspect plus généraliste que celà apporte.
-Cette approche permet de syncrhoniser le contenu de n'importe quel wikitty service
-avec un autre, et donc de redéployer simplement tout les wikittys que l'on souhaite
-d'un wikitty service à un autre.
+Cette approche permet de syncrhoniser le contenu de n'importe quel wikitty
+service avec un autre, et donc de redéployer simplement tout les wikittys que
+l'on souhaite d'un wikitty service à un autre.
-La nature du wikitty service cible importe pas, on peut synchroniser un wikitty service
-sur un file system avec un wikitty service sur un serveur cajo, ou deux wikitty service
-sur des serveurs cajo, cette approche se veut plus universelle. Et pourra être testé justement
-entre deux wikitty service sur serveur.
+La nature du wikitty service cible importe pas, on peut synchroniser un wikitty
+service sur un file system avec un wikitty service sur un serveur cajo, ou deux
+ wikitty service sur des serveurs cajo, cette approche se veut plus universelle.
+Et pourra être testé justement entre deux wikitty service sur serveur.
Définitions
@@ -38,15 +38,16 @@
- Name: correspondant au nom du fichier
- MimeType: crrespondant au type, qui donnera l'extension
- - Content: le contenu binaire pour pour les PubData et textuel pour les PubText
+ - Content: le contenu binaire pour pour les PubData et textuel pour les
+ PubText
-Le mimetype donne l'extention par exemple pour un PubData si on a en mimetype "image/png"
- alors l'extension du fichier associé sera ".png". Dans le cas d'un PubText
-le mimetype donnera l'extension et le langage de la source par exemple si on a
-en mimetype "application/javascript" le langage est javascript et l'extension
-sera donc ".js".
+Le mimetype donne l'extention par exemple pour un PubData si on a en mimetype
+"image/png" alors l'extension du fichier associé sera ".png". Dans le cas d'un
+PubText le mimetype donnera l'extension et le langage de la source par exemple
+si on a en mimetype "application/javascript" le langage est javascript et
+l'extension sera donc ".js".
A ces objets wikitty on associe un wikittyLabel, c'est un objet qui peut
contenir un ensemble de label différent, un label par exemple
@@ -77,22 +78,22 @@
l'on aura transformé en fichier, celà pour une synchronisation ultérieure avec un
autre wikitty service.
-On conservera trace ausi dans ce même fichier de propriété du label courant, permettant
-de ne pas faire d'opération "complexes" et pénible sur les noms de fichier afin de retrouver
-le label de travail. Conserver trace du label actuel à l'avantage de n'avoir pas
-besoin de rechercher dans l'arborescence la première occurence du fichier de propriété
-pour pouvoir reconstituer le label complet.
+On conservera trace ausi dans ce même fichier de propriété du label courant,
+permettant de ne pas faire d'opération "complexes" et pénible sur les noms de
+fichier afin de retrouver le label de travail. Conserver trace du label actuel à
+l'avantage de n'avoir pas besoin de rechercher dans l'arborescence la première
+occurence du fichier de propriété pour pouvoir reconstituer le label complet.
-On distinguera deux fichiers de propriétés pour les informations un qui conservera
-les id des wikitty lié à leur nom de fichier. Et un autre fichiers de propriété
-qui conservera un checksum, la version et les id aussi.
+On distinguera deux fichiers de propriétés pour les informations un qui
+conservera les id des wikitty lié à leur nom de fichier. Et un autre fichiers de
+propriété qui conservera un checksum, la version et les id aussi.
-On conserve les id dans un premier fichier puisque celà permet simplement de récupérer
-l'ensemble des id et leurs noms de fichier lié sans avoir besoin de faire le tri
-parmis toutes les propriétés enregistrées. On converse l'id aussi dans un autre fichier de
-propriété, à défaut d'avoir un system de type bidimap pour les proriétés, celà permet
-de récupérer l'id d'un wikitty à partir de son nom de fichier, et inversement du nom de fichier
-à l'id.
+On conserve les id dans un premier fichier puisque celà permet simplement de
+récupérer l'ensemble des id et leurs noms de fichier lié sans avoir besoin de
+faire le tri parmis toutes les propriétés enregistrées. On converse l'id aussi
+dans un autre fichier de propriété, à défaut d'avoir un system de type bidimap
+pour les proriétés, celà permet de récupérer l'id d'un wikitty à partir de son
+nom de fichier, et inversement du nom de fichier à l'id.
La propriété checksum sera utilisée pour enregistrer la somme de controle de
l'objet lors de son enregistrement, pour plus tard, savoir si celui ci à été
@@ -149,14 +150,14 @@
---------------------------
Un tel service devra fournir les méthodes suivantes les méthodes de sauvegarde
-des wikitty, de restauration, ainsi qu'un certain nombre de fonctionnalités concernant
-les recherches de wikitty.
+des wikitty, de restauration, ainsi qu'un certain nombre de fonctionnalités
+concernant les recherches de wikitty.
Le wikitty service sur file system prendra en charge les recherches sur critéria
-de façon compléte. A chaque recherche sur le wikitty service file system, il faudra
-indexer les nouveaux wikitty, enlever les property des fichiers/wikitty supprimé,
-incrémenter la version mineur si il y a eut des modifications depuis la dernière
-indexation.
+de façon compléte. A chaque recherche sur le wikitty service file system,
+il faudra indexer les nouveaux wikitty, enlever les property des
+fichiers/wikitty supprimé, incrémenter la version mineur si il y a eut des
+modifications depuis la dernière indexation.
Fonctionnalités
@@ -167,28 +168,30 @@
Définitions
***********
-La fonctionnalité CP permet de transférer l'ensemble des wikittys ciblés par l'uri,
-d'un service wikitty à un autre. Son fonctionnement doit être similaire à la commande
-linux "rsync".
+La fonctionnalité CP permet de transférer l'ensemble des wikittys ciblés par
+l'uri, d'un service wikitty à un autre. Son fonctionnement doit être similaire à
+ la commande linux "rsync".
On reprendra donc quelques options comme:
- Recursion pour savoir si l'on s'occupe des sous labels du label ciblé.
- Update, qui permettra de mettre à jour ce qui est présent et antérieur
sur la cible et d'y envoyer les nouveaux wikitty. Par défaut cette option
- sera active, et sera desactivée lorsque les autres option (delete ou existing)
- seront choisis.
+ sera active, et sera desactivée lorsque les autres options (delete ou
+ existing) seront choisis.
- Existing qui est un update mais sans l'envois des nouveaux fichiers, on
- envois juste ce qui à été mis à jour et qui existe sur le wikitty service cible.
+ envois juste ce qui à été mis à jour et qui existe sur le wikitty service
+ cible.
- Delete pour supprimer dans le wikitty cible, ce qui n'existe plus dans le
wikitty origine.
-La suppression n'est pas une vraie suppression elle se contente de supprimer le label
-ciblé du wikitty.
+La suppression n'est pas une vraie suppression elle se contente de supprimer le
+label ciblé du wikitty, sauf le cas d'un wikitty publication file system où il
+s'agira de la suppresion du fichier et des informations du wikitty.
-En fonction des uris des wikitty services ciblé par la fonction, une implémentation
-différente de service wikitty sera instancié, en fonction des protocoles (file, hessian
-ou cajo).
+En fonction des uris des wikitty services ciblé par la fonction, une
+implémentation différente de service wikitty sera instancié, en fonction des
+protocoles (file, hessian ou cajo).
Prototype commande
@@ -209,8 +212,8 @@
conservé, c'est à dire que des wikitties de la cible si ils ont besoin de se
mettre à jour, leurs labels seront conservés.
Dans le cas de wikitty qui n'existe pas dans la cible, on remplacera le label
-origine qui à permis de trouver ces wikitties et le remplacer par le label cible,
-les autres labels du wikitty seront transmit.
+origine qui à permis de trouver ces wikitties et le remplacer par le label
+cible, les autres labels du wikitty seront transmit.
Commit/update
@@ -219,17 +222,20 @@
Définitions
***********
-On va conserver des fonctionnalités de type commit/update, l'utilisation de ces fonctions
-nécessitera un "repository" wikitty publication file system existant dans l'arborescence.
-Le but de ces fonctionnalités est de faire des Sync avec un autre wikitty service sans
-avoir besoin de redonner sont adresse explicitement à chaque fois avec la commande sync.
+On va conserver des fonctionnalités de type commit/update, l'utilisation de ces
+fonctions nécessitera un "repository" wikitty publication file system existant
+dans l'arborescence. Le but de ces fonctionnalités est de faire des Sync avec un
+autre wikitty service sans avoir besoin de redonner sont adresse explicitement à
+chaque fois avec la commande sync.
-Un commit sera équivalent à un sync du "reposistory" local vers un autre wikitty service.
-Un update sera équivalent à un sync d'un autre wikitty service vers le repositotory local.
+Un commit sera équivalent à un sync du "reposistory" local vers un autre wikitty
+service. Un update sera équivalent à un sync d'un autre wikitty service vers le
+repositotory local.
-Pour ce faire dans le dossier racine qui contient l'arborescence des wikitty sous forme de fichier
-on enregistrera dans un dossier ".wp" un fichier "ws.properties" qui contiendra l'adresse
-du dernier wikitty service utilisé pour faire un sync.
+Pour ce faire dans le dossier racine qui contient l'arborescence des wikitty
+sous forme de fichier on enregistrera dans un dossier ".wp" un fichier
+"ws.properties" qui contiendra l'adresse du dernier wikitty service utilisé pour
+faire un sync.
Prototype commande
@@ -237,7 +243,8 @@
''wp [update|commit] [--norecursion] [--delete|--existing] [label] [URI file]''
-L'URI file est optionnelle, si pas précisée on va commit/update le dossier local.
+L'URI file est optionnelle, si pas précisée on va commit/update le dossier
+courrant.
-Pour le commit update, on doit forcément préciser le label pour le wikitty service cible,
-celà pour permettre de commit ou update au bon endroit.
+Pour le commit update, on doit forcément préciser le label pour le wikitty
+service cible, celà pour permettre de commit ou update au bon endroit.
1
0
Author: mfortun
Date: 2011-04-29 15:25:31 +0200 (Fri, 29 Apr 2011)
New Revision: 849
Url: http://nuiton.org/repositories/revision/wikitty/849
Log:
* complete the specs about the label for the commit/update operation
Modified:
trunk/wikitty-publication/src/site/rst/sync.rst
Modified: trunk/wikitty-publication/src/site/rst/sync.rst
===================================================================
--- trunk/wikitty-publication/src/site/rst/sync.rst 2011-04-29 12:26:10 UTC (rev 848)
+++ trunk/wikitty-publication/src/site/rst/sync.rst 2011-04-29 13:25:31 UTC (rev 849)
@@ -235,7 +235,9 @@
Prototype commande
******************
-''wp [update|commit] [--norecursion] [--delete|--existing] [URI file]''
+''wp [update|commit] [--norecursion] [--delete|--existing] [label] [URI file]''
L'URI file est optionnelle, si pas précisée on va commit/update le dossier local.
+Pour le commit update, on doit forcément préciser le label pour le wikitty service cible,
+celà pour permettre de commit ou update au bon endroit.
1
0
r848 - trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro
by mfortun@users.nuiton.org 29 Apr '11
by mfortun@users.nuiton.org 29 Apr '11
29 Apr '11
Author: mfortun
Date: 2011-04-29 14:26:10 +0200 (Fri, 29 Apr 2011)
New Revision: 848
Url: http://nuiton.org/repositories/revision/wikitty/848
Log:
* add a method that print wikitty publication usage
Modified:
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java
Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java 2011-04-29 12:20:25 UTC (rev 847)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java 2011-04-29 12:26:10 UTC (rev 848)
@@ -541,7 +541,6 @@
String wikittyServiceInter = "";
String wikittyServiceFileSystem = "";
-
String labelInitial = "";
PropertiesExtended homeProperty = null;
@@ -575,7 +574,7 @@
wikittyServiceFileSystem = "file://"
+ homePropertyDir.getAbsolutePath() + "#" + labelCurrent;
labelInitial = homeProperty.getProperty(LABEL_KEY);
-
+
wikittyServiceInter += "#" + label
+ labelCurrent.replaceFirst(labelInitial, "");
@@ -601,7 +600,7 @@
.get(WIKITTY_SERVICE_INTERLOCUTEUR);
labelInitial = homeProperty.getProperty(LABEL_KEY);
-
+
wikittyServiceInter += "#" + label
+ originUri.getFragment().replaceFirst(labelInitial, "");
@@ -632,8 +631,23 @@
} else {
synchronisation(wikittyServiceInter, wikittyServiceFileSystem);
}
-
+
}
+ static public void usage() {
+ System.out.println("");
+
+ String usage = "Usage"
+ + "\n"
+ + "''wp sync [--norecursion] "
+ + "[--delete|--existing] [URI origin] [URI target]''"
+ + "\n \nwith URI :\n"
+ + "file:///truc/machin/#label\n"
+ + "hessian://www.adresse.com:8827/etc/etc#label\n"
+ + "cajo://www.adresse.com:8827/etc/etc#label"
+ + " \n\n or: \n"
+ + "''wp [update|commit] [--norecursion] [--delete|--existing] [URI file]''";
+ System.out.println(usage);
+ }
}
1
0
r847 - trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro
by mfortun@users.nuiton.org 29 Apr '11
by mfortun@users.nuiton.org 29 Apr '11
29 Apr '11
Author: mfortun
Date: 2011-04-29 14:20:25 +0200 (Fri, 29 Apr 2011)
New Revision: 847
Url: http://nuiton.org/repositories/revision/wikitty/847
Log:
* change commit update signature, add a label param
Modified:
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java
Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java 2011-04-29 10:33:12 UTC (rev 846)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java 2011-04-29 12:20:25 UTC (rev 847)
@@ -96,6 +96,10 @@
*/
static public String LABEL_KEY = "working.label";
+ /**
+ *
+ */
+
/*
* Class don't have to be instantiate
*/
@@ -183,7 +187,8 @@
*/
// once on the service origin
- applicationConfig.setOption(WIKITTY_SERVICE_INTERLOCUTEUR, target);
+ applicationConfig.setOption(WIKITTY_SERVICE_INTERLOCUTEUR, new String(
+ target.replaceAll("\\#.*", "")));
ApplicationConfig temp1 = setUpApplicationConfigServerConnector(uriOrigin);
@@ -193,7 +198,8 @@
// store the other uri in the application, if the service is a
// wikittypublication file system
// it can need it to store wikittyservice property
- applicationConfig.setOption(WIKITTY_SERVICE_INTERLOCUTEUR, origin);
+ applicationConfig.setOption(WIKITTY_SERVICE_INTERLOCUTEUR, new String(
+ origin.replaceAll("\\#.*", "")));
// once on the service target
ApplicationConfig temp2 = setUpApplicationConfigServerConnector(uriTarget);
@@ -419,9 +425,9 @@
.criteria();
}
-
+
log.debug(criteriaOnLabels);
-
+
return criteriaOnLabels;
}
@@ -454,13 +460,13 @@
"org.nuiton.wikitty.services.WikittyServiceCajoClient");
// remove fragment from the uri.
- url = url.replaceAll("\\#.*", "");
+ url = new String(url.replaceAll("\\#.*", ""));
} else if (uri.getScheme().equals("hessian")) {
result.setOption(WIKITTY_OPTION_COMPONENT,
"org.nuiton.wikitty.services.WikittyServiceHessianClient");
// remove fragment from the uri.
- url = url.replaceAll("\\#.*", "");
+ url = new String(url.replaceAll("\\#.*", ""));
}
// set protocol to http, no use finally
@@ -479,23 +485,25 @@
}
- static public void update(String... uriFileSystem) throws Exception {
+ static public void update(String label, String... uriFileSystem)
+ throws Exception {
// only difference between update and commit is the param's order
// when calling synchronisation method
- commitUpdateDelegate(false, uriFileSystem);
+ commitUpdateDelegate(label, false, uriFileSystem);
}
- static public void commit(String... uriFileSystem) throws Exception {
+ static public void commit(String label, String... uriFileSystem)
+ throws Exception {
// only difference between update and commit is the param's order
// when calling synchronisation method
- commitUpdateDelegate(true, uriFileSystem);
+ commitUpdateDelegate(label, true, uriFileSystem);
}
- protected static void commitUpdateDelegate(boolean isCommit,
+ static protected void commitUpdateDelegate(String label, boolean isCommit,
String... uriFileSystem) throws Exception {
File currentDir = new File(FileUtil.getCurrentDirectory()
@@ -533,7 +541,7 @@
String wikittyServiceInter = "";
String wikittyServiceFileSystem = "";
- String wikittyServiceInterSave = "";
+
String labelInitial = "";
PropertiesExtended homeProperty = null;
@@ -567,8 +575,9 @@
wikittyServiceFileSystem = "file://"
+ homePropertyDir.getAbsolutePath() + "#" + labelCurrent;
labelInitial = homeProperty.getProperty(LABEL_KEY);
- wikittyServiceInterSave = wikittyServiceInter;
- wikittyServiceInter += labelCurrent.replaceFirst(labelInitial, "");
+
+ wikittyServiceInter += "#" + label
+ + labelCurrent.replaceFirst(labelInitial, "");
break;
// if a param is set it mean that the uri of the File system is set
@@ -592,9 +601,9 @@
.get(WIKITTY_SERVICE_INTERLOCUTEUR);
labelInitial = homeProperty.getProperty(LABEL_KEY);
- wikittyServiceInterSave = wikittyServiceInter;
- wikittyServiceInter += originUri.getFragment().replaceFirst(
- labelInitial, "");
+
+ wikittyServiceInter += "#" + label
+ + originUri.getFragment().replaceFirst(labelInitial, "");
break;
@@ -623,12 +632,8 @@
} else {
synchronisation(wikittyServiceInter, wikittyServiceFileSystem);
}
- // FIXME mfortun-2011-04-28 find a better way to do this, it's needed
- // because of the labels and how construct label for the wikitty service
- // interlocuteur
- homeProperty.setProperty(WIKITTY_SERVICE_INTERLOCUTEUR,
- wikittyServiceInterSave);
- homeProperty.store();
+
}
+
}
1
0
r846 - trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro
by mfortun@users.nuiton.org 29 Apr '11
by mfortun@users.nuiton.org 29 Apr '11
29 Apr '11
Author: mfortun
Date: 2011-04-29 12:33:12 +0200 (Fri, 29 Apr 2011)
New Revision: 846
Url: http://nuiton.org/repositories/revision/wikitty/846
Log:
* add logging
Modified:
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java
Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java 2011-04-28 13:53:40 UTC (rev 845)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java 2011-04-29 10:33:12 UTC (rev 846)
@@ -30,14 +30,13 @@
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
+import java.util.Map.Entry;
import java.util.Set;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuiton.util.ApplicationConfig;
import org.nuiton.util.ArgumentsParserException;
import org.nuiton.util.FileUtil;
-import org.nuiton.util.StringUtil;
import org.nuiton.wikitty.WikittyProxy;
import org.nuiton.wikitty.WikittyServiceFactory;
import org.nuiton.wikitty.WikittyUtil;
@@ -97,6 +96,13 @@
*/
static public String LABEL_KEY = "working.label";
+ /*
+ * Class don't have to be instantiate
+ */
+ private WikittyPublication() {
+
+ }
+
/**
* @param args
* @throws ArgumentsParserException
@@ -153,16 +159,9 @@
static public void synchronisation(String origin, String target)
throws URISyntaxException {
- System.out.println(origin);
- System.out.println(target);
-
boolean isRecur = applicationConfig
.getOptionAsBoolean(IS_RECURSION_OPTION);
- URI uriOrigin = new URI(origin);
-
- URI uriTarget = new URI(target);
-
boolean isDelete = applicationConfig
.getOptionAsBoolean(IS_DELETE_OPTION);
boolean isExisting = applicationConfig
@@ -170,6 +169,14 @@
// update operation is the default operation
boolean isUpdate = !isDelete && !isExisting;
+ log.info("Sync uri origin: " + origin + " uri target: " + target
+ + " isRecur:" + isRecur + " isUpdate:" + isUpdate
+ + " isDelete:" + isDelete + "isExisting:" + isExisting);
+
+ URI uriOrigin = new URI(origin);
+
+ URI uriTarget = new URI(target);
+
/*
* necessary to have property correctly initialize in order to obtain
* the correct implementation of the wikitty service
@@ -219,6 +226,25 @@
existOnlyOnTarget.addAll(listTarget);
existOnlyOnTarget.removeAll(listOrigin);
+ if (log.isDebugEnabled()) {
+ log.debug("Wikitty exist on both: " + existInBoth.size());
+ for (String ex : existInBoth) {
+ log.debug(ex);
+ }
+
+ log.debug("Wikitty exist only on origin: "
+ + existOnlyOnOrigin.size());
+ for (String ex : existOnlyOnOrigin) {
+ log.debug(ex);
+ }
+
+ log.debug("Wikitty exist only on target: "
+ + existOnlyOnTarget.size());
+ for (String ex : existOnlyOnTarget) {
+ log.debug(ex);
+ }
+ }
+
/*
* FIXME mfortun-2011-04-27 remove all that stuff for the safety of the
* version when a solution rise for the wikitty version
@@ -229,6 +255,8 @@
*/
if (isUpdate) {
+ log.info("Store on target new wikitty");
+
List<Wikitty> newWikitties = proxyOrigin.restore(existOnlyOnOrigin);
for (Wikitty wikittyNew : newWikitties) {
@@ -286,6 +314,8 @@
*/
if (isDelete) {
+ log.info("Remove from target deleted wikitty");
+
for (String id : existOnlyOnTarget) {
Wikitty w = proxyTarget.restore(id);
@@ -296,6 +326,8 @@
}
} else {
+
+ log.info("Update existing wikitty");
/*
* case existing and update, update those which are on both location
*/
@@ -360,8 +392,11 @@
static protected Criteria constructCriteriaLabelRecur(String label,
boolean isRecur) {
+ log.info("Construct criteria with label: " + label + " isRecur:"
+ + isRecur);
+
// Construct the criteria
- Criteria labelCriteria;
+ Criteria criteriaOnLabels;
Search mainRequest = Search.query();
Search subRoqu = mainRequest.or();
@@ -371,7 +406,7 @@
if (isRecur) {
// and extension with the name that containt the label (recursivity)
- labelCriteria = mainRequest.exteq(WikittyLabel.EXT_WIKITTYLABEL)
+ criteriaOnLabels = mainRequest.exteq(WikittyLabel.EXT_WIKITTYLABEL)
.sw(WikittyLabel.FQ_FIELD_WIKITTYLABEL_LABELS, label)
.criteria();
@@ -379,12 +414,15 @@
// and extension with the name strictly equals to the label (no
// recursivity)
- labelCriteria = mainRequest.exteq(WikittyLabel.EXT_WIKITTYLABEL)
+ criteriaOnLabels = mainRequest.exteq(WikittyLabel.EXT_WIKITTYLABEL)
.eq(WikittyLabel.FQ_FIELD_WIKITTYLABEL_LABELS, label)
.criteria();
}
- return labelCriteria;
+
+ log.debug(criteriaOnLabels);
+
+ return criteriaOnLabels;
}
@@ -397,6 +435,9 @@
*/
static protected ApplicationConfig setUpApplicationConfigServerConnector(
URI uri) {
+
+ log.info("Construct application config for uri: " + uri);
+
// prepare new application config
ApplicationConfig result = new ApplicationConfig();
@@ -432,6 +473,8 @@
result.setOption(WIKITTY_OPTION_URL, url);
+ log.debug("Application config: " + result.getFlatOptions());
+
return result;
}
@@ -455,6 +498,22 @@
protected static void commitUpdateDelegate(boolean isCommit,
String... uriFileSystem) throws Exception {
+ File currentDir = new File(FileUtil.getCurrentDirectory()
+ .getAbsolutePath());
+
+ if (isCommit) {
+ log.info("Commit args.length:+" + uriFileSystem.length);
+ } else {
+ log.info("Update args.length:+" + uriFileSystem.length);
+ }
+
+ if (log.isDebugEnabled()) {
+ for (String args : uriFileSystem) {
+ log.debug(args);
+ }
+ log.debug("Current dir:" + currentDir);
+ }
+
/*
* Alors c'est facile si on a un élément dans le param c'est que on
* spécifie l'endroit du FS à updater/commit, ce qui veut dire que on
@@ -476,10 +535,8 @@
String wikittyServiceFileSystem = "";
String wikittyServiceInterSave = "";
- File currentDir = new File(FileUtil.getCurrentDirectory()
- .getAbsolutePath());
String labelInitial = "";
- PropertiesExtended homePorperty = null;
+ PropertiesExtended homeProperty = null;
// Check number of argument
switch (uriFileSystem.length) {
// if none, then the current dir have to be commit.
@@ -489,12 +546,12 @@
File homePropertyDir = WikittyPublicationFileSystem
.searchWikittyPublicationHomePropertie(currentDir);
- homePorperty = WikittyPublicationFileSystem
+ homeProperty = WikittyPublicationFileSystem
.getWikittyPublicationProperties(homePropertyDir,
WikittyPublicationFileSystem.WIKITTY_FILE_SERVICE);
// load the wikitty service uri (distant one)
- wikittyServiceInter = homePorperty
+ wikittyServiceInter = homeProperty
.getProperty(WIKITTY_SERVICE_INTERLOCUTEUR);
// construct the current uri for wikitty service file system
@@ -509,7 +566,7 @@
// construct uri of the wikitty publication file system
wikittyServiceFileSystem = "file://"
+ homePropertyDir.getAbsolutePath() + "#" + labelCurrent;
- labelInitial = homePorperty.getProperty(LABEL_KEY);
+ labelInitial = homeProperty.getProperty(LABEL_KEY);
wikittyServiceInterSave = wikittyServiceInter;
wikittyServiceInter += labelCurrent.replaceFirst(labelInitial, "");
@@ -527,14 +584,14 @@
// then search for the home property file to load the wikitty
// service uri
File workingDir = new File(originUri.getPath());
- homePorperty = WikittyPublicationFileSystem
+ homeProperty = WikittyPublicationFileSystem
.getWikittyPublicationProperties(workingDir,
WikittyPublicationFileSystem.WIKITTY_FILE_SERVICE);
- wikittyServiceInter = (String) homePorperty
+ wikittyServiceInter = (String) homeProperty
.get(WIKITTY_SERVICE_INTERLOCUTEUR);
- labelInitial = homePorperty.getProperty(LABEL_KEY);
+ labelInitial = homeProperty.getProperty(LABEL_KEY);
wikittyServiceInterSave = wikittyServiceInter;
wikittyServiceInter += originUri.getFragment().replaceFirst(
labelInitial, "");
@@ -547,20 +604,31 @@
// exception
break;
}
+
+ if (log.isDebugEnabled()) {
+
+ log.debug("homeProperty :" + homeProperty.getOrigin());
+ for (Entry<Object, Object> ee : homeProperty.entrySet()) {
+ log.debug(ee.getKey() + "=" + ee.getValue());
+ }
+
+ log.debug("wikitty Inter:" + wikittyServiceInter
+ + " wikittyFileSystem" + wikittyServiceFileSystem);
+ }
+
// delegate to synchronisation
// only difference between update and commit is the param's order
if (isCommit) {
synchronisation(wikittyServiceFileSystem, wikittyServiceInter);
-
} else {
synchronisation(wikittyServiceInter, wikittyServiceFileSystem);
}
// FIXME mfortun-2011-04-28 find a better way to do this, it's needed
// because of the labels and how construct label for the wikitty service
// interlocuteur
- homePorperty.setProperty(WIKITTY_SERVICE_INTERLOCUTEUR,
+ homeProperty.setProperty(WIKITTY_SERVICE_INTERLOCUTEUR,
wikittyServiceInterSave);
- homePorperty.store();
+ homeProperty.store();
}
}
Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java 2011-04-28 13:53:40 UTC (rev 845)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java 2011-04-29 10:33:12 UTC (rev 846)
@@ -212,6 +212,8 @@
label = homeFile.getName();
}
+ log.info("HomeDir:" + homeFile + "Label:" + label);
+
File homeProperty = new File(homeFile.getAbsolutePath()
+ File.separator + PROPERTY_DIRECTORY);
@@ -225,21 +227,27 @@
// the original label use to create if not exist
if (!propertyWikittyService.containsKey(WikittyPublication.LABEL_KEY)) {
+ log.debug("Writing home property label"
+ + propertyWikittyService.getOrigin());
propertyWikittyService.setProperty(WikittyPublication.LABEL_KEY,
this.label);
}
// the service use to update or commit
- propertyWikittyService
- .setProperty(
- WikittyPublication.WIKITTY_SERVICE_INTERLOCUTEUR,
- app.getOption(WikittyPublication.WIKITTY_SERVICE_INTERLOCUTEUR));
+ String uriService = app
+ .getOption(WikittyPublication.WIKITTY_SERVICE_INTERLOCUTEUR);
+ log.debug("Writing home property service on:"
+ + propertyWikittyService.getOrigin() + " uri" + uriService);
+ propertyWikittyService.setProperty(
+ WikittyPublication.WIKITTY_SERVICE_INTERLOCUTEUR, uriService);
+
propertyWikittyService.store();
this.recursion = app
.getOptionAsBoolean(WikittyPublication.IS_RECURSION_OPTION);
- // TODO mfotun-2011-04-28 add a support for filtered file with a property file
+ // TODO mfotun-2011-04-28 add a support for filtered file with a
+ // property file
this.directoryNameBlackList = new ArrayList<String>();
directoryNameBlackList.add(".svn");
directoryNameBlackList.add(".git");
@@ -367,17 +375,22 @@
*/
public WikittyEvent store(String securityToken,
Collection<Wikitty> wikitties, boolean force) {
+ log.info("Store wikitty: " + wikitties.size() + " isForce" + force);
WikittyEvent result = new WikittyEvent(this);
try {
for (Wikitty w : wikitties) {
+ log.debug("Works on : " + w);
Set<String> set = WikittyLabelHelper.getLabels(w);
String ourDir = "";
// search for our label recursion determine how search the label
// if have to match exactly or startswith
+ log.debug("Sets of labels (" + "isRecur" + recursion
+ + " label:" + label + ")");
for (String name : set) {
+ log.debug(name);
if (!recursion && name.equalsIgnoreCase(label)) {
ourDir = name;
} else if (recursion && name.startsWith(label)) {
@@ -396,9 +409,13 @@
.get(w.getId());
if (idSystem != null) {
+
File wikittyFile = new File(idSystem.getPath()
+ File.separator + idSystem.getFileName());
+ log.debug("Deleted wikitty id:" + w.getId() + " File:"
+ + wikittyFile);
+
if (wikittyFile.exists()) {
wikittyFile.delete();
}
@@ -436,6 +453,7 @@
// construct the file differently if wikittyPubData or
// wikittyPubText
if (w.hasExtension(WikittyPubData.EXT_WIKITTYPUBDATA)) {
+ log.debug("Wikitty has wikittyPubData Ext");
name = WikittyPubDataHelper.getName(w);
// String mime = WikittyPubDataHelper.getMimeType(w);
byte[] content = WikittyPubDataHelper.getContent(w);
@@ -451,6 +469,7 @@
} else if (w
.hasExtension(WikittyPubText.EXT_WIKITTYPUBTEXT)) {
+ log.debug("Wikitty has wikittyPubText Ext");
name = WikittyPubTextHelper.getName(w);
// String mime = WikittyPubTextHelper.getMimeType(w);
String content = WikittyPubTextHelper.getContent(w);
@@ -463,6 +482,9 @@
wikittyFile.createNewFile();
FileUtil.writeString(wikittyFile, content);
+ } else {
+ // unsupported kind of wikitty, just jump.
+ continue;
}
// if file properly write, write wikittyProperties
@@ -553,6 +575,7 @@
*/
public List<Wikitty> restore(String securityToken, List<String> id) {
List<Wikitty> result = new ArrayList<Wikitty>();
+ log.info("restore wikitty, number: " + id.size());
try {
// construct the starts file from the label and the working
// directory
@@ -582,9 +605,14 @@
return result;
}
+ /*
+ * TODO mfortun-2011-04-29 see if method really needed ?
+ */
@Override
public WikittyEvent delete(String securityToken, Collection<String> ids) {
+ log.info("Delete called wikitty size:" + ids.size());
+
try {
// load localisation of all the wikitties
BidiMap location = harvestLocalWikitties(homeFile, true);
@@ -593,6 +621,8 @@
Object value = location.get(id);
+ log.debug("delete wikitty id: " + id + " corresponding file :"
+ + value);
if (value != null) {
FileSystemWIkittyId localisation = (FileSystemWIkittyId) value;
@@ -1034,6 +1064,7 @@
BidiMap map = harvestLocalWikitties(starts, true);
// put all local wikitties in a map
+
for (Object o : map.keySet()) {
String id = (String) o;
FileSystemWIkittyId location = (FileSystemWIkittyId) map
@@ -1063,6 +1094,10 @@
String id = entry.getKey();
Wikitty w = entry.getValue();
// if macth
+
+ log.debug("Check restriction for wikitty: " + w
+ + " Restriction:" + restriction);
+
if (checkRestriction(restriction, w)) {
// increment result number
@@ -1129,6 +1164,10 @@
String id = entry.getKey();
Wikitty w = entry.getValue();
// if macth
+
+ log.debug("Check restriction for wikitty: " + w
+ + " Restriction:" + restriction);
+
if (checkRestriction(restriction, w)) {
// increment result number
currentIndex++;
@@ -1191,6 +1230,8 @@
*/
public List<File> harvestPropertyDirectory(File starts, boolean recursivly) {
+ log.info("harvest property directory starts:" + starts + "isRecur"
+ + recursivly);
List<File> result = new ArrayList<File>();
for (File child : starts.listFiles()) {
@@ -1218,12 +1259,15 @@
throws Exception {
BidiMap result = new DualHashBidiMap();
+ log.info("harvest localWikitty");
List<File> propertiesDirectory = harvestPropertyDirectory(starts,
recursivly);
// use the list of property to retrieve wikitty
for (File propsDir : propertiesDirectory) {
+ log.debug("harvest wikitty on " + propertiesDirectory);
+
Properties idProps = new Properties();
File idFile = new File(propsDir.getCanonicalPath() + File.separator
+ WikittyPublicationFileSystem.WIKITTY_ID_PROPERTIES_FILE);
@@ -1235,11 +1279,14 @@
// simply load the id property file to retrieve wikitty id
// with the path to the propertyfile and the value of the file
// construct FileSytemWikittyId
+ log.debug("List of file/wikitty");
for (Object id : ids) {
String name = idProps.getProperty((String) id);
String path = propsDir.getParent();
FileSystemWIkittyId value = new FileSystemWIkittyId(name, path);
+ log.debug("ID:" + id + " fileInformation:" + value);
+
result.put((String) id, value);
}
@@ -1273,6 +1320,8 @@
static public PropertiesExtended getWikittyPublicationProperties(
File starts, String name) throws IOException {
+ log.debug("getwikittyPublicationProperties :" + name + " on dir:"
+ + starts);
File propertieDirectory = new File(starts.getCanonicalPath()
+ File.separator
+ WikittyPublicationFileSystem.PROPERTY_DIRECTORY);
@@ -1305,6 +1354,8 @@
protected Wikitty restore(String id, FileSystemWIkittyId fileId)
throws IOException {
+ log.debug("restore wikitty id:" + id + " file: " + fileId);
+
Wikitty result = new WikittyImpl(id);
result.addExtension(WikittyLabelImpl.extensionWikittyLabel);
@@ -1333,6 +1384,8 @@
// create the correct wikittypubxxx
if (mimeHelper.isPubTextMime(mimeType)) {
+ log.debug("restore wikitty id:" + id + " file: " + fileId
+ + " pubTextType");
result.addExtension(WikittyPubTextImpl.extensionWikittyPubText);
WikittyPubTextHelper.setName(result, name);
WikittyPubTextHelper.setMimeType(result, mimeType);
@@ -1340,6 +1393,8 @@
FileUtil.readAsString(fileToTransform));
WikittyPubTextHelper.setFileExtension(result, extension);
} else {
+ log.debug("restore wikitty id:" + id + " file: " + fileId
+ + " pubDataType");
result.addExtension(WikittyPubDataImpl.extensionWikittyPubData);
WikittyPubDataHelper.setName(result, name);
WikittyPubDataHelper.setMimeType(result, mimeType);
@@ -1372,6 +1427,8 @@
protected void harvestNewCheckModificationsAndDeleted(File starts,
String label) throws IOException {
+ log.info("Check for wikitty on disk: new, deleted and modified. Directory:"
+ + starts + " Label:" + label);
// write property directory if not exist
File propertyFile = new File(starts + File.separator
+ PROPERTY_DIRECTORY);
@@ -1428,6 +1485,8 @@
// check for the deleted
if (filesWikitty.size() != listChildFileNonDir.size()) {
+ log.info("remove wikitty informations for deleted file");
+
meta = getWikittyPublicationProperties(starts,
WIKITTY_FILE_META_PROPERTIES_FILE);
@@ -1435,6 +1494,7 @@
for (String fileRemoved : filesWikitty) {
+ log.debug("remove wikitty informations for:" + filesWikitty);
// remove properties
ids.remove(meta.get(META_PREFIX_KEY_ID + fileRemoved));
@@ -1461,6 +1521,8 @@
*/
protected void checkModifications(File child) throws IOException {
+ log.info("Check if there was modification on :" + child);
+
// will check if there was modification with checksum
BufferedInputStream input = new BufferedInputStream(
new FileInputStream(child));
@@ -1503,6 +1565,9 @@
protected void writeWikittyFileProperties(File towrite, String wikittyID,
String wikittyVersion) throws IOException {
+ log.info("Write wikitty information file: " + towrite + " Id:"
+ + wikittyID + " version:" + wikittyVersion);
+
if (towrite.exists() && !towrite.isDirectory()) {
Wikitty wikitty = new WikittyImpl(wikittyID);
if (wikittyVersion != null) {
@@ -1539,7 +1604,7 @@
meta.store();
} else {
throw new IOException(towrite.toString()
- + " not exist or isn't a directory");
+ + " not exist or is a directory");
}
}
@@ -1557,6 +1622,8 @@
label = labelToPath(label);
+ log.info("Create directory from path:" + label);
+
String[] pathElements = StringUtil.split(label, File.separator);
boolean result = false;
@@ -1584,6 +1651,7 @@
* @return the correct path
*/
public String labelToPath(String label) {
+
String result = label;
result = result.replace(".", File.separator);
@@ -1592,6 +1660,8 @@
result = result.replace(File.separator + File.separator, File.separator
+ ".");
+ log.info("Convert label to path: " + label + " path:" + result);
+
return result;
}
@@ -1609,6 +1679,8 @@
static public File searchWikittyPublicationHomePropertie(File start)
throws IOException {
+ log.info("Search for home propertie from :" + start);
+
if (start != null && start.exists() && start.isDirectory()) {
// recursion, we search in the parents for the home property file
@@ -1628,11 +1700,13 @@
return searchWikittyPublicationHomePropertie(start.getParentFile());
} else {
- // Exception
- /*
- * TODO mfortun-2011-04-27 write/set the appropriate exception here
- */
- return null;
+ if (start == null) {
+ throw new IOException("Start cannot be null");
+ }
+ if (!start.exists()) {
+ throw new IOException(start + " doen't exist");
+ }
+ throw new IOException(start + " is not a directory");
}
}
1
0
Author: mfortun
Date: 2011-04-28 15:53:40 +0200 (Thu, 28 Apr 2011)
New Revision: 845
Url: http://nuiton.org/repositories/revision/wikitty/845
Log:
* update the specs with the commit/update requirements
Modified:
trunk/wikitty-publication/src/site/rst/sync.rst
Modified: trunk/wikitty-publication/src/site/rst/sync.rst
===================================================================
--- trunk/wikitty-publication/src/site/rst/sync.rst 2011-04-28 13:31:52 UTC (rev 844)
+++ trunk/wikitty-publication/src/site/rst/sync.rst 2011-04-28 13:53:40 UTC (rev 845)
@@ -144,6 +144,21 @@
11daz5facz=scripttut.js
jbdub1dza8=script.js
+
+Wikitty Service File System
+---------------------------
+
+Un tel service devra fournir les méthodes suivantes les méthodes de sauvegarde
+des wikitty, de restauration, ainsi qu'un certain nombre de fonctionnalités concernant
+les recherches de wikitty.
+
+Le wikitty service sur file system prendra en charge les recherches sur critéria
+de façon compléte. A chaque recherche sur le wikitty service file system, il faudra
+indexer les nouveaux wikitty, enlever les property des fichiers/wikitty supprimé,
+incrémenter la version mineur si il y a eut des modifications depuis la dernière
+indexation.
+
+
Fonctionnalités
---------------
@@ -198,23 +213,29 @@
les autres labels du wikitty seront transmit.
-Wikitty Service File System
----------------------------
+Commit/update
++++++++++++++
-Un tel service devra fournir les méthodes suivantes les méthodes de sauvegarde
-des wikitty, de restauration, ainsi qu'un certain nombre de fonctionnalités concernant
-les recherches de wikitty.
+Définitions
+***********
-Le wikitty service sur file system prendra en charge les recherches sur critéria
-de façon compléte. A chaque recherche sur le wikitty service file system, il faudra
-indexer les nouveaux wikitty, enlever les property des fichiers/wikitty supprimé,
-incrémenter la version mineur si il y a eut des modifications depuis la dernière
-indexation.
+On va conserver des fonctionnalités de type commit/update, l'utilisation de ces fonctions
+nécessitera un "repository" wikitty publication file system existant dans l'arborescence.
+Le but de ces fonctionnalités est de faire des Sync avec un autre wikitty service sans
+avoir besoin de redonner sont adresse explicitement à chaque fois avec la commande sync.
+Un commit sera équivalent à un sync du "reposistory" local vers un autre wikitty service.
+Un update sera équivalent à un sync d'un autre wikitty service vers le repositotory local.
+Pour ce faire dans le dossier racine qui contient l'arborescence des wikitty sous forme de fichier
+on enregistrera dans un dossier ".wp" un fichier "ws.properties" qui contiendra l'adresse
+du dernier wikitty service utilisé pour faire un sync.
-Commit/update
--------------
+
+Prototype commande
+******************
+''wp [update|commit] [--norecursion] [--delete|--existing] [URI file]''
+L'URI file est optionnelle, si pas précisée on va commit/update le dossier local.
1
0
r844 - trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro
by mfortun@users.nuiton.org 28 Apr '11
by mfortun@users.nuiton.org 28 Apr '11
28 Apr '11
Author: mfortun
Date: 2011-04-28 15:31:52 +0200 (Thu, 28 Apr 2011)
New Revision: 844
Url: http://nuiton.org/repositories/revision/wikitty/844
Log:
* commit/update basically works
* correct a bug with label in synchronization
Modified:
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java
trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java
Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java 2011-04-27 17:46:44 UTC (rev 843)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublication.java 2011-04-28 13:31:52 UTC (rev 844)
@@ -37,6 +37,7 @@
import org.nuiton.util.ApplicationConfig;
import org.nuiton.util.ArgumentsParserException;
import org.nuiton.util.FileUtil;
+import org.nuiton.util.StringUtil;
import org.nuiton.wikitty.WikittyProxy;
import org.nuiton.wikitty.WikittyServiceFactory;
import org.nuiton.wikitty.WikittyUtil;
@@ -151,6 +152,10 @@
static public void synchronisation(String origin, String target)
throws URISyntaxException {
+
+ System.out.println(origin);
+ System.out.println(target);
+
boolean isRecur = applicationConfig
.getOptionAsBoolean(IS_RECURSION_OPTION);
@@ -189,7 +194,7 @@
WikittyServiceFactory.buildWikittyService(temp2));
String labelOrigin = uriOrigin.getFragment();
- String labelTarget = uriOrigin.getFragment();
+ String labelTarget = uriTarget.getFragment();
Criteria critOrigin = constructCriteriaLabelRecur(labelOrigin, isRecur);
Criteria critTarget = constructCriteriaLabelRecur(labelTarget, isRecur);
@@ -239,8 +244,8 @@
for (String labels : saveLabelOrigin) {
if (isRecur && labels.startsWith(labelOrigin)) {
- String finalLabelTarge = labels.replace(labelOrigin,
- labelTarget);
+ String finalLabelTarge = new String(labels.replace(
+ labelOrigin, labelTarget));
targetLabels.add(finalLabelTarge);
} else if (!isRecur && labels.equals(labelOrigin)) {
targetLabels.add(labelTarget);
@@ -433,6 +438,23 @@
static public void update(String... uriFileSystem) throws Exception {
+ // only difference between update and commit is the param's order
+ // when calling synchronisation method
+ commitUpdateDelegate(false, uriFileSystem);
+
+ }
+
+ static public void commit(String... uriFileSystem) throws Exception {
+
+ // only difference between update and commit is the param's order
+ // when calling synchronisation method
+ commitUpdateDelegate(true, uriFileSystem);
+
+ }
+
+ protected static void commitUpdateDelegate(boolean isCommit,
+ String... uriFileSystem) throws Exception {
+
/*
* Alors c'est facile si on a un élément dans le param c'est que on
* spécifie l'endroit du FS à updater/commit, ce qui veut dire que on
@@ -448,26 +470,34 @@
* et pareil on va construire les adresses pour faire une synchro
*/
- }
+ // update is from wikitty service store to wikitty service File System
- static public void commit(String... uriFileSystem) throws Exception {
+ String wikittyServiceInter = "";
+ String wikittyServiceFileSystem = "";
+ String wikittyServiceInterSave = "";
- String target = "";
- String origin = "";
-
File currentDir = new File(FileUtil.getCurrentDirectory()
.getAbsolutePath());
-
+ String labelInitial = "";
PropertiesExtended homePorperty = null;
+ // Check number of argument
switch (uriFileSystem.length) {
+ // if none, then the current dir have to be commit.
case 0:
+ // search for the home property dir that containt uri to the wikitty
+ // service
+ File homePropertyDir = WikittyPublicationFileSystem
+ .searchWikittyPublicationHomePropertie(currentDir);
homePorperty = WikittyPublicationFileSystem
- .searchWikittyPublicationHomePropertie(currentDir);
+ .getWikittyPublicationProperties(homePropertyDir,
+ WikittyPublicationFileSystem.WIKITTY_FILE_SERVICE);
- target = (String) homePorperty.get(WIKITTY_SERVICE_INTERLOCUTEUR);
+ // load the wikitty service uri (distant one)
+ wikittyServiceInter = homePorperty
+ .getProperty(WIKITTY_SERVICE_INTERLOCUTEUR);
- // construct the current uri for origin
+ // construct the current uri for wikitty service file system
// search the current label
PropertiesExtended metaPropertiesExtended = WikittyPublicationFileSystem
.getWikittyPublicationProperties(
@@ -476,58 +506,61 @@
String labelCurrent = metaPropertiesExtended
.getProperty(WikittyPublicationFileSystem.META_CURRENT_LABEL);
- origin = "file:///" + currentDir.getAbsolutePath() + "#"
- + labelCurrent;
+ // construct uri of the wikitty publication file system
+ wikittyServiceFileSystem = "file://"
+ + homePropertyDir.getAbsolutePath() + "#" + labelCurrent;
+ labelInitial = homePorperty.getProperty(LABEL_KEY);
+ wikittyServiceInterSave = wikittyServiceInter;
+ wikittyServiceInter += labelCurrent.replaceFirst(labelInitial, "");
- synchronisation(origin, target);
break;
-
+ // if a param is set it mean that the uri of the File system is set
case 1:
- origin = uriFileSystem[0];
- URI originUri = new URI(origin);
+ wikittyServiceFileSystem = uriFileSystem[0];
+ URI originUri = new URI(wikittyServiceFileSystem);
+ // check if uri of wikitty publication file system is well formed,
+ // must be a file "protocol"
if (!originUri.getScheme().equals("file")) {
// Exception
}
+ // then search for the home property file to load the wikitty
+ // service uri
File workingDir = new File(originUri.getPath());
homePorperty = WikittyPublicationFileSystem
- .searchWikittyPublicationHomePropertie(workingDir);
+ .getWikittyPublicationProperties(workingDir,
+ WikittyPublicationFileSystem.WIKITTY_FILE_SERVICE);
- target = (String) homePorperty.get(WIKITTY_SERVICE_INTERLOCUTEUR);
+ wikittyServiceInter = (String) homePorperty
+ .get(WIKITTY_SERVICE_INTERLOCUTEUR);
- // TODO mfortun 2011-04-27 do something on labels ?
+ labelInitial = homePorperty.getProperty(LABEL_KEY);
+ wikittyServiceInterSave = wikittyServiceInter;
+ wikittyServiceInter += originUri.getFragment().replaceFirst(
+ labelInitial, "");
- synchronisation(origin, target);
break;
+ // Exception, correct number of argument is 0 or 1
default:
// exception
break;
}
+ // delegate to synchronisation
+ // only difference between update and commit is the param's order
+ if (isCommit) {
+ synchronisation(wikittyServiceFileSystem, wikittyServiceInter);
- /*
- * Alors c'est facile si on a un élément dans le param c'est que on
- * spécifie l'endroit du FS à updater/commit, ce qui veut dire que on
- * doit aller chercher ensuite dans le dossier donné l'adresse du
- * wikitty service. Notons que si il y a un élément ça doit forcément
- * être une uri avec le protocole file. après on appelle simplement la
- * méthode synchro avec l'ordre correct entre uritarget et uri origin.
- *
- * dans le cas ou ya pas d'argument ça veut dire que on doit
- * commit/update le dossier courant donc aller chercher dans
- * l'arborescence l'adresse du wikitty service.
- *
- * et pareil on va construire les adresses pour faire une synchro
- */
-
+ } else {
+ synchronisation(wikittyServiceInter, wikittyServiceFileSystem);
+ }
+ // FIXME mfortun-2011-04-28 find a better way to do this, it's needed
+ // because of the labels and how construct label for the wikitty service
+ // interlocuteur
+ homePorperty.setProperty(WIKITTY_SERVICE_INTERLOCUTEUR,
+ wikittyServiceInterSave);
+ homePorperty.store();
}
- /*
- * TODO mfortun-2011-04-18 plus tard il faudra rajouter un fonctionnement
- * commit update à la commande sync, en se servant de l'adresse du wikitty
- * service que l'on aura enregitré quelque part. Un commit/update sera juste
- * un alias sur le sync classique en se servant d'une adresse enregistré
- * dans un fichier et une adresse en ligne de commande
- */
}
Modified: trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java
===================================================================
--- trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java 2011-04-27 17:46:44 UTC (rev 843)
+++ trunk/wikitty-publication/src/main/java/org/nuiton/wikitty/publication/synchro/WikittyPublicationFileSystem.java 2011-04-28 13:31:52 UTC (rev 844)
@@ -216,16 +216,18 @@
+ File.separator + PROPERTY_DIRECTORY);
if (!homeProperty.exists()) {
- homeProperty.createNewFile();
+ homeProperty.mkdir();
}
// write/update the "home property file"
PropertiesExtended propertyWikittyService = getWikittyPublicationProperties(
homeFile, WIKITTY_FILE_SERVICE);
- // the original label use to create
- propertyWikittyService.setProperty(WikittyPublication.LABEL_KEY,
- this.label);
+ // the original label use to create if not exist
+ if (!propertyWikittyService.containsKey(WikittyPublication.LABEL_KEY)) {
+ propertyWikittyService.setProperty(WikittyPublication.LABEL_KEY,
+ this.label);
+ }
// the service use to update or commit
propertyWikittyService
.setProperty(
@@ -237,6 +239,7 @@
this.recursion = app
.getOptionAsBoolean(WikittyPublication.IS_RECURSION_OPTION);
+ // TODO mfotun-2011-04-28 add a support for filtered file with a property file
this.directoryNameBlackList = new ArrayList<String>();
directoryNameBlackList.add(".svn");
directoryNameBlackList.add(".git");
@@ -1603,8 +1606,8 @@
* @throws IOException
* if error while reading property file
*/
- static public PropertiesExtended searchWikittyPublicationHomePropertie(
- File start) throws IOException {
+ static public File searchWikittyPublicationHomePropertie(File start)
+ throws IOException {
if (start != null && start.exists() && start.isDirectory()) {
@@ -1619,7 +1622,7 @@
File propertie = new File(propertyDirectory.getCanonicalPath()
+ File.separator + WIKITTY_FILE_SERVICE);
if (propertie.exists()) {
- return new PropertiesExtended(propertie);
+ return start;
}
}
1
0