Commit inicial
This commit is contained in:
commit
e322e8f4ca
41
.classpath
Normal file
41
.classpath
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="test" value="true"/>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="test" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="module" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="output" path="target/classes"/>
|
||||||
|
</classpath>
|
||||||
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
/bin/
|
||||||
|
*.class
|
||||||
|
/target/
|
||||||
23
.project
Normal file
23
.project
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>aadd_act5_2</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
||||||
2
.settings/org.eclipse.core.resources.prefs
Normal file
2
.settings/org.eclipse.core.resources.prefs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
encoding/<project>=UTF-8
|
||||||
121
.settings/org.eclipse.jdt.core.prefs
Normal file
121
.settings/org.eclipse.jdt.core.prefs
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.builder.annotationPath.allLocations=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull
|
||||||
|
org.eclipse.jdt.core.compiler.annotation.nonnull.secondary=
|
||||||
|
org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault
|
||||||
|
org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary=
|
||||||
|
org.eclipse.jdt.core.compiler.annotation.notowning=org.eclipse.jdt.annotation.NotOwning
|
||||||
|
org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
|
||||||
|
org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
|
||||||
|
org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.annotation.owning=org.eclipse.jdt.annotation.Owning
|
||||||
|
org.eclipse.jdt.core.compiler.annotation.resourceanalysis=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=24
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=24
|
||||||
|
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||||
|
org.eclipse.jdt.core.compiler.problem.APILeak=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.annotatedTypeArgumentToUnannotated=info
|
||||||
|
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.deadCode=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.deprecation=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.incompatibleOwningContract=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.insufficientResourceAnalysis=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.missingSerialVersion=info
|
||||||
|
org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.nullReference=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.suppressWarningsNotFullyAnalysed=info
|
||||||
|
org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.terminalDeprecation=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentType=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentTypeStrict=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unlikelyEqualsArgumentType=info
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unstableAutoModuleName=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unusedImport=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unusedLambdaParameter=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore
|
||||||
|
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
|
||||||
|
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
|
||||||
|
org.eclipse.jdt.core.compiler.release=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.source=24
|
||||||
4
.settings/org.eclipse.m2e.core.prefs
Normal file
4
.settings/org.eclipse.m2e.core.prefs
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
activeProfiles=
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
resolveWorkspaceProjects=true
|
||||||
|
version=1
|
||||||
20
pom.xml
Normal file
20
pom.xml
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>aadd_act5_2</groupId>
|
||||||
|
<artifactId>aadd_act5_2</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<!-- Source: https://mvnrepository.com/artifact/org.mongodb/mongodb-driver-sync -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mongodb</groupId>
|
||||||
|
<artifactId>mongodb-driver-sync</artifactId>
|
||||||
|
<version>5.6.2</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
||||||
91
src/main/java/es/palomafp/aadd/inm/AppMapaMundi.java
Normal file
91
src/main/java/es/palomafp/aadd/inm/AppMapaMundi.java
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
package es.palomafp.aadd.inm;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import es.palomafp.aadd.inm.dao.IContinenteDAO;
|
||||||
|
import es.palomafp.aadd.inm.dao.IPaisDAO;
|
||||||
|
import es.palomafp.aadd.inm.dao.mgdb.ContinenteDaoMongoDB;
|
||||||
|
import es.palomafp.aadd.inm.dao.mgdb.PaisDaoMongoDB;
|
||||||
|
import es.palomafp.aadd.inm.vo.Continente;
|
||||||
|
import es.palomafp.aadd.inm.vo.Pais;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* AppMapaMundi: Clase principal para tratar la información de MapaMundi en MongoDB.
|
||||||
|
*
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 30 enero 2026
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class AppMapaMundi {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
AppMapaMundi app = new AppMapaMundi();
|
||||||
|
|
||||||
|
// app.probarCRUDContinente();
|
||||||
|
|
||||||
|
app.probarCRUDPais();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void probarCRUDPais() {
|
||||||
|
IPaisDAO paisDAO = new PaisDaoMongoDB();
|
||||||
|
|
||||||
|
String codigoContinente= "01";
|
||||||
|
Continente continente = new Continente();
|
||||||
|
continente.setCodigo(codigoContinente);
|
||||||
|
continente.setNombreContinente("América");
|
||||||
|
|
||||||
|
Pais pais = new Pais();
|
||||||
|
int identificador= 213;
|
||||||
|
pais.setIdentificador(identificador);
|
||||||
|
pais.setNombrePais("De las maravillas");
|
||||||
|
pais.setCapital("Centro de la maravilla");
|
||||||
|
pais.setContinente(continente);
|
||||||
|
|
||||||
|
|
||||||
|
Pais paisBBDD= paisDAO.obtenerPaisPorID(identificador);
|
||||||
|
System.out.println("paisBBDD: " + paisBBDD);
|
||||||
|
|
||||||
|
if (paisBBDD==null) {
|
||||||
|
paisDAO.crearPais(pais);
|
||||||
|
}else {
|
||||||
|
pais.setNombrePais("Worderful Land");
|
||||||
|
paisDAO.actualizarPais(pais);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Pais> listaPais= paisDAO.obtenerListaPaises();
|
||||||
|
System.out.println(listaPais);
|
||||||
|
|
||||||
|
paisDAO.borrarPais(identificador);
|
||||||
|
|
||||||
|
listaPais= paisDAO.obtenerListaPaises();
|
||||||
|
System.out.println(listaPais);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void probarCRUDContinente() {
|
||||||
|
IContinenteDAO continenteDAO = new ContinenteDaoMongoDB();
|
||||||
|
|
||||||
|
|
||||||
|
String codigoContinente= "01";
|
||||||
|
Continente continente = new Continente();
|
||||||
|
continente.setCodigo(codigoContinente);
|
||||||
|
continente.setNombreContinente("América");
|
||||||
|
|
||||||
|
Continente continenteBBDD= continenteDAO.obtenerContinentePorID(codigoContinente);
|
||||||
|
System.out.println("continenteBBDD: " + continenteBBDD);
|
||||||
|
|
||||||
|
if (continenteBBDD==null) {
|
||||||
|
continenteDAO.crearContinente(continente);
|
||||||
|
}else {
|
||||||
|
continente.setNombreContinente("Antártida Profunda");
|
||||||
|
continenteDAO.actualizarContinente(continente);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Continente> listaContinente= continenteDAO.obtenerListaContientes();
|
||||||
|
System.out.println(listaContinente);
|
||||||
|
|
||||||
|
continenteDAO.borrarContinente(codigoContinente);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
25
src/main/java/es/palomafp/aadd/inm/dao/IContinenteDAO.java
Normal file
25
src/main/java/es/palomafp/aadd/inm/dao/IContinenteDAO.java
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
package es.palomafp.aadd.inm.dao;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import es.palomafp.aadd.inm.vo.Continente;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* IContinenteDAO: Interfaz que define las operaciones de acceso a datos para
|
||||||
|
* Continente.
|
||||||
|
*
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 31 oct 2025
|
||||||
|
*/
|
||||||
|
public interface IContinenteDAO {
|
||||||
|
Continente obtenerContinentePorID(String codigo);
|
||||||
|
|
||||||
|
List<Continente> obtenerListaContientes();
|
||||||
|
|
||||||
|
void crearContinente(Continente continente);
|
||||||
|
|
||||||
|
void actualizarContinente(Continente continente);
|
||||||
|
|
||||||
|
void borrarContinente(String codigo);
|
||||||
|
}
|
||||||
24
src/main/java/es/palomafp/aadd/inm/dao/IPaisDAO.java
Normal file
24
src/main/java/es/palomafp/aadd/inm/dao/IPaisDAO.java
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package es.palomafp.aadd.inm.dao;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import es.palomafp.aadd.inm.vo.Pais;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* IPaisDAO: Interfaz que define las operaciones de acceso a datos para País.
|
||||||
|
*
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 31 oct 2025
|
||||||
|
*/
|
||||||
|
public interface IPaisDAO {
|
||||||
|
Pais obtenerPaisPorID(int identificador);
|
||||||
|
|
||||||
|
List<Pais> obtenerListaPaises();
|
||||||
|
|
||||||
|
void crearPais(Pais pais);
|
||||||
|
|
||||||
|
void actualizarPais(Pais pais);
|
||||||
|
|
||||||
|
void borrarPais(int identificador);
|
||||||
|
}
|
||||||
@ -0,0 +1,111 @@
|
|||||||
|
package es.palomafp.aadd.inm.dao.mgdb;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bson.Document;
|
||||||
|
import org.bson.conversions.Bson;
|
||||||
|
|
||||||
|
import com.mongodb.client.FindIterable;
|
||||||
|
import com.mongodb.client.MongoCollection;
|
||||||
|
import com.mongodb.client.model.Filters;
|
||||||
|
import com.mongodb.client.model.Updates;
|
||||||
|
|
||||||
|
import es.palomafp.aadd.inm.dao.IContinenteDAO;
|
||||||
|
import es.palomafp.aadd.inm.gestor.GestorConexionMongoDB;
|
||||||
|
import es.palomafp.aadd.inm.vo.Continente;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* ContinenteDaoMongoDB: Implentación MongoDB de las operaciones de IContinenteDAO.
|
||||||
|
*
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 30 enero 2026
|
||||||
|
*/
|
||||||
|
public class ContinenteDaoMongoDB implements IContinenteDAO {
|
||||||
|
private final static String COLECCION_CONTINENTE = "C_CONTINENTE";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Continente obtenerContinentePorID(String codigo) {
|
||||||
|
Continente continente = null;
|
||||||
|
// Obtener o crear una colección MongoDB
|
||||||
|
MongoCollection<Document> coleccionMDb = GestorConexionMongoDB.getMongoDatabase()
|
||||||
|
.getCollection(COLECCION_CONTINENTE);
|
||||||
|
|
||||||
|
// Consultar Colección con filtro 'like' del documento (Alumnos cuyo nombre
|
||||||
|
// empieza por 'P')
|
||||||
|
Bson filtro = Filters.eq("_id", codigo);
|
||||||
|
Document documentoEncontrado = coleccionMDb.find(filtro).first();
|
||||||
|
|
||||||
|
if (documentoEncontrado != null) {
|
||||||
|
continente = new Continente();
|
||||||
|
continente.setCodigo(codigo);
|
||||||
|
continente.setNombreContinente(documentoEncontrado.getString("nombre"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return continente;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Continente> obtenerListaContientes() {
|
||||||
|
List<Continente> listaContinentes= null;
|
||||||
|
// Obtener colección MongoDB
|
||||||
|
MongoCollection<Document> coleccionMDb = GestorConexionMongoDB.getMongoDatabase()
|
||||||
|
.getCollection(COLECCION_CONTINENTE);
|
||||||
|
|
||||||
|
FindIterable<Document> documentosEncontrados=null;
|
||||||
|
documentosEncontrados = documentosEncontrados=coleccionMDb.find();
|
||||||
|
if (documentosEncontrados != null) {
|
||||||
|
listaContinentes=new ArrayList<Continente>();
|
||||||
|
for (Document documentoEncontrado : documentosEncontrados) {
|
||||||
|
Continente continente = new Continente();
|
||||||
|
continente.setCodigo(documentoEncontrado.getString("_id"));
|
||||||
|
continente.setNombreContinente(documentoEncontrado.getString("nombre"));
|
||||||
|
|
||||||
|
listaContinentes.add(continente);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return listaContinentes;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void crearContinente(Continente continente) {
|
||||||
|
// Obtener o crear una colección MongoDB
|
||||||
|
MongoCollection<Document> coleccionMDb = GestorConexionMongoDB.getMongoDatabase()
|
||||||
|
.getCollection(COLECCION_CONTINENTE);
|
||||||
|
|
||||||
|
// Insertar UN DOCUMENTO en la colección
|
||||||
|
Document documentoContinente = new Document();
|
||||||
|
documentoContinente.append("_id", continente.getCodigo()).append("codigo", continente.getCodigo())
|
||||||
|
.append("nombre", continente.getNombreContinente());
|
||||||
|
|
||||||
|
coleccionMDb.insertOne(documentoContinente);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actualizarContinente(Continente continente) {
|
||||||
|
// Obtener o crear una colección MongoDB
|
||||||
|
MongoCollection<Document> coleccionMDb = GestorConexionMongoDB.getMongoDatabase()
|
||||||
|
.getCollection(COLECCION_CONTINENTE);
|
||||||
|
|
||||||
|
// Actualizar UN Continente en la colección
|
||||||
|
Bson filtro = Filters.eq("_id", continente.getCodigo());
|
||||||
|
Bson nuevoContinente = Updates.set("nombre", continente.getNombreContinente());
|
||||||
|
coleccionMDb.updateOne(filtro, nuevoContinente);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarContinente(String codigo) {
|
||||||
|
// Obtener o crear una colección MongoDB
|
||||||
|
MongoCollection<Document> coleccionMDb = GestorConexionMongoDB.getMongoDatabase()
|
||||||
|
.getCollection(COLECCION_CONTINENTE);
|
||||||
|
|
||||||
|
// Borrar UNO por clave
|
||||||
|
Bson filtro = Filters.eq("_id", codigo);
|
||||||
|
coleccionMDb.deleteOne(filtro);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
133
src/main/java/es/palomafp/aadd/inm/dao/mgdb/PaisDaoMongoDB.java
Normal file
133
src/main/java/es/palomafp/aadd/inm/dao/mgdb/PaisDaoMongoDB.java
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
package es.palomafp.aadd.inm.dao.mgdb;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bson.Document;
|
||||||
|
import org.bson.conversions.Bson;
|
||||||
|
|
||||||
|
import com.mongodb.client.FindIterable;
|
||||||
|
import com.mongodb.client.MongoCollection;
|
||||||
|
import com.mongodb.client.model.Filters;
|
||||||
|
|
||||||
|
import es.palomafp.aadd.inm.dao.IPaisDAO;
|
||||||
|
import es.palomafp.aadd.inm.gestor.GestorConexionMongoDB;
|
||||||
|
import es.palomafp.aadd.inm.vo.Continente;
|
||||||
|
import es.palomafp.aadd.inm.vo.Pais;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* ContinenteDaoMongoDB: Implentación MongoDB de las operaciones de
|
||||||
|
* IContinenteDAO.
|
||||||
|
*
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 30 enero 2026
|
||||||
|
*/
|
||||||
|
public class PaisDaoMongoDB implements IPaisDAO {
|
||||||
|
private final static String COLECCION_PAIS = "C_PAIS";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Pais obtenerPaisPorID(int identificador) {
|
||||||
|
Pais pais = null;
|
||||||
|
// Obtener o crear una colección MongoDB
|
||||||
|
MongoCollection<Document> coleccionMDb = GestorConexionMongoDB.getMongoDatabase().getCollection(COLECCION_PAIS);
|
||||||
|
|
||||||
|
// Consultar por ID
|
||||||
|
Bson filtro = Filters.eq("_id", identificador);
|
||||||
|
Document documentoEncontrado = coleccionMDb.find(filtro).first();
|
||||||
|
|
||||||
|
if (documentoEncontrado != null) {
|
||||||
|
pais = getPaisFromDocumentoPais(documentoEncontrado);
|
||||||
|
}
|
||||||
|
|
||||||
|
return pais;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Pais> obtenerListaPaises() {
|
||||||
|
List<Pais> listaPaises = null;
|
||||||
|
// Obtener colección MongoDB
|
||||||
|
MongoCollection<Document> coleccionMDb = GestorConexionMongoDB.getMongoDatabase().getCollection(COLECCION_PAIS);
|
||||||
|
|
||||||
|
FindIterable<Document> documentosEncontrados = null;
|
||||||
|
documentosEncontrados = documentosEncontrados = coleccionMDb.find();
|
||||||
|
if (documentosEncontrados != null) {
|
||||||
|
listaPaises = new ArrayList<Pais>();
|
||||||
|
for (Document documentoEncontrado : documentosEncontrados) {
|
||||||
|
Pais pais = getPaisFromDocumentoPais(documentoEncontrado);
|
||||||
|
|
||||||
|
listaPaises.add(pais);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return listaPaises;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void crearPais(Pais pais) {
|
||||||
|
// Obtener o crear una colección MongoDB
|
||||||
|
MongoCollection<Document> coleccionMDb = GestorConexionMongoDB.getMongoDatabase().getCollection(COLECCION_PAIS);
|
||||||
|
|
||||||
|
// Insertar UN DOCUMENTO en la colección
|
||||||
|
Document documentoPais = new Document();
|
||||||
|
|
||||||
|
|
||||||
|
documentoPais.append("_id", pais.getIdentificador())
|
||||||
|
.append("nombre", pais.getNombrePais())
|
||||||
|
.append("capital", pais.getCapital());
|
||||||
|
|
||||||
|
//Se carga la información del continente
|
||||||
|
Document documentoContinente = new Document();
|
||||||
|
documentoContinente.append("codigo", pais.getContinente().getCodigo())
|
||||||
|
.append("nombre", pais.getContinente().getNombreContinente());
|
||||||
|
|
||||||
|
documentoPais.append("continente", documentoContinente);
|
||||||
|
|
||||||
|
coleccionMDb.insertOne(documentoPais);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actualizarPais(Pais pais) {
|
||||||
|
// Obtener o crear una colección MongoDB
|
||||||
|
MongoCollection<Document> coleccionMDb = GestorConexionMongoDB.getMongoDatabase().getCollection(COLECCION_PAIS);
|
||||||
|
/*
|
||||||
|
// Actualizar UN Continente en la colección
|
||||||
|
Bson filtro = Filters.eq("_id", continente.getCodigo());
|
||||||
|
Bson nuevoContinente = Updates.set("nombre", continente.getNombreContinente());
|
||||||
|
coleccionMDb.updateOne(filtro, nuevoContinente);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarPais(int identificador) {
|
||||||
|
// Obtener o crear una colección MongoDB
|
||||||
|
MongoCollection<Document> coleccionMDb = GestorConexionMongoDB.getMongoDatabase().getCollection(COLECCION_PAIS);
|
||||||
|
|
||||||
|
// Borrar UNO por clave
|
||||||
|
Bson filtro = Filters.eq("_id", identificador);
|
||||||
|
coleccionMDb.deleteOne(filtro);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private Pais getPaisFromDocumentoPais(Document documentoPais) {
|
||||||
|
Pais pais = null;
|
||||||
|
int identificador = documentoPais.getInteger("_id");
|
||||||
|
String nombrePais = documentoPais.getString("nombre");
|
||||||
|
String capital = documentoPais.getString("capital");
|
||||||
|
|
||||||
|
Document documentoContinente = (Document) documentoPais.get("continente");
|
||||||
|
String codigoContinente = documentoContinente.getString("codigo");
|
||||||
|
String nombreContinente = documentoContinente.getString("nombre");
|
||||||
|
Continente continente = new Continente();
|
||||||
|
continente.setCodigo(codigoContinente);
|
||||||
|
continente.setNombreContinente(nombreContinente);
|
||||||
|
|
||||||
|
pais = new Pais();
|
||||||
|
pais.setIdentificador(identificador);
|
||||||
|
pais.setNombrePais(nombrePais);
|
||||||
|
pais.setCapital(capital);
|
||||||
|
pais.setContinente(continente);
|
||||||
|
|
||||||
|
return pais;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,39 @@
|
|||||||
|
package es.palomafp.aadd.inm.gestor;
|
||||||
|
|
||||||
|
import com.mongodb.client.MongoClient;
|
||||||
|
import com.mongodb.client.MongoClients;
|
||||||
|
import com.mongodb.client.MongoDatabase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* GestorConexionMongoDB: Clase que realiza la gestión de Conexiones a MongoDB.
|
||||||
|
*
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 30 enero 2026
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class GestorConexionMongoDB {
|
||||||
|
private static MongoDatabase mongoDBDatabase= null;
|
||||||
|
|
||||||
|
private GestorConexionMongoDB() { // Constructor privado para evitar instanciación
|
||||||
|
}
|
||||||
|
|
||||||
|
// Carga la configuración desde META-INF/persistence.xml
|
||||||
|
static {
|
||||||
|
// Cadena de conexion con la base de datos MongoDB
|
||||||
|
String uri = GestorFicheroConfiguracion.obtenerValor("url.conexion.mongodb");
|
||||||
|
// Se abre la conexión con MongoDB
|
||||||
|
MongoClient clienteMongo = MongoClients.create(uri);
|
||||||
|
|
||||||
|
// Obtener una base de datos MongoDB desde Java
|
||||||
|
String bbddMongoDB= GestorFicheroConfiguracion.obtenerValor("bbdd.mongodb");
|
||||||
|
mongoDBDatabase = clienteMongo.getDatabase(bbddMongoDB);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MongoDatabase getMongoDatabase() {
|
||||||
|
return mongoDBDatabase;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,39 @@
|
|||||||
|
/**
|
||||||
|
* GestorFicheroConfiguracion: clase utilitaria para leer propiedades del archivo application.properties.
|
||||||
|
* Provee un método estático que devuelve el valor asociado a una clave.
|
||||||
|
*
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 25 nov 2025
|
||||||
|
*/
|
||||||
|
package es.palomafp.aadd.inm.gestor;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
public class GestorFicheroConfiguracion {
|
||||||
|
private static final Properties PROPIEDADES = new Properties();
|
||||||
|
|
||||||
|
static {
|
||||||
|
try (InputStream is = GestorFicheroConfiguracion.class.getClassLoader()
|
||||||
|
.getResourceAsStream("conf.properties")) {
|
||||||
|
if (is != null) {
|
||||||
|
PROPIEDADES.load(is);
|
||||||
|
} else {
|
||||||
|
throw new IllegalStateException("No se encontró application.properties en el classpath");
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new IllegalStateException("Error al cargar application.properties", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtiene el valor asociado a la clave especificada.
|
||||||
|
*
|
||||||
|
* @param clave la clave a buscar
|
||||||
|
* @return el valor o {@code null} si no existe
|
||||||
|
*/
|
||||||
|
public static String obtenerValor(String clave) {
|
||||||
|
return PROPIEDADES.getProperty(clave);
|
||||||
|
}
|
||||||
|
}
|
||||||
38
src/main/java/es/palomafp/aadd/inm/vo/Continente.java
Normal file
38
src/main/java/es/palomafp/aadd/inm/vo/Continente.java
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
package es.palomafp.aadd.inm.vo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Continente: Clase que se usa para mapear la tabla de continentes
|
||||||
|
*
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 5 dic 2025
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class Continente {
|
||||||
|
private String codigo;
|
||||||
|
|
||||||
|
private String nombreContinente;
|
||||||
|
|
||||||
|
public String getCodigo() {
|
||||||
|
return codigo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCodigo(String codigo) {
|
||||||
|
this.codigo = codigo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNombreContinente() {
|
||||||
|
return nombreContinente;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNombreContinente(String nombreContinente) {
|
||||||
|
this.nombreContinente = nombreContinente;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Continente [codigo=" + codigo + ", nombreContinente=" + nombreContinente + "]\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
58
src/main/java/es/palomafp/aadd/inm/vo/Pais.java
Normal file
58
src/main/java/es/palomafp/aadd/inm/vo/Pais.java
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
package es.palomafp.aadd.inm.vo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Continente: Clase que se usa para mapear la tabla de Países
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 5 dic 2025
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class Pais {
|
||||||
|
private int identificador;
|
||||||
|
|
||||||
|
private String nombrePais;
|
||||||
|
|
||||||
|
private String capital;
|
||||||
|
|
||||||
|
private Continente continente;
|
||||||
|
|
||||||
|
public int getIdentificador() {
|
||||||
|
return identificador;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIdentificador(int identificador) {
|
||||||
|
this.identificador = identificador;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNombrePais() {
|
||||||
|
return nombrePais;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNombrePais(String nombrePais) {
|
||||||
|
this.nombrePais = nombrePais;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCapital() {
|
||||||
|
return capital;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCapital(String capital) {
|
||||||
|
this.capital = capital;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Continente getContinente() {
|
||||||
|
return continente;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContinente(Continente continente) {
|
||||||
|
this.continente = continente;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Pais [identificador=" + identificador + ", nombrePais=" + nombrePais + ", capital=" + capital
|
||||||
|
+ ", continente=" + continente + "]\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
2
src/main/resources/conf.properties
Normal file
2
src/main/resources/conf.properties
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
url.conexion.mongodb=mongodb://localhost:27017
|
||||||
|
bbdd.mongodb=MapaMundi
|
||||||
Loading…
Reference in New Issue
Block a user