Update of /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/sql/entities
In directory sc8-pr-cvs1:/tmp/cvs-serv2763/src/java/org/neuclear/commons/sql/entities
Modified Files:
DataColumnDefinition.java Entity.java EntityModel.java
Added Files:
Schema.java
Log Message:
Mainly fixes to SQLLedger to support the schema generated by the new EntityModel
--- NEW FILE: Schema.java ---
package org.neuclear.commons.sql.entities;
/*
NeuClear Distributed Transaction Clearing Platform
(C) 2003 Pelle Braendgaard
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
$Id: Schema.java,v 1.1 2003/12/26 22:51:17 pelle Exp $
$Log: Schema.java,v $
Revision 1.1 2003/12/26 22:51:17 pelle
Mainly fixes to SQLLedger to support the schema generated by the new EntityModel
*/
/**
* User: pelleb
* Date: Dec 26, 2003
* Time: 3:21:10 PM
*/
public class Schema {
}
Index: DataColumnDefinition.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/sql/entities/DataColumnDefinition.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** DataColumnDefinition.java 24 Dec 2003 00:25:40 -0000 1.1
--- DataColumnDefinition.java 26 Dec 2003 22:51:17 -0000 1.2
***************
*** 21,24 ****
--- 21,27 ----
$Id$
$Log$
+ Revision 1.2 2003/12/26 22:51:17 pelle
+ Mainly fixes to SQLLedger to support the schema generated by the new EntityModel
+
Revision 1.1 2003/12/24 00:25:40 pelle
Created a kind of poor man's version of ofbiz.org's EntityEngine. It doesnt use xml to configure it, but code.
***************
*** 54,58 ****
return "TIMESTAMP";
case FIELD_ID:
! return "BIGINT";
case FIELD_BOOLEAN:
return "TINYINT";
--- 57,61 ----
return "TIMESTAMP";
case FIELD_ID:
! return "IDENTITY";
case FIELD_BOOLEAN:
return "TINYINT";
Index: Entity.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/sql/entities/Entity.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Entity.java 24 Dec 2003 00:25:40 -0000 1.1
--- Entity.java 26 Dec 2003 22:51:17 -0000 1.2
***************
*** 21,24 ****
--- 21,27 ----
$Id$
$Log$
+ Revision 1.2 2003/12/26 22:51:17 pelle
+ Mainly fixes to SQLLedger to support the schema generated by the new EntityModel
+
Revision 1.1 2003/12/24 00:25:40 pelle
Created a kind of poor man's version of ofbiz.org's EntityEngine. It doesnt use xml to configure it, but code.
***************
*** 36,40 ****
*/
public class Entity {
! public Entity(EntityModel model,String id,Object[] data) {
this.model = model;
this.data=data;
--- 39,43 ----
*/
public class Entity {
! Entity(EntityModel model,String id,Object[] data) {
this.model = model;
this.data=data;
Index: EntityModel.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-commons/src/java/org/neuclear/commons/sql/entities/EntityModel.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** EntityModel.java 24 Dec 2003 00:25:40 -0000 1.1
--- EntityModel.java 26 Dec 2003 22:51:17 -0000 1.2
***************
*** 27,30 ****
--- 27,33 ----
$Id$
$Log$
+ Revision 1.2 2003/12/26 22:51:17 pelle
+ Mainly fixes to SQLLedger to support the schema generated by the new EntityModel
+
Revision 1.1 2003/12/24 00:25:40 pelle
Created a kind of poor man's version of ofbiz.org's EntityEngine. It doesnt use xml to configure it, but code.
***************
*** 47,50 ****
--- 50,54 ----
foreign=new LinkedList();
this.name=name;
+ this.uri=uri;
id=new DataColumnDefinition(this,idname,uri?ColumnDefinition.FIELD_URI:ColumnDefinition.FIELD_ID);
addColumn(id);
***************
*** 53,57 ****
this(name,"id",uri);
}
! public final void create(Connection con){
//first lets build all the Dependencies
for (int i = 0; i < foreign.size(); i++) {
--- 57,61 ----
this(name,"id",uri);
}
! public synchronized final void create(Connection con){
//first lets build all the Dependencies
for (int i = 0; i < foreign.size(); i++) {
***************
*** 59,68 ****
definition.getRef().create(con);
}
- System.out.println("Attempting to create: "+getName());
try {
PreparedStatement stmt=con.prepareStatement(createDDL());
stmt.execute();
} catch (SQLException e) {
! System.out.println(e.getLocalizedMessage());
}
}
--- 63,73 ----
definition.getRef().create(con);
}
try {
PreparedStatement stmt=con.prepareStatement(createDDL());
stmt.execute();
+ System.out.println("Created: "+getName());
} catch (SQLException e) {
! if (e.getMessage().indexOf("exists")==-1)
! System.out.println(e.getLocalizedMessage());
}
}
***************
*** 72,84 ****
buf.append(" (\n");
Iterator iter=colseq.iterator();
while(iter.hasNext()) {
ColumnDefinition col=(ColumnDefinition)iter.next();
buf.append(col.createDDL());
- buf.append(",\n");
}
iter=foreign.iterator();
while(iter.hasNext()) {
ReferenceDefinition col=(ReferenceDefinition)iter.next();
! buf.append("FOREIGN KEY (");
buf.append(col.getName());
buf.append(") REFERENCES ");
--- 77,94 ----
buf.append(" (\n");
Iterator iter=colseq.iterator();
+ boolean first=true;
while(iter.hasNext()) {
+ if (first)
+ first=false;
+ else
+ buf.append(",\n");
+
ColumnDefinition col=(ColumnDefinition)iter.next();
buf.append(col.createDDL());
}
iter=foreign.iterator();
while(iter.hasNext()) {
ReferenceDefinition col=(ReferenceDefinition)iter.next();
! buf.append(",\nFOREIGN KEY (");
buf.append(col.getName());
buf.append(") REFERENCES ");
***************
*** 86,90 ****
buf.append("(");
buf.append(col.getRef().getId().getName());
! buf.append(") ON DELETE CASCADE,\n");
// buf.append("INDEX ");
// buf.append(col.getName());
--- 96,100 ----
buf.append("(");
buf.append(col.getRef().getId().getName());
! buf.append(") ON DELETE CASCADE");
// buf.append("INDEX ");
// buf.append(col.getName());
***************
*** 93,99 ****
// buf.append("),\n");
}
! buf.append("PRIMARY KEY(");
! buf.append(id.getName());
! buf.append(")\n)");
return buf.toString();
}
--- 103,112 ----
// buf.append("),\n");
}
! if (uri){
! buf.append(",\nPRIMARY KEY(");
! buf.append(id.getName());
! buf.append(")");
! }
! buf.append("\n)");
return buf.toString();
}
***************
*** 158,162 ****
return id;
}
! final Entity insertEntity(Connection con,Object data[]) throws SQLException {
if ((data.length%2==1))//&&(data.length/2<columns.size()))
throw new SQLException("Incorrect amount of parameters");
--- 171,175 ----
return id;
}
! public final Entity insertEntity(Connection con,Object data[]) throws SQLException {
if ((data.length%2==1))//&&(data.length/2<columns.size()))
throw new SQLException("Incorrect amount of parameters");
***************
*** 221,224 ****
--- 234,238 ----
private final List foreign;
private final String name;
+ private final boolean uri;
}
|