Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
48 views

Y G Ysdf SDF SDF SF S Aw Fghghjef Esf Sef Fseaefasef F Ef SF F E Fe S F Esf Es Fe Ef Af W Ad WD Awd WD E Q W

This document contains code for a database application that stores book and author information. It defines classes for Author and Book objects, and includes methods to create, read, update and delete data from an embedded database. The main method calls functions to populate the initial database, retrieve book and author data, update a book title, and remove a book.

Uploaded by

haprada
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Y G Ysdf SDF SDF SF S Aw Fghghjef Esf Sef Fseaefasef F Ef SF F E Fe S F Esf Es Fe Ef Af W Ad WD Awd WD E Q W

This document contains code for a database application that stores book and author information. It defines classes for Author and Book objects, and includes methods to create, read, update and delete data from an embedded database. The main method calls functions to populate the initial database, retrieve book and author data, update a book title, and remove a book.

Uploaded by

haprada
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Y

G
Ysdf
Sdf
Sdf
Sf
S

Aw
Fghghjef
Esf
Sef

Fseaefasef
F
Ef
Sf
F
E
Fe
S
F
Esf
Es

fe
Ef
Af
W

Ad
Wd
Awd
Wd

E
Q
W
R
E
4
R
4

Gh
Mh
Mh
M
M
Gm
M
G
Mg

Fh
F
H
F

D
G
D
Gd
Gd
r
A
W
dad
Yg
9g
99asdf
Sadfcassdf
As
Fzxvzxvzv
Zv
Zv
Z
Xv
Zv
Zv
V
Z
vz
Sadasdf
As
Df
Asf
Asf
saf
Fds
Af
dasf

Sds
Af
das
gpackage mibase;
asdf
asdfQWERqas
sad
f
asfdas
fas
fsaf
sf
safsf
as
dsfa
sf
asdf
saf
sa
f
f
sad
f
QW
RQR
QWERasf
Asf
As
Fas
F
Asf
As
fa
Q
RWQR
WR
Q
REW
a
sfd

dasfd
af
as
fas
3
33
232
f
dcsa
/**
*asfa
Fa
Fas
Fa
Sf
as
* @author avemar71asdf
Asf

Asdf
Ds
Fd
Sfds
Af
Sdaf
Safas
Fd
assa
*/

import com.db4o.*;

public class MiBase {


ds
as
fa
sdfa
f
af
a
fsa
dfas
df
dsf
sf
sf
da
fa

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
ObjectContainer db = Db4o.openFile("C:\\baseDB40\\base.yap");
//crearBD(db);
consultarLibros(db);
//consultarAutor(db,"Carlos Sánchez Vera");
//consultarLibrosAutor(db,"Alvaro Vega Díaz");
//actualizar(db);
eliminar(db);
consultarLibros(db);
db.close();
}

private static void crearBD(ObjectContainer base){


Libro l1 = new Libro("Libro a");
Libro l2 = new Libro("Libro b");
Libro l3 = new Libro("Libro c");
Libro l4 = new Libro("Libro d");
Libro l5 = new Libro("Libro e");
Libro l6 = new Libro("Libro f");
Libro l7 = new Libro("Libro g");
Libro l8 = new Libro("Libro h");

Autor a1 = new Autor("Carlos Sánchez Vera","Bogotá");


Autor a2 = new Autor("Alvaro Vega Díaz","Caracas");

a1.addLibro(l1); l1.setAutor(a1);
a1.addLibro(l2); l2.setAutor(a1);
a1.addLibro(l3); l3.setAutor(a1);
a1.addLibro(l4); l4.setAutor(a1);
a2.addLibro(l5); l5.setAutor(a2);
a2.addLibro(l6); l6.setAutor(a2);
a2.addLibro(l7); l7.setAutor(a2);
a2.addLibro(l8); l8.setAutor(a2);

base.set(a1);
base.set(a2);

}
private static void consultarLibros(ObjectContainer base){
Libro l = new Libro(null);
ObjectSet result = base.get(l);

System.out.println("Tengo "+result.size()+" libros");


while (result.hasNext()){
System.out.println(result.next());
}
}

private static void consultarAutor (ObjectContainer base, String nombre) {


Autor a = new Autor(nombre,null);
ObjectSet result = base.get(a);
System.out.println("Tengo "+result.size()+" coincidencias");
while (result.hasNext()){
System.out.println(result.next());
}
}

private static void consultarLibrosAutor(ObjectContainer base, String


nombre){
Autor a = new Autor(nombre,null);
Libro l = new Libro(null, a);
ObjectSet result = base.get(l);

System.out.println("Tengo "+result.size()+" libros del


autor"+a.getNombre());
while (result.hasNext()){
System.out.println(result.next());
}
}

private static void actualizar(ObjectContainer base) {


Libro l = new Libro("Libro a");
ObjectSet result = base.get(l);
Libro lb = (Libro) result.next();
lb.setTitulo("Libro Nuevo A");
base.set(lb);
}

private static void eliminar(ObjectContainer base) {


Libro l = new Libro("Libro Nuevo A");
ObjectSet result = base.get(l);
Libro lb = (Libro) result.next();
base.delete(lb);
}
}

package mibase;

/**
*
* @author avemar71
*/

import java.util.List;
import java.util.ArrayList;

public class Autor {


private String nombre;
private String ciudad;
private List libros;
public Autor (String nombre, String ciudad) {
this.nombre = nombre;
this.ciudad = ciudad;
this.libros = new ArrayList();
}

public void addLibro (Libro l){


libros.add(l);
}

public void setNombre (String n){


this.nombre = n;
}

public String getNombre (){


return this.nombre;
}
public void setCiudad (String c){
this.ciudad = c;
}

public String getCiudad (){


return this.ciudad;
}

public void setLibros (List l){


libros = l;
}

public List getLibros(){


return libros;
}

public String toString(){


return nombre+" de la ciudad de "+ciudad;
}
}
package mibase;

/**
* @author avemar71
*/
public class Libro {
protected String titulo;
protected Autor autor;

public Libro (String titulo) {


this.titulo = titulo;
}

public Libro (String titulo, Autor autor) {


this.titulo = titulo;
this.autor = autor;
}

public void setTitulo (String t) {


this.titulo = t;
}

public String getTitulo () {


return this.titulo;
}

public void setAutor (Autor a) {


this.autor = a;
}

public Autor getAutor () {


return this.autor;
}

public String toString() {


return titulo + ", "+this.autor.getNombre();
}
}

You might also like