Skip to content

Commit

Permalink
fourth
Browse files Browse the repository at this point in the history
  • Loading branch information
Bael committed Nov 27, 2011
1 parent 0e28dcf commit 0d2ed19
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 15 deletions.
Binary file modified bin/core/DataWorker.class
Binary file not shown.
Binary file modified bin/core/Persistent.class
Binary file not shown.
13 changes: 13 additions & 0 deletions src/Core/Persistent.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,18 @@ public void Save()
e.printStackTrace();
}
}


public Persistent LoadData()
{
Persistent p = null;
try {
p = DataWorker.Instance().LoadObjectById(this.Id, this);
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return p;
}

}
37 changes: 22 additions & 15 deletions src/core/DataWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class DataWorker {

private static DataWorker dataWorker;
private LogWriter log;
private Connection connection;
public static DataWorker Instance()
{
if (dataWorker == null)
Expand All @@ -34,14 +35,17 @@ public static DataWorker Init()
DataWorker worker = new DataWorker();
worker.log = new LogWriter();
worker.log.FileName = "c:\\temp\\javaLog.txt";

worker.connection = ConnectionManager.Instance().getConnection();

return worker;
}
public void UpdateIndicesOnCreate(Persistent obj)
{

}

public void UpdateIndicesOnUpdate(Persistent obj)
public void UpdateIndicesOnUpdate(Persistent oldObj, Persistent obj)
{

}
Expand Down Expand Up @@ -148,21 +152,19 @@ public void SetNodeSubscriptField(Field field, Persistent obj, NodeReference nod

public Persistent SaveObject(Persistent obj) throws IllegalAccessException
{

NodeReference node = null;
try
{
Connection conn = ConnectionManager.Instance().getConnection();
String globalName = obj.GetStorageGlobalName();
node = conn.createNodeReference(globalName);
node = connection.createNodeReference(globalName);
}
catch (Exception ex)
{
log.WriteToFile(ex.toString(), true);
throw ex;
}


Persistent oldObj = null;
if (obj.Id == 0)
{
node.increment(1);
Expand All @@ -171,8 +173,10 @@ public Persistent SaveObject(Persistent obj) throws IllegalAccessException
}
else
{
oldObj = LoadObjectById(obj.Id, obj);
//node.setSubscriptCount(0);
node.appendSubscript(obj.Id);
//znode .setSubscriptCount((int)obj.Id);
//node.appendSubscript(obj.Id);
}

Class info = obj.getClass();
Expand All @@ -184,8 +188,14 @@ public Persistent SaveObject(Persistent obj) throws IllegalAccessException
field = fields[i];
SetNodeSubscriptField(field, obj, node);
}

UpdateIndicesOnCreate(obj);
if (oldObj == null)
{
UpdateIndicesOnCreate(obj);
}
else
{
UpdateIndicesOnUpdate(oldObj, obj);
}
return obj;
}

Expand All @@ -197,16 +207,16 @@ public void DeleteObjectById(Long id, String globalName)

public Persistent LoadObjectById(Long id, Persistent obj) throws IllegalAccessException
{
NodeReference node = ConnectionManager.Instance().getConnection().createNodeReference(obj.GetStorageGlobalName());
NodeReference node = connection.createNodeReference(obj.GetStorageGlobalName());

InitSchema(obj);

node.setSubscriptCount(0);
node.appendSubscript(id);
Field field;
String subscript = "";
Object nodeValue = null;
do {
Object nodeValue = null;
do {
subscript = node.nextSubscript(subscript);
if (subscript.length() > 0)
{
Expand All @@ -232,7 +242,7 @@ public Persistent LoadObjectById(Long id, Persistent obj) throws IllegalAccessEx
}
}
}
} while (subscript.length() > 0);
}while (subscript.length() > 0);


return obj;
Expand All @@ -250,9 +260,6 @@ private void InitSchema(Object obj)
SchemaClassName = classInfo.getName();
Field[] fields = classInfo.getFields();


///System.out.println("Step7");
///System.out.println("Access all the fields");
for (int i = 0; i < fields.length; i++)
{
fieldsMap.put(fields[i].getName(), fields[i]);
Expand Down

0 comments on commit 0d2ed19

Please sign in to comment.