Skip to content

Commit

Permalink
Work around applyed to handle differents in storagetype for orientdb …
Browse files Browse the repository at this point in the history
…version < 2.0
  • Loading branch information
GoorMoon committed Jan 23, 2015
1 parent 8552493 commit 72b9244
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 20 deletions.
19 changes: 15 additions & 4 deletions src/Orient/Orient.Client/API/OServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ public bool ConfigSet(string configKey, string configValue)

#endregion

public Dictionary<string, string> Databases()
public Dictionary<string, ODatabaseInfo> Databases()
{
Dictionary<string, string> returnValue = new Dictionary<string, string>();
Dictionary<string, ODatabaseInfo> returnValue = new Dictionary<string, ODatabaseInfo>();
DBList operation = new DBList(null);
ODocument document = _connection.ExecuteOperation(operation);
if (OClient.Serializer == ORecordFormat.ORecordDocument2csv)
Expand All @@ -87,15 +87,26 @@ public bool ConfigSet(string configKey, string configValue)
foreach (var item in databases)
{
string[] keyValue = item.Split(new char[] { ':' }, 2);
returnValue.Add(keyValue[0].Replace("\"", ""), keyValue[1].Replace("\"", ""));
var info = new ODatabaseInfo();
OStorageType storageType;

Enum.TryParse<OStorageType>(keyValue[1].Replace("\"", "").Split(':')[0], true, out storageType);
info.DataBaseName = keyValue[0].Replace("\"", "");
info.StorageType = storageType;
info.Path = keyValue[1].Replace("\"", "").Split(':')[1];
returnValue.Add(info.DataBaseName, info);
//returnValue.Add(keyValue[0].Replace("\"", ""), keyValue[1].Replace("\"", ""));
}
}
else
{
var databases = document.GetField<Dictionary<string, object>>("databases");
foreach (var item in databases)
{
returnValue.Add(item.Key, item.Value.ToString());
var info = new ODatabaseInfo();
info.DataBaseName = item.Key;
info.Path = item.Value.ToString();
returnValue.Add(info.DataBaseName, info);
}
}
return returnValue;
Expand Down
14 changes: 14 additions & 0 deletions src/Orient/Orient.Client/API/Types/DatabaseInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Orient.Client.API.Types
{
public class ODatabaseInfo
{
public string DataBaseName { get; set; }
public OStorageType StorageType { get; set; }
public string Path { get; set; }
}
}
1 change: 1 addition & 0 deletions src/Orient/Orient.Client/Orient.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<Compile Include="API\Query\OSqlCreateProperty.cs" />
<Compile Include="API\Query\OSqlDeleteCluster.cs" />
<Compile Include="API\Query\OSqlSchema.cs" />
<Compile Include="API\Types\DatabaseInfo.cs" />
<Compile Include="API\Types\IBaseRecord.cs" />
<Compile Include="API\Types\OBaseRecord.cs" />
<Compile Include="API\Types\OEdge.cs" />
Expand Down
9 changes: 9 additions & 0 deletions src/Orient/Orient.Client/Protocol/Operations/BaseOperation.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using Orient.Client.Protocol.Serializers;

Expand All @@ -24,5 +26,12 @@ public IRecordSerializer Serializer

public abstract Request Request(Request request);

protected bool EndOfStream(BinaryReader reader)
{
BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic;
var length = (Int32)typeof(BufferedStream).GetField("_readLen", flags).GetValue(reader.BaseStream);
var pos = (Int32)typeof(BufferedStream).GetField("_readPos", flags).GetValue(reader.BaseStream);
return length == pos;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ class CommitTransaction : BaseOperation
private List<TransactionRecord> _records;

public CommitTransaction(List<TransactionRecord> records, ODatabase database)
:base(database)
: base(database)
{
_records = records;
// _database = database;
// _database = database;
}

public override Request Request(Request request)
Expand Down Expand Up @@ -88,8 +88,9 @@ public override ODocument Response(Response response)
updateRecordVersions.Add(orid, newVersion);
}
responseDocument.SetField("UpdatedRecordVersions", updateRecordVersions);

if (_database.ProtocolVersion >= 20)

// Work around differents in storage type < version 2.0
if (_database.ProtocolVersion >= 20 && !EndOfStream(reader))
{
int collectionChanges = reader.ReadInt32EndianAware();
if (collectionChanges > 0)
Expand Down
6 changes: 2 additions & 4 deletions src/Orient/Orient.Client/Protocol/Operations/RecordCreate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ public override ODocument Response(Response response)
_document.OVersion = reader.ReadInt32EndianAware();
}

if (_database.ProtocolVersion >= 20)
//if (_database.ProtocolVersion > 21)
// Work around differents in storage type < version 2.0
if (_database.ProtocolVersion >= 20 && !EndOfStream(reader))
{
int collectionChangesCount = reader.ReadInt32EndianAware();
for (var i = 0; i < collectionChangesCount; i++)
Expand All @@ -96,8 +96,6 @@ public override ODocument Response(Response response)
}
}
return responseDocument;


}

}
Expand Down
3 changes: 2 additions & 1 deletion src/Orient/Orient.Client/Protocol/Operations/RecordUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public override ODocument Response(Response response)

_document.OVersion = reader.ReadInt32EndianAware();

if (_database.ProtocolVersion >= 20)
// Work around differents in storage type < version 2.0
if (_database.ProtocolVersion >= 20 && !EndOfStream(reader))
{
int collectionChangesCount = reader.ReadInt32EndianAware();
for (var i = 0; i < collectionChangesCount; i++)
Expand Down
2 changes: 1 addition & 1 deletion src/Orient/Orient.NUnit/Server/ServerOperationsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void TestDbList()
using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
{
OServer server = TestConnection.GetServer();
Dictionary<string, string> databases = server.Databases();
Dictionary<string, ODatabaseInfo> databases = server.Databases();
Assert.IsTrue(databases.Count > 0);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Orient/Orient.NUnit/TestConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static TestConnection()
GlobalTestDatabaseName = "globalTestDatabaseForNetDriver001";
GlobalTestDatabaseType = ODatabaseType.Graph;
GlobalTestDatabaseAlias = "globalTestDatabaseForNetDriver001Alias";
GlobalTestDatabaseStorageType = OStorageType.Memory;
GlobalTestDatabaseStorageType = OStorageType.PLocal;
}

public static void CreateTestDatabase()
Expand All @@ -42,9 +42,9 @@ public static void DropTestDatabase()
{
try
{
if (_server.DatabaseExist(GlobalTestDatabaseName, OStorageType.Memory))
if (_server.DatabaseExist(GlobalTestDatabaseName, GlobalTestDatabaseStorageType))
{
_server.DropDatabase(GlobalTestDatabaseName, OStorageType.Memory);
_server.DropDatabase(GlobalTestDatabaseName, GlobalTestDatabaseStorageType);
}
break;
}
Expand Down
8 changes: 5 additions & 3 deletions src/Orient/Orient.NUnit/TestConnectionProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class TestConnectionProxy : IDisposable
public static string GlobalTestDatabaseName { get; private set; }
public static ODatabaseType GlobalTestDatabaseType { get; private set; }
public static string GlobalTestDatabaseAlias { get; private set; }
public static OStorageType GlobalTestDatabaseStorageType { get; private set; }

private OServer _server;

Expand All @@ -28,13 +29,14 @@ public TestConnectionProxy(int port)
GlobalTestDatabaseName = "globalTestDatabaseForNetDriver001";
GlobalTestDatabaseType = ODatabaseType.Graph;
GlobalTestDatabaseAlias = "globalTestDatabaseForNetDriver001AliasProxy";
GlobalTestDatabaseStorageType = OStorageType.PLocal;
}

public void CreateTestDatabase()
{
DropTestDatabase();

_server.CreateDatabase(GlobalTestDatabaseName, GlobalTestDatabaseType, OStorageType.Memory);
_server.CreateDatabase(GlobalTestDatabaseName, GlobalTestDatabaseType, GlobalTestDatabaseStorageType);
}

public void DropTestDatabase()
Expand All @@ -44,9 +46,9 @@ public void DropTestDatabase()
{
try
{
if (_server.DatabaseExist(GlobalTestDatabaseName, OStorageType.Memory))
if (_server.DatabaseExist(GlobalTestDatabaseName, GlobalTestDatabaseStorageType))
{
_server.DropDatabase(GlobalTestDatabaseName, OStorageType.Memory);
_server.DropDatabase(GlobalTestDatabaseName, GlobalTestDatabaseStorageType);
}
break;
}
Expand Down

0 comments on commit 72b9244

Please sign in to comment.