This is an automated email from the git hooks/post-receive script. New commit to branch feature/spgeed in repository pollen. See https://gitlab.nuiton.org/chorem/pollen.git commit 07dfb70295beca7a365df0f985cf500f1013409e Author: Killian <killian.herbreteau@epitech.eu> Date: Tue Nov 12 12:05:11 2019 +0100 add Spgeed Dao doc --- spgeedDAO.md | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) diff --git a/spgeedDAO.md b/spgeedDAO.md new file mode 100644 index 00000000..6acf9ae8 --- /dev/null +++ b/spgeedDAO.md @@ -0,0 +1,123 @@ +# How To + +This `How To` will describe you how to reproduce / continue some work done / To Do on Pollen. +* Create Spgeed Dao + +## Create Spgeed Dao + +`Spgeed Dao` must to be written with Strings + +Example : +``` java +public interface PollenUserSpgeedDao { + String getUsers = "SELECT * FROM pollenuser"; + + @Select(sql = getUsers) + PollenUser[] getUsers(); +} +``` + +### Simple request + +!!! warning + sql String can't be created using method + +Bad Example : +``` java +public class userDaoUtils { + + public static String getUsers(String condition) { + String getUser = "SELECT * FROM pollenuser"; + + if (StringUtils.isBlank(condition) { + return getUser; + } else { + return getUser + " WHERE " + condition; + } + } +} + +public interface PollenUserSpgeedDao { + + @Select(sql = userDaoUtils.getUsers(null)) + PollenUser[] getUsers(); + + @Select(sql = userDaoUtils.getUsers("name = ${userName}")) + PollenUser getUserWithName(String userName); +} +``` +How to avoid using method to create String request : +``` java +public interface PollenUserSpgeedDao { + + String getAllUsers = "SELECT * FROM pollenuser"; + + @Select(sql = getAllUsers) + PollenUser[] getUsers(); + + String getUserWithName = getAllUsers + " WHERE name = ${userName}"; + + @Select(sql = getUserWithName) + PollenUser getUserWithName(String userName); +} +``` + +### Dao Structure + +How to structure dao : +``` java +import static org.chorem.pollen.persistence.entity.PollenUser.*; + +public interface PollenUserSpgeedDao { + + String userName = "pu"; // User nickname + + String aggName = "users_agg"; // User aggregation name, used to refer to the user aggregation + + String properties = username + "." + PROPERTY_TOPIA_ID + ", " // See below + + userName + "." + PROPERTY_TOPIA_VERSION + ", " // etc +} +``` + +In the properties String must appear : +- Every properties no foreign key (ex : topiaId, topiaVersion, pollenUser.name) +- Every foreign key that doesn't appear in the object (ex : pollenUserEmailAddress.pollenuser), they will be reused to join table. +Exemple : +``` java +public abstract class AbstractTopiaEntity implements TopiaEntity { + protected String topiaId; // Must appear + + protected long topiaVersion; // Must appear + + protected Date topiaCreateDate = new Date(); // Must appear +} +public abstract class PollenUserAbstract extends AbstractTopiaEntity implements PollenUser { + + protected String name; // Must appear + + protected boolean administrator; // Must appear + + protected String language; // Must appear + + protected String password; // Must appear + + protected String salt; // Must appear + + protected boolean banned; // Must appear + + protected Date gtuValidationDate; // Must appear + + protected Date premiumTo; // Must appear + + protected boolean canCreatePoll; // Must appear + + protected Collection<UserCredential> userCredential; // Can't appear (reference to userCredential table) + + protected PollenResource avatar; // Can't appear (reference to pollenResource table) + + protected PollenUserEmailAddress defaultEmailAddress; // Must not appear + + protected Collection<PollenUserEmailAddress> emailAddresses; // Can't appear (reference to pollenUserEmailAddress table) +} +``` +Those who `Can't appear` cause they are reference from another table must appear in their own request to join in those one. \ No newline at end of file -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.