Skip to content
Snippets Groups Projects
Commit 31e85409 authored by Nicolas Dagneaux's avatar Nicolas Dagneaux
Browse files

ça avance

parent 74830a92
No related branches found
No related tags found
No related merge requests found
Pipeline #38586 passed
......@@ -2,9 +2,9 @@
JAVAFILES=$(find src/main/java -type f -name '*.java' | tr '\n' ' ')
PACKAGES=$(find src/main/java/fr -type d -mindepth 3 | sed 's/src\/main\/java\///' |tr '/' '.' | tr '\n' ' ')
JAVAFXFOLDER="/Library/Frameworks/javafx-sdk-21"
JAVAFXFOLDER="/home/public/javafx-sdk-17.0.2"
VARGS="--module-path=$JAVAFXFOLDER:$JAVAFXFOLDER/lib --add-modules=javafx.controls,javafx.fxml"
javadoc $VARGS -sourcepath src/main/java -d doc -docletpath lib/umldoclet-2.1.0.jar -doclet nl.talsmasoftware.umldoclet.UMLDoclet $PACKAGES
#javadoc $VARGS -sourcepath src/main/java -d doc -docletpath lib/umldoclet-2.1.0.jar -doclet nl.talsmasoftware.umldoclet.UMLDoclet $PACKAGES
javac -g -d bin $VARGS $JAVAFILES && jar cfv doc/dist/univlille-iutinfo-java-utils.jar doc -C bin .
\ No newline at end of file
javac -g -d bin $VARGS $JAVAFILES && jar cfv univlille-iutinfo-java-utils.jar doc -C bin .
package fr.univlille.iutinfo.sql;
import fr.univlille.iutinfo.sql.Pojo.Pojo;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
abstract class DAOBasic<E>
{
private static final Map<Class, Method> sqlGetters;
private String tableName;
private Class<E> reflectionClass;
public DAOBasic(Class pojoClass)
{
this.tableName = pojoClass.getName().toLowerCase();
}
static
{
try
{
sqlGetters = Map.of(
String.class, ResultSet.class.getDeclaredMethod("getString", int.class)
);
} catch (NoSuchMethodException e)
{
throw new RuntimeException(e);
}
}
public List<E> findAll() throws SQLException, IOException, ClassNotFoundException
{
List<E> resultList = new ArrayList<E>();
String sqlRequest = "SELECT * FROM " + this.tableName;
DBLoop<List<E>> loop = new DBLoop<List<E>>(resultList, sqlRequest, (((obj, rs) ->
{
Constructor pojoConstructor = this.reflectionClass.getConstructors()[0];
Object[] pojoConstructorsParam = new Object[pojoConstructor.getParameterCount()];
for (int i = 0; i < pojoConstructor.getParameterCount(); i++)
{
pojoConstructorsParam[i] = DAOBasic.sqlGetters.get(this.reflectionClass.getDeclaredFields()[i]);
}
obj.add((E)pojoConstructor.newInstance(pojoConstructorsParam));
})));
return loop.executeLoop();
}
}
package fr.univlille.iutinfo.sql;
import java.lang.reflect.InvocationTargetException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
......@@ -16,5 +17,5 @@ public interface Loopable<E>
* @param rs la ligne de résultat en cours de traitement
* @throws SQLException en cas d'erreur SQL.
*/
public void doLoop(E obj, ResultSet rs) throws SQLException;
public void doLoop(E obj, ResultSet rs) throws SQLException, InvocationTargetException, InstantiationException, IllegalAccessException;
}
package fr.univlille.iutinfo.sql;
import java.sql.SQLException;
import java.util.List;
public class DAOBasicTest
{
public static void main(String[] args) throws Exception
{
DBConnector.init(new DBConnectionDescriptor(
"org.postgresql.Driver",
"jdbc:postgresql://psqlserv/but2",
"nicolasdagneauxetu",
"moi"));
List<Etudiant> etus = DAOBasic.findAll(Etudiant.class);
}
}
package fr.univlille.iutinfo.sql;
import java.util.List;
public record Etudiant(String nom, String prenom)
{
public class EtudiantDAO extends DAOBasic<Etudiant>
{
public EtudiantDAO()
{
}
public List<Etudiant> findAll()
{
return super.findAll();
}
}
}
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment