Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add type DATE #98

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/earlgrey/core/ModelCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import earlgrey.error.Error70;
import earlgrey.error.Error800;
import earlgrey.types.IType;
import oracle.sql.DATE;

public class ModelCore {
protected ResultSet set;
Expand Down Expand Up @@ -217,6 +218,9 @@ else if(campo.getType().equals(String.class)){
else if(campo.getType().equals(Timestamp.class)){
campo.set(m, set.getString(llave));
}
else if(campo.getType().equals(DATE.class)){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct Sintax

if (Condition) {
// Code
} else if (Condition) {
// Code
} else {
// Code
}

campo.set(m, set.getDate(llave));
}
else if(IType.class.isAssignableFrom(campo.getType())){
try {
Method inv = campo.getType().getMethod("GetSQLResult", Object.class);
Expand Down Expand Up @@ -255,6 +259,9 @@ else if(campo.getType().equals(String.class)){
else if(campo.getType().equals(Timestamp.class)){
campo.set(m, set.getString(llave));
}
else if(campo.getType().equals(DATE.class)){
campo.set(m, set.getDate(llave));
}
else if(IType.class.isAssignableFrom(campo.getType())){
try {
Method inv = campo.getType().getMethod("GetSQLResult", Object.class);
Expand Down Expand Up @@ -324,6 +331,9 @@ else if(campo.getType().equals(String.class)){
else if(campo.getType().equals(Timestamp.class)){
objeto.put(llave, set.getString(llave));
}
else if(campo.getType().equals(DATE.class)){
objeto.put(llave, set.getDate(llave));
}
else if(IType.class.isAssignableFrom(campo.getType())){
try {
Method inv = campo.getType().getMethod("GetSQLResult", Object.class);
Expand Down Expand Up @@ -368,6 +378,9 @@ else if(campo.getType().equals(String.class)){
else if(campo.getType().equals(Timestamp.class)){
objeto.put(llave, set.getString(llave));
}
else if(campo.getType().equals(DATE.class)){
objeto.put(llave, set.getDate(llave));
}
else if(IType.class.isAssignableFrom(campo.getType())){
try {
Method inv = campo.getType().getMethod("GetSQLResult", Object.class);
Expand Down Expand Up @@ -454,6 +467,9 @@ else if(campo.getType().equals(String.class)){
else if(campo.getType().equals(Timestamp.class)){
campo.set(this, query.getString(llave));
}
else if(campo.getType().equals(DATE.class)){
campo.set(this, query.getString(llave));
}
}
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException | JSONException e) {
// TODO Auto-generated catch block
Expand Down Expand Up @@ -588,7 +604,9 @@ private Hashtable<String,Criteria> getparams(JSONObject params) {
campo.set(mc, params.getString(key));
} else if(campo.getType().equals(Timestamp.class)){
campo.set(mc, params.getString(key));
}
} else if(campo.getType().equals(DATE.class)){
campo.set(mc, params.getString(key));
}
else {
continue;
}
Expand Down
32 changes: 26 additions & 6 deletions src/earlgrey/database/OracleConnector.java
Original file line number Diff line number Diff line change
@@ -1,39 +1,35 @@
package earlgrey.database;

import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

import org.json.JSONException;
import org.json.JSONObject;

import earlgrey.annotations.DatabaseDriver;
import earlgrey.core.ConnectionPool;
import earlgrey.core.Logging;
import earlgrey.core.ModelCore;
import earlgrey.core.Properties;
import earlgrey.core.ResourceMaping;
import earlgrey.def.Database;
import earlgrey.error.Error800;
import earlgrey.types.IType;
import earlgrey.types.ObraType;
import oracle.jdbc.OraclePreparedStatement;
import oracle.sql.DATE;

@DatabaseDriver(type="SQL", name="Oracle", id = Database.ORACLE)
public class OracleConnector implements Connector{
Expand Down Expand Up @@ -385,6 +381,14 @@ else if(campo.getType().equals(Timestamp.class)){
e.printStackTrace();
}
}
else if(campo.getType().equals(DATE.class)){
try {
this.pstm.setDATE(this.prepared_fields++, (DATE)prepare_fields.get(campo));
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else if(campo.getType().equals(String.class)){
try {
this.pstm.setString(this.prepared_fields++, (String)prepare_fields.get(campo));
Expand Down Expand Up @@ -451,7 +455,15 @@ else if(campo.getType().equals(Timestamp.class)){
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
else if(campo.getType().equals(DATE.class)){
try {
this.pstm.setDATE(this.prepared_fields++, (DATE)prepare_fields.get(campo));
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Evitar el uso de print stacktrace y codigo try autogenerados
Gestionar el error de mejor forma.

}
}
else if(campo.getType().equals(String.class)){
try {
this.pstm.setString(this.prepared_fields++, "%"+(String)prepare_match_fields.get(campo)+"%");
Expand Down Expand Up @@ -577,6 +589,14 @@ else if(campo.getType().equals(Timestamp.class)){
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else if(campo.getType().equals(DATE.class)){
try {
this.pstm.setDATE(this.prepared_fields++, (DATE)prepare_fields.get(campo));
} catch (SQLException e) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mismo caso, en este caso seria bueno informar al logger de earlgrey que ocurrio

// TODO Auto-generated catch block
e.printStackTrace();
}
}
else if(campo.getType().equals(String.class)){
try {
Expand Down