You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by pr...@apache.org on 2012/08/31 20:54:01 UTC
[2/6] Moved Awsapi (EC2/S3) from Hibernate framework to CloudStack
Generic Dao Framework
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/model/SMetaVO.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/model/SMetaVO.java b/awsapi/src/com/cloud/bridge/model/SMetaVO.java
new file mode 100644
index 0000000..537310f
--- /dev/null
+++ b/awsapi/src/com/cloud/bridge/model/SMetaVO.java
@@ -0,0 +1,112 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.bridge.model;
+
+import java.io.Serializable;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name="meta")
+public class SMetaVO implements Serializable {
+ private static final long serialVersionUID = 7459503272337054283L;
+
+ @Id
+ @GeneratedValue(strategy=GenerationType.IDENTITY)
+ @Column(name="ID")
+ private Long id;
+
+ @Column(name="Target")
+ private String target;
+
+ @Column(name="TargetID")
+ private long targetId;
+
+ @Column(name="Name")
+ private String name;
+
+ @Column(name="Value")
+ private String value;
+
+ public SMetaVO() {}
+
+ public Long getId() {
+ return id;
+ }
+
+ private void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getTarget() {
+ return target;
+ }
+
+ public void setTarget(String target) {
+ this.target = target;
+ }
+
+ public long getTargetId() {
+ return targetId;
+ }
+
+ public void setTargetId(long targetId) {
+ this.targetId = targetId;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if(this == other)
+ return true;
+
+ if(!(other instanceof SMetaVO))
+ return false;
+
+ return getTarget().equals(((SMetaVO)other).getTarget()) && getTargetId() == ((SMetaVO)other).getTargetId()
+ && getName().equals(((SMetaVO)other).getName());
+ }
+
+ @Override
+ public int hashCode() {
+ int hashCode = 0;
+ hashCode = hashCode*17 + getTarget().hashCode();
+ hashCode = hashCode*17 + (int)getTargetId();
+ hashCode = hashCode*17 + getName().hashCode();
+ return hashCode;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/model/SObject.hbm.xml
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/model/SObject.hbm.xml b/awsapi/src/com/cloud/bridge/model/SObject.hbm.xml
deleted file mode 100644
index 3929bcd..0000000
--- a/awsapi/src/com/cloud/bridge/model/SObject.hbm.xml
+++ /dev/null
@@ -1,59 +0,0 @@
-<?xml version="1.0"?>
-<!--
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied. See the License for the
-specific language governing permissions and limitations
-under the License.
--->
-<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
-
-<hibernate-mapping>
- <class name="com.cloud.bridge.model.SObject" table="sobject" lazy="true">
- <id name="id" type="long" column="ID" >
- <generator class="native" />
- </id>
-
- <property name="nameKey">
- <column name="NameKey" />
- </property>
-
- <property name="ownerCanonicalId">
- <column name="OwnerCanonicalId" />
- </property>
-
- <property name="nextSequence">
- <column name="NextSequence" />
- </property>
-
- <property name="deletionMark">
- <column name="DeletionMark" />
- </property>
-
- <property name="createTime" type="com.cloud.bridge.persist.GMTDateTimeUserType">
- <column name="CreateTime" />
- </property>
-
- <many-to-one name="bucket" column="SBucketID"
- class="com.cloud.bridge.model.SBucket"
- cascade="none"
- />
-
- <set name="items" inverse="true" lazy="true" cascade="all-delete-orphan">
- <key column="SObjectID" />
- <one-to-many class="com.cloud.bridge.model.SObjectItem" />
- </set>
- </class>
-</hibernate-mapping>
-
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/model/SObject.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/model/SObject.java b/awsapi/src/com/cloud/bridge/model/SObject.java
deleted file mode 100644
index 1692b68..0000000
--- a/awsapi/src/com/cloud/bridge/model/SObject.java
+++ /dev/null
@@ -1,206 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.bridge.model;
-
-import java.io.Serializable;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-public class SObject implements Serializable {
- private static final long serialVersionUID = 8566744941395660486L;
-
- private Long id;
-
- private String nameKey;
- private String ownerCanonicalId;
-
- private int nextSequence;
- private String deletionMark; // This must also a unique ID to give to the REST client
-
- private Date createTime;
-
- private SBucket bucket;
-
- private Set<SObjectItem> items = new HashSet<SObjectItem>();
-
- public SObject() {
- deletionMark = null;
- }
-
- public Long getId() {
- return id;
- }
-
- private void setId(Long id) {
- this.id = id;
- }
-
- public String getNameKey() {
- return nameKey;
- }
-
- public void setNameKey(String nameKey) {
- this.nameKey = nameKey;
- }
-
- public String getOwnerCanonicalId() {
- return ownerCanonicalId;
- }
-
- public void setOwnerCanonicalId(String ownerCanonicalId) {
- this.ownerCanonicalId = ownerCanonicalId;
- }
-
- public int getNextSequence() {
- return nextSequence;
- }
-
- public void setNextSequence(int nextSequence) {
- this.nextSequence = nextSequence;
- }
-
- public String getDeletionMark() {
- return deletionMark;
- }
-
- public void setDeletionMark(String deletionMark) {
- this.deletionMark = deletionMark;
- }
-
- public Date getCreateTime() {
- return createTime;
- }
-
- public void setCreateTime(Date createTime) {
- this.createTime = createTime;
- }
-
- public SBucket getBucket() {
- return bucket;
- }
-
- public void setBucket(SBucket bucket) {
- this.bucket = bucket;
- }
-
- public Set<SObjectItem> getItems() {
- return items;
- }
-
- public void setItems(Set<SObjectItem> items) {
- this.items = items;
- }
-
- public void deleteItem( long id ) {
- Iterator<SObjectItem> it = getItems().iterator();
-
- while( it.hasNext())
- {
- SObjectItem oneItem = it.next();
- if (id == oneItem.getId()) {
- boolean bRemoved = items.remove( oneItem );
- System.out.println( "deleteItem from sobject: " + bRemoved );
- return;
- }
- }
- }
-
- public SObjectItem getLatestVersion( boolean versioningOff ) {
- Iterator<SObjectItem> it = getItems().iterator();
- int maxVersion = 0;
- int curVersion = 0;
- SObjectItem latestItem = null;
-
- while( it.hasNext())
- {
- SObjectItem item = it.next();
-
- // If versioning is off then return the item with the null version string (if exists)
- // For example, the bucket could have allowed versioning and then it was suspended
- // If an application wants a specific version it will need to explicitly ask for it
- try {
- String version = item.getVersion();
- if (versioningOff && null == version) {
- return item;
- }
- curVersion = Integer.parseInt( version );
-
- } catch (NumberFormatException e) {
- curVersion = 0;
- }
-
- if(curVersion >= maxVersion) {
- maxVersion = curVersion;
- latestItem = item;
- }
- }
- return latestItem;
- }
-
- /**
- * S3 versioning allows the client to request the return of a specific version,
- * not just the last version.
- *
- * @param wantVersion
- * @return
- */
- public SObjectItem getVersion( String wantVersion )
- {
- Iterator<SObjectItem> it = getItems().iterator();
- while( it.hasNext())
- {
- SObjectItem item = it.next();
- String curVersion = item.getVersion();
- if (null != curVersion && wantVersion.equalsIgnoreCase( curVersion )) return item;
- }
- return null;
- }
-
- @Override
- public boolean equals(Object other) {
- if(this == other)
- return true;
-
- if(!(other instanceof SObject))
- return false;
-
- if(!getNameKey().equals(((SObject)other).getNameKey()))
- return false;
-
- if(getBucket() != null) {
- if(!getBucket().equals(((SObject)other).getBucket()))
- return false;
- } else {
- if(((SObject)other).getBucket() != null)
- return false;
- }
-
- return true;
- }
-
- @Override
- public int hashCode() {
- int hashCode = 0;
- hashCode = hashCode*17 + getNameKey().hashCode();
-
- if(getBucket() != null)
- hashCode = hashCode*17 + getBucket().hashCode();
- return hashCode;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/model/SObjectItem.hbm.xml
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/model/SObjectItem.hbm.xml b/awsapi/src/com/cloud/bridge/model/SObjectItem.hbm.xml
deleted file mode 100644
index 02297a2..0000000
--- a/awsapi/src/com/cloud/bridge/model/SObjectItem.hbm.xml
+++ /dev/null
@@ -1,62 +0,0 @@
-<?xml version="1.0"?>
-<!--
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied. See the License for the
-specific language governing permissions and limitations
-under the License.
--->
-<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
-
-<hibernate-mapping>
- <class name="com.cloud.bridge.model.SObjectItem" table="sobject_item" lazy="true">
- <id name="id" type="long" column="ID" >
- <generator class="native" />
- </id>
-
- <property name="version">
- <column name="Version" />
- </property>
-
- <property name="md5">
- <column name="MD5" />
- </property>
-
- <property name="storedPath">
- <column name="StoredPath" />
- </property>
-
- <property name="storedSize">
- <column name="StoredSize" />
- </property>
-
- <property name="createTime" type="com.cloud.bridge.persist.GMTDateTimeUserType">
- <column name="CreateTime" />
- </property>
-
- <property name="lastModifiedTime" type="com.cloud.bridge.persist.GMTDateTimeUserType">
- <column name="LastModifiedTime" />
- </property>
-
- <property name="lastAccessTime" type="com.cloud.bridge.persist.GMTDateTimeUserType">
- <column name="LastAccessTime" />
- </property>
-
- <many-to-one name="theObject" column="SObjectID"
- class="com.cloud.bridge.model.SObject"
- cascade="none"
- />
- </class>
-</hibernate-mapping>
-
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/model/SObjectItem.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/model/SObjectItem.java b/awsapi/src/com/cloud/bridge/model/SObjectItem.java
deleted file mode 100644
index bbff267..0000000
--- a/awsapi/src/com/cloud/bridge/model/SObjectItem.java
+++ /dev/null
@@ -1,149 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.bridge.model;
-
-import java.io.Serializable;
-import java.util.Date;
-
-public class SObjectItem implements Serializable {
- private static final long serialVersionUID = -7351173256185687851L;
-
- private Long id;
-
- private SObject theObject;
- private String version;
- private String md5;
- private String storedPath;
- private long storedSize;
-
- private Date createTime;
- private Date lastModifiedTime;
- private Date lastAccessTime;
-
- public SObjectItem() {
- }
-
- public Long getId() {
- return id;
- }
-
- private void setId(Long id) {
- this.id = id;
- }
-
- public SObject getTheObject() {
- return theObject;
- }
-
- public void setTheObject(SObject theObject) {
- this.theObject = theObject;
- }
-
- public String getVersion() {
- return version;
- }
-
- public void setVersion(String version) {
- this.version = version;
- }
-
- public String getMd5() {
- return md5;
- }
-
- public void setMd5(String md5) {
- this.md5 = md5;
- }
-
- public String getStoredPath() {
- return storedPath;
- }
-
- public void setStoredPath(String storedPath) {
- this.storedPath = storedPath; // TODO - storedpath holds integer, called from S3Engine.allocObjectItem
- }
-
- public long getStoredSize() {
- return storedSize;
- }
-
- public void setStoredSize(long storedSize) {
- this.storedSize = storedSize;
- }
-
- public Date getCreateTime() {
- return createTime;
- }
-
- public void setCreateTime(Date createTime) {
- this.createTime = createTime;
- }
-
- public Date getLastModifiedTime() {
- return lastModifiedTime;
- }
-
- public void setLastModifiedTime(Date lastModifiedTime) {
- this.lastModifiedTime = lastModifiedTime;
- }
-
- public Date getLastAccessTime() {
- return lastAccessTime;
- }
-
- public void setLastAccessTime(Date lastAccessTime) {
- this.lastAccessTime = lastAccessTime;
- }
-
- @Override
- public boolean equals(Object other) {
- if(this == other)
- return true;
-
- if(!(other instanceof SObjectItem))
- return false;
-
- if(version != null) {
- if(!version.equals(((SObjectItem)other).getVersion()))
- return false;
- } else {
- if(((SObjectItem)other).getVersion() != null)
- return false;
- }
-
- if(theObject.getId() != null) {
- if(!theObject.getId().equals(((SObjectItem)other).getTheObject()))
- return false;
- } else {
- if(((SObjectItem)other).getTheObject() != null)
- return false;
- }
- return true;
- }
-
- @Override
- public int hashCode() {
- int hashCode = 0;
- if(version != null)
- hashCode = hashCode*17 + version.hashCode();
-
- if(theObject != null)
- hashCode = hashCode*17 + theObject.hashCode();
-
- return hashCode;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/model/SObjectItemVO.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/model/SObjectItemVO.java b/awsapi/src/com/cloud/bridge/model/SObjectItemVO.java
new file mode 100644
index 0000000..8d86103
--- /dev/null
+++ b/awsapi/src/com/cloud/bridge/model/SObjectItemVO.java
@@ -0,0 +1,191 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.bridge.model;
+
+import java.io.Serializable;
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import javax.persistence.Transient;
+
+@Entity
+@Table(name="sobject_item")
+public class SObjectItemVO {
+ private static final long serialVersionUID = -7351173256185687851L;
+
+ @Id
+ @GeneratedValue(strategy=GenerationType.IDENTITY)
+ @Column(name="ID")
+ private Long id;
+
+ @Column(name="SObjectID")
+ private long sObjectID;
+
+ @Column(name="Version")
+ private String version;
+
+ @Column(name="MD5")
+ private String md5;
+
+ @Column(name="StoredPath")
+ private String storedPath;
+
+ @Column(name="StoredSize")
+ private long storedSize;
+
+ @Column(name="CreateTime")
+ @Temporal(value=TemporalType.TIMESTAMP)
+ private Date createTime;
+
+ @Column(name="LastModifiedTime")
+ @Temporal(value=TemporalType.TIMESTAMP)
+ private Date lastModifiedTime;
+
+ @Column(name="LastAccessTime")
+ @Temporal(value=TemporalType.TIMESTAMP)
+ private Date lastAccessTime;
+
+ @Transient
+ private SObjectVO theObject;
+ public SObjectItemVO() {
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ private void setId(Long id) {
+ this.id = id;
+ }
+
+ public SObjectVO getTheObject() {
+ return theObject;
+ }
+
+ public void setTheObject(SObjectVO theObject) {
+ this.theObject = theObject;
+ }
+
+ public long getsObjectID() {
+ return sObjectID;
+ }
+
+ public void setsObjectID(long sObjectID) {
+ this.sObjectID = sObjectID;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
+ public String getMd5() {
+ return md5;
+ }
+
+ public void setMd5(String md5) {
+ this.md5 = md5;
+ }
+
+ public String getStoredPath() {
+ return storedPath;
+ }
+
+ public void setStoredPath(String storedPath) {
+ this.storedPath = storedPath; // TODO - storedpath holds integer, called from S3Engine.allocObjectItem
+ }
+
+ public long getStoredSize() {
+ return storedSize;
+ }
+
+ public void setStoredSize(long storedSize) {
+ this.storedSize = storedSize;
+ }
+
+ public Date getCreateTime() {
+ return createTime;
+ }
+
+ public void setCreateTime(Date createTime) {
+ this.createTime = createTime;
+ }
+
+ public Date getLastModifiedTime() {
+ return lastModifiedTime;
+ }
+
+ public void setLastModifiedTime(Date lastModifiedTime) {
+ this.lastModifiedTime = lastModifiedTime;
+ }
+
+ public Date getLastAccessTime() {
+ return lastAccessTime;
+ }
+
+ public void setLastAccessTime(Date lastAccessTime) {
+ this.lastAccessTime = lastAccessTime;
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if(this == other)
+ return true;
+
+ if(!(other instanceof SObjectItemVO))
+ return false;
+
+ if(version != null) {
+ if(!version.equals(((SObjectItemVO)other).getVersion()))
+ return false;
+ } else {
+ if(((SObjectItemVO)other).getVersion() != null)
+ return false;
+ }
+
+ if(theObject.getId() != null) {
+ if(!theObject.getId().equals(((SObjectItemVO)other).getTheObject()))
+ return false;
+ } else {
+ if(((SObjectItemVO)other).getTheObject() != null)
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int hashCode = 0;
+ if(version != null)
+ hashCode = hashCode*17 + version.hashCode();
+
+ if(theObject != null)
+ hashCode = hashCode*17 + theObject.hashCode();
+
+ return hashCode;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/model/SObjectVO.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/model/SObjectVO.java b/awsapi/src/com/cloud/bridge/model/SObjectVO.java
new file mode 100644
index 0000000..02f576a
--- /dev/null
+++ b/awsapi/src/com/cloud/bridge/model/SObjectVO.java
@@ -0,0 +1,242 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.bridge.model;
+
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import javax.persistence.Transient;
+
+
+@Entity
+@Table(name="sobject")
+public class SObjectVO {
+ //private static final long serialVersionUID = 8566744941395660486L;
+
+ @Id
+ @GeneratedValue(strategy=GenerationType.IDENTITY)
+ @Column(name="ID")
+ private Long id;
+
+ @Column(name="SBucketID")
+ private long bucketID;
+
+ @Column(name="NameKey")
+ private String nameKey;
+
+ @Column(name="OwnerCanonicalID")
+ private String ownerCanonicalId;
+
+ @Column(name="NextSequence")
+ private int nextSequence;
+
+ @Column(name="DeletionMark")
+ private String deletionMark; // This must also a unique ID to give to the REST client
+
+ @Column(name="CreateTime")
+ @Temporal(value=TemporalType.TIMESTAMP)
+ private Date createTime;
+
+ @Transient
+ private SBucket bucket;
+
+ @Transient
+ private Set<SObjectItemVO> items = new HashSet<SObjectItemVO>();
+
+ public SObjectVO() {
+ deletionMark = null;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ private void setId(Long id) {
+ this.id = id;
+ }
+
+ public long getBucketID() {
+ return bucketID;
+ }
+
+ public void setBucketID(long bucketID) {
+ this.bucketID = bucketID;
+ }
+
+ public String getNameKey() {
+ return nameKey;
+ }
+
+ public void setNameKey(String nameKey) {
+ this.nameKey = nameKey;
+ }
+
+ public String getOwnerCanonicalId() {
+ return ownerCanonicalId;
+ }
+
+ public void setOwnerCanonicalId(String ownerCanonicalId) {
+ this.ownerCanonicalId = ownerCanonicalId;
+ }
+
+ public int getNextSequence() {
+ return nextSequence;
+ }
+
+ public void setNextSequence(int nextSequence) {
+ this.nextSequence = nextSequence;
+ }
+
+ public String getDeletionMark() {
+ return deletionMark;
+ }
+
+ public void setDeletionMark(String deletionMark) {
+ this.deletionMark = deletionMark;
+ }
+
+ public Date getCreateTime() {
+ return createTime;
+ }
+
+ public void setCreateTime(Date createTime) {
+ this.createTime = createTime;
+ }
+
+ public SBucket getBucket() {
+ return bucket;
+ }
+
+ public void setBucket(SBucket bucket) {
+ this.bucket = bucket;
+ }
+
+ public Set<SObjectItemVO> getItems() {
+ return items;
+ }
+
+ public void setItems(Set<SObjectItemVO> items) {
+ this.items = items;
+ }
+
+ public void deleteItem( long id ) {
+ Iterator<SObjectItemVO> it = getItems().iterator();
+
+ while( it.hasNext())
+ {
+ SObjectItemVO oneItem = it.next();
+ if (id == oneItem.getId()) {
+ boolean bRemoved = items.remove( oneItem );
+ System.out.println( "deleteItem from sobject: " + bRemoved );
+ return;
+ }
+ }
+ }
+
+ public SObjectItemVO getLatestVersion( boolean versioningOff ) {
+ Iterator<SObjectItemVO> it = getItems().iterator();
+ int maxVersion = 0;
+ int curVersion = 0;
+ SObjectItemVO latestItem = null;
+
+ while( it.hasNext())
+ {
+ SObjectItemVO item = it.next();
+
+ // If versioning is off then return the item with the null version string (if exists)
+ // For example, the bucket could have allowed versioning and then it was suspended
+ // If an application wants a specific version it will need to explicitly ask for it
+ try {
+ String version = item.getVersion();
+ if (versioningOff && null == version) {
+ return item;
+ }
+ curVersion = Integer.parseInt( version );
+
+ } catch (NumberFormatException e) {
+ curVersion = 0;
+ }
+
+ if(curVersion >= maxVersion) {
+ maxVersion = curVersion;
+ latestItem = item;
+ }
+ }
+ return latestItem;
+ }
+
+ /**
+ * S3 versioning allows the client to request the return of a specific version,
+ * not just the last version.
+ *
+ * @param wantVersion
+ * @return
+ */
+ public SObjectItemVO getVersion( String wantVersion )
+ {
+ Iterator<SObjectItemVO> it = getItems().iterator();
+ while( it.hasNext())
+ {
+ SObjectItemVO item = it.next();
+ String curVersion = item.getVersion();
+ if (null != curVersion && wantVersion.equalsIgnoreCase( curVersion )) return item;
+ }
+ return null;
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if(this == other)
+ return true;
+
+ if(!(other instanceof SObjectVO))
+ return false;
+
+ if(!getNameKey().equals(((SObjectVO)other).getNameKey()))
+ return false;
+
+ if(getBucket() != null) {
+ if(!getBucket().equals(((SObjectVO)other).getBucket()))
+ return false;
+ } else {
+ if(((SObjectVO)other).getBucket() != null)
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int hashCode = 0;
+ hashCode = hashCode*17 + getNameKey().hashCode();
+
+ if(getBucket() != null)
+ hashCode = hashCode*17 + getBucket().hashCode();
+ return hashCode;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/model/UserCredentials.hbm.xml
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/model/UserCredentials.hbm.xml b/awsapi/src/com/cloud/bridge/model/UserCredentials.hbm.xml
deleted file mode 100644
index d2f3919..0000000
--- a/awsapi/src/com/cloud/bridge/model/UserCredentials.hbm.xml
+++ /dev/null
@@ -1,38 +0,0 @@
-<?xml version="1.0"?>
-<!--
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied. See the License for the
-specific language governing permissions and limitations
-under the License.
--->
-<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
-
-<hibernate-mapping>
- <class name="com.cloud.bridge.model.UserCredentials" table="usercredentials" lazy="true">
- <id name="id" type="long" column="ID" >
- <generator class="native" />
- </id>
- <property name="accessKey">
- <column name="AccessKey" />
- </property>
- <property name="secretKey">
- <column name="SecretKey" />
- </property>
- <property name="certUniqueId">
- <column name="CertUniqueId" />
- </property>
- </class>
-</hibernate-mapping>
-
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/model/UserCredentials.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/model/UserCredentials.java b/awsapi/src/com/cloud/bridge/model/UserCredentials.java
deleted file mode 100644
index b674f40..0000000
--- a/awsapi/src/com/cloud/bridge/model/UserCredentials.java
+++ /dev/null
@@ -1,95 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.bridge.model;
-
-import java.io.Serializable;
-
-public class UserCredentials implements Serializable {
- private static final long serialVersionUID = 7459503272337054299L;
-
- private Long id;
- private String accessKey;
- private String secretKey;
- private String certUniqueId;
-
- public UserCredentials() {
- }
-
- public Long getId() {
- return id;
- }
-
- private void setId(Long id) {
- this.id = id;
- }
-
- public String getAccessKey() {
- return accessKey;
- }
-
- public void setAccessKey(String accessKey) {
- this.accessKey = accessKey;
- }
-
- public String getSecretKey() {
- return secretKey;
- }
-
- public void setSecretKey(String secretKey) {
- this.secretKey = secretKey;
- }
-
- public String getCertUniqueId() {
- return certUniqueId;
- }
-
- public void setCertUniqueId(String certUniqueId) {
- this.certUniqueId = certUniqueId;
- }
-
- @Override
- public boolean equals(Object other) {
- if (this == other) return true;
-
- if (!(other instanceof UserCredentials)) return false;
-
- // The cert id can be null. The cert is unused in the REST API.
- if ( getAccessKey().equals(((UserCredentials)other).getAccessKey()) &&
- getSecretKey().equals(((UserCredentials)other).getSecretKey()))
- {
- String thisCertId = getCertUniqueId();
- String otherCertId = ((UserCredentials)other).getCertUniqueId();
-
- if (null == thisCertId && null == otherCertId) return true;
-
- if (null != thisCertId && null != otherCertId) return thisCertId.equals( otherCertId );
- }
- return false;
- }
-
- @Override
- public int hashCode() {
- int hashCode = 0;
- String thisCertId = getCertUniqueId();
-
- // The cert id can be null. The cert is unused in the REST API.
- hashCode = hashCode*17 + getAccessKey().hashCode();
- hashCode = hashCode*17 + getSecretKey().hashCode();
- if (null != thisCertId) hashCode = hashCode*17 + thisCertId.hashCode();
- return hashCode;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/model/UserCredentialsVO.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/model/UserCredentialsVO.java b/awsapi/src/com/cloud/bridge/model/UserCredentialsVO.java
new file mode 100644
index 0000000..dae5fd9
--- /dev/null
+++ b/awsapi/src/com/cloud/bridge/model/UserCredentialsVO.java
@@ -0,0 +1,117 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.bridge.model;
+
+import java.io.Serializable;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name="usercredentials")
+public class UserCredentialsVO{
+ private static final long serialVersionUID = 7459503272337054299L;
+
+ @Id
+ @GeneratedValue(strategy=GenerationType.IDENTITY)
+ @Column(name="ID")
+ private Long id;
+
+ @Column(name="AccessKey")
+ private String accessKey;
+
+ @Column(name="SecretKey")
+ private String secretKey;
+
+ @Column(name="CertUniqueId")
+ private String certUniqueId;
+
+ public UserCredentialsVO() { }
+
+ public UserCredentialsVO(String accessKey, String secretKey) {
+ this.accessKey = accessKey;
+ this.secretKey = secretKey;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ private void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getAccessKey() {
+ return accessKey;
+ }
+
+ public void setAccessKey(String accessKey) {
+ this.accessKey = accessKey;
+ }
+
+ public String getSecretKey() {
+ return secretKey;
+ }
+
+ public void setSecretKey(String secretKey) {
+ this.secretKey = secretKey;
+ }
+
+ public String getCertUniqueId() {
+ return certUniqueId;
+ }
+
+ public void setCertUniqueId(String certUniqueId) {
+ this.certUniqueId = certUniqueId;
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (this == other) return true;
+
+ if (!(other instanceof UserCredentialsVO)) return false;
+
+ // The cert id can be null. The cert is unused in the REST API.
+ if ( getAccessKey().equals(((UserCredentialsVO)other).getAccessKey()) &&
+ getSecretKey().equals(((UserCredentialsVO)other).getSecretKey()))
+ {
+ String thisCertId = getCertUniqueId();
+ String otherCertId = ((UserCredentialsVO)other).getCertUniqueId();
+
+ if (null == thisCertId && null == otherCertId) return true;
+
+ if (null != thisCertId && null != otherCertId) return thisCertId.equals( otherCertId );
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ int hashCode = 0;
+ String thisCertId = getCertUniqueId();
+
+ // The cert id can be null. The cert is unused in the REST API.
+ hashCode = hashCode*17 + getAccessKey().hashCode();
+ hashCode = hashCode*17 + getSecretKey().hashCode();
+ if (null != thisCertId) hashCode = hashCode*17 + thisCertId.hashCode();
+ return hashCode;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/persist/EntityDao.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/persist/EntityDao.java b/awsapi/src/com/cloud/bridge/persist/EntityDao.java
deleted file mode 100644
index cc4a8c7..0000000
--- a/awsapi/src/com/cloud/bridge/persist/EntityDao.java
+++ /dev/null
@@ -1,118 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.bridge.persist;
-
-import java.io.Serializable;
-import java.util.List;
-
-import org.hibernate.Query;
-import org.hibernate.Session;
-
-import com.cloud.bridge.util.QueryHelper;
-
-/**
- * Provide methods for getting, saving, deleting or updating state per session or, in a given session, returnin a List in
- * response to queryEntities for a particular instantation of the EntityDao generic class, as defined here.
- * Any instantation of EntityDao passes in the class for which it is instantiating. For example a new instance of SBucketDao
- * passes in com.cloud.bridge.model.SBucket as its clazz.
- * Instantiators, providing an Entity definition, are the classes
- * MHostDao,
- * MHostMountDao,
- * SAclDao,
- * SBucketDao,
- * SHostDao,
- * SMetaDao,
- * SObjectDao,
- * SObjectItemDao,
- * CloudStackSvcOfferingDao
- */
-
-public class EntityDao<T> {
- private Class<?> clazz;
-
- private boolean isCloudStackSession = false;
-
- // Constructor to implement CloudStackSvcOffering: see class CloudStackSvcOfferingDao
- public EntityDao(Class<?> clazz){
- this(clazz, false);
- }
-
- public EntityDao(Class<?> clazz, boolean isCloudStackSession) {
- this.clazz = clazz;
- this.isCloudStackSession = isCloudStackSession;
- // Note : beginTransaction can be called multiple times
- // "If a new underlying transaction is required, begin the transaction. Otherwise continue the new work in the
- // context of the existing underlying transaction." from the Hibernate spec
- PersistContext.beginTransaction(isCloudStackSession);
- }
-
- @SuppressWarnings("unchecked")
- public T get(Serializable id) {
- Session session = PersistContext.getSession(isCloudStackSession);
- return (T)session.get(clazz, id);
- }
-
- public T save(T entity) {
- Session session = PersistContext.getSession(isCloudStackSession);
- session.saveOrUpdate(entity);
- return entity;
- }
-
- public T update(T entity) {
- Session session = PersistContext.getSession(isCloudStackSession);
- session.saveOrUpdate(entity);
- return entity;
- }
-
- public void delete(T entity) {
- Session session = PersistContext.getSession(isCloudStackSession);
- session.delete(entity);
- }
-
- public T queryEntity(String hql, Object[] params) {
- Session session = PersistContext.getSession(isCloudStackSession);
- Query query = session.createQuery(hql);
- query.setMaxResults(1);
- QueryHelper.bindParameters(query, params);
- return (T)query.uniqueResult();
- }
-
- public List<T> queryEntities(String hql, Object[] params) {
- Session session = PersistContext.getSession(isCloudStackSession);
- Query query = session.createQuery(hql);
- QueryHelper.bindParameters(query, params);
-
- return (List<T>)query.list();
- }
-
- public List<T> queryEntities(String hql, int offset, int limit, Object[] params) {
- Session session = PersistContext.getSession(isCloudStackSession);
- Query query = session.createQuery(hql);
- QueryHelper.bindParameters(query, params);
- query.setFirstResult(offset);
- query.setMaxResults(limit);
- return (List<T>)query.list();
- }
-
- public int executeUpdate(String hql, Object[] params) {
- Session session = PersistContext.getSession(isCloudStackSession);
- Query query = session.createQuery(hql);
- QueryHelper.bindParameters(query, params);
-
- return query.executeUpdate();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/persist/GMTDateTimeUserType.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/persist/GMTDateTimeUserType.java b/awsapi/src/com/cloud/bridge/persist/GMTDateTimeUserType.java
deleted file mode 100644
index cf16233..0000000
--- a/awsapi/src/com/cloud/bridge/persist/GMTDateTimeUserType.java
+++ /dev/null
@@ -1,102 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.bridge.persist;
-
-import java.io.Serializable;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Types;
-import java.util.Date;
-
-import org.hibernate.HibernateException;
-import org.hibernate.usertype.UserType;
-
-import com.cloud.bridge.util.DateHelper;
-
-/**
- * GMTDateTimeUserType implements a Hibernate user type, it deals with GMT date/time conversion
- * between Java Date/Calendar and MySQL DATE types
- */
-public class GMTDateTimeUserType implements UserType {
-
- private static final int[] SQL_TYPES = { Types.VARBINARY };
-
- public Class<?> returnedClass() { return Date.class; }
-
- public boolean equals(Object x, Object y) {
- if (x == y)
- return true;
-
- if (x == null || y == null)
- return false;
-
- return x.equals(y);
- }
-
- public int hashCode(Object x) {
- if(x != null)
- return x.hashCode();
-
- return 0;
- }
-
- public Object deepCopy(Object value) {
- if(value != null)
- return ((Date)value).clone();
- return null;
- }
-
- public boolean isMutable() {
- return true;
- }
-
- public Object nullSafeGet(ResultSet resultSet, String[] names, Object owner)
- throws HibernateException, SQLException {
-
- String dateString = resultSet.getString(names[0]);
- if(dateString != null)
- return DateHelper.parseDateString(DateHelper.GMT_TIMEZONE, dateString);
- return null;
- }
-
- public void nullSafeSet(PreparedStatement statement, Object value, int index)
- throws HibernateException, SQLException {
- if (value == null) {
- statement.setNull(index, Types.TIMESTAMP);
- } else {
- Date dt = (Date)value;
- statement.setString(index, DateHelper.getDateDisplayString(DateHelper.GMT_TIMEZONE, dt));
- }
- }
-
- public Object assemble(Serializable cached, Object owner) throws HibernateException {
- return DateHelper.parseDateString(DateHelper.GMT_TIMEZONE, (String)cached);
- }
-
- public Serializable disassemble(Object value) throws HibernateException {
- return DateHelper.getDateDisplayString(DateHelper.GMT_TIMEZONE, (Date)value);
- }
-
- public Object replace(Object original, Object target, Object owner) throws HibernateException {
- return ((Date)original).clone();
- }
-
- public int[] sqlTypes() {
- return SQL_TYPES;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/persist/PersistContext.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/persist/PersistContext.java b/awsapi/src/com/cloud/bridge/persist/PersistContext.java
deleted file mode 100644
index 8e5e0de..0000000
--- a/awsapi/src/com/cloud/bridge/persist/PersistContext.java
+++ /dev/null
@@ -1,359 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.bridge.persist;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.log4j.Logger;
-import org.hibernate.HibernateException;
-import org.hibernate.Session;
-import org.hibernate.Transaction;
-
-import com.cloud.bridge.util.CloudSessionFactory;
-import com.cloud.bridge.util.CloudStackSessionFactory;
-import com.cloud.bridge.util.OrderedPair;
-
-/**
- *
- * We use Per-thread based hibernate session and transaction pattern. Transaction will be
- * started implicitly by EntityDao instances and be committed implicitly in the end of
- * request-process cycle. All requests are guarded by a dynamic proxy.
- *
- * We will try to keep transaction management as implicit as we can, so that
- * most of service layer implementation contains business-logic only, all business logic are
- * built on top of domain object model, and all persistent layer handling lie within persist layer
- * in Dao classes.
- *
- * PersistContext class also provides per-thread based registry service and global named-lock service
- */
-public class PersistContext {
- protected final static Logger logger = Logger.getLogger(PersistContext.class);
-
- private static final CloudSessionFactory sessionFactory;
-
- private static final ThreadLocal<Session> threadSession = new ThreadLocal<Session>();
- private static final ThreadLocal<Transaction> threadTransaction = new ThreadLocal<Transaction>();
- private static final ThreadLocal<Map<String, Object>> threadStore = new ThreadLocal<Map<String, Object>>();
-
- private static final CloudStackSessionFactory cloudStackSessionFactory;
- private static final ThreadLocal<Session> threadCloudStackSession = new ThreadLocal<Session>();
- private static final ThreadLocal<Transaction> threadCloudStackTransaction = new ThreadLocal<Transaction>();
-
- static {
- try {
- sessionFactory = CloudSessionFactory.getInstance();
- cloudStackSessionFactory = CloudStackSessionFactory.getInstance();
- } catch(HibernateException e) {
- logger.error("Exception " + e.getMessage(), e);
- throw new PersistException(e);
- }
- }
-
- public static Session getSession(boolean cloudStackSession) {
- Session s = null;
- try {
- if(cloudStackSession){
- s = threadCloudStackSession.get();
- if(s == null) {
- s = cloudStackSessionFactory.openSession();
- threadCloudStackSession.set(s);
- }
- }else{
- s = threadSession.get();
- if(s == null) {
- s = sessionFactory.openSession();
- threadSession.set(s);
- }
- }
- } catch(HibernateException e) {
- logger.error("Exception " + e.getMessage(), e);
- throw new PersistException(e);
- }
- return s;
- }
-
- public static Session getSession() {
- return getSession(false);
- }
-
- public static void closeSession() {
- closeSession(false);
- }
-
- public static void closeSession(boolean cloudStackSession) {
- try {
- if(cloudStackSession){
- Session s = (Session) threadCloudStackSession.get();
- threadCloudStackSession.set(null);
- if (s != null && s.isOpen())
- s.close();
- }else{
- Session s = (Session) threadSession.get();
- threadSession.set(null);
-
- if (s != null && s.isOpen())
- s.close();
- }
- }catch(HibernateException e) {
- logger.error("Exception " + e.getMessage(), e);
- throw new PersistException(e);
- }
- }
-
- public static void beginTransaction(boolean cloudStackTxn) {
- Transaction tx = null;
- try {
- if(cloudStackTxn){
- tx = threadCloudStackTransaction.get();
- }else{
- tx = threadTransaction.get();
- }
-
- if (tx == null) {
- tx = getSession(cloudStackTxn).beginTransaction();
- if(cloudStackTxn){
- threadCloudStackTransaction.set(tx);
- }else{
- threadTransaction.set(tx);
- }
- }
- } catch(HibernateException e) {
- logger.error("Exception " + e.getMessage(), e);
- throw new PersistException(e);
- }
- }
-
- public static void beginTransaction() {
- beginTransaction(false);
- }
-
- public static void commitTransaction(boolean cloudStackTxn) {
- Transaction tx = null;
-
- if(cloudStackTxn){
- tx = threadCloudStackTransaction.get();
- }else{
- tx = threadTransaction.get();
- }
-
- try {
- if ( tx != null && !tx.wasCommitted() && !tx.wasRolledBack() ){
- tx.commit();
- }
- if(cloudStackTxn){
- threadCloudStackTransaction.set(null);
- }else{
- threadTransaction.set(null);
- }
- } catch (HibernateException e) {
- logger.error("Exception " + e.getMessage(), e);
-
- rollbackTransaction(cloudStackTxn);
- throw new PersistException(e);
- }
- }
-
- public static void commitTransaction() {
- commitTransaction(false);
- }
-
- public static void rollbackTransaction(boolean cloudStackTxn) {
- Transaction tx = null;
-
- if(cloudStackTxn){
- tx = (Transaction)threadCloudStackTransaction.get();
- threadCloudStackTransaction.set(null);
- }else{
- tx = (Transaction)threadTransaction.get();
- threadTransaction.set(null);
- }
- try {
- if ( tx != null && !tx.wasCommitted() && !tx.wasRolledBack() ) {
- tx.rollback();
- }
- } catch (HibernateException e) {
- logger.error("Exception " + e.getMessage(), e);
- throw new PersistException(e);
- } finally {
- closeSession(cloudStackTxn);
- }
- }
-
- public static void rollbackTransaction() {
- rollbackTransaction(false);
- }
-
- public static void flush() {
- commitTransaction();
- beginTransaction();
- }
-
- /**
- * acquireNamedLock/releaseNamedLock must be called in pairs and within the same thread
- * they can not be called recursively neither
- *
- * @param name
- * @param timeoutSeconds
- * @return
- */
- public static boolean acquireNamedLock(String name, int timeoutSeconds) {
- Connection jdbcConnection = getJDBCConnection(name, true);
- if(jdbcConnection == null) {
- logger.warn("Unable to acquire named lock connection for named lock: " + name);
- return false;
- }
-
- PreparedStatement pstmt = null;
- try {
- pstmt = jdbcConnection.prepareStatement("SELECT COALESCE(GET_LOCK(?, ?),0)");
-
- pstmt.setString(1, name);
- pstmt.setInt(2, timeoutSeconds);
-
- ResultSet rs = pstmt.executeQuery();
- if (rs != null && rs.first()) {
- if(rs.getInt(1) > 0) {
- return true;
- } else {
- logger.error("GET_LOCK() timed out on lock : " + name);
- }
- }
- } catch (SQLException e) {
- logger.error("GET_LOCK() throws exception ", e);
- } catch (Throwable e) {
- logger.error("GET_LOCK() throws exception ", e);
- } finally {
- if (pstmt != null) {
- try {
- pstmt.close();
- } catch (SQLException e) {
- logger.error("Unexpected exception " + e.getMessage(), e);
- }
- }
- }
-
- releaseJDBCConnection(name);
- return false;
- }
-
- public static boolean releaseNamedLock(String name) {
- Connection jdbcConnection = getJDBCConnection(name, false);
- if(jdbcConnection == null) {
- logger.error("Unable to acquire DB connection for global lock system");
- return false;
- }
-
- PreparedStatement pstmt = null;
- try {
- pstmt = jdbcConnection.prepareStatement("SELECT COALESCE(RELEASE_LOCK(?), 0)");
- pstmt.setString(1, name);
- ResultSet rs = pstmt.executeQuery();
- if(rs != null && rs.first())
- return rs.getInt(1) > 0;
- logger.error("RELEASE_LOCK() returns unexpected result : " + rs.getInt(1));
- } catch (SQLException e) {
- logger.error("RELEASE_LOCK() throws exception ", e);
- } catch (Throwable e) {
- logger.error("RELEASE_LOCK() throws exception ", e);
- } finally {
- releaseJDBCConnection(name);
- }
- return false;
- }
-
- @SuppressWarnings("deprecation")
- private static Connection getJDBCConnection(String name, boolean allocNew) {
- String registryKey = "JDBC-Connection." + name;
- OrderedPair<Session, Connection> info = (OrderedPair<Session, Connection>)getThreadStoreObject(registryKey);
- if(info == null && allocNew) {
- Session session = sessionFactory.openSession();
- Connection connection = session.connection();
- if(connection == null) {
- session.close();
- return null;
- }
-
- try {
- connection.setAutoCommit(true);
- } catch(SQLException e) {
- logger.warn("Unexpected exception " + e.getMessage(), e);
- try {
- connection.close();
- session.close();
- } catch(Throwable ex) {
- logger.warn("Unexpected exception " + e.getMessage(), e);
- }
- return null;
- }
-
- registerThreadStoreObject(registryKey, new OrderedPair<Session, Connection>(session, connection));
- return connection;
- }
-
- if(info != null)
- return info.getSecond();
-
- return null;
- }
-
- private static void releaseJDBCConnection(String name) {
- String registryKey = "JDBC-Connection." + name;
- OrderedPair<Session, Connection> info = (OrderedPair<Session, Connection>)unregisterThreadStoreObject(registryKey);
- if(info != null) {
- try {
- info.getSecond().close();
- info.getFirst().close();
- } catch(Throwable e) {
- logger.warn("Unexpected exception " + e.getMessage(), e);
- }
- }
- }
-
- public static void registerThreadStoreObject(String name, Object object) {
- Map<String, Object> store = getThreadStore();
- store.put(name, object);
- }
-
- public static Object getThreadStoreObject(String name) {
- Map<String, Object> store = getThreadStore();
- return store.get(name);
- }
-
- public static Object unregisterThreadStoreObject(String name) {
- Map<String, Object> store = getThreadStore();
- if(store.containsKey(name)) {
- Object value = store.get(name);
- store.remove(name);
- return value;
- }
- return null;
- }
-
- private static Map<String, Object> getThreadStore() {
- Map<String, Object> store = threadStore.get();
- if(store == null) {
- store = new HashMap<String, Object>();
- threadStore.set(store);
- }
- return store;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/persist/PersistException.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/persist/PersistException.java b/awsapi/src/com/cloud/bridge/persist/PersistException.java
deleted file mode 100644
index 920cf40..0000000
--- a/awsapi/src/com/cloud/bridge/persist/PersistException.java
+++ /dev/null
@@ -1,36 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.bridge.persist;
-
-public class PersistException extends RuntimeException {
- private static final long serialVersionUID = -7137918292537610367L;
-
- public PersistException() {
- }
-
- public PersistException(String message) {
- super(message);
- }
-
- public PersistException(Throwable e) {
- super(e);
- }
-
- public PersistException(String message, Throwable e) {
- super(message, e);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/persist/dao/BucketPolicyDao.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/persist/dao/BucketPolicyDao.java b/awsapi/src/com/cloud/bridge/persist/dao/BucketPolicyDao.java
index dda0e2d..f23db43 100644
--- a/awsapi/src/com/cloud/bridge/persist/dao/BucketPolicyDao.java
+++ b/awsapi/src/com/cloud/bridge/persist/dao/BucketPolicyDao.java
@@ -1,159 +1,12 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
package com.cloud.bridge.persist.dao;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.Properties;
+import com.cloud.bridge.model.BucketPolicyVO;
+import com.cloud.utils.db.GenericDao;
-import org.apache.log4j.Logger;
+public interface BucketPolicyDao extends GenericDao<BucketPolicyVO, Long> {
-import com.cloud.bridge.util.ConfigurationHelper;
+ void deletePolicy(String bucketName);
-public class BucketPolicyDao {
- public static final Logger logger = Logger.getLogger(BucketPolicyDao.class);
+ BucketPolicyVO getByName(String bucketName);
- private Connection conn = null;
- private String dbName = null;
- private String dbUser = null;
- private String dbPassword = null;
- private String dbHost = null;
- private String dbPort = null;
-
- public BucketPolicyDao()
- {
- File propertiesFile = ConfigurationHelper.findConfigurationFile("db.properties");
- Properties EC2Prop = null;
-
- if (null != propertiesFile) {
- EC2Prop = new Properties();
- try {
- EC2Prop.load( new FileInputStream( propertiesFile ));
- } catch (FileNotFoundException e) {
- logger.warn("Unable to open properties file: " + propertiesFile.getAbsolutePath(), e);
- } catch (IOException e) {
- logger.warn("Unable to read properties file: " + propertiesFile.getAbsolutePath(), e);
- }
- dbHost = EC2Prop.getProperty( "db.cloud.host" );
- dbName = EC2Prop.getProperty( "db.awsapi.name" );
- dbUser = EC2Prop.getProperty( "db.cloud.username" );
- dbPassword = EC2Prop.getProperty( "db.cloud.password" );
- dbPort = EC2Prop.getProperty( "db.cloud.port" );
- }
- }
-
- public void addPolicy( String bucketName, String owner, String policy )
- throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
- {
- PreparedStatement statement = null;
-
- openConnection();
- try {
- statement = conn.prepareStatement ( "INSERT INTO bucket_policies (BucketName, OwnerCanonicalID, Policy) VALUES (?,?,?)" );
- statement.setString( 1, bucketName );
- statement.setString( 2, owner );
- statement.setString( 3, policy );
- int count = statement.executeUpdate();
- statement.close();
-
- } finally {
- closeConnection();
- }
- }
-
- /**
- * Since a bucket policy can exist before its bucket we also need to keep the policy's owner
- * so we can restrict who modifies it (because of the "s3:CreateBucket" action).
- */
- public String getPolicyOwner( String bucketName )
- throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
- {
- PreparedStatement statement = null;
- String owner = null;
-
- openConnection();
- try {
- statement = conn.prepareStatement ( "SELECT OwnerCanonicalID FROM bucket_policies WHERE BucketName=?" );
- statement.setString( 1, bucketName );
- ResultSet rs = statement.executeQuery();
- if (rs.next()) owner = rs.getString( "OwnerCanonicalID" );
- statement.close();
- return owner;
-
- } finally {
- closeConnection();
- }
- }
-
- public String getPolicy( String bucketName )
- throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
- {
- PreparedStatement statement = null;
- String policy = null;
-
- openConnection();
- try {
- statement = conn.prepareStatement ( "SELECT Policy FROM bucket_policies WHERE BucketName=?" );
- statement.setString( 1, bucketName );
- ResultSet rs = statement.executeQuery();
- if (rs.next()) policy = rs.getString( "Policy" );
- statement.close();
- return policy;
-
- } finally {
- closeConnection();
- }
- }
-
- public void deletePolicy( String bucketName )
- throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
- {
- PreparedStatement statement = null;
-
- openConnection();
- try {
- statement = conn.prepareStatement ( "DELETE FROM bucket_policies WHERE BucketName=?" );
- statement.setString( 1, bucketName );
- int count = statement.executeUpdate();
- statement.close();
-
- } finally {
- closeConnection();
- }
- }
-
- private void openConnection()
- throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
- {
- if (null == conn) {
- Class.forName( "com.mysql.jdbc.Driver" ).newInstance();
- conn = DriverManager.getConnection( "jdbc:mysql://" + dbHost + ":" + dbPort + "/" + dbName, dbUser, dbPassword );
- }
- }
-
- private void closeConnection() throws SQLException {
- if (null != conn) conn.close();
- conn = null;
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/persist/dao/BucketPolicyDaoImpl.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/persist/dao/BucketPolicyDaoImpl.java b/awsapi/src/com/cloud/bridge/persist/dao/BucketPolicyDaoImpl.java
new file mode 100644
index 0000000..41bf311
--- /dev/null
+++ b/awsapi/src/com/cloud/bridge/persist/dao/BucketPolicyDaoImpl.java
@@ -0,0 +1,72 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.bridge.persist.dao;
+
+
+import javax.ejb.Local;
+
+import org.apache.log4j.Logger;
+import com.cloud.bridge.model.BucketPolicyVO;
+import com.cloud.utils.component.ComponentLocator;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.Transaction;
+
+@Local(value={BucketPolicyDao.class})
+public class BucketPolicyDaoImpl extends GenericDaoBase<BucketPolicyVO, Long> implements BucketPolicyDao{
+ public static final Logger logger = Logger.getLogger(BucketPolicyDaoImpl.class);
+ public BucketPolicyDaoImpl(){ }
+
+ /**
+ * Since a bucket policy can exist before its bucket we also need to keep the policy's owner
+ * so we can restrict who modifies it (because of the "s3:CreateBucket" action).
+ */
+ @Override
+ public BucketPolicyVO getByName( String bucketName ) {
+ SearchBuilder <BucketPolicyVO> searchByBucket = createSearchBuilder();
+ searchByBucket.and("BucketName", searchByBucket.entity().getBucketName(), SearchCriteria.Op.EQ);
+ Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
+ try {
+ txn.start();
+ SearchCriteria<BucketPolicyVO> sc = searchByBucket.create();
+ sc.setParameters("BucketName", bucketName);
+ return findOneBy(sc);
+
+ }finally {
+ txn.close();
+ }
+
+ }
+
+ @Override
+ public void deletePolicy( String bucketName ) {
+ SearchBuilder <BucketPolicyVO> deleteByBucket = createSearchBuilder();
+ deleteByBucket.and("BucketName", deleteByBucket.entity().getBucketName(), SearchCriteria.Op.EQ);
+ Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
+ try {
+ txn.start();
+ SearchCriteria<BucketPolicyVO> sc = deleteByBucket.create();
+ sc.setParameters("BucketName", bucketName);
+ remove(sc);
+
+ }finally {
+ txn.close();
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/persist/dao/CloudStackAccountDao.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/persist/dao/CloudStackAccountDao.java b/awsapi/src/com/cloud/bridge/persist/dao/CloudStackAccountDao.java
index 31a5be8..bf8c97a 100644
--- a/awsapi/src/com/cloud/bridge/persist/dao/CloudStackAccountDao.java
+++ b/awsapi/src/com/cloud/bridge/persist/dao/CloudStackAccountDao.java
@@ -1,35 +1,11 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
package com.cloud.bridge.persist.dao;
-import org.apache.log4j.Logger;
+import com.cloud.bridge.model.CloudStackAccountVO;
+import com.cloud.utils.db.GenericDao;
-import com.cloud.bridge.persist.EntityDao;
-import com.cloud.stack.models.CloudStackAccount;
+public interface CloudStackAccountDao extends
+ GenericDao<CloudStackAccountVO, String> {
+ String getDefaultZoneId(String accountId);
+
-public class CloudStackAccountDao extends EntityDao<CloudStackAccount> {
- public static final Logger logger = Logger.getLogger(CloudStackAccountDao.class);
-
- public CloudStackAccountDao() {
- super(CloudStackAccount.class, true);
- }
-
- public CloudStackAccount getdefaultZoneId( String id ) {
- return queryEntity("from CloudStackAccount where id=?", new Object[] {id});
- }
}
-
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/persist/dao/CloudStackAccountDaoImpl.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/persist/dao/CloudStackAccountDaoImpl.java b/awsapi/src/com/cloud/bridge/persist/dao/CloudStackAccountDaoImpl.java
new file mode 100644
index 0000000..be3cd77
--- /dev/null
+++ b/awsapi/src/com/cloud/bridge/persist/dao/CloudStackAccountDaoImpl.java
@@ -0,0 +1,39 @@
+package com.cloud.bridge.persist.dao;
+
+import javax.ejb.Local;
+
+import com.cloud.bridge.model.CloudStackAccountVO;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.Transaction;
+
+@Local(value={CloudStackAccountDao.class})
+public class CloudStackAccountDaoImpl extends GenericDaoBase<CloudStackAccountVO, String> implements CloudStackAccountDao {
+
+ @Override
+ public String getDefaultZoneId(String accountId) {
+
+ SearchBuilder<CloudStackAccountVO> SearchByUUID = createSearchBuilder();
+ Transaction txn = Transaction.open(Transaction.CLOUD_DB);
+ try {
+ txn.start();
+ SearchByUUID.and("uuid", SearchByUUID.entity().getUuid(),
+ SearchCriteria.Op.EQ);
+ SearchByUUID.done();
+ SearchCriteria<CloudStackAccountVO> sc = SearchByUUID.create();
+ sc.setParameters("uuid", accountId);
+ CloudStackAccountVO account = findOneBy(sc);
+ if (null != account)
+ if(null != account.getDefaultZoneId())
+ return Long.toString(account.getDefaultZoneId());
+ return null;
+ } finally {
+ txn.commit();
+ txn.close();
+ }
+
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/persist/dao/CloudStackConfigurationDao.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/persist/dao/CloudStackConfigurationDao.java b/awsapi/src/com/cloud/bridge/persist/dao/CloudStackConfigurationDao.java
index ed16974..8c2c185 100644
--- a/awsapi/src/com/cloud/bridge/persist/dao/CloudStackConfigurationDao.java
+++ b/awsapi/src/com/cloud/bridge/persist/dao/CloudStackConfigurationDao.java
@@ -1,42 +1,9 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
package com.cloud.bridge.persist.dao;
-import org.apache.log4j.Logger;
-
-import com.cloud.bridge.persist.EntityDao;
-import com.cloud.stack.models.CloudStackConfiguration;
-
-
-public class CloudStackConfigurationDao extends EntityDao<CloudStackConfiguration> {
- public static final Logger logger = Logger.getLogger(CloudStackConfigurationDao.class);
-
- public CloudStackConfigurationDao() {
- super(CloudStackConfiguration.class, true);
- }
-
-
- public String getConfigValue( String configName ){
- CloudStackConfiguration config = queryEntity("from CloudStackConfiguration where name=?", new Object[] {configName});
- if(config != null){
- return config.getValue();
- }
- return null;
- }
+import com.cloud.bridge.model.CloudStackConfigurationVO;
+import com.cloud.utils.db.GenericDao;
+public interface CloudStackConfigurationDao extends GenericDao<CloudStackConfigurationVO, String> {
+ public String getConfigValue(String name);
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/persist/dao/CloudStackConfigurationDaoImpl.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/persist/dao/CloudStackConfigurationDaoImpl.java b/awsapi/src/com/cloud/bridge/persist/dao/CloudStackConfigurationDaoImpl.java
new file mode 100644
index 0000000..1e7a70f
--- /dev/null
+++ b/awsapi/src/com/cloud/bridge/persist/dao/CloudStackConfigurationDaoImpl.java
@@ -0,0 +1,45 @@
+package com.cloud.bridge.persist.dao;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import javax.ejb.Local;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.bridge.model.CloudStackConfigurationVO;
+import com.cloud.utils.component.ComponentLocator;
+import com.cloud.utils.db.DB;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.Transaction;
+
+
+@Local(value={CloudStackConfigurationDao.class})
+public class CloudStackConfigurationDaoImpl extends GenericDaoBase<CloudStackConfigurationVO, String> implements CloudStackConfigurationDao {
+ private static final Logger s_logger = Logger.getLogger(CloudStackConfigurationDaoImpl.class);
+
+ final SearchBuilder<CloudStackConfigurationVO> NameSearch= createSearchBuilder();
+
+ public CloudStackConfigurationDaoImpl() { }
+
+
+ @Override
+ @DB
+ public String getConfigValue(String name) {
+ NameSearch.and("name", NameSearch.entity().getName(), SearchCriteria.Op.EQ);
+ Transaction txn = Transaction.currentTxn();
+ try {
+ txn.start();
+ SearchCriteria<CloudStackConfigurationVO> sc = NameSearch.create();
+ sc.setParameters("name", name);
+ return findOneBy(sc).getValue();
+ }finally {
+
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/persist/dao/CloudStackSvcOfferingDao.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/persist/dao/CloudStackSvcOfferingDao.java b/awsapi/src/com/cloud/bridge/persist/dao/CloudStackSvcOfferingDao.java
index 5013eac..4b0c9e1 100644
--- a/awsapi/src/com/cloud/bridge/persist/dao/CloudStackSvcOfferingDao.java
+++ b/awsapi/src/com/cloud/bridge/persist/dao/CloudStackSvcOfferingDao.java
@@ -1,42 +1,13 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
package com.cloud.bridge.persist.dao;
-import org.apache.log4j.Logger;
+import com.cloud.bridge.model.CloudStackServiceOfferingVO;
+import com.cloud.utils.db.GenericDao;
-import com.cloud.bridge.persist.EntityDao;
-import com.cloud.stack.models.CloudStackConfiguration;
-import com.cloud.stack.models.CloudStackServiceOffering;
+public interface CloudStackSvcOfferingDao extends GenericDao<CloudStackServiceOfferingVO, String>{
+ public CloudStackServiceOfferingVO getSvcOfferingByName(String name);
-public class CloudStackSvcOfferingDao extends EntityDao<CloudStackServiceOffering> {
- public static final Logger logger = Logger.getLogger(CloudStackSvcOfferingDao.class);
+ public CloudStackServiceOfferingVO getSvcOfferingById(String id);
- public CloudStackSvcOfferingDao() {
- super(CloudStackServiceOffering.class, true);
- }
-
-
- public CloudStackServiceOffering getSvcOfferingByName( String name ){
- return queryEntity("from CloudStackServiceOffering where name=?", new Object[] {name});
- }
-
- public CloudStackServiceOffering getSvcOfferingById( String id ){
- return queryEntity("from CloudStackServiceOffering where id=?", new Object[] {id});
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/persist/dao/CloudStackSvcOfferingDaoImpl.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/persist/dao/CloudStackSvcOfferingDaoImpl.java b/awsapi/src/com/cloud/bridge/persist/dao/CloudStackSvcOfferingDaoImpl.java
new file mode 100644
index 0000000..dca3891
--- /dev/null
+++ b/awsapi/src/com/cloud/bridge/persist/dao/CloudStackSvcOfferingDaoImpl.java
@@ -0,0 +1,75 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.bridge.persist.dao;
+
+import javax.ejb.Local;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.bridge.model.CloudStackServiceOfferingVO;
+import com.cloud.bridge.model.SHostVO;
+import com.cloud.stack.models.CloudStackConfiguration;
+import com.cloud.stack.models.CloudStackServiceOffering;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.Transaction;
+
+@Local(value={CloudStackSvcOfferingDao.class})
+public class CloudStackSvcOfferingDaoImpl extends GenericDaoBase<CloudStackServiceOfferingVO, String> implements CloudStackSvcOfferingDao {
+ public static final Logger logger = Logger.getLogger(CloudStackSvcOfferingDaoImpl.class);
+
+ public CloudStackSvcOfferingDaoImpl() { }
+
+ @Override
+ public CloudStackServiceOfferingVO getSvcOfferingByName( String name ){
+ SearchBuilder <CloudStackServiceOfferingVO> searchByName = createSearchBuilder();
+ searchByName.and("name", searchByName.entity().getName(), SearchCriteria.Op.EQ);
+ searchByName.done();
+ Transaction txn = Transaction.open(Transaction.CLOUD_DB);
+ try {
+ txn.start();
+ SearchCriteria<CloudStackServiceOfferingVO> sc = searchByName.create();
+ sc.setParameters("name", name);
+ return findOneBy(sc);
+
+ }finally {
+ txn.close();
+ }
+
+
+ }
+ @Override
+ public CloudStackServiceOfferingVO getSvcOfferingById( String id ){
+ SearchBuilder <CloudStackServiceOfferingVO> searchByID = createSearchBuilder();
+ searchByID.and("id", searchByID.entity().getName(), SearchCriteria.Op.EQ);
+ searchByID.done();
+ Transaction txn = Transaction.open(Transaction.CLOUD_DB);
+ try {
+ txn.start();
+ SearchCriteria<CloudStackServiceOfferingVO> sc = searchByID.create();
+ sc.setParameters("id", id);
+ return findOneBy(sc);
+
+ }finally {
+ txn.close();
+ }
+
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/persist/dao/MHostDao.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/persist/dao/MHostDao.java b/awsapi/src/com/cloud/bridge/persist/dao/MHostDao.java
index 7250131..a4b65d7 100644
--- a/awsapi/src/com/cloud/bridge/persist/dao/MHostDao.java
+++ b/awsapi/src/com/cloud/bridge/persist/dao/MHostDao.java
@@ -1,30 +1,12 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
package com.cloud.bridge.persist.dao;
-import com.cloud.bridge.model.MHost;
-import com.cloud.bridge.persist.EntityDao;
+import com.cloud.bridge.model.MHostVO;
+import com.cloud.utils.db.GenericDao;
+
+public interface MHostDao extends GenericDao<MHostVO, Long> {
+
+ MHostVO getByHostKey(String hostKey);
+
+ public void updateHeartBeat(MHostVO mhost);
-public class MHostDao extends EntityDao<MHost> {
- public MHostDao() {
- super(MHost.class);
- }
-
- public MHost getByHostKey(String hostKey) {
- return queryEntity("from MHost where hostKey=?", new Object[] {hostKey});
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39aa7d86/awsapi/src/com/cloud/bridge/persist/dao/MHostDaoImpl.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/persist/dao/MHostDaoImpl.java b/awsapi/src/com/cloud/bridge/persist/dao/MHostDaoImpl.java
new file mode 100644
index 0000000..aff6f81
--- /dev/null
+++ b/awsapi/src/com/cloud/bridge/persist/dao/MHostDaoImpl.java
@@ -0,0 +1,61 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.bridge.persist.dao;
+import javax.ejb.Local;
+
+import com.cloud.bridge.model.MHostVO;
+import com.cloud.utils.db.DB;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.Transaction;
+
+@Local(value={MHostDao.class})
+public class MHostDaoImpl extends GenericDaoBase<MHostVO, Long> implements MHostDao{
+ final SearchBuilder<MHostVO> NameSearch= createSearchBuilder();
+
+ public MHostDaoImpl() {
+ }
+
+ @DB
+ @Override
+ public MHostVO getByHostKey(String hostKey) {
+ NameSearch.and("MHostKey", NameSearch.entity().getHostKey(), SearchCriteria.Op.EQ);
+ Transaction txn = Transaction.open("cloudbridge", Transaction.AWSAPI_DB, true);
+ try {
+ txn.start();
+ SearchCriteria<MHostVO> sc = NameSearch.create();
+ sc.setParameters("MHostKey", hostKey);
+ return findOneBy(sc);
+
+ }finally {
+ txn.close();
+ }
+ }
+
+ @Override
+ public void updateHeartBeat(MHostVO mhost) {
+ Transaction txn = Transaction.open("cloudbridge", Transaction.AWSAPI_DB, true);
+ try {
+ txn.start();
+ update(mhost.getId(), mhost);
+ txn.commit();
+ }finally {
+ txn.close();
+ }
+ }
+}
\ No newline at end of file